diff options
Diffstat (limited to 'src/devices/adsl')
| -rw-r--r-- | src/devices/adsl/nm-atm-manager.c | 83 | ||||
| -rw-r--r-- | src/devices/adsl/nm-device-adsl.c | 73 |
2 files changed, 77 insertions, 79 deletions
diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c index b04e9fe7..32c4c386 100644 --- a/src/devices/adsl/nm-atm-manager.c +++ b/src/devices/adsl/nm-atm-manager.c @@ -21,13 +21,14 @@ #include "nm-default.h" #include <string.h> -#include <gudev/gudev.h> #include <gmodule.h> +#include <libudev.h> #include "nm-setting-adsl.h" #include "nm-device-adsl.h" #include "devices/nm-device-factory.h" #include "platform/nm-platform.h" +#include "nm-utils/nm-udev-utils.h" /*****************************************************************************/ @@ -39,7 +40,7 @@ #define NM_ATM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ATM_MANAGER, NMAtmManagerClass)) typedef struct { - GUdevClient *client; + NMUdevClient *udev_client; GSList *devices; } NMAtmManagerPrivate; @@ -73,35 +74,34 @@ nm_device_factory_create (GError **error) /*****************************************************************************/ static gboolean -dev_get_attrs (GUdevDevice *udev_device, +dev_get_attrs (struct udev_device *udev_device, const char **out_path, char **out_driver) { - GUdevDevice *parent = NULL; + struct udev_device *parent = NULL; const char *driver, *path; g_return_val_if_fail (udev_device != NULL, FALSE); g_return_val_if_fail (out_path != NULL, FALSE); g_return_val_if_fail (out_driver != NULL, FALSE); - path = g_udev_device_get_sysfs_path (udev_device); + path = udev_device_get_syspath (udev_device); if (!path) { nm_log_warn (LOGD_PLATFORM, "couldn't determine device path; ignoring..."); return FALSE; } - driver = g_udev_device_get_driver (udev_device); + driver = udev_device_get_driver (udev_device); if (!driver) { /* Try the parent */ - parent = g_udev_device_get_parent (udev_device); + parent = udev_device_get_parent (udev_device); if (parent) - driver = g_udev_device_get_driver (parent); + driver = udev_device_get_driver (parent); } *out_path = path; *out_driver = g_strdup (driver); - g_clear_object (&parent); return TRUE; } @@ -115,7 +115,7 @@ device_destroyed (gpointer user_data, GObject *dead) } static void -adsl_add (NMAtmManager *self, GUdevDevice *udev_device) +adsl_add (NMAtmManager *self, struct udev_device *udev_device) { NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); const char *ifname, *sysfs_path = NULL; @@ -126,7 +126,7 @@ adsl_add (NMAtmManager *self, GUdevDevice *udev_device) g_return_if_fail (udev_device != NULL); - ifname = g_udev_device_get_name (udev_device); + ifname = udev_device_get_sysname (udev_device); if (!ifname) { nm_log_warn (LOGD_PLATFORM, "failed to get device's interface name"); return; @@ -165,10 +165,10 @@ adsl_add (NMAtmManager *self, GUdevDevice *udev_device) } static void -adsl_remove (NMAtmManager *self, GUdevDevice *udev_device) +adsl_remove (NMAtmManager *self, struct udev_device *udev_device) { NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); - const char *iface = g_udev_device_get_name (udev_device); + const char *iface = udev_device_get_sysname (udev_device); GSList *iter; nm_log_dbg (LOGD_PLATFORM, "(%s): removing ATM device", iface); @@ -194,42 +194,49 @@ start (NMDeviceFactory *factory) { NMAtmManager *self = NM_ATM_MANAGER (factory); NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); - GUdevEnumerator *enumerator; - GList *devices, *iter; - - enumerator = g_udev_enumerator_new (priv->client); - g_udev_enumerator_add_match_subsystem (enumerator, "atm"); - g_udev_enumerator_add_match_is_initialized (enumerator); - devices = g_udev_enumerator_execute (enumerator); - for (iter = devices; iter; iter = g_list_next (iter)) { - adsl_add (self, G_UDEV_DEVICE (iter->data)); - g_object_unref (G_UDEV_DEVICE (iter->data)); + struct udev_enumerate *enumerate; + struct udev_list_entry *devices; + + enumerate = nm_udev_client_enumerate_new (priv->udev_client); + udev_enumerate_add_match_is_initialized (enumerate); + udev_enumerate_scan_devices (enumerate); + devices = udev_enumerate_get_list_entry (enumerate); + for (; devices; devices = udev_list_entry_get_next (devices)) { + struct udev_device *udevice; + + udevice = udev_device_new_from_syspath (udev_enumerate_get_udev (enumerate), + udev_list_entry_get_name (devices)); + if (udevice) { + adsl_add (self, udevice); + udev_device_unref (udevice); + } } - g_list_free (devices); - g_object_unref (enumerator); + udev_enumerate_unref (enumerate); } static void -handle_uevent (GUdevClient *client, - const char *action, - GUdevDevice *device, +handle_uevent (NMUdevClient *client, + struct udev_device *device, gpointer user_data) { NMAtmManager *self = NM_ATM_MANAGER (user_data); const char *subsys; const char *ifindex; guint64 seqnum; + const char *action; + + action = udev_device_get_action (device); g_return_if_fail (action != NULL); /* A bit paranoid */ - subsys = g_udev_device_get_subsystem (device); + subsys = udev_device_get_subsystem (device); g_return_if_fail (!g_strcmp0 (subsys, "atm")); - ifindex = g_udev_device_get_property (device, "IFINDEX"); - seqnum = g_udev_device_get_seqnum (device); + ifindex = udev_device_get_property_value (device, "IFINDEX"); + seqnum = udev_device_get_seqnum (device); nm_log_dbg (LOGD_PLATFORM, "UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, - action, subsys, g_udev_device_get_name (device), ifindex ? ifindex : "unknown", seqnum); + action, subsys, udev_device_get_sysname (device), ifindex ? ifindex : "unknown", seqnum); if (!strcmp (action, "add")) adsl_add (self, device); @@ -243,10 +250,9 @@ static void nm_atm_manager_init (NMAtmManager *self) { NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); - const char *subsys[] = { "atm", NULL }; - priv->client = g_udev_client_new (subsys); - g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); + priv->udev_client = nm_udev_client_new ((const char *[]) {"atm", NULL }, + handle_uevent, self); } static void @@ -256,15 +262,12 @@ dispose (GObject *object) NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); GSList *iter; - if (priv->client) { - g_signal_handlers_disconnect_by_func (priv->client, handle_uevent, self); - g_clear_object (&priv->client); - } - for (iter = priv->devices; iter; iter = iter->next) g_object_weak_unref (G_OBJECT (iter->data), device_destroyed, self); g_clear_pointer (&priv->devices, g_slist_free); + priv->udev_client = nm_udev_client_unref (priv->udev_client); + G_OBJECT_CLASS (nm_atm_manager_parent_class)->dispose (object); } diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 53841a7f..fe622bdf 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -129,7 +129,7 @@ complete_connection (NMDevice *device, if (s_adsl && !nm_setting_verify (NM_SETTING (s_adsl), NULL, error)) return FALSE; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_ADSL_SETTING_NAME, existing_connections, @@ -273,14 +273,14 @@ pppoe_vcc_config (NMDeviceAdsl *self) return FALSE; /* Watch for the 'nas' interface going away */ - g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, + g_signal_connect (nm_device_get_platform (device), NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), self); _LOGD (LOGD_ADSL, "ATM setup successful"); /* otherwise we're good for stage3 */ - nm_platform_link_set_up (NM_PLATFORM_GET, priv->nas_ifindex, NULL); + nm_platform_link_set_up (nm_device_get_platform (device), priv->nas_ifindex, NULL); return TRUE; } @@ -306,7 +306,7 @@ nas_update_cb (gpointer user_data) } g_warn_if_fail (priv->nas_ifindex < 0); - priv->nas_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->nas_ifname); + priv->nas_ifindex = nm_platform_link_get_ifindex (nm_device_get_platform (device), priv->nas_ifname); if (priv->nas_ifindex < 0) { /* Keep waiting for it to appear */ return G_SOURCE_CONTINUE; @@ -329,12 +329,12 @@ nas_update_cb (gpointer user_data) static NMActStageReturn br2684_create_iface (NMDeviceAdsl *self, NMSettingAdsl *s_adsl, - NMDeviceStateReason *out_reason) + NMDeviceStateReason *out_failure_reason) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); struct atm_newif_br2684 ni; - int err, fd, errsv; - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; + nm_auto_close int fd = -1; + int err, errsv; guint num = 0; g_return_val_if_fail (s_adsl != NULL, FALSE); @@ -348,7 +348,7 @@ br2684_create_iface (NMDeviceAdsl *self, if (fd < 0) { errsv = errno; _LOGE (LOGD_ADSL, "failed to open ATM control socket (%d)", errsv); - *out_reason = NM_DEVICE_STATE_REASON_BR2684_FAILED; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_BR2684_FAILED); return NM_ACT_STAGE_RETURN_FAILURE; } @@ -374,39 +374,36 @@ br2684_create_iface (NMDeviceAdsl *self, priv->nas_update_count = 0; priv->nas_update_id = g_timeout_add (100, nas_update_cb, self); - ret = NM_ACT_STAGE_RETURN_POSTPONE; - break; - } else if (errno != EEXIST) { + return NM_ACT_STAGE_RETURN_POSTPONE; + } + if (errno != EEXIST) { errsv = errno; _LOGW (LOGD_ADSL, "failed to create br2684 interface (%d)", errsv); - *out_reason = NM_DEVICE_STATE_REASON_BR2684_FAILED; break; } } - close (fd); - return ret; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_BR2684_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; } static NMActStageReturn -act_stage2_config (NMDevice *device, NMDeviceStateReason *out_reason) +act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMSettingAdsl *s_adsl; const char *protocol; - g_assert (out_reason); - s_adsl = nm_connection_get_setting_adsl (nm_device_get_applied_connection (device)); - g_assert (s_adsl); + g_return_val_if_fail (s_adsl, NM_ACT_STAGE_RETURN_FAILURE); protocol = nm_setting_adsl_get_protocol (s_adsl); _LOGD (LOGD_ADSL, "using ADSL protocol '%s'", protocol); if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE) == 0) { /* PPPoE needs RFC2684 bridging before we can do PPP over it */ - ret = br2684_create_iface (self, s_adsl, out_reason); + ret = br2684_create_iface (self, s_adsl, out_failure_reason); } else if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA) == 0) { /* PPPoA doesn't need anything special */ ret = NM_ACT_STAGE_RETURN_SUCCESS; @@ -451,20 +448,19 @@ ppp_ip4_config (NMPPPManager *ppp_manager, static NMActStageReturn act_stage3_ip4_config_start (NMDevice *device, NMIP4Config **out_config, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); NMSettingAdsl *s_adsl; NMActRequest *req; GError *err = NULL; - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; const char *ppp_iface; req = nm_device_get_act_request (device); - g_assert (req); + g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE); s_adsl = (NMSettingAdsl *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_ADSL); - g_assert (s_adsl); + g_return_val_if_fail (s_adsl, NM_ACT_STAGE_RETURN_FAILURE); /* PPPoE uses the NAS interface, not the ATM interface */ if (g_strcmp0 (nm_setting_adsl_get_protocol (s_adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE) == 0) { @@ -478,27 +474,26 @@ act_stage3_ip4_config_start (NMDevice *device, } priv->ppp_manager = nm_ppp_manager_create (ppp_iface, &err); - if ( priv->ppp_manager - && nm_ppp_manager_start (priv->ppp_manager, req, - nm_setting_adsl_get_username (s_adsl), - 30, 0, &err)) { - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, - G_CALLBACK (ppp_state_changed), - self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK (ppp_ip4_config), - self); - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else { + if ( !priv->ppp_manager + || !nm_ppp_manager_start (priv->ppp_manager, req, + nm_setting_adsl_get_username (s_adsl), + 30, 0, &err)) { _LOGW (LOGD_ADSL, "PPP failed to start: %s", err->message); g_error_free (err); g_clear_object (&priv->ppp_manager); - *reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; } - return ret; + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, + G_CALLBACK (ppp_state_changed), + self); + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, + G_CALLBACK (ppp_ip4_config), + self); + return NM_ACT_STAGE_RETURN_POSTPONE; } static void @@ -513,7 +508,7 @@ adsl_cleanup (NMDeviceAdsl *self) g_clear_object (&priv->ppp_manager); } - g_signal_handlers_disconnect_by_func (NM_PLATFORM_GET, G_CALLBACK (link_changed_cb), self); + g_signal_handlers_disconnect_by_func (nm_device_get_platform (NM_DEVICE (self)), G_CALLBACK (link_changed_cb), self); if (priv->brfd >= 0) { close (priv->brfd); @@ -547,7 +542,7 @@ carrier_update_cb (gpointer user_data) path = g_strdup_printf ("/sys/class/atm/%s/carrier", NM_ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (NM_DEVICE (self)))); - carrier = (int) nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (path), 10, 0, 1, -1); + carrier = (int) nm_platform_sysctl_get_int_checked (nm_device_get_platform (NM_DEVICE (self)), NMP_SYSCTL_PATHID_ABSOLUTE (path), 10, 0, 1, -1); g_free (path); if (carrier != -1) |