diff --git a/ChangeLog b/ChangeLog index a06967bfc5..ef2bfefb9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2008-04-30 Dan Williams + + * src/NetworkManagerSystem.c + src/NetworkManagerSystem.h + - (nm_system_device_is_up, nm_system_device_is_up_with_iface): new + functions to check device flags for IFF_UP + + * src/nm-serial-device.c + - (real_is_up): remove; NMDevice now returns TRUE if the subclass doesn't + implement is_up + + * src/nm-device-802-3-ethernet.c + src/nm-device-802-11-wireless.c + - (real_hw_is_up): call nm_system_device_is_up() + + * src/nm-device.c + - (real_hw_is_up): move to nm_system_device_is_up_with_iface() + - (real_is_up): remove; nm_device_is_up() returns TRUE if subclass + does not implement + 2008-04-29 Dan Williams Handle HAL dropouts better; allow NM to start up even if HAL isn't up yet. diff --git a/src/NetworkManagerSystem.c b/src/NetworkManagerSystem.c index a2633c4014..e64f0311bb 100644 --- a/src/NetworkManagerSystem.c +++ b/src/NetworkManagerSystem.c @@ -436,6 +436,41 @@ out: return success; } +gboolean +nm_system_device_is_up (NMDevice *device) +{ + g_return_val_if_fail (device != NULL, FALSE); + + return nm_system_device_is_up_with_iface (nm_device_get_iface (device)); +} + +gboolean +nm_system_device_is_up_with_iface (const char *iface) +{ + struct ifreq ifr; + int err, fd; + + fd = socket (PF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + nm_warning ("couldn't open control socket."); + return FALSE; + } + + /* Get device's flags */ + strncpy (ifr.ifr_name, iface, IFNAMSIZ); + err = ioctl (fd, SIOCGIFFLAGS, &ifr); + close (fd); + + if (!err) + return (!((ifr.ifr_flags^IFF_UP) & IFF_UP)); + + if (errno != ENODEV) { + nm_warning ("%s: could not get flags for device %s. errno = %d", + __func__, iface, errno); + } + + return FALSE; +} gboolean nm_system_device_set_mtu (const char *iface, guint32 mtu) diff --git a/src/NetworkManagerSystem.h b/src/NetworkManagerSystem.h index ceae29b066..0e34ba7746 100644 --- a/src/NetworkManagerSystem.h +++ b/src/NetworkManagerSystem.h @@ -70,6 +70,9 @@ gboolean nm_system_vpn_device_unset_from_ip4_config (NMDevice *active_device, gboolean nm_system_device_set_up_down (NMDevice *dev, gboolean up); gboolean nm_system_device_set_up_down_with_iface (const char *iface, gboolean up); +gboolean nm_system_device_is_up (NMDevice *device); +gboolean nm_system_device_is_up_with_iface (const char *iface); + gboolean nm_system_device_update_resolv_conf (void *data, int len, const char *domain_name); void nm_system_set_hostname (NMIP4Config *config); diff --git a/src/nm-device-802-11-wireless.c b/src/nm-device-802-11-wireless.c index 18117da3b7..47c4624611 100644 --- a/src/nm-device-802-11-wireless.c +++ b/src/nm-device-802-11-wireless.c @@ -733,7 +733,7 @@ out: static gboolean real_hw_is_up (NMDevice *device) { - return NM_DEVICE_CLASS (nm_device_802_11_wireless_parent_class)->hw_is_up (device); + return nm_system_device_is_up (device); } static gboolean diff --git a/src/nm-device-802-3-ethernet.c b/src/nm-device-802-3-ethernet.c index 59d1527841..96081c8222 100644 --- a/src/nm-device-802-3-ethernet.c +++ b/src/nm-device-802-3-ethernet.c @@ -342,7 +342,7 @@ real_take_down (NMDevice *dev) static gboolean real_hw_is_up (NMDevice *device) { - return NM_DEVICE_CLASS (nm_device_802_3_ethernet_parent_class)->hw_is_up (device); + return nm_system_device_is_up (device); } static gboolean diff --git a/src/nm-device.c b/src/nm-device.c index 817bb7f5fa..f23e3803a1 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -196,37 +196,6 @@ error: return NULL; } - -static gboolean -real_hw_is_up (NMDevice *self) -{ - struct ifreq ifr; - const char *iface; - int err, fd; - - fd = socket (PF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - nm_warning ("couldn't open control socket."); - return FALSE; - } - - /* Get device's flags */ - iface = nm_device_get_iface (self); - strncpy (ifr.ifr_name, iface, IFNAMSIZ); - err = ioctl (fd, SIOCGIFFLAGS, &ifr); - close (fd); - - if (!err) - return (!((ifr.ifr_flags^IFF_UP) & IFF_UP)); - - if (errno != ENODEV) { - nm_warning ("%s: could not get flags for device %s. errno = %d", - __func__, iface, errno); - } - - return FALSE; -} - static gboolean nm_device_hw_is_up (NMDevice *self) { @@ -1474,12 +1443,6 @@ nm_device_hw_take_down (NMDevice *self, gboolean wait) g_usleep (200); } -static gboolean -real_is_up (NMDevice *self) -{ - return TRUE; -} - static gboolean nm_device_bring_up (NMDevice *self, gboolean wait) { @@ -1693,8 +1656,6 @@ nm_device_class_init (NMDeviceClass *klass) object_class->get_property = get_property; object_class->constructor = constructor; - klass->hw_is_up = real_hw_is_up; - klass->is_up = real_is_up; klass->get_type_capabilities = real_get_type_capabilities; klass->get_generic_capabilities = real_get_generic_capabilities; klass->act_stage1_prepare = real_act_stage1_prepare; diff --git a/src/nm-serial-device.c b/src/nm-serial-device.c index d862dabed3..4e42521805 100644 --- a/src/nm-serial-device.c +++ b/src/nm-serial-device.c @@ -1010,13 +1010,6 @@ real_deactivate_quickly (NMDevice *device) nm_serial_device_close (self); } -static gboolean -real_is_up (NMDevice *device) -{ - /* Serial devices are always "up" */ - return TRUE; -} - static guint32 real_get_generic_capabilities (NMDevice *dev) { @@ -1052,7 +1045,6 @@ nm_serial_device_class_init (NMSerialDeviceClass *klass) object_class->finalize = finalize; parent_class->get_generic_capabilities = real_get_generic_capabilities; - parent_class->is_up = real_is_up; parent_class->act_stage2_config = real_act_stage2_config; parent_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config; parent_class->deactivate_quickly = real_deactivate_quickly;