From 590b9a830d4e926e36028d8bcfc89143096a569d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 16:57:39 +0100 Subject: [PATCH 1/9] device: accept UNKNOWN device types during create_and_realize() There are the link-types NONE and UNKNOWN. NONE is a linktype that is never returned by platform, but UNKNOWN is very much a valid (albeit unspecified) type. Effectively, create_and_realized() should create a link of a known type, thus it should never return an UNKNOWN link type at this point. Still change it because it feels more correct. --- src/devices/nm-device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8b9c52f3db..1c1eeed59f 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1761,7 +1761,7 @@ nm_device_create_and_realize (NMDevice *self, GError **error) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMPlatformLink plink = { .type = NM_LINK_TYPE_UNKNOWN }; + NMPlatformLink plink = { .type = NM_LINK_TYPE_NONE }; /* Must be set before device is realized */ priv->is_nm_owned = !nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface); @@ -1772,8 +1772,8 @@ nm_device_create_and_realize (NMDevice *self, return FALSE; } - NM_DEVICE_GET_CLASS (self)->setup_start (self, (plink.type != NM_LINK_TYPE_UNKNOWN) ? &plink : NULL); - nm_device_setup_finish (self, (plink.type != NM_LINK_TYPE_UNKNOWN) ? &plink : NULL); + NM_DEVICE_GET_CLASS (self)->setup_start (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); + nm_device_setup_finish (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); g_return_val_if_fail (nm_device_check_connection_compatible (self, connection), TRUE); return TRUE; From 2a14a28fe05ef4db30d03cd37dd03c143bf881fd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 17:00:14 +0100 Subject: [PATCH 2/9] device: pass const NMPlatformLink instance to setup_start()/setup_finish() NMPlatformLink is a plain struct (not a GObject, for which we usually don't use const). We certainly don't want the functions to modify the passed-in data. --- src/devices/nm-device-ethernet.c | 2 +- src/devices/nm-device-generic.c | 2 +- src/devices/nm-device-ip-tunnel.c | 2 +- src/devices/nm-device-macvlan.c | 2 +- src/devices/nm-device-tun.c | 2 +- src/devices/nm-device-vlan.c | 2 +- src/devices/nm-device-vxlan.c | 2 +- src/devices/nm-device.c | 8 ++++---- src/devices/nm-device.h | 6 +++--- src/devices/wifi/nm-device-wifi.c | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 9aec4ca66f..c9fd691cfd 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -305,7 +305,7 @@ nm_device_ethernet_init (NMDeviceEthernet *self) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->setup_start (device, plink); diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c index 0689d71676..b6fe16be65 100644 --- a/src/devices/nm-device-generic.c +++ b/src/devices/nm-device-generic.c @@ -61,7 +61,7 @@ get_type_description (NMDevice *device) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NMDeviceGeneric *self = NM_DEVICE_GENERIC (device); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self); diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 0e3e53d877..e0ccd6666e 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -771,7 +771,7 @@ create_and_realize (NMDevice *device, } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NM_DEVICE_CLASS (nm_device_ip_tunnel_parent_class)->setup_start (device, plink); diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index c980fd17a2..c536fa136c 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -559,7 +559,7 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->setup_start (device, plink); diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 36d87e250b..045df73309 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -241,7 +241,7 @@ realize (NMDevice *device, NMPlatformLink *plink, GError **error) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NM_DEVICE_CLASS (nm_device_tun_parent_class)->setup_start (device, plink); reload_tun_properties (device); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 63938c8968..f276fa3869 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -148,7 +148,7 @@ nm_device_vlan_set_parent (NMDeviceVlan *self, NMDevice *parent) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NMDeviceVlan *self = NM_DEVICE_VLAN (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 7eabbcdb1f..3c96414008 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -143,7 +143,7 @@ link_changed (NMDevice *device, NMPlatformLink *info) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { g_assert (plink->type == NM_LINK_TYPE_VXLAN); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 1c1eeed59f..ba2231768a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1780,7 +1780,7 @@ nm_device_create_and_realize (NMDevice *self, } static void -update_device_from_platform_link (NMDevice *self, NMPlatformLink *plink) +update_device_from_platform_link (NMDevice *self, const NMPlatformLink *plink) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); const char *udi; @@ -1836,7 +1836,7 @@ check_carrier (NMDevice *self) } static void -setup_start (NMDevice *self, NMPlatformLink *plink) +setup_start (NMDevice *self, const NMPlatformLink *plink) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); static guint32 id = 0; @@ -1943,7 +1943,7 @@ setup_start (NMDevice *self, NMPlatformLink *plink) } static void -setup_finish (NMDevice *self, NMPlatformLink *plink) +setup_finish (NMDevice *self, const NMPlatformLink *plink) { if (plink) { update_device_from_platform_link (self, plink); @@ -1952,7 +1952,7 @@ setup_finish (NMDevice *self, NMPlatformLink *plink) } void -nm_device_setup_finish (NMDevice *self, NMPlatformLink *plink) +nm_device_setup_finish (NMDevice *self, const NMPlatformLink *plink) { g_return_if_fail (!plink || link_type_compatible (self, plink->type, NULL, NULL)); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 36f5cc68d1..655f52d1f3 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -197,7 +197,7 @@ typedef struct { * any tasks that affect other interfaces (like master/slave or parent/child * stuff). */ - void (*setup_start) (NMDevice *self, NMPlatformLink *plink); + void (*setup_start) (NMDevice *self, const NMPlatformLink *plink); /** * setup_finish(): @@ -208,7 +208,7 @@ typedef struct { * backing resource properties. After this function finishes, the device * is ready for network connectivity. */ - void (*setup_finish) (NMDevice *self, NMPlatformLink *plink); + void (*setup_finish) (NMDevice *self, const NMPlatformLink *plink); /** * unrealize(): @@ -509,7 +509,7 @@ gboolean nm_device_create_and_realize (NMDevice *self, NMDevice *parent, GError **error); void nm_device_setup_finish (NMDevice *self, - NMPlatformLink *plink); + const NMPlatformLink *plink); gboolean nm_device_unrealize (NMDevice *device, gboolean remove_resources, GError **error); diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 6febd10b55..af8880dcfd 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -424,7 +424,7 @@ periodic_update_cb (gpointer user_data) } static void -setup_start (NMDevice *device, NMPlatformLink *plink) +setup_start (NMDevice *device, const NMPlatformLink *plink) { NM_DEVICE_CLASS (nm_device_wifi_parent_class)->setup_start (device, plink); From a4de9187ff216a9281710261d122ad97c063322c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 15:13:57 +0100 Subject: [PATCH 3/9] platform: return pointer to NMPlatformLink object for add functions Let the link-add functions return the internal pointer to the platform link object. Similar to link-get, which doesn't copy the link either. Also adjust the sole users of the add-functions (create-and-realize) to take the pointer. Eventually we still copy the returned data, because accessing platform can invalidate the returned pointer. Thus we don't actually safe any copying by this (at least every use of the function currently leads to the data being copied). Still change it, because I think the API of NMPlatform should look like that. --- src/devices/nm-device-bond.c | 2 +- src/devices/nm-device-bridge.c | 3 +- src/devices/nm-device-infiniband.c | 4 +-- src/devices/nm-device-ip-tunnel.c | 3 +- src/devices/nm-device-macvlan.c | 3 +- src/devices/nm-device-tun.c | 3 +- src/devices/nm-device-vlan.c | 4 +-- src/devices/nm-device-vxlan.c | 3 +- src/devices/nm-device.c | 9 ++++-- src/devices/nm-device.h | 6 ++-- src/devices/team/nm-device-team.c | 2 +- src/platform/nm-fake-platform.c | 20 +++++++------ src/platform/nm-linux-platform.c | 34 +++++++++++----------- src/platform/nm-platform.c | 34 +++++++++++----------- src/platform/nm-platform.h | 46 +++++++++++++++--------------- src/platform/tests/test-link.c | 6 ++-- 16 files changed, 92 insertions(+), 90 deletions(-) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 6471d3e4a2..72ded91f7d 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -448,7 +448,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { const char *iface = nm_device_get_iface (device); diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 39d41ae4d4..298a799024 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -377,7 +377,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { NMSettingBridge *s_bridge; @@ -387,7 +387,6 @@ create_and_realize (NMDevice *device, NMPlatformError plerr; g_assert (iface); - g_assert (out_plink); s_bridge = nm_connection_get_setting_bridge (connection); g_assert (s_bridge); diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index 50b7f1bb8f..792bdcd053 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -236,15 +236,13 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { NMSettingInfiniband *s_infiniband; int parent_ifindex, p_key; NMPlatformError plerr; - g_assert (out_plink); - if (!NM_IS_DEVICE_INFINIBAND (parent)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Parent interface %s must be an InfiniBand interface", diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index e0ccd6666e..bcb6dbf247 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -613,7 +613,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { const char *iface = nm_device_get_iface (device); @@ -628,7 +628,6 @@ create_and_realize (NMDevice *device, s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection); g_assert (s_ip_tunnel); - g_assert (out_plink); switch (nm_setting_ip_tunnel_get_mode (s_ip_tunnel)) { case NM_IP_TUNNEL_MODE_GRE: diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index c536fa136c..12cd95ba58 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -220,7 +220,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { const char *iface = nm_device_get_iface (device); @@ -231,7 +231,6 @@ create_and_realize (NMDevice *device, s_macvlan = nm_connection_get_setting_macvlan (connection); g_assert (s_macvlan); - g_assert (out_plink); parent_ifindex = nm_device_get_ifindex (parent); g_warn_if_fail (parent_ifindex > 0); diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 045df73309..469d93cc1d 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -199,7 +199,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { const char *iface = nm_device_get_iface (device); @@ -209,7 +209,6 @@ create_and_realize (NMDevice *device, s_tun = nm_connection_get_setting_tun (connection); g_assert (s_tun); - g_assert (out_plink); user = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_owner (s_tun), 10, 0, G_MAXINT32, -1); group = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_group (s_tun), 10, 0, G_MAXINT32, -1); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index f276fa3869..4e5da03207 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -207,7 +207,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); @@ -216,8 +216,6 @@ create_and_realize (NMDevice *device, int parent_ifindex, vlan_id; NMPlatformError plerr; - g_assert (out_plink); - s_vlan = nm_connection_get_setting_vlan (connection); g_assert (s_vlan); diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 3c96414008..514554c4c4 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -174,7 +174,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { const char *iface = nm_device_get_iface (device); @@ -186,7 +186,6 @@ create_and_realize (NMDevice *device, s_vxlan = nm_connection_get_setting_vxlan (connection); g_assert (s_vxlan); - g_assert (out_plink); if (parent) props.parent_ifindex = nm_device_get_ifindex (parent); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ba2231768a..b993a063a5 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1761,7 +1761,8 @@ nm_device_create_and_realize (NMDevice *self, GError **error) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMPlatformLink plink = { .type = NM_LINK_TYPE_NONE }; + NMPlatformLink plink_copy; + const NMPlatformLink *plink = NULL; /* Must be set before device is realized */ priv->is_nm_owned = !nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface); @@ -1770,10 +1771,12 @@ nm_device_create_and_realize (NMDevice *self, if (NM_DEVICE_GET_CLASS (self)->create_and_realize) { if (!NM_DEVICE_GET_CLASS (self)->create_and_realize (self, connection, parent, &plink, error)) return FALSE; + plink_copy = *plink; + plink = &plink_copy; } - NM_DEVICE_GET_CLASS (self)->setup_start (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); - nm_device_setup_finish (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); + NM_DEVICE_GET_CLASS (self)->setup_start (self, plink); + nm_device_setup_finish (self, plink); g_return_val_if_fail (nm_device_check_connection_compatible (self, connection), TRUE); return TRUE; diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 655f52d1f3..3ad900f385 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -170,7 +170,9 @@ typedef struct { * @self: the #NMDevice * @connection: the #NMConnection being activated * @parent: the parent #NMDevice, if any - * @out_plink: on success, a backing kernel network device if one exists + * @out_plink: on success, a backing kernel network device if one exists. + * The returned pointer is owned by platform and only valid until the + * next platform operation. * @error: location to store error, or %NULL * * Create any backing resources (kernel devices, etc) required for this @@ -183,7 +185,7 @@ typedef struct { gboolean (*create_and_realize) (NMDevice *self, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error); /** diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index c91e2c404b..74803225d8 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -673,7 +673,7 @@ static gboolean create_and_realize (NMDevice *device, NMConnection *connection, NMDevice *parent, - NMPlatformLink *out_plink, + const NMPlatformLink **out_plink, GError **error) { const char *iface = nm_device_get_iface (device); diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 09327a4d81..d6125aaaf3 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -292,10 +292,11 @@ link_add (NMPlatform *platform, NMLinkType type, const void *address, size_t address_len, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform); NMFakePlatformLink device; + NMFakePlatformLink *new_device; link_init (&device, priv->links->len, type, name); @@ -306,6 +307,7 @@ link_add (NMPlatform *platform, } g_array_append_val (priv->links, device); + new_device = &g_array_index (priv->links, NMFakePlatformLink, priv->links->len - 1); if (device.link.ifindex) { g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, NMP_OBJECT_TYPE_LINK, device.link.ifindex, &device, NM_PLATFORM_SIGNAL_ADDED); @@ -314,7 +316,7 @@ link_add (NMPlatform *platform, } if (out_link) - *out_link = device.link; + *out_link = &new_device->link; return TRUE; } @@ -672,11 +674,11 @@ slave_get_option (NMPlatform *platform, int slave, const char *option) } static gboolean -vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, NMPlatformLink *out_link) +vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, const NMPlatformLink **out_link) { NMFakePlatformLink *device; - if (!link_add (platform, name, NM_LINK_TYPE_VLAN, NULL, 0, NULL)) + if (!link_add (platform, name, NM_LINK_TYPE_VLAN, NULL, 0, out_link)) return FALSE; device = link_get (platform, nm_platform_link_get_ifindex (platform, name)); @@ -689,7 +691,7 @@ vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint device->link.parent = parent; if (out_link) - *out_link = device->link; + *out_link = &device->link; return TRUE; } @@ -712,11 +714,11 @@ static gboolean link_vxlan_add (NMPlatform *platform, const char *name, NMPlatformLnkVxlan *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMFakePlatformLink *device; - if (!link_add (platform, name, NM_LINK_TYPE_VXLAN, NULL, 0, NULL)) + if (!link_add (platform, name, NM_LINK_TYPE_VXLAN, NULL, 0, out_link)) return FALSE; device = link_get (platform, nm_platform_link_get_ifindex (platform, name)); @@ -729,12 +731,12 @@ link_vxlan_add (NMPlatform *platform, device->link.parent = props->parent_ifindex; if (out_link) - *out_link = device->link; + *out_link = &device->link; return TRUE; } static gboolean -infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatformLink *out_link) +infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link) { NMFakePlatformLink *device, *parent_device; gs_free char *name = NULL; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 730f4b1c86..6d84d10450 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -3592,7 +3592,7 @@ do_add_link_with_lookup (NMPlatform *platform, NMLinkType link_type, const char *name, struct nl_msg *nlmsg, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { const NMPObject *obj; @@ -3600,8 +3600,8 @@ do_add_link_with_lookup (NMPlatform *platform, obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, 0, name, FALSE, link_type, NULL, NULL); - if (out_link && obj) - *out_link = obj->link; + if (out_link) + *out_link = obj ? &obj->link : NULL; return !!obj; } @@ -3801,7 +3801,7 @@ link_add (NMPlatform *platform, NMLinkType type, const void *address, size_t address_len, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; @@ -4160,7 +4160,7 @@ vlan_add (NMPlatform *platform, int parent, int vlan_id, guint32 vlan_flags, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; @@ -4204,7 +4204,7 @@ static int link_gre_add (NMPlatform *platform, const char *name, NMPlatformLnkGre *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *info; @@ -4259,7 +4259,7 @@ static int link_ip6tnl_add (NMPlatform *platform, const char *name, NMPlatformLnkIp6Tnl *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *info; @@ -4320,7 +4320,7 @@ static int link_ipip_add (NMPlatform *platform, const char *name, NMPlatformLnkIpIp *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *info; @@ -4372,7 +4372,7 @@ link_macvlan_add (NMPlatform *platform, const char *name, int parent, NMPlatformLnkMacvlan *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *info; @@ -4420,7 +4420,7 @@ static int link_sit_add (NMPlatform *platform, const char *name, NMPlatformLnkSit *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *info; @@ -4471,7 +4471,7 @@ static gboolean link_vxlan_add (NMPlatform *platform, const char *name, NMPlatformLnkVxlan *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *info; @@ -4714,7 +4714,7 @@ link_vlan_change (NMPlatform *platform, static int tun_add (NMPlatform *platform, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr, - gboolean multi_queue, NMPlatformLink *out_link) + gboolean multi_queue, const NMPlatformLink **out_link) { const NMPObject *obj; struct ifreq ifr = { }; @@ -4765,8 +4765,8 @@ tun_add (NMPlatform *platform, const char *name, gboolean tap, 0, name, FALSE, tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, NULL, NULL); - if (out_link && obj) - *out_link = obj->link; + if (out_link) + *out_link = obj ? &obj->link : NULL; return !!obj; } @@ -4887,7 +4887,7 @@ slave_get_option (NMPlatform *platform, int slave, const char *option) /******************************************************************/ static gboolean -infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatformLink *out_link) +infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); const NMPObject *obj_parent; @@ -4911,8 +4911,8 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatfor obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, 0, ifname, FALSE, NM_LINK_TYPE_INFINIBAND, NULL, NULL); - if (out_link && obj) - *out_link = obj->link; + if (out_link) + *out_link = obj ? &obj->link : NULL; return !!obj; } diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index fe42465c77..cf58e9b252 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -571,7 +571,7 @@ nm_platform_link_get_by_address (NMPlatform *self, } static NMPlatformError -_link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, NMPlatformLink *out_link) +_link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, const NMPlatformLink **out_link) { const NMPlatformLink *pllink; @@ -586,11 +586,13 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, N wrong_type ? ", expected " : "", wrong_type ? nm_link_type_to_string (type) : ""); if (out_link) - *out_link = *pllink; + *out_link = pllink; if (wrong_type) return NM_PLATFORM_ERROR_WRONG_TYPE; return NM_PLATFORM_ERROR_EXISTS; } + if (out_link) + *out_link = NULL; return NM_PLATFORM_ERROR_SUCCESS; } @@ -619,7 +621,7 @@ nm_platform_link_add (NMPlatform *self, NMLinkType type, const void *address, size_t address_len, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; @@ -648,7 +650,7 @@ nm_platform_link_add (NMPlatform *self, * Create a software ethernet-like interface */ NMPlatformError -nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link) +nm_platform_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0, out_link); } @@ -1488,7 +1490,7 @@ nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len, out_link); } @@ -1502,7 +1504,7 @@ nm_platform_bridge_add (NMPlatform *self, * Create a software bonding device. */ NMPlatformError -nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link) +nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0, out_link); } @@ -1516,7 +1518,7 @@ nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_li * Create a software teaming device. */ NMPlatformError -nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link) +nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0, out_link); } @@ -1537,7 +1539,7 @@ nm_platform_vlan_add (NMPlatform *self, int parent, int vlanid, guint32 vlanflags, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; @@ -1572,7 +1574,7 @@ NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; @@ -1608,7 +1610,7 @@ nm_platform_link_vxlan_add (NMPlatform *self, NMPlatformError nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr, - gboolean multi_queue, NMPlatformLink *out_link) + gboolean multi_queue, const NMPlatformLink **out_link) { NMPlatformError plerr; @@ -1779,7 +1781,7 @@ NMPlatformError nm_platform_link_gre_add (NMPlatform *self, const char *name, NMPlatformLnkGre *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; char buffer[INET_ADDRSTRLEN]; @@ -1806,7 +1808,7 @@ nm_platform_link_gre_add (NMPlatform *self, } NMPlatformError -nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link) +nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link) { gs_free char *parent_name = NULL; gs_free char *name = NULL; @@ -1915,7 +1917,7 @@ NMPlatformError nm_platform_link_ip6tnl_add (NMPlatform *self, const char *name, NMPlatformLnkIp6Tnl *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; char buffer[INET6_ADDRSTRLEN]; @@ -1954,7 +1956,7 @@ NMPlatformError nm_platform_link_ipip_add (NMPlatform *self, const char *name, NMPlatformLnkIpIp *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; char buffer[INET_ADDRSTRLEN]; @@ -1994,7 +1996,7 @@ nm_platform_link_macvlan_add (NMPlatform *self, const char *name, int parent, NMPlatformLnkMacvlan *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; NMLinkType type; @@ -2034,7 +2036,7 @@ NMPlatformError nm_platform_link_sit_add (NMPlatform *self, const char *name, NMPlatformLnkSit *props, - NMPlatformLink *out_link) + const NMPlatformLink **out_link) { NMPlatformError plerr; char buffer[INET_ADDRSTRLEN]; diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index cef962c29c..46d1312226 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -506,7 +506,7 @@ typedef struct { NMLinkType type, const void *address, size_t address_len, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); gboolean (*link_delete) (NMPlatform *, int ifindex); const char *(*link_get_type_name) (NMPlatform *, int ifindex); gboolean (*link_get_unmanaged) (NMPlatform *, int ifindex, gboolean *unmanaged); @@ -550,7 +550,7 @@ typedef struct { gboolean (*slave_set_option) (NMPlatform *, int ifindex, const char *option, const char *value); char * (*slave_get_option) (NMPlatform *, int ifindex, const char *option); - gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link); + gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link); gboolean (*link_vlan_change) (NMPlatform *self, int ifindex, NMVlanFlags flags_mask, @@ -562,23 +562,23 @@ typedef struct { const NMVlanQosMapping *egress_map, gsize n_egress_map); gboolean (*link_vxlan_add) (NMPlatform *, const char *name, NMPlatformLnkVxlan *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); gboolean (*link_gre_add) (NMPlatform *, const char *name, NMPlatformLnkGre *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); gboolean (*link_ip6tnl_add) (NMPlatform *, const char *name, NMPlatformLnkIp6Tnl *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); gboolean (*link_ipip_add) (NMPlatform *, const char *name, NMPlatformLnkIpIp *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); gboolean (*link_macvlan_add) (NMPlatform *, const char *name, int parent, NMPlatformLnkMacvlan *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); gboolean (*link_sit_add) (NMPlatform *, const char *name, NMPlatformLnkSit *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); - gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, NMPlatformLink *out_link); + gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, const NMPlatformLink **out_link); gboolean (*tun_add) (NMPlatform *platform, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, - gboolean vnet_hdr, gboolean multi_queue, NMPlatformLink *out_link); + gboolean vnet_hdr, gboolean multi_queue, const NMPlatformLink **out_link); gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps); gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, guint8 *bssid); @@ -700,10 +700,10 @@ const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const ch const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length); GArray *nm_platform_link_get_all (NMPlatform *self); -NMPlatformError nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link); -NMPlatformError nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, NMPlatformLink *out_link); -NMPlatformError nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link); -NMPlatformError nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link); +NMPlatformError nm_platform_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); +NMPlatformError nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link); +NMPlatformError nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); +NMPlatformError nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); gboolean nm_platform_link_delete (NMPlatform *self, int ifindex); /* convienience methods to lookup the link and access fields of NMPlatformLink. */ @@ -773,7 +773,7 @@ const NMPlatformLnkSit *nm_platform_link_get_lnk_sit (NMPlatform *self, int ifin const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); -NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link); +NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link); gboolean nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_link_vlan_change (NMPlatform *self, @@ -787,12 +787,12 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self, const NMVlanQosMapping *egress_map, gsize n_egress_map); -NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, NMPlatformLink *out_link); +NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, const NMPlatformLink **out_link); NMPlatformError nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, - gboolean vnet_hdr, gboolean multi_queue, NMPlatformLink *out_link); + gboolean vnet_hdr, gboolean multi_queue, const NMPlatformLink **out_link); -NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link); +NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link); gboolean nm_platform_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode); gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex); @@ -821,15 +821,15 @@ const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Addr const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); NMPlatformError nm_platform_link_gre_add (NMPlatform *self, const char *name, NMPlatformLnkGre *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); NMPlatformError nm_platform_link_ip6tnl_add (NMPlatform *self, const char *name, NMPlatformLnkIp6Tnl *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); NMPlatformError nm_platform_link_ipip_add (NMPlatform *self, const char *name, NMPlatformLnkIpIp *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); NMPlatformError nm_platform_link_macvlan_add (NMPlatform *self, const char *name, int parent, NMPlatformLnkMacvlan *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); NMPlatformError nm_platform_link_sit_add (NMPlatform *self, const char *name, NMPlatformLnkSit *props, - NMPlatformLink *out_link); + const NMPlatformLink **out_link); const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, int plen); GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex); diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 9da6bff7fa..8fb00f5bd6 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -462,11 +462,13 @@ test_bridge_addr (void) { char addr[ETH_ALEN]; NMPlatformLink link; - const NMPlatformLink *plink; + const NMPlatformLink *plink = NULL; nm_utils_hwaddr_aton ("de:ad:be:ef:00:11", addr, sizeof (addr)); - g_assert_cmpint (nm_platform_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &link), ==, NM_PLATFORM_ERROR_SUCCESS); + g_assert_cmpint (nm_platform_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &plink), ==, NM_PLATFORM_ERROR_SUCCESS); + g_assert (plink); + link = *plink; g_assert_cmpstr (link.name, ==, DEVICE_NAME); g_assert_cmpint (link.addr.len, ==, sizeof (addr)); From 6a7730241b28b7103aba7eb9ba73f213494c845b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 16:12:37 +0100 Subject: [PATCH 4/9] trival: fix whitespace --- src/platform/nm-linux-platform.c | 88 ++++++++++++++++---------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 6d84d10450..17ccee41b0 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4716,59 +4716,59 @@ tun_add (NMPlatform *platform, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr, gboolean multi_queue, const NMPlatformLink **out_link) { - const NMPObject *obj; - struct ifreq ifr = { }; - int fd; + const NMPObject *obj; + struct ifreq ifr = { }; + int fd; - _LOGD ("link: add %s '%s' owner %" G_GINT64_FORMAT " group %" G_GINT64_FORMAT, - tap ? "tap" : "tun", name, owner, group); + _LOGD ("link: add %s '%s' owner %" G_GINT64_FORMAT " group %" G_GINT64_FORMAT, + tap ? "tap" : "tun", name, owner, group); - fd = open ("/dev/net/tun", O_RDWR); - if (fd < 0) - return FALSE; + fd = open ("/dev/net/tun", O_RDWR); + if (fd < 0) + return FALSE; - strncpy (ifr.ifr_name, name, IFNAMSIZ); - ifr.ifr_flags = tap ? IFF_TAP : IFF_TUN; + strncpy (ifr.ifr_name, name, IFNAMSIZ); + ifr.ifr_flags = tap ? IFF_TAP : IFF_TUN; - if (!pi) - ifr.ifr_flags |= IFF_NO_PI; - if (vnet_hdr) - ifr.ifr_flags |= IFF_VNET_HDR; - if (multi_queue) - ifr.ifr_flags |= NM_IFF_MULTI_QUEUE; + if (!pi) + ifr.ifr_flags |= IFF_NO_PI; + if (vnet_hdr) + ifr.ifr_flags |= IFF_VNET_HDR; + if (multi_queue) + ifr.ifr_flags |= NM_IFF_MULTI_QUEUE; - if (ioctl (fd, TUNSETIFF, &ifr)) { - close (fd); - return FALSE; - } + if (ioctl (fd, TUNSETIFF, &ifr)) { + close (fd); + return FALSE; + } - if (owner >= 0 && owner < G_MAXINT32) { - if (ioctl (fd, TUNSETOWNER, (uid_t) owner)) { - close (fd); - return FALSE; - } - } + if (owner >= 0 && owner < G_MAXINT32) { + if (ioctl (fd, TUNSETOWNER, (uid_t) owner)) { + close (fd); + return FALSE; + } + } - if (group >= 0 && group < G_MAXINT32) { - if (ioctl (fd, TUNSETGROUP, (gid_t) group)) { - close (fd); - return FALSE; - } - } + if (group >= 0 && group < G_MAXINT32) { + if (ioctl (fd, TUNSETGROUP, (gid_t) group)) { + close (fd); + return FALSE; + } + } - if (ioctl (fd, TUNSETPERSIST, 1)) { - close (fd); - return FALSE; - } - do_request_link (platform, 0, name, TRUE); - obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, - 0, name, FALSE, - tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, - NULL, NULL); - if (out_link) - *out_link = obj ? &obj->link : NULL; + if (ioctl (fd, TUNSETPERSIST, 1)) { + close (fd); + return FALSE; + } + do_request_link (platform, 0, name, TRUE); + obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, + 0, name, FALSE, + tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, + NULL, NULL); + if (out_link) + *out_link = obj ? &obj->link : NULL; - return !!obj; + return !!obj; } static gboolean From eef388990f134fd30045807860055ef22afbbd5c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 16:14:49 +0100 Subject: [PATCH 5/9] platform/trivial: rename link related functions Link related functions should have a "nm_platform_link" prefix. Rename. Naming is a subjective matter and one might argue that omitting the "link" part from the name is shorter and even preferred. However, I think functions related to links should have a common prefix as the underlyings are strongly related. --- src/devices/nm-device-bond.c | 3 +- src/devices/nm-device-bridge.c | 10 ++-- src/devices/nm-device-infiniband.c | 4 +- src/devices/nm-device-tun.c | 18 +++---- src/devices/nm-device-veth.c | 2 +- src/devices/nm-device-vlan.c | 12 ++--- src/devices/team/nm-device-team.c | 2 +- src/platform/nm-linux-platform.c | 2 +- src/platform/nm-platform.c | 66 +++++++++++++------------ src/platform/nm-platform.h | 36 ++++++++------ src/platform/tests/test-address.c | 2 +- src/platform/tests/test-cleanup.c | 2 +- src/platform/tests/test-link.c | 78 +++++++++++++++--------------- src/platform/tests/test-route.c | 2 +- src/tests/test-route-manager.c | 4 +- 15 files changed, 128 insertions(+), 115 deletions(-) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 72ded91f7d..33f0ad159f 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -455,9 +455,8 @@ create_and_realize (NMDevice *device, NMPlatformError plerr; g_assert (iface); - g_assert (out_plink); - plerr = nm_platform_bond_add (NM_PLATFORM_GET, iface, out_plink); + plerr = nm_platform_link_bond_add (NM_PLATFORM_GET, iface, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create bond interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 298a799024..187fee0356 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -400,11 +400,11 @@ create_and_realize (NMDevice *device, } } - plerr = nm_platform_bridge_add (NM_PLATFORM_GET, - iface, - hwaddr ? mac_address : NULL, - hwaddr ? ETH_ALEN : 0, - out_plink); + plerr = nm_platform_link_bridge_add (NM_PLATFORM_GET, + iface, + hwaddr ? mac_address : NULL, + hwaddr ? ETH_ALEN : 0, + out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create bridge interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index 792bdcd053..50e1feb06d 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -226,7 +226,7 @@ update_connection (NMDevice *device, NMConnection *connection) ifindex = nm_device_get_ifindex (device); if (ifindex > 0) { - if (!nm_platform_infiniband_get_properties (NM_PLATFORM_GET, ifindex, NULL, NULL, &transport_mode)) + if (!nm_platform_link_infiniband_get_properties (NM_PLATFORM_GET, ifindex, NULL, NULL, &transport_mode)) transport_mode = "datagram"; } g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_TRANSPORT_MODE, transport_mode, NULL); @@ -268,7 +268,7 @@ create_and_realize (NMDevice *device, return FALSE; } - plerr = nm_platform_infiniband_partition_add (NM_PLATFORM_GET, parent_ifindex, p_key, out_plink); + plerr = nm_platform_link_infiniband_add (NM_PLATFORM_GET, parent_ifindex, p_key, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create InfiniBand P_Key interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 469d93cc1d..3501ddb466 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -68,7 +68,7 @@ reload_tun_properties (NMDeviceTun *self) ifindex = nm_device_get_ifindex (NM_DEVICE (self)); if (ifindex > 0) { - if (!nm_platform_tun_get_properties (NM_PLATFORM_GET, ifindex, &props)) { + if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, ifindex, &props)) { _LOGD (LOGD_DEVICE, "tun-properties: cannot loading tun properties from platform for ifindex %d", ifindex); ifindex = 0; } else if (g_strcmp0 (priv->mode, props.mode) != 0) { @@ -162,7 +162,7 @@ update_connection (NMDevice *device, NMConnection *connection) nm_connection_add_setting (connection, (NMSetting *) s_tun); } - if (!nm_platform_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { + if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_HW, "failed to get TUN interface info while updating connection."); return; } @@ -213,13 +213,13 @@ create_and_realize (NMDevice *device, user = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_owner (s_tun), 10, 0, G_MAXINT32, -1); group = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_group (s_tun), 10, 0, G_MAXINT32, -1); - plerr = nm_platform_tun_add (NM_PLATFORM_GET, iface, - nm_setting_tun_get_mode (s_tun) == NM_SETTING_TUN_MODE_TAP, - user, group, - nm_setting_tun_get_pi (s_tun), - nm_setting_tun_get_vnet_hdr (s_tun), - nm_setting_tun_get_multi_queue (s_tun), - out_plink); + plerr = nm_platform_link_tun_add (NM_PLATFORM_GET, iface, + nm_setting_tun_get_mode (s_tun) == NM_SETTING_TUN_MODE_TAP, + user, group, + nm_setting_tun_get_pi (s_tun), + nm_setting_tun_get_vnet_hdr (s_tun), + nm_setting_tun_get_multi_queue (s_tun), + out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create TUN/TAP interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index 07187205fb..986c93d8f9 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -81,7 +81,7 @@ get_peer (NMDeviceVeth *self) if (priv->ever_had_peer) return priv->peer; - if (!nm_platform_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &peer_ifindex)) { + if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &peer_ifindex)) { _LOGW (LOGD_HW, "could not read veth properties"); return NULL; } diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 4e5da03207..401ef4fd3e 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -232,12 +232,12 @@ create_and_realize (NMDevice *device, vlan_id = nm_setting_vlan_get_id (s_vlan); - plerr = nm_platform_vlan_add (NM_PLATFORM_GET, - iface, - parent_ifindex, - vlan_id, - nm_setting_vlan_get_flags (s_vlan), - out_plink); + plerr = nm_platform_link_vlan_add (NM_PLATFORM_GET, + iface, + parent_ifindex, + vlan_id, + nm_setting_vlan_get_flags (s_vlan), + out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create VLAN interface '%s' for '%s': %s", diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 74803225d8..827a4efad9 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -679,7 +679,7 @@ create_and_realize (NMDevice *device, const char *iface = nm_device_get_iface (device); NMPlatformError plerr; - plerr = nm_platform_team_add (NM_PLATFORM_GET, iface, out_plink); + plerr = nm_platform_link_team_add (NM_PLATFORM_GET, iface, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create team master interface '%s' for '%s': %s", diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 17ccee41b0..d7a4536bb4 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -618,7 +618,7 @@ _linktype_get_type (NMPlatform *platform, NMPlatformTunProperties props; if ( platform - && nm_platform_tun_get_properties_ifname (platform, ifname, &props)) { + && nm_platform_link_tun_get_properties_ifname (platform, ifname, &props)) { if (!g_strcmp0 (props.mode, "tap")) return NM_LINK_TYPE_TAP; if (!g_strcmp0 (props.mode, "tun")) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index cf58e9b252..46cc505404 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -642,7 +642,7 @@ nm_platform_link_add (NMPlatform *self, } /** - * nm_platform_dummy_add: + * nm_platform_link_dummy_add: * @self: platform instance * @name: New interface name * @out_link: on success, the link object @@ -650,7 +650,7 @@ nm_platform_link_add (NMPlatform *self, * Create a software ethernet-like interface */ NMPlatformError -nm_platform_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) +nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0, out_link); } @@ -1476,7 +1476,7 @@ nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformL /*****************************************************************************/ /** - * nm_platform_bridge_add: + * nm_platform_link_bridge_add: * @self: platform instance * @name: New interface name * @address: (allow-none): set the mac address of the new bridge @@ -1486,17 +1486,17 @@ nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformL * Create a software bridge. */ NMPlatformError -nm_platform_bridge_add (NMPlatform *self, - const char *name, - const void *address, - size_t address_len, - const NMPlatformLink **out_link) +nm_platform_link_bridge_add (NMPlatform *self, + const char *name, + const void *address, + size_t address_len, + const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len, out_link); } /** - * nm_platform_bond_add: + * nm_platform_link_bond_add: * @self: platform instance * @name: New interface name * @out_link: on success, the link object @@ -1504,13 +1504,13 @@ nm_platform_bridge_add (NMPlatform *self, * Create a software bonding device. */ NMPlatformError -nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) +nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0, out_link); } /** - * nm_platform_team_add: + * nm_platform_link_team_add: * @self: platform instance * @name: New interface name * @out_link: on success, the link object @@ -1518,13 +1518,13 @@ nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink * * Create a software teaming device. */ NMPlatformError -nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) +nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0, out_link); } /** - * nm_platform_vlan_add: + * nm_platform_link_vlan_add: * @self: platform instance * @name: New interface name * @vlanid: VLAN identifier @@ -1534,7 +1534,7 @@ nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink * * Create a software VLAN device. */ NMPlatformError -nm_platform_vlan_add (NMPlatform *self, +nm_platform_link_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, @@ -1594,7 +1594,7 @@ nm_platform_link_vxlan_add (NMPlatform *self, } /** - * nm_platform_tun_add: + * nm_platform_link_tun_add: * @self: platform instance * @name: new interface name * @tap: whether the interface is a TAP @@ -1608,9 +1608,15 @@ nm_platform_link_vxlan_add (NMPlatform *self, * Create a TUN or TAP interface. */ NMPlatformError -nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, - gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr, - gboolean multi_queue, const NMPlatformLink **out_link) +nm_platform_link_tun_add (NMPlatform *self, + const char *name, + gboolean tap, + gint64 owner, + gint64 group, + gboolean pi, + gboolean vnet_hdr, + gboolean multi_queue, + const NMPlatformLink **out_link) { NMPlatformError plerr; @@ -1747,7 +1753,7 @@ nm_platform_link_vlan_change (NMPlatform *self, } gboolean -nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to) +nm_platform_link_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to) { NMVlanQosMapping map = { .from = from, @@ -1758,7 +1764,7 @@ nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int t } gboolean -nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to) +nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to) { NMVlanQosMapping map = { .from = from, @@ -1808,7 +1814,7 @@ nm_platform_link_gre_add (NMPlatform *self, } NMPlatformError -nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link) +nm_platform_link_infiniband_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link) { gs_free char *parent_name = NULL; gs_free char *name = NULL; @@ -1838,11 +1844,11 @@ nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, c } gboolean -nm_platform_infiniband_get_properties (NMPlatform *self, - int ifindex, - int *out_parent, - int *out_p_key, - const char **out_mode) +nm_platform_link_infiniband_get_properties (NMPlatform *self, + int ifindex, + int *out_parent, + int *out_p_key, + const char **out_mode) { const NMPlatformLnkInfiniband *plnk; const NMPlatformLink *plink; @@ -2063,7 +2069,7 @@ nm_platform_link_sit_add (NMPlatform *self, } gboolean -nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex) +nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex) { const NMPlatformLink *plink; int peer_ifindex; @@ -2093,7 +2099,7 @@ nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_if } gboolean -nm_platform_tun_get_properties_ifname (NMPlatform *self, const char *ifname, NMPlatformTunProperties *props) +nm_platform_link_tun_get_properties_ifname (NMPlatform *self, const char *ifname, NMPlatformTunProperties *props) { char *path, *val; gboolean success = TRUE; @@ -2154,14 +2160,14 @@ nm_platform_tun_get_properties_ifname (NMPlatform *self, const char *ifname, NMP } gboolean -nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props) +nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props) { _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (props != NULL, FALSE); - return nm_platform_tun_get_properties_ifname (self, nm_platform_link_get_name (self, ifindex), props); + return nm_platform_link_tun_get_properties_ifname (self, nm_platform_link_get_name (self, ifindex), props); } gboolean diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 46d1312226..5d9b31bf84 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -700,10 +700,10 @@ const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const ch const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length); GArray *nm_platform_link_get_all (NMPlatform *self); -NMPlatformError nm_platform_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); -NMPlatformError nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link); -NMPlatformError nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); -NMPlatformError nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); +NMPlatformError nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); +NMPlatformError nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link); +NMPlatformError nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); +NMPlatformError nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link); gboolean nm_platform_link_delete (NMPlatform *self, int ifindex); /* convienience methods to lookup the link and access fields of NMPlatformLink. */ @@ -756,6 +756,7 @@ gboolean nm_platform_link_supports_vlans (NMPlatform *self, int ifindex); gboolean nm_platform_link_enslave (NMPlatform *self, int master, int slave); gboolean nm_platform_link_release (NMPlatform *self, int master, int slave); + gboolean nm_platform_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value); char *nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *option); gboolean nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value); @@ -773,9 +774,9 @@ const NMPlatformLnkSit *nm_platform_link_get_lnk_sit (NMPlatform *self, int ifin const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); -NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link); -gboolean nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to); -gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to); +NMPlatformError nm_platform_link_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link); +gboolean nm_platform_link_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to); +gboolean nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_link_vlan_change (NMPlatform *self, int ifindex, NMVlanFlags flags_mask, @@ -789,16 +790,23 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self, NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, const NMPlatformLink **out_link); -NMPlatformError nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, - gboolean vnet_hdr, gboolean multi_queue, const NMPlatformLink **out_link); +NMPlatformError nm_platform_link_tun_add (NMPlatform *self, + const char *name, + gboolean tap, + gint64 owner, + gint64 group, + gboolean pi, + gboolean vnet_hdr, + gboolean multi_queue, + const NMPlatformLink **out_link); -NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link); -gboolean nm_platform_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode); +NMPlatformError nm_platform_link_infiniband_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link); +gboolean nm_platform_link_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode); -gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex); -gboolean nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *properties); +gboolean nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex); +gboolean nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *properties); -gboolean nm_platform_tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props); +gboolean nm_platform_link_tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props); gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps); gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid); diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c index fdf24c7997..68bf2fd70e 100644 --- a/src/platform/tests/test-address.c +++ b/src/platform/tests/test-address.c @@ -354,7 +354,7 @@ _g_test_run (gconstpointer user_data) nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, DEVICE_NAME)); - g_assert_cmpint (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL), ==, NM_PLATFORM_ERROR_SUCCESS); + g_assert_cmpint (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL), ==, NM_PLATFORM_ERROR_SUCCESS); ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); g_assert_cmpint (ifindex, >, 0); diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c index 94ce05491d..9e624a028a 100644 --- a/src/platform/tests/test-cleanup.c +++ b/src/platform/tests/test-cleanup.c @@ -35,7 +35,7 @@ test_cleanup_internal (void) inet_pton (AF_INET6, "2001:db8:e:f:1:2:3:4", &gateway6); /* Create and set up device */ - g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS); + g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS); accept_signal (link_added); free_signal (link_added); g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME), NULL)); diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 8fb00f5bd6..0cee24cd8d 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -61,8 +61,8 @@ test_bogus(void) g_assert (!nm_platform_link_supports_vlans (NM_PLATFORM_GET, BOGUS_IFINDEX)); g_assert (!nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL)); - g_assert (!nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0)); - g_assert (!nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0)); + g_assert (!nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0)); + g_assert (!nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0)); } static void @@ -83,15 +83,15 @@ software_add (NMLinkType link_type, const char *name) { switch (link_type) { case NM_LINK_TYPE_DUMMY: - return nm_platform_dummy_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS; + return nm_platform_link_dummy_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS; case NM_LINK_TYPE_BRIDGE: - return nm_platform_bridge_add (NM_PLATFORM_GET, name, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS; + return nm_platform_link_bridge_add (NM_PLATFORM_GET, name, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS; case NM_LINK_TYPE_BOND: { gboolean bond0_exists = !!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, "bond0"); NMPlatformError plerr; - plerr = nm_platform_bond_add (NM_PLATFORM_GET, name, NULL); + plerr = nm_platform_link_bond_add (NM_PLATFORM_GET, name, NULL); /* Check that bond0 is *not* automatically created. */ if (!bond0_exists) @@ -99,14 +99,14 @@ software_add (NMLinkType link_type, const char *name) return plerr == NM_PLATFORM_ERROR_SUCCESS; } case NM_LINK_TYPE_TEAM: - return nm_platform_team_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS; + return nm_platform_link_team_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS; case NM_LINK_TYPE_VLAN: { SignalData *parent_added; SignalData *parent_changed; /* Don't call link_callback for the bridge interface */ parent_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, PARENT_NAME); - if (nm_platform_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS) + if (nm_platform_link_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS) accept_signal (parent_added); free_signal (parent_added); @@ -123,7 +123,7 @@ software_add (NMLinkType link_type, const char *name) accept_signal (parent_changed); free_signal (parent_changed); - return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS; + return nm_platform_link_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS; } } default: @@ -466,7 +466,7 @@ test_bridge_addr (void) nm_utils_hwaddr_aton ("de:ad:be:ef:00:11", addr, sizeof (addr)); - g_assert_cmpint (nm_platform_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &plink), ==, NM_PLATFORM_ERROR_SUCCESS); + g_assert_cmpint (nm_platform_link_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &plink), ==, NM_PLATFORM_ERROR_SUCCESS); g_assert (plink); link = *plink; g_assert_cmpstr (link.name, ==, DEVICE_NAME); @@ -518,11 +518,11 @@ test_internal (void) g_assert (!nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); /* Add device */ - g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS); + g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS); accept_signal (link_added); /* Try to add again */ - g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_EXISTS); + g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_EXISTS); /* Check device index, name and type */ ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); @@ -1092,58 +1092,58 @@ test_vlan_set_xgress (void) /* ingress-qos-map */ - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 4, 5)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 4, 5)); _assert_ingress_qos_mappings (ifindex, 1, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 3, 7)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 3, 7)); _assert_ingress_qos_mappings (ifindex, 2, 3, 7, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 3, 8)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 3, 8)); _assert_ingress_qos_mappings (ifindex, 2, 3, 8, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, 4)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, 4)); _assert_ingress_qos_mappings (ifindex, 3, 0, 4, 3, 8, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, G_MAXUINT32)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, G_MAXUINT32)); _assert_ingress_qos_mappings (ifindex, 3, 0, G_MAXUINT32, 3, 8, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, G_MAXUINT32 - 1)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, G_MAXUINT32 - 1)); _assert_ingress_qos_mappings (ifindex, 3, 0, G_MAXUINT32 - 1, 3, 8, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, 5)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, 5)); _assert_ingress_qos_mappings (ifindex, 3, 0, 5, 3, 8, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, 5)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 0, 5)); _assert_ingress_qos_mappings (ifindex, 3, 0, 5, 3, 8, 4, 5); /* Set invalid values: */ - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 8, 3)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 8, 3)); _assert_ingress_qos_mappings (ifindex, 3, 0, 5, 3, 8, 4, 5); - g_assert (nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 9, 4)); + g_assert (nm_platform_link_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, 9, 4)); _assert_ingress_qos_mappings (ifindex, 3, 0, 5, 3, 8, @@ -1151,36 +1151,36 @@ test_vlan_set_xgress (void) /* egress-qos-map */ - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 7, 3)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 7, 3)); _assert_egress_qos_mappings (ifindex, 1, 7, 3); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 8, 4)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 8, 4)); _assert_egress_qos_mappings (ifindex, 2, 7, 3, 8, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 0, 4)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 0, 4)); _assert_egress_qos_mappings (ifindex, 3, 0, 4, 7, 3, 8, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 1, 4)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 1, 4)); _assert_egress_qos_mappings (ifindex, 4, 0, 4, 1, 4, 7, 3, 8, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 1, 5)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 1, 5)); _assert_egress_qos_mappings (ifindex, 4, 0, 4, 1, 5, 7, 3, 8, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 9, 5)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 9, 5)); _assert_egress_qos_mappings (ifindex, 5, 0, 4, 1, 5, @@ -1188,7 +1188,7 @@ test_vlan_set_xgress (void) 8, 4, 9, 5); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 8, 5)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 8, 5)); _assert_egress_qos_mappings (ifindex, 5, 0, 4, 1, 5, @@ -1196,27 +1196,27 @@ test_vlan_set_xgress (void) 8, 5, 9, 5); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 8, 0)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 8, 0)); _assert_egress_qos_mappings (ifindex, 4, 0, 4, 1, 5, 7, 3, 9, 5); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 0, 0)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 0, 0)); _assert_egress_qos_mappings (ifindex, 3, 1, 5, 7, 3, 9, 5); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 100, 4)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 100, 4)); _assert_egress_qos_mappings (ifindex, 4, 1, 5, 7, 3, 9, 5, 100, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, G_MAXUINT32, 4)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, G_MAXUINT32, 4)); _assert_egress_qos_mappings (ifindex, 5, 1, 5, 7, 3, @@ -1224,7 +1224,7 @@ test_vlan_set_xgress (void) 100, 4, G_MAXUINT32, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, G_MAXUINT32, 8)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, G_MAXUINT32, 8)); _assert_egress_qos_mappings (ifindex, 5, 1, 5, 7, 3, @@ -1232,20 +1232,20 @@ test_vlan_set_xgress (void) 100, 4, G_MAXUINT32, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, G_MAXUINT32, 0)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, G_MAXUINT32, 0)); _assert_egress_qos_mappings (ifindex, 4, 1, 5, 7, 3, 9, 5, 100, 4); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 100, 0)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 100, 0)); _assert_egress_qos_mappings (ifindex, 3, 1, 5, 7, 3, 9, 5); - g_assert (nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 1, 0)); + g_assert (nm_platform_link_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, 1, 0)); _assert_egress_qos_mappings (ifindex, 2, 7, 3, 9, 5); @@ -1559,11 +1559,11 @@ test_nl_bugs_veth (void) ifindex_veth0 = nmtstp_assert_wait_for_link (IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex; ifindex_veth1 = nmtstp_assert_wait_for_link (IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex; - /* assert that nm_platform_veth_get_properties() returns the expected peer ifindexes. */ - g_assert (nm_platform_veth_get_properties (NM_PLATFORM_GET, ifindex_veth0, &i)); + /* assert that nm_platform_link_veth_get_properties() returns the expected peer ifindexes. */ + g_assert (nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex_veth0, &i)); g_assert_cmpint (i, ==, ifindex_veth1); - g_assert (nm_platform_veth_get_properties (NM_PLATFORM_GET, ifindex_veth1, &i)); + g_assert (nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex_veth1, &i)); g_assert_cmpint (i, ==, ifindex_veth0); /* assert that NMPlatformLink.parent is the peer-ifindex. */ diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index 0ceac56374..f7611f97dc 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -295,7 +295,7 @@ setup_tests (void) nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, DEVICE_NAME)); - g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS); + g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS); accept_signal (link_added); free_signal (link_added); diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index eba7d9ef77..347c122c36 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -876,7 +876,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data) "nm-test-device0"); nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device0")); g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, "nm-test-device0")); - g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, "nm-test-device0", NULL) == NM_PLATFORM_ERROR_SUCCESS); + g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, "nm-test-device0", NULL) == NM_PLATFORM_ERROR_SUCCESS); accept_signal (link_added); free_signal (link_added); fixture->ifindex0 = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device0"); @@ -888,7 +888,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data) "nm-test-device1"); nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device1")); g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, "nm-test-device1")); - g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, "nm-test-device1", NULL) == NM_PLATFORM_ERROR_SUCCESS); + g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, "nm-test-device1", NULL) == NM_PLATFORM_ERROR_SUCCESS); accept_signal (link_added); free_signal (link_added); fixture->ifindex1 = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device1"); From 9166ee6958efc7a751fdad3833db55d8104af6b6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 17:33:30 +0100 Subject: [PATCH 6/9] platform/trivial: rename sysctl slave/master option functions These function purely operate on sysctl by reading/writing to file. Rename them to reflect that they are not related to netlink parts of platform. --- src/devices/nm-device-bond.c | 6 +++--- src/devices/nm-device-bridge.c | 8 ++++---- src/platform/nm-platform.c | 8 ++++---- src/platform/nm-platform.h | 8 ++++---- src/platform/tests/test-link.c | 12 ++++++------ 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 33f0ad159f..5f72ebdae5 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -130,7 +130,7 @@ set_bond_attr (NMDevice *device, const char *attr, const char *value) gboolean ret; int ifindex = nm_device_get_ifindex (device); - ret = nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, attr, value); + ret = nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, attr, value); if (!ret) _LOGW (LOGD_HW, "failed to set bonding attribute '%s' to '%s'", attr, value); return ret; @@ -164,7 +164,7 @@ update_connection (NMDevice *device, NMConnection *connection) /* Read bond options from sysfs and update the Bond setting to match */ options = nm_setting_bond_get_valid_options (s_bond); while (options && *options) { - gs_free char *value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, *options); + gs_free char *value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, *options); const char *defvalue = nm_setting_bond_get_option_default (s_bond, *options); if (value && !ignore_if_zero (*options, value) && (g_strcmp0 (value, defvalue) != 0)) { @@ -320,7 +320,7 @@ apply_bonding_config (NMDevice *device) } /* Clear ARP targets */ - contents = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "arp_ip_target"); + contents = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "arp_ip_target"); set_arp_targets (device, contents, " \n", "-"); g_free (contents); diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 187fee0356..69b67c259e 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -199,9 +199,9 @@ commit_option (NMDevice *device, NMSetting *setting, const Option *option, gbool value = g_strdup_printf ("%u", uval); if (slave) - nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); + nm_platform_sysctl_slave_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); else - nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); + nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); } static void @@ -245,7 +245,7 @@ update_connection (NMDevice *device, NMConnection *connection) } for (option = master_options; option->name; option++) { - gs_free char *str = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, option->sysname); + gs_free char *str = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, option->sysname); int value; if (str) { @@ -284,7 +284,7 @@ master_update_slave_connection (NMDevice *device, } for (option = slave_options; option->name; option++) { - gs_free char *str = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex_slave, option->sysname); + gs_free char *str = nm_platform_sysctl_slave_get_option (NM_PLATFORM_GET, ifindex_slave, option->sysname); int value; if (str) { diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 46cc505404..82568fc32a 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1637,7 +1637,7 @@ nm_platform_link_tun_add (NMPlatform *self, } gboolean -nm_platform_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) +nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) { _CHECK_SELF (self, klass, FALSE); @@ -1650,7 +1650,7 @@ nm_platform_master_set_option (NMPlatform *self, int ifindex, const char *option } char * -nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *option) +nm_platform_sysctl_master_get_option (NMPlatform *self, int ifindex, const char *option) { _CHECK_SELF (self, klass, NULL); @@ -1662,7 +1662,7 @@ nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *option } gboolean -nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) +nm_platform_sysctl_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) { _CHECK_SELF (self, klass, FALSE); @@ -1675,7 +1675,7 @@ nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, } char * -nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *option) +nm_platform_sysctl_slave_get_option (NMPlatform *self, int ifindex, const char *option) { _CHECK_SELF (self, klass, NULL); diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 5d9b31bf84..1913b9c54b 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -757,10 +757,10 @@ gboolean nm_platform_link_supports_vlans (NMPlatform *self, int ifindex); gboolean nm_platform_link_enslave (NMPlatform *self, int master, int slave); gboolean nm_platform_link_release (NMPlatform *self, int master, int slave); -gboolean nm_platform_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value); -char *nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *option); -gboolean nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value); -char *nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *option); +gboolean nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value); +char *nm_platform_sysctl_master_get_option (NMPlatform *self, int ifindex, const char *option); +gboolean nm_platform_sysctl_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value); +char *nm_platform_sysctl_slave_get_option (NMPlatform *self, int ifindex, const char *option); const NMPObject *nm_platform_link_get_lnk (NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link); const NMPlatformLnkGre *nm_platform_link_get_lnk_gre (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 0cee24cd8d..3446983b68 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -274,8 +274,8 @@ test_slave (int master, int type, SignalData *master_changed) switch (type) { case NM_LINK_TYPE_BRIDGE: if (nmtstp_is_sysfs_writable ()) { - g_assert (nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, "priority", "789")); - value = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex, "priority"); + g_assert (nm_platform_sysctl_slave_set_option (NM_PLATFORM_GET, ifindex, "priority", "789")); + value = nm_platform_sysctl_slave_get_option (NM_PLATFORM_GET, ifindex, "priority"); g_assert_cmpstr (value, ==, "789"); g_free (value); } @@ -367,16 +367,16 @@ test_software (NMLinkType link_type, const char *link_typename) switch (link_type) { case NM_LINK_TYPE_BRIDGE: if (nmtstp_is_sysfs_writable ()) { - g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "789")); - value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay"); + g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "789")); + value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay"); g_assert_cmpstr (value, ==, "789"); g_free (value); } break; case NM_LINK_TYPE_BOND: if (nmtstp_is_sysfs_writable ()) { - g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup")); - value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "mode"); + g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup")); + value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "mode"); /* When reading back, the output looks slightly different. */ g_assert (g_str_has_prefix (value, "active-backup")); g_free (value); From 1a7b19ea6aa6008a3297e8befeac6be7cba1cc86 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 17:29:46 +0100 Subject: [PATCH 7/9] platform: move reading sysctl-options for master/slave to NMPlatform These functions are only helpers for accessing sysctl and independent from NMLinuxPlatform. Move their implementation to the base class. --- src/platform/nm-fake-platform.c | 36 ------------- src/platform/nm-linux-platform.c | 87 -------------------------------- src/platform/nm-platform.c | 75 ++++++++++++++++++++++++--- src/platform/nm-platform.h | 4 -- 4 files changed, 67 insertions(+), 135 deletions(-) diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index d6125aaaf3..e6757078c7 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -641,38 +641,6 @@ link_release (NMPlatform *platform, int master_idx, int slave_idx) return TRUE; } -static gboolean -master_set_option (NMPlatform *platform, int master, const char *option, const char *value) -{ - gs_free char *path = g_strdup_printf ("master:%d:%s", master, option); - - return sysctl_set (platform, path, value); -} - -static char * -master_get_option (NMPlatform *platform, int master, const char *option) -{ - gs_free char *path = g_strdup_printf ("master:%d:%s", master, option); - - return sysctl_get (platform, path); -} - -static gboolean -slave_set_option (NMPlatform *platform, int slave, const char *option, const char *value) -{ - gs_free char *path = g_strdup_printf ("slave:%d:%s", slave, option); - - return sysctl_set (platform, path, value); -} - -static char * -slave_get_option (NMPlatform *platform, int slave, const char *option) -{ - gs_free char *path = g_strdup_printf ("slave:%d:%s", slave, option); - - return sysctl_get (platform, path); -} - static gboolean vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, const NMPlatformLink **out_link) { @@ -1478,10 +1446,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass) platform_class->link_enslave = link_enslave; platform_class->link_release = link_release; - platform_class->master_set_option = master_set_option; - platform_class->master_get_option = master_get_option; - platform_class->slave_set_option = slave_set_option; - platform_class->slave_get_option = slave_get_option; platform_class->vlan_add = vlan_add; platform_class->link_vlan_change = link_vlan_change; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index d7a4536bb4..dc816cf8b1 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4801,89 +4801,6 @@ link_release (NMPlatform *platform, int master, int slave) return link_enslave (platform, 0, slave); } -static char * -link_option_path (NMPlatform *platform, int master, const char *category, const char *option) -{ - const char *name = nm_platform_link_get_name (platform, master); - - if (!name || !category || !option) - return NULL; - - return g_strdup_printf ("/sys/class/net/%s/%s/%s", - ASSERT_VALID_PATH_COMPONENT (name), - ASSERT_VALID_PATH_COMPONENT (category), - ASSERT_VALID_PATH_COMPONENT (option)); -} - -static gboolean -link_set_option (NMPlatform *platform, int master, const char *category, const char *option, const char *value) -{ - gs_free char *path = link_option_path (platform, master, category, option); - - return path && nm_platform_sysctl_set (platform, path, value); -} - -static char * -link_get_option (NMPlatform *platform, int master, const char *category, const char *option) -{ - gs_free char *path = link_option_path (platform, master, category, option); - - return path ? nm_platform_sysctl_get (platform, path) : NULL; -} - -static const char * -master_category (NMPlatform *platform, int master) -{ - switch (nm_platform_link_get_type (platform, master)) { - case NM_LINK_TYPE_BRIDGE: - return "bridge"; - case NM_LINK_TYPE_BOND: - return "bonding"; - default: - return NULL; - } -} - -static const char * -slave_category (NMPlatform *platform, int slave) -{ - int master = nm_platform_link_get_master (platform, slave); - - if (master <= 0) - return NULL; - - switch (nm_platform_link_get_type (platform, master)) { - case NM_LINK_TYPE_BRIDGE: - return "brport"; - default: - return NULL; - } -} - -static gboolean -master_set_option (NMPlatform *platform, int master, const char *option, const char *value) -{ - return link_set_option (platform, master, master_category (platform, master), option, value); -} - -static char * -master_get_option (NMPlatform *platform, int master, const char *option) -{ - return link_get_option (platform, master, master_category (platform, master), option); -} - -static gboolean -slave_set_option (NMPlatform *platform, int slave, const char *option, const char *value) -{ - return link_set_option (platform, slave, slave_category (platform, slave), option, value); -} - -static char * -slave_get_option (NMPlatform *platform, int slave, const char *option) -{ - return link_get_option (platform, slave, slave_category (platform, slave), option); -} - /******************************************************************/ static gboolean @@ -5967,10 +5884,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->link_enslave = link_enslave; platform_class->link_release = link_release; - platform_class->master_set_option = master_set_option; - platform_class->master_get_option = master_get_option; - platform_class->slave_set_option = slave_set_option; - platform_class->slave_get_option = slave_get_option; platform_class->vlan_add = vlan_add; platform_class->link_vlan_change = link_vlan_change; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 82568fc32a..e79f48c452 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1636,6 +1636,67 @@ nm_platform_link_tun_add (NMPlatform *self, return NM_PLATFORM_ERROR_SUCCESS; } +/*****************************************************************************/ + +static char * +link_option_path (NMPlatform *self, int master, const char *category, const char *option) +{ + const char *name = nm_platform_link_get_name (self, master); + + if (!name || !category || !option) + return NULL; + + return g_strdup_printf ("/sys/class/net/%s/%s/%s", + ASSERT_VALID_PATH_COMPONENT (name), + ASSERT_VALID_PATH_COMPONENT (category), + ASSERT_VALID_PATH_COMPONENT (option)); +} + +static gboolean +link_set_option (NMPlatform *self, int master, const char *category, const char *option, const char *value) +{ + gs_free char *path = link_option_path (self, master, category, option); + + return path && nm_platform_sysctl_set (self, path, value); +} + +static char * +link_get_option (NMPlatform *self, int master, const char *category, const char *option) +{ + gs_free char *path = link_option_path (self, master, category, option); + + return path ? nm_platform_sysctl_get (self, path) : NULL; +} + +static const char * +master_category (NMPlatform *self, int master) +{ + switch (nm_platform_link_get_type (self, master)) { + case NM_LINK_TYPE_BRIDGE: + return "bridge"; + case NM_LINK_TYPE_BOND: + return "bonding"; + default: + return NULL; + } +} + +static const char * +slave_category (NMPlatform *self, int slave) +{ + int master = nm_platform_link_get_master (self, slave); + + if (master <= 0) + return NULL; + + switch (nm_platform_link_get_type (self, master)) { + case NM_LINK_TYPE_BRIDGE: + return "brport"; + default: + return NULL; + } +} + gboolean nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) { @@ -1644,9 +1705,8 @@ nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (option, FALSE); g_return_val_if_fail (value, FALSE); - g_return_val_if_fail (klass->master_set_option, FALSE); - return klass->master_set_option (self, ifindex, option, value); + return link_set_option (self, ifindex, master_category (self, ifindex), option, value); } char * @@ -1656,9 +1716,8 @@ nm_platform_sysctl_master_get_option (NMPlatform *self, int ifindex, const char g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (option, FALSE); - g_return_val_if_fail (klass->master_set_option, FALSE); - return klass->master_get_option (self, ifindex, option); + return link_get_option (self, ifindex, master_category (self, ifindex), option); } gboolean @@ -1669,9 +1728,8 @@ nm_platform_sysctl_slave_set_option (NMPlatform *self, int ifindex, const char * g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (option, FALSE); g_return_val_if_fail (value, FALSE); - g_return_val_if_fail (klass->slave_set_option, FALSE); - return klass->slave_set_option (self, ifindex, option, value); + return link_set_option (self, ifindex, slave_category (self, ifindex), option, value); } char * @@ -1681,11 +1739,12 @@ nm_platform_sysctl_slave_get_option (NMPlatform *self, int ifindex, const char * g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (option, FALSE); - g_return_val_if_fail (klass->slave_set_option, FALSE); - return klass->slave_get_option (self, ifindex, option); + return link_get_option (self, ifindex, slave_category (self, ifindex), option); } +/******************************************************************************/ + gboolean nm_platform_link_vlan_change (NMPlatform *self, int ifindex, diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 1913b9c54b..143ab2d994 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -545,10 +545,6 @@ typedef struct { gboolean (*link_enslave) (NMPlatform *, int master, int slave); gboolean (*link_release) (NMPlatform *, int master, int slave); - gboolean (*master_set_option) (NMPlatform *, int ifindex, const char *option, const char *value); - char * (*master_get_option) (NMPlatform *, int ifindex, const char *option); - gboolean (*slave_set_option) (NMPlatform *, int ifindex, const char *option, const char *value); - char * (*slave_get_option) (NMPlatform *, int ifindex, const char *option); gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link); gboolean (*link_vlan_change) (NMPlatform *self, From 9eea5b63a297115808d784e61bab1c9c54b42324 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 17:47:58 +0100 Subject: [PATCH 8/9] platform: remove g_return() checks for platform klass implementation With g_return() we try to catch wrong invocations of a function or passing invalid arguments. Having ~forgot~ to overwrite a virtual function is such a serious and fundamental issue, that checking for it at runtime is wasteful and unnessesary. If we ever hit such a situation, just crash. --- src/platform/nm-platform.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index e79f48c452..9eff6406e3 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -281,7 +281,6 @@ nm_platform_sysctl_set (NMPlatform *self, const char *path, const char *value) g_return_val_if_fail (path, FALSE); g_return_val_if_fail (value, FALSE); - g_return_val_if_fail (klass->sysctl_set, FALSE); return klass->sysctl_set (self, path, value); } @@ -333,7 +332,6 @@ nm_platform_sysctl_get (NMPlatform *self, const char *path) _CHECK_SELF (self, klass, NULL); g_return_val_if_fail (path, NULL); - g_return_val_if_fail (klass->sysctl_get, NULL); return klass->sysctl_get (self, path); } @@ -413,8 +411,6 @@ nm_platform_link_get_all (NMPlatform *self) _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (klass->link_get_all, NULL); - links = klass->link_get_all (self); if (!links || links->len == 0) @@ -628,7 +624,6 @@ nm_platform_link_add (NMPlatform *self, _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG); g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG); - g_return_val_if_fail (klass->link_add, NM_PLATFORM_ERROR_BUG); g_return_val_if_fail ( (address != NULL) ^ (address_len == 0) , NM_PLATFORM_ERROR_BUG); plerr = _link_add_check_existing (self, name, type, out_link); @@ -744,8 +739,6 @@ nm_platform_link_get_type_name (NMPlatform *self, int ifindex) { _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (klass->link_get_type_name, NULL); - return klass->link_get_type_name (self, ifindex); } @@ -971,7 +964,6 @@ nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolea _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (klass->check_support_user_ipv6ll, FALSE); if (klass->link_set_user_ipv6ll_enabled) return klass->link_set_user_ipv6ll_enabled (self, ifindex, enabled); @@ -994,7 +986,6 @@ nm_platform_link_set_address (NMPlatform *self, int ifindex, gconstpointer addre g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (address, FALSE); g_return_val_if_fail (length > 0, FALSE); - g_return_val_if_fail (klass->link_set_address, FALSE); _LOGD ("link: setting '%s' (%d) hardware address", nm_platform_link_get_name (self, ifindex), ifindex); return klass->link_set_address (self, ifindex, address, length); @@ -1073,7 +1064,6 @@ nm_platform_link_supports_carrier_detect (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (klass->link_supports_carrier_detect, FALSE); return klass->link_supports_carrier_detect (self, ifindex); } @@ -1084,7 +1074,6 @@ nm_platform_link_supports_vlans (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (klass->link_supports_vlans, FALSE); return klass->link_supports_vlans (self, ifindex); } @@ -1103,7 +1092,6 @@ nm_platform_link_set_up (NMPlatform *self, int ifindex, gboolean *out_no_firmwar _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (klass->link_set_up, FALSE); _LOGD ("link: setting up '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); return klass->link_set_up (self, ifindex, out_no_firmware); @@ -1122,7 +1110,6 @@ nm_platform_link_set_down (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (klass->link_set_down, FALSE); _LOGD ("link: setting down '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); return klass->link_set_down (self, ifindex); @@ -1141,7 +1128,6 @@ nm_platform_link_set_arp (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (klass->link_set_arp, FALSE); _LOGD ("link: setting arp '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); return klass->link_set_arp (self, ifindex); @@ -1160,7 +1146,6 @@ nm_platform_link_set_noarp (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (klass->link_set_noarp, FALSE); _LOGD ("link: setting noarp '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); return klass->link_set_noarp (self, ifindex); @@ -1181,7 +1166,6 @@ nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu) g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (mtu > 0, FALSE); - g_return_val_if_fail (klass->link_set_mtu, FALSE); _LOGD ("link: setting '%s' (%d) mtu %"G_GUINT32_FORMAT, nm_platform_link_get_name (self, ifindex), ifindex, mtu); return klass->link_set_mtu (self, ifindex, mtu); @@ -1296,7 +1280,6 @@ nm_platform_link_get_driver_info (NMPlatform *self, _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (klass->link_get_driver_info, FALSE); return klass->link_get_driver_info (self, ifindex, @@ -1320,7 +1303,6 @@ nm_platform_link_enslave (NMPlatform *self, int master, int slave) g_return_val_if_fail (master > 0, FALSE); g_return_val_if_fail (slave> 0, FALSE); - g_return_val_if_fail (klass->link_enslave, FALSE); _LOGD ("link: enslaving '%s' (%d) to master '%s' (%d)", nm_platform_link_get_name (self, slave), slave, @@ -1343,7 +1325,6 @@ nm_platform_link_release (NMPlatform *self, int master, int slave) g_return_val_if_fail (master > 0, FALSE); g_return_val_if_fail (slave > 0, FALSE); - g_return_val_if_fail (klass->link_release, FALSE); if (nm_platform_link_get_master (self, slave) != master) return FALSE; @@ -1548,7 +1529,6 @@ nm_platform_link_vlan_add (NMPlatform *self, g_return_val_if_fail (parent >= 0, NM_PLATFORM_ERROR_BUG); g_return_val_if_fail (vlanid >= 0, NM_PLATFORM_ERROR_BUG); g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG); - g_return_val_if_fail (klass->vlan_add, NM_PLATFORM_ERROR_BUG); plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VLAN, out_link); if (plerr != NM_PLATFORM_ERROR_SUCCESS) @@ -1623,7 +1603,6 @@ nm_platform_link_tun_add (NMPlatform *self, _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG); g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG); - g_return_val_if_fail (klass->tun_add, NM_PLATFORM_ERROR_BUG); plerr = _link_add_check_existing (self, name, tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, out_link); if (plerr != NM_PLATFORM_ERROR_SUCCESS) @@ -1883,7 +1862,6 @@ nm_platform_link_infiniband_add (NMPlatform *self, int parent, int p_key, const g_return_val_if_fail (parent >= 0, NM_PLATFORM_ERROR_BUG); g_return_val_if_fail (p_key >= 0, NM_PLATFORM_ERROR_BUG); - g_return_val_if_fail (klass->infiniband_partition_add, NM_PLATFORM_ERROR_BUG); parent_name = g_strdup (nm_platform_link_get_name (self, parent)); if ( !parent_name @@ -2416,7 +2394,6 @@ nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, NULL); g_return_val_if_fail (ifindex > 0, NULL); - g_return_val_if_fail (klass->ip4_address_get_all, NULL); return klass->ip4_address_get_all (self, ifindex); } @@ -2427,7 +2404,6 @@ nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, NULL); g_return_val_if_fail (ifindex > 0, NULL); - g_return_val_if_fail (klass->ip6_address_get_all, NULL); return klass->ip6_address_get_all (self, ifindex); } @@ -2448,7 +2424,6 @@ nm_platform_ip4_address_add (NMPlatform *self, g_return_val_if_fail (plen > 0, FALSE); g_return_val_if_fail (lifetime > 0, FALSE); g_return_val_if_fail (preferred <= lifetime, FALSE); - g_return_val_if_fail (klass->ip4_address_add, FALSE); g_return_val_if_fail (!label || strlen (label) < sizeof (((NMPlatformIP4Address *) NULL)->label), FALSE); if (_LOGD_ENABLED ()) { @@ -2485,7 +2460,6 @@ nm_platform_ip6_address_add (NMPlatform *self, g_return_val_if_fail (plen > 0, FALSE); g_return_val_if_fail (lifetime > 0, FALSE); g_return_val_if_fail (preferred <= lifetime, FALSE); - g_return_val_if_fail (klass->ip6_address_add, FALSE); if (_LOGD_ENABLED ()) { NMPlatformIP6Address addr = { 0 }; @@ -2515,7 +2489,6 @@ nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (plen > 0, FALSE); - g_return_val_if_fail (klass->ip4_address_delete, FALSE); _LOGD ("address: deleting IPv4 address %s/%d, %sifindex %d%s", nm_utils_inet4_ntop (address, NULL), plen, @@ -2535,7 +2508,6 @@ nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr a g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (plen > 0, FALSE); - g_return_val_if_fail (klass->ip6_address_delete, FALSE); _LOGD ("address: deleting IPv6 address %s/%d, ifindex %d%s", nm_utils_inet6_ntop (&address, NULL), plen, ifindex, @@ -2768,7 +2740,6 @@ nm_platform_ip4_route_add (NMPlatform *self, _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (0 <= plen && plen <= 32, FALSE); - g_return_val_if_fail (klass->ip4_route_add, FALSE); if (_LOGD_ENABLED ()) { NMPlatformIP4Route route = { 0 }; @@ -2796,7 +2767,6 @@ nm_platform_ip6_route_add (NMPlatform *self, _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (0 <= plen && plen <= 128, FALSE); - g_return_val_if_fail (klass->ip6_route_add, FALSE); if (_LOGD_ENABLED ()) { NMPlatformIP6Route route = { 0 }; @@ -2821,8 +2791,6 @@ nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, _CHECK_SELF (self, klass, FALSE); - g_return_val_if_fail (klass->ip4_route_delete, FALSE); - _LOGD ("route: deleting IPv4 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s", nm_utils_inet4_ntop (network, NULL), plen, metric, ifindex, _to_string_dev (self, ifindex, str_dev, sizeof (str_dev))); @@ -2836,8 +2804,6 @@ nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr net _CHECK_SELF (self, klass, FALSE); - g_return_val_if_fail (klass->ip6_route_delete, FALSE); - _LOGD ("route: deleting IPv6 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s", nm_utils_inet6_ntop (&network, NULL), plen, metric, ifindex, _to_string_dev (self, ifindex, str_dev, sizeof (str_dev))); From 76521816a572e8da5c1e094a14fc320e4d79dc3f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Dec 2015 18:03:07 +0100 Subject: [PATCH 9/9] platform/trivial: remove obsolete code comment The explainations no longer hold for the most part. Documentation that is not directly the code is bound the expire. The code is the best documentation!! :) --- src/platform/nm-platform.h | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 143ab2d994..e57c023b7c 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -456,34 +456,6 @@ typedef struct { /******************************************************************/ -/* NMPlatform abstract class and its implementations provide a layer between - * networkmanager's device management classes and the operating system kernel. - * - * How it works, is best seen in tests/nm-platform-test.c source file. - * - * NMPlatform provides interface to configure kernel interfaces and receive - * notifications about both internal and external configuration changes. It - * respects the following rules: - * - * 1) Every change made through NMPlatform is readily available and the respective - * signals are called synchronously. - * - * 2) State of an object retrieved from NMPlatform (through functions or events) - * is at least as recent than the state retrieved before. - * - * Any failure of the above rules should be fixed in NMPlatform implementations - * and tested in nm-platform-test. Synchronization hacks should never be put - * to any other code. That's why NMPlatform was created and that's why the - * testing code was written for it. - * - * In future, parts of linux platform implementation may be moved to the libnl - * library. - * - * If you have any problems related to NMPlatform on your system, you should - * always first run tests/nm-linux-platform-test as root and with all - * network configuration daemons stopped. Look at the code first. - */ - struct _NMPlatform { GObject parent; };