mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 00:30:09 +01:00
device: share implementation of hw_is_up, hw_bring_up and hw_take_down
This commit is contained in:
parent
0f05bfb01f
commit
e7caad20c9
6 changed files with 32 additions and 88 deletions
|
|
@ -254,22 +254,6 @@ complete_connection (NMDevice *device,
|
|||
return nm_modem_complete_connection (priv->modem, connection, existing_connections, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_is_up (NMDevice *device)
|
||||
{
|
||||
int ifindex = nm_device_get_ip_ifindex (device);
|
||||
|
||||
return ifindex > 0 ? nm_system_iface_is_up (ifindex) : TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_bring_up (NMDevice *device, gboolean *no_firmware)
|
||||
{
|
||||
int ifindex = nm_device_get_ip_ifindex (device);
|
||||
|
||||
return ifindex > 0 ? nm_system_iface_set_up (ifindex, TRUE, no_firmware) : TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
deactivate (NMDevice *device)
|
||||
{
|
||||
|
|
@ -508,8 +492,6 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
|
|||
device_class->get_best_auto_connection = get_best_auto_connection;
|
||||
device_class->check_connection_compatible = check_connection_compatible;
|
||||
device_class->complete_connection = complete_connection;
|
||||
device_class->hw_is_up = hw_is_up;
|
||||
device_class->hw_bring_up = hw_bring_up;
|
||||
device_class->deactivate = deactivate;
|
||||
device_class->act_stage1_prepare = act_stage1_prepare;
|
||||
device_class->act_stage2_config = act_stage2_config;
|
||||
|
|
|
|||
|
|
@ -186,24 +186,6 @@ constructor (GType type,
|
|||
return object;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_is_up (NMDevice *device)
|
||||
{
|
||||
return nm_system_iface_is_up (nm_device_get_ip_ifindex (device));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_bring_up (NMDevice *dev, gboolean *no_firmware)
|
||||
{
|
||||
return nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware);
|
||||
}
|
||||
|
||||
static void
|
||||
hw_take_down (NMDevice *dev)
|
||||
{
|
||||
nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), FALSE, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_up (NMDevice *device)
|
||||
{
|
||||
|
|
@ -554,9 +536,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
|
|||
|
||||
parent_class->get_type_capabilities = NULL;
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->hw_is_up = hw_is_up;
|
||||
parent_class->hw_bring_up = hw_bring_up;
|
||||
parent_class->hw_take_down = hw_take_down;
|
||||
parent_class->is_up = is_up;
|
||||
parent_class->bring_up = bring_up;
|
||||
parent_class->take_down = take_down;
|
||||
|
|
|
|||
|
|
@ -129,12 +129,6 @@ get_carrier_sync (NMDeviceVlan *self)
|
|||
return !!(ifflags & IFF_LOWER_UP);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_is_up (NMDevice *device)
|
||||
{
|
||||
return nm_system_iface_is_up (nm_device_get_ip_ifindex (device));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_bring_up (NMDevice *dev, gboolean *no_firmware)
|
||||
{
|
||||
|
|
@ -142,7 +136,7 @@ hw_bring_up (NMDevice *dev, gboolean *no_firmware)
|
|||
guint i = 20;
|
||||
|
||||
while (i-- > 0 && !success) {
|
||||
success = nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware);
|
||||
success = NM_DEVICE_GET_CLASS (dev)->hw_bring_up (dev, no_firmware);
|
||||
g_usleep (50);
|
||||
}
|
||||
|
||||
|
|
@ -162,12 +156,6 @@ hw_bring_up (NMDevice *dev, gboolean *no_firmware)
|
|||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
hw_take_down (NMDevice *dev)
|
||||
{
|
||||
nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), FALSE, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
update_hw_address (NMDevice *dev)
|
||||
{
|
||||
|
|
@ -760,9 +748,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
|
|||
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->update_hw_address = update_hw_address;
|
||||
parent_class->hw_is_up = hw_is_up;
|
||||
parent_class->hw_bring_up = hw_bring_up;
|
||||
parent_class->hw_take_down = hw_take_down;
|
||||
parent_class->can_interrupt_activation = can_interrupt_activation;
|
||||
parent_class->is_available = is_available;
|
||||
|
||||
|
|
|
|||
|
|
@ -803,25 +803,13 @@ periodic_update (gpointer user_data)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_is_up (NMDevice *device)
|
||||
{
|
||||
return nm_system_iface_is_up (nm_device_get_ip_ifindex (device));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_bring_up (NMDevice *device, gboolean *no_firmware)
|
||||
{
|
||||
if (!NM_DEVICE_WIFI_GET_PRIVATE (device)->enabled)
|
||||
return FALSE;
|
||||
|
||||
return nm_system_iface_set_up (nm_device_get_ip_ifindex (device), TRUE, no_firmware);
|
||||
}
|
||||
|
||||
static void
|
||||
hw_take_down (NMDevice *device)
|
||||
{
|
||||
nm_system_iface_set_up (nm_device_get_ip_ifindex (device), FALSE, NULL);
|
||||
return NM_DEVICE_GET_CLASS (device)->hw_bring_up (device, no_firmware);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -880,7 +868,7 @@ _set_hw_addr (NMDeviceWifi *self, const guint8 *addr, const char *detail)
|
|||
}
|
||||
|
||||
/* Can't change MAC address while device is up */
|
||||
hw_take_down (dev);
|
||||
nm_device_hw_take_down (dev, FALSE);
|
||||
|
||||
success = nm_system_iface_set_mac (nm_device_get_ip_ifindex (dev), (struct ether_addr *) addr);
|
||||
if (success) {
|
||||
|
|
@ -3789,9 +3777,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
|
|||
|
||||
parent_class->get_type_capabilities = get_type_capabilities;
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->hw_is_up = hw_is_up;
|
||||
parent_class->hw_bring_up = hw_bring_up;
|
||||
parent_class->hw_take_down = hw_take_down;
|
||||
parent_class->is_up = is_up;
|
||||
parent_class->bring_up = bring_up;
|
||||
parent_class->take_down = take_down;
|
||||
|
|
|
|||
|
|
@ -356,33 +356,21 @@ nm_device_wired_init (NMDeviceWired * self)
|
|||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_is_up (NMDevice *device)
|
||||
{
|
||||
return nm_system_iface_is_up (nm_device_get_ip_ifindex (device));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_bring_up (NMDevice *dev, gboolean *no_firmware)
|
||||
{
|
||||
gboolean success, carrier;
|
||||
gboolean result, carrier;
|
||||
guint32 caps;
|
||||
|
||||
success = nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware);
|
||||
if (success) {
|
||||
result = NM_DEVICE_GET_CLASS(dev)->hw_bring_up (dev, no_firmware);
|
||||
if (result) {
|
||||
caps = nm_device_get_capabilities (dev);
|
||||
if (caps & NM_DEVICE_CAP_CARRIER_DETECT) {
|
||||
carrier = get_carrier_sync (NM_DEVICE_WIRED (dev));
|
||||
set_carrier (NM_DEVICE_WIRED (dev), carrier, carrier ? FALSE : TRUE);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
hw_take_down (NMDevice *dev)
|
||||
{
|
||||
nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), FALSE, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -505,9 +493,7 @@ nm_device_wired_class_init (NMDeviceWiredClass *klass)
|
|||
object_class->constructor = constructor;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
parent_class->hw_is_up = hw_is_up;
|
||||
parent_class->hw_bring_up = hw_bring_up;
|
||||
parent_class->hw_take_down = hw_take_down;
|
||||
parent_class->can_interrupt_activation = can_interrupt_activation;
|
||||
parent_class->update_hw_address = update_hw_address;
|
||||
parent_class->is_available = is_available;
|
||||
|
|
|
|||
|
|
@ -498,6 +498,14 @@ nm_device_hw_is_up (NMDevice *self)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_is_up (NMDevice *device)
|
||||
{
|
||||
int ifindex = nm_device_get_ip_ifindex (device);
|
||||
|
||||
return ifindex > 0 ? nm_system_iface_is_up (ifindex) : TRUE;
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_generic_capabilities (NMDevice *dev)
|
||||
{
|
||||
|
|
@ -3919,6 +3927,14 @@ out:
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hw_bring_up (NMDevice *device, gboolean *no_firmware)
|
||||
{
|
||||
int ifindex = nm_device_get_ip_ifindex (device);
|
||||
|
||||
return ifindex > 0 ? nm_system_iface_set_up (ifindex, TRUE, no_firmware) : TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_device_hw_take_down (NMDevice *self, gboolean block)
|
||||
{
|
||||
|
|
@ -3939,6 +3955,12 @@ nm_device_hw_take_down (NMDevice *self, gboolean block)
|
|||
g_usleep (200);
|
||||
}
|
||||
|
||||
static void
|
||||
hw_take_down (NMDevice *device)
|
||||
{
|
||||
nm_system_iface_set_up (nm_device_get_ip_ifindex (device), FALSE, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
|
||||
{
|
||||
|
|
@ -4330,6 +4352,9 @@ nm_device_class_init (NMDeviceClass *klass)
|
|||
klass->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout;
|
||||
klass->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout;
|
||||
klass->check_connection_available = check_connection_available;
|
||||
klass->hw_is_up = hw_is_up;
|
||||
klass->hw_bring_up = hw_bring_up;
|
||||
klass->hw_take_down = hw_take_down;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue