diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 342350a6cb..980b6a8d96 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -1324,7 +1324,7 @@ get_new_connection_ifname (const GSList *existing, for (i = 0; i < 500; i++) { name = g_strdup_printf ("%s%d", prefix, i); - if (nm_platform_link_exists (name)) + if (nm_platform_link_exists (NM_PLATFORM_GET, name)) goto next; for (iter = existing, found = FALSE; iter; iter = g_slist_next (iter)) { diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index ce265ba447..fe26adbfcf 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -144,7 +144,7 @@ set_nas_iface (NMDeviceAdsl *self, int idx, const char *name) g_return_if_fail (name != NULL); g_warn_if_fail (priv->nas_ifindex <= 0); - priv->nas_ifindex = idx > 0 ? idx : nm_platform_link_get_ifindex (name); + priv->nas_ifindex = idx > 0 ? idx : nm_platform_link_get_ifindex (NM_PLATFORM_GET, name); g_warn_if_fail (priv->nas_ifindex > 0); g_warn_if_fail (priv->nas_ifname == NULL); @@ -352,7 +352,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_reason) _LOGD (LOGD_ADSL, "ATM setup successful"); /* otherwise we're good for stage3 */ - nm_platform_link_set_up (priv->nas_ifindex); + nm_platform_link_set_up (NM_PLATFORM_GET, priv->nas_ifindex); ret = NM_ACT_STAGE_RETURN_SUCCESS; } else if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA) == 0) { @@ -492,7 +492,7 @@ carrier_update_cb (gpointer user_data) path = g_strdup_printf ("/sys/class/atm/%s/carrier", ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (NM_DEVICE (self)))); - carrier = (int) nm_platform_sysctl_get_int_checked (path, 10, 0, 1, -1); + carrier = (int) nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, path, 10, 0, 1, -1); g_free (path); if (carrier != -1) @@ -526,7 +526,7 @@ get_atm_index (const char *iface) path = g_strdup_printf ("/sys/class/atm/%s/atmindex", ASSERT_VALID_PATH_COMPONENT (iface)); - idx = (int) nm_platform_sysctl_get_int_checked (path, 10, 0, G_MAXINT, -1); + idx = (int) nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, path, 10, 0, G_MAXINT, -1); g_free (path); return idx; diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index c0d7141f37..0821fe4253 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -145,7 +145,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 (ifindex, attr, value); + ret = nm_platform_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; @@ -179,7 +179,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 (ifindex, *options); + gs_free char *value = nm_platform_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)) { @@ -335,7 +335,7 @@ apply_bonding_config (NMDevice *device) } /* Clear ARP targets */ - contents = nm_platform_master_get_option (ifindex, "arp_ip_target"); + contents = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "arp_ip_target"); set_arp_targets (device, contents, " \n", "-"); g_free (contents); @@ -411,7 +411,8 @@ enslave_slave (NMDevice *device, if (configure) { nm_device_take_down (slave, TRUE); - success = nm_platform_link_enslave (nm_device_get_ip_ifindex (device), + success = nm_platform_link_enslave (NM_PLATFORM_GET, + nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); @@ -435,7 +436,8 @@ release_slave (NMDevice *device, gboolean success = TRUE, no_firmware = FALSE; if (configure) { - success = nm_platform_link_release (nm_device_get_ip_ifindex (device), + success = nm_platform_link_release (NM_PLATFORM_GET, + nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) { @@ -581,11 +583,11 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, iface = nm_connection_get_interface_name (connection); g_return_val_if_fail (iface != NULL, NULL); - if ( !nm_platform_bond_add (iface) - && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) { + if ( !nm_platform_bond_add (NM_PLATFORM_GET, iface) + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { nm_log_warn (LOGD_DEVICE | LOGD_BOND, "(%s): failed to create bonding master interface for '%s': %s", iface, nm_connection_get_id (connection), - nm_platform_get_error_msg ()); + nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index d2cc70c1bf..30081e1e23 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -213,9 +213,9 @@ commit_option (NMDevice *device, NMSetting *setting, const Option *option, gbool value = g_strdup_printf ("%u", uval); if (slave) - nm_platform_slave_set_option (ifindex, option->sysname, value); + nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); else - nm_platform_master_set_option (ifindex, option->sysname, value); + nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); } static void @@ -259,7 +259,7 @@ update_connection (NMDevice *device, NMConnection *connection) } for (option = master_options; option->name; option++) { - gs_free char *str = nm_platform_master_get_option (ifindex, option->sysname); + gs_free char *str = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, option->sysname); int value; if (str) { @@ -298,7 +298,7 @@ master_update_slave_connection (NMDevice *device, } for (option = slave_options; option->name; option++) { - gs_free char *str = nm_platform_slave_get_option (ifindex_slave, option->sysname); + gs_free char *str = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex_slave, option->sysname); int value; if (str) { @@ -346,7 +346,7 @@ enslave_slave (NMDevice *device, NMDeviceBridge *self = NM_DEVICE_BRIDGE (device); if (configure) { - if (!nm_platform_link_enslave (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave))) + if (!nm_platform_link_enslave (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave))) return FALSE; commit_slave_options (slave, nm_connection_get_setting_bridge_port (connection)); @@ -372,7 +372,8 @@ release_slave (NMDevice *device, gboolean success = TRUE; if (configure) { - success = nm_platform_link_release (nm_device_get_ip_ifindex (device), + success = nm_platform_link_release (NM_PLATFORM_GET, + nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) { @@ -519,13 +520,14 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, mac_address_str = NULL; } - if ( !nm_platform_bridge_add (iface, + if ( !nm_platform_bridge_add (NM_PLATFORM_GET, + iface, mac_address_str ? mac_address : NULL, mac_address_str ? ETH_ALEN : 0) - && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) { + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { nm_log_warn (LOGD_DEVICE | LOGD_BRIDGE, "(%s): failed to create bridge master interface for '%s': %s", iface, nm_connection_get_id (connection), - nm_platform_get_error_msg ()); + nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 7fa3d3a41e..f50da78d64 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -210,7 +210,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) || !strcmp (item, "portno")) { char *path, *value; path = g_strdup_printf ("%s/%s", parent_path, item); - value = nm_platform_sysctl_get (path); + value = nm_platform_sysctl_get (NM_PLATFORM_GET, path); if (value && *value) g_hash_table_insert (priv->s390_options, g_strdup (item), g_strdup (value)); else @@ -263,7 +263,7 @@ constructor (GType type, if (object) { #ifndef G_DISABLE_ASSERT int ifindex = nm_device_get_ifindex (NM_DEVICE (object)); - NMLinkType link_type = nm_platform_link_get_type (ifindex); + NMLinkType link_type = nm_platform_link_get_type (NM_PLATFORM_GET, ifindex); g_assert ( link_type == NM_LINK_TYPE_ETHERNET || link_type == NM_LINK_TYPE_VETH @@ -375,7 +375,7 @@ get_generic_capabilities (NMDevice *device) { NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device); - if (nm_platform_link_supports_carrier_detect (nm_device_get_ifindex (device))) + if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, nm_device_get_ifindex (device))) return NM_DEVICE_CAP_CARRIER_DETECT; else { _LOGI (LOGD_HW, "driver '%s' does not support carrier detection.", @@ -1160,7 +1160,7 @@ dcb_state (NMDevice *device, gboolean timeout) g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_CONFIG); - carrier = nm_platform_link_is_connected (nm_device_get_ifindex (device)); + carrier = nm_platform_link_is_connected (NM_PLATFORM_GET, nm_device_get_ifindex (device)); _LOGD (LOGD_DCB, "dcb_state() wait %d carrier %d timeout %d", priv->dcb_wait, carrier, timeout); switch (priv->dcb_wait) { @@ -1278,7 +1278,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason) s_dcb = (NMSettingDcb *) device_get_setting (device, NM_TYPE_SETTING_DCB); if (s_dcb) { /* lldpad really really wants the carrier to be up */ - if (nm_platform_link_is_connected (nm_device_get_ifindex (device))) { + if (nm_platform_link_is_connected (NM_PLATFORM_GET, nm_device_get_ifindex (device))) { if (!dcb_enable (device)) { *reason = NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED; return NM_ACT_STAGE_RETURN_FAILURE; diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c index 0704c7d313..8b328e07fe 100644 --- a/src/devices/nm-device-generic.c +++ b/src/devices/nm-device-generic.c @@ -48,7 +48,7 @@ enum { static NMDeviceCapabilities get_generic_capabilities (NMDevice *dev) { - if (nm_platform_link_supports_carrier_detect (nm_device_get_ifindex (dev))) + if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, nm_device_get_ifindex (dev))) return NM_DEVICE_CAP_CARRIER_DETECT; else return NM_DEVICE_CAP_NONE; @@ -117,7 +117,7 @@ constructed (GObject *object) int ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self)); if (ifindex != 0) - priv->type_description = g_strdup (nm_platform_link_get_type_name (ifindex)); + priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex)); } G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object); diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c index 9c25b398ce..6313bfd714 100644 --- a/src/devices/nm-device-gre.c +++ b/src/devices/nm-device-gre.c @@ -71,7 +71,7 @@ update_properties (NMDevice *device) GObject *object = G_OBJECT (device); NMPlatformGreProperties props; - if (!nm_platform_gre_get_properties (nm_device_get_ifindex (device), &props)) { + if (!nm_platform_gre_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_HW, "could not read gre properties"); return; } diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index cfb15c76e4..0a3b17c708 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -105,7 +105,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) } } - ok = nm_platform_sysctl_set (mode_path, transport_mode); + ok = nm_platform_sysctl_set (NM_PLATFORM_GET, mode_path, transport_mode); g_free (mode_path); if (!ok) { @@ -226,7 +226,7 @@ update_connection (NMDevice *device, NMConnection *connection) mode_path = g_strdup_printf ("/sys/class/net/%s/mode", ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (device))); - contents = nm_platform_sysctl_get (mode_path); + contents = nm_platform_sysctl_get (NM_PLATFORM_GET, mode_path); g_free (mode_path); if (contents) { if (strstr (contents, "datagram")) @@ -328,11 +328,11 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, parent_ifindex = nm_device_get_ifindex (parent); p_key = nm_setting_infiniband_get_p_key (s_infiniband); - if ( !nm_platform_infiniband_partition_add (parent_ifindex, p_key) - && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) { + if ( !nm_platform_infiniband_partition_add (NM_PLATFORM_GET, parent_ifindex, p_key) + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { nm_log_warn (LOGD_DEVICE | LOGD_INFINIBAND, "(%s): failed to add InfiniBand P_Key interface for '%s': %s", iface, nm_connection_get_id (connection), - nm_platform_get_error_msg ()); + nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index bcd3861774..608e541db0 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -64,7 +64,7 @@ update_properties (NMDevice *device) GObject *object = G_OBJECT (device); NMPlatformMacvlanProperties props; - if (!nm_platform_macvlan_get_properties (nm_device_get_ifindex (device), &props)) { + if (!nm_platform_macvlan_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_HW, "could not read macvlan properties"); return; } diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 9a3fab5ec8..4f4ed69b25 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -65,7 +65,7 @@ reload_tun_properties (NMDeviceTun *self) GObject *object = G_OBJECT (self); NMPlatformTunProperties props; - if (!nm_platform_tun_get_properties (nm_device_get_ifindex (NM_DEVICE (self)), &props)) { + if (!nm_platform_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &props)) { _LOGD (LOGD_HW, "could not read tun properties"); return; } @@ -123,7 +123,7 @@ constructed (GObject *object) gboolean properties_read; NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (self); - properties_read = nm_platform_tun_get_properties (nm_device_get_ifindex (NM_DEVICE (self)), &priv->props); + properties_read = nm_platform_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &priv->props); G_OBJECT_CLASS (nm_device_tun_parent_class)->constructed (object); diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index 6a05cc3214..5eba1b3c39 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -82,7 +82,7 @@ get_peer (NMDeviceVeth *self) if (priv->ever_had_peer) return priv->peer; - if (!nm_platform_veth_get_properties (nm_device_get_ifindex (device), &props)) { + if (!nm_platform_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _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 2f32d3165b..34fa585488 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -281,7 +281,7 @@ update_connection (NMDevice *device, NMConnection *connection) nm_connection_add_setting (connection, (NMSetting *) s_vlan); } - if (!nm_platform_vlan_get_info (ifindex, &parent_ifindex, &vlan_id)) { + if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent_ifindex, &vlan_id)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info while updating connection."); return; } @@ -353,12 +353,12 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) num = nm_setting_vlan_get_num_priorities (s_vlan, NM_VLAN_INGRESS_MAP); for (i = 0; i < num; i++) { if (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_INGRESS_MAP, i, &from, &to)) - nm_platform_vlan_set_ingress_map (ifindex, from, to); + nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, from, to); } num = nm_setting_vlan_get_num_priorities (s_vlan, NM_VLAN_EGRESS_MAP); for (i = 0; i < num; i++) { if (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, i, &from, &to)) - nm_platform_vlan_set_egress_map (ifindex, from, to); + nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, from, to); } } @@ -437,14 +437,14 @@ constructed (GObject *object) return; } - itype = nm_platform_link_get_type (ifindex); + itype = nm_platform_link_get_type (NM_PLATFORM_GET, ifindex); if (itype != NM_LINK_TYPE_VLAN) { _LOGE (LOGD_VLAN, "failed to get VLAN interface type."); priv->invalid = TRUE; return; } - if (!nm_platform_vlan_get_info (ifindex, &parent_ifindex, &vlan_id)) { + if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent_ifindex, &vlan_id)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info."); priv->invalid = TRUE; return; @@ -603,7 +603,7 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error) return NULL; /* Have to find the parent device */ - if (!nm_platform_vlan_get_info (plink->ifindex, &parent_ifindex, NULL)) { + if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, plink->ifindex, &parent_ifindex, NULL)) { nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", plink->name); return NULL; } @@ -662,11 +662,12 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, nm_setting_vlan_get_id (s_vlan)); } - if ( !nm_platform_vlan_add (iface, + if ( !nm_platform_vlan_add (NM_PLATFORM_GET, + iface, nm_device_get_ifindex (parent), nm_setting_vlan_get_id (s_vlan), nm_setting_vlan_get_flags (s_vlan)) - && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) { + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { nm_log_warn (LOGD_DEVICE | LOGD_VLAN, "(%s) failed to add VLAN interface for '%s'", iface, nm_connection_get_id (connection)); g_free (iface); diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index ed6b8fa051..25ee804dfa 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -76,7 +76,7 @@ update_properties (NMDevice *device) GObject *object = G_OBJECT (device); NMPlatformVxlanProperties props; - if (!nm_platform_vxlan_get_properties (nm_device_get_ifindex (device), &props)) { + if (!nm_platform_vxlan_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_HW, "could not read vxlan properties"); return; } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 99ba3d5a6c..d0c5d8a332 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -464,13 +464,13 @@ reason_to_string (NMDeviceStateReason reason) gboolean nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *value) { - return nm_platform_sysctl_set (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property), value); + return nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property), value); } static guint32 nm_device_ipv6_sysctl_get_int32 (NMDevice *self, const char *property, gint32 fallback) { - return nm_platform_sysctl_get_int32 (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property), fallback); + return nm_platform_sysctl_get_int32 (NM_PLATFORM_GET, nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property), fallback); } gboolean @@ -578,13 +578,13 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) priv->ip_iface = g_strdup (iface); if (priv->ip_iface) { - priv->ip_ifindex = nm_platform_link_get_ifindex (priv->ip_iface); + priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface); if (priv->ip_ifindex > 0) { - if (nm_platform_check_support_user_ipv6ll ()) - nm_platform_link_set_user_ipv6ll_enabled (priv->ip_ifindex, TRUE); + if (nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET)) + nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, priv->ip_ifindex, TRUE); - if (!nm_platform_link_is_up (priv->ip_ifindex)) - nm_platform_link_set_up (priv->ip_ifindex); + if (!nm_platform_link_is_up (NM_PLATFORM_GET, priv->ip_ifindex)) + nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex); } else { /* Device IP interface must always be a kernel network interface */ _LOGW (LOGD_HW, "failed to look up interface index"); @@ -614,10 +614,10 @@ get_ip_iface_identifier (NMDevice *self, NMUtilsIPv6IfaceId *out_iid) ifindex = nm_device_get_ip_ifindex (self); g_assert (ifindex); - link_type = nm_platform_link_get_type (ifindex); + link_type = nm_platform_link_get_type (NM_PLATFORM_GET, ifindex); g_return_val_if_fail (link_type > NM_LINK_TYPE_UNKNOWN, 0); - hwaddr = nm_platform_link_get_address (ifindex, &hwaddr_len); + hwaddr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddr_len); if (!hwaddr_len) return FALSE; @@ -1042,7 +1042,7 @@ nm_device_finish_init (NMDevice *self) /* Do not manage externally created software devices until they are IFF_UP */ if ( is_software_external (self) - && !nm_platform_link_is_up (priv->ifindex) + && !nm_platform_link_is_up (NM_PLATFORM_GET, priv->ifindex) && priv->ifindex > 0) nm_device_set_initial_unmanaged_flag (self, NM_UNMANAGED_EXTERNAL_DOWN, TRUE); @@ -1230,7 +1230,7 @@ device_set_master (NMDevice *self, int ifindex) } else { _LOGW (LOGD_DEVICE, "enslaved to unknown device %d %s", ifindex, - nm_platform_link_get_name (ifindex)); + nm_platform_link_get_name (NM_PLATFORM_GET, ifindex)); } } @@ -1286,7 +1286,7 @@ device_link_changed (NMDevice *self, NMPlatformLink *info) nm_device_enslave_slave (priv->master, self, NULL); } - if (priv->rdisc && nm_platform_link_get_ipv6_token (priv->ifindex, &token_iid)) { + if (priv->rdisc && nm_platform_link_get_ipv6_token (NM_PLATFORM_GET, priv->ifindex, &token_iid)) { _LOGD (LOGD_DEVICE, "IPv6 tokenized identifier present on device %s", priv->iface); if (nm_rdisc_set_iid (priv->rdisc, token_iid)) nm_rdisc_start (priv->rdisc); @@ -1979,7 +1979,7 @@ device_has_config (NMDevice *self) return TRUE; /* Slaves are also configured by definition */ - if (nm_platform_link_get_master (priv->ifindex) > 0) + if (nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex) > 0) return TRUE; return FALSE; @@ -2876,9 +2876,9 @@ _device_get_default_route_from_platform (NMDevice *self, int addr_family, NMPlat GArray *routes; if (addr_family == AF_INET) - routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); + routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); else - routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); + routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); if (routes) { guint route_metric = G_MAXUINT32, m; @@ -3171,7 +3171,7 @@ dhcp4_start (NMDevice *self, g_object_unref (priv->dhcp4_config); priv->dhcp4_config = nm_dhcp4_config_new (); - hw_addr = nm_platform_link_get_address (nm_device_get_ip_ifindex (self), &hw_addr_len); + hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), &hw_addr_len); if (hw_addr_len) { tmp = g_byte_array_sized_new (hw_addr_len); g_byte_array_append (tmp, hw_addr, hw_addr_len); @@ -3768,7 +3768,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection) s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip6); - hw_addr = nm_platform_link_get_address (nm_device_get_ip_ifindex (self), &hw_addr_len); + hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), &hw_addr_len); if (hw_addr_len) { tmp = g_byte_array_sized_new (hw_addr_len); g_byte_array_append (tmp, hw_addr, hw_addr_len); @@ -3973,7 +3973,8 @@ check_and_add_ipv6ll_addr (NMDevice *self) lladdr.s6_addr16[0] = htons (0xfe80); nm_utils_ipv6_addr_set_interface_identfier (&lladdr, iid); _LOGD (LOGD_IP6, "adding IPv6LL address %s", nm_utils_inet6_ntop (&lladdr, NULL)); - if (!nm_platform_ip6_address_add (ip_ifindex, + if (!nm_platform_ip6_address_add (NM_PLATFORM_GET, + ip_ifindex, lladdr, in6addr_any, 64, @@ -4023,7 +4024,7 @@ print_support_extended_ifa_flags (NMSettingIP6ConfigPrivacy use_tempaddr) if (s_libnl == -1) { s_libnl = !!nm_platform_check_support_libnl_extended_ifa_flags (); - s_kernel = !!nm_platform_check_support_kernel_extended_ifa_flags (); + s_kernel = !!nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET); if (s_libnl && s_kernel) { nm_log_dbg (LOGD_IP6, "kernel and libnl support extended IFA_FLAGS (needed by NM for IPv6 private addresses)"); @@ -4074,8 +4075,8 @@ nm_device_set_mtu (NMDevice *self, guint32 mtu) if (priv->ip6_mtu) nm_device_ipv6_set_mtu (self, priv->ip6_mtu); - if (priv->mtu != nm_platform_link_get_mtu (ifindex)) - nm_platform_link_set_mtu (ifindex, priv->mtu); + if (priv->mtu != nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex)) + nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, priv->mtu); } static void @@ -4128,7 +4129,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self) * from adding a prefix route for this address. **/ system_support = nm_platform_check_support_libnl_extended_ifa_flags () && - nm_platform_check_support_kernel_extended_ifa_flags (); + nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET); } if (system_support) @@ -4249,7 +4250,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self) } if (changed & NM_RDISC_CONFIG_HOP_LIMIT) - nm_platform_sysctl_set_ip6_hop_limit_safe (nm_device_get_ip_iface (self), rdisc->hop_limit); + nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, nm_device_get_ip_iface (self), rdisc->hop_limit); if (changed & NM_RDISC_CONFIG_MTU) priv->ip6_mtu = rdisc->mtu; @@ -4289,7 +4290,7 @@ addrconf6_start_with_link_ready (NMDevice *self) g_assert (priv->rdisc); - if (nm_platform_link_get_ipv6_token (priv->ifindex, &iid)) { + if (nm_platform_link_get_ipv6_token (NM_PLATFORM_GET, priv->ifindex, &iid)) { _LOGD (LOGD_DEVICE, "IPv6 tokenized identifier present on device %s", priv->iface); } else if (!nm_device_get_ip_iface_identifier (self, &iid)) { _LOGW (LOGD_IP6, "failed to get interface identifier; IPv6 cannot continue"); @@ -4404,7 +4405,7 @@ save_ip6_properties (NMDevice *self) g_hash_table_remove_all (priv->ip6_saved_properties); for (i = 0; i < G_N_ELEMENTS (ip6_properties_to_save); i++) { - value = nm_platform_sysctl_get (nm_utils_ip6_property_path (ifname, ip6_properties_to_save[i])); + value = nm_platform_sysctl_get (NM_PLATFORM_GET, nm_utils_ip6_property_path (ifname, ip6_properties_to_save[i])); if (value) { g_hash_table_insert (priv->ip6_saved_properties, (char *) ip6_properties_to_save[i], @@ -4445,7 +4446,7 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable) const char *iface = nm_device_get_ip_iface (self); char *value; - if (!nm_platform_check_support_user_ipv6ll ()) + if (!nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET)) return; priv->nm_ipv6ll = enable; @@ -4453,13 +4454,13 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable) const char *detail = enable ? "enable" : "disable"; _LOGD (LOGD_IP6, "will %s userland IPv6LL", detail); - if ( !nm_platform_link_set_user_ipv6ll_enabled (ifindex, enable) - && nm_platform_get_error () != NM_PLATFORM_ERROR_NOT_FOUND) + if ( !nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, ifindex, enable) + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_NOT_FOUND) _LOGW (LOGD_IP6, "failed to %s userspace IPv6LL address handling", detail); if (enable) { /* Bounce IPv6 to ensure the kernel stops IPv6LL address generation */ - value = nm_platform_sysctl_get (nm_utils_ip6_property_path (iface, "disable_ipv6")); + value = nm_platform_sysctl_get (NM_PLATFORM_GET, nm_utils_ip6_property_path (iface, "disable_ipv6")); if (g_strcmp0 (value, "0") == 0) nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); g_free (value); @@ -4824,7 +4825,7 @@ nm_device_activate_stage3_ip_config_start (gpointer user_data) nm_device_state_changed (self, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE); /* Device should be up before we can do anything with it */ - if (!nm_platform_link_is_up (nm_device_get_ip_ifindex (self))) + if (!nm_platform_link_is_up (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self))) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); /* If the device is a slave, then we don't do any IP configuration but we @@ -5079,14 +5080,14 @@ share_init (void) char **iter; int errsv; - if (!nm_platform_sysctl_set ("/proc/sys/net/ipv4/ip_forward", "1")) { + if (!nm_platform_sysctl_set (NM_PLATFORM_GET, "/proc/sys/net/ipv4/ip_forward", "1")) { errsv = errno; nm_log_err (LOGD_SHARING, "share: error starting IP forwarding: (%d) %s", errsv, strerror (errsv)); return FALSE; } - if (!nm_platform_sysctl_set ("/proc/sys/net/ipv4/ip_dynaddr", "1")) { + if (!nm_platform_sysctl_set (NM_PLATFORM_GET, "/proc/sys/net/ipv4/ip_dynaddr", "1")) { errsv = errno; nm_log_err (LOGD_SHARING, "share: error starting IP forwarding: (%d) %s", errsv, strerror (errsv)); @@ -5297,9 +5298,9 @@ nm_device_activate_ip4_config_commit (gpointer user_data) /* Interface must be IFF_UP before IP config can be applied */ ip_ifindex = nm_device_get_ip_ifindex (self); - if (!nm_platform_link_is_up (ip_ifindex) && !nm_device_uses_assumed_connection (self)) { - nm_platform_link_set_up (ip_ifindex); - if (!nm_platform_link_is_up (ip_ifindex)) + if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_uses_assumed_connection (self)) { + nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex); + if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex)) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); } @@ -5405,9 +5406,9 @@ nm_device_activate_ip6_config_commit (gpointer user_data) /* Interface must be IFF_UP before IP config can be applied */ ip_ifindex = nm_device_get_ip_ifindex (self); - if (!nm_platform_link_is_up (ip_ifindex) && !nm_device_uses_assumed_connection (self)) { - nm_platform_link_set_up (ip_ifindex); - if (!nm_platform_link_is_up (ip_ifindex)) + if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_uses_assumed_connection (self)) { + nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex); + if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex)) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); } @@ -5576,7 +5577,7 @@ delete_on_deactivate_link_delete (gpointer user_data) _LOGD (LOGD_DEVICE, "delete_on_deactivate: cleanup and delete virtual link #%d (id=%u)", data->ifindex, data->idle_add_id); - nm_platform_link_delete (data->ifindex); + nm_platform_link_delete (NM_PLATFORM_GET, data->ifindex); g_free (data); return FALSE; } @@ -5710,7 +5711,7 @@ delete_cb (NMDevice *self, } /* Authorized */ - nm_platform_link_delete (nm_device_get_ifindex (self)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_device_get_ifindex (self)); dbus_g_method_return (context); } @@ -6450,7 +6451,7 @@ is_up (NMDevice *self) { int ifindex = nm_device_get_ip_ifindex (self); - return ifindex > 0 ? nm_platform_link_is_up (ifindex) : TRUE; + return ifindex > 0 ? nm_platform_link_is_up (NM_PLATFORM_GET, ifindex) : TRUE; } gboolean @@ -6475,7 +6476,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) do { g_usleep (200); - if (!nm_platform_link_refresh (ifindex)) + if (!nm_platform_link_refresh (NM_PLATFORM_GET, ifindex)) return FALSE; device_is_up = nm_device_is_up (self); } while (!device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until); @@ -6515,7 +6516,7 @@ check_carrier (NMDevice *self) int ifindex = nm_device_get_ip_ifindex (self); if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) - nm_device_set_carrier (self, nm_platform_link_is_connected (ifindex)); + nm_device_set_carrier (self, nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); } static gboolean @@ -6530,9 +6531,9 @@ bring_up (NMDevice *self, gboolean *no_firmware) return TRUE; } - result = nm_platform_link_set_up (ifindex); + result = nm_platform_link_set_up (NM_PLATFORM_GET, ifindex); if (no_firmware) - *no_firmware = nm_platform_get_error () == NM_PLATFORM_ERROR_NO_FIRMWARE; + *no_firmware = nm_platform_get_error (NM_PLATFORM_GET) == NM_PLATFORM_ERROR_NO_FIRMWARE; /* Store carrier immediately. */ if (result && nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) @@ -6562,7 +6563,7 @@ nm_device_take_down (NMDevice *self, gboolean block) do { g_usleep (200); - if (!nm_platform_link_refresh (ifindex)) + if (!nm_platform_link_refresh (NM_PLATFORM_GET, ifindex)) return; device_is_up = nm_device_is_up (self); } while (device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until); @@ -6582,7 +6583,7 @@ take_down (NMDevice *self) int ifindex = nm_device_get_ip_ifindex (self); if (ifindex > 0) - return nm_platform_link_set_down (ifindex); + return nm_platform_link_set_down (NM_PLATFORM_GET, ifindex); /* devices without ifindex are always up. */ _LOGD (LOGD_HW, "cannot take down device without ifindex"); @@ -7177,7 +7178,7 @@ cp_connection_updated (NMConnectionProvider *cp, NMConnection *connection, gpoin gboolean nm_device_supports_vlans (NMDevice *self) { - return nm_platform_link_supports_vlans (nm_device_get_ifindex (self)); + return nm_platform_link_supports_vlans (NM_PLATFORM_GET, nm_device_get_ifindex (self)); } /** @@ -7441,8 +7442,8 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, gboolean deconfig /* Take out any entries in the routing table and any IP address the device had. */ ifindex = nm_device_get_ip_ifindex (self); if (ifindex > 0) { - nm_platform_route_flush (ifindex); - nm_platform_address_flush (ifindex); + nm_platform_route_flush (NM_PLATFORM_GET, ifindex); + nm_platform_address_flush (NM_PLATFORM_GET, ifindex); } _cleanup_generic_post (self, deconfigure); @@ -8119,7 +8120,7 @@ nm_device_update_hw_address (NMDevice *self) if (ifindex <= 0) return; - hwaddr = nm_platform_link_get_address (ifindex, &hwaddrlen); + hwaddr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddrlen); if (hwaddrlen) { if (!priv->hw_addr || !nm_utils_hwaddr_matches (priv->hw_addr, -1, hwaddr, hwaddrlen)) { @@ -8165,7 +8166,7 @@ nm_device_set_hw_addr (NMDevice *self, const char *addr, /* Can't change MAC address while device is up */ nm_device_take_down (self, FALSE); - success = nm_platform_link_set_address (nm_device_get_ip_ifindex (self), addr_bytes, priv->hw_addr_len); + success = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, priv->hw_addr_len); if (success) { /* MAC address succesfully changed; update the current MAC to match */ nm_device_update_hw_address (self); @@ -8372,11 +8373,11 @@ constructor (GType type, /* trigger initial ip config change to initialize ip-config */ priv->queued_ip_config_id = g_idle_add (queued_ip_config_change, self); - if (nm_platform_check_support_user_ipv6ll ()) { + if (nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET)) { int ip_ifindex = nm_device_get_ip_ifindex (self); if (ip_ifindex > 0) - priv->nm_ipv6ll = nm_platform_link_get_user_ipv6ll_enabled (ip_ifindex); + priv->nm_ipv6ll = nm_platform_link_get_user_ipv6ll_enabled (NM_PLATFORM_GET, ip_ifindex); } return object; @@ -8422,17 +8423,17 @@ constructed (GObject *object) } if (priv->ifindex > 0) { - priv->is_software = nm_platform_link_is_software (priv->ifindex); - priv->physical_port_id = nm_platform_link_get_physical_port_id (priv->ifindex); - priv->dev_id = nm_platform_link_get_dev_id (priv->ifindex); - priv->mtu = nm_platform_link_get_mtu (priv->ifindex); + priv->is_software = nm_platform_link_is_software (NM_PLATFORM_GET, priv->ifindex); + priv->physical_port_id = nm_platform_link_get_physical_port_id (NM_PLATFORM_GET, priv->ifindex); + priv->dev_id = nm_platform_link_get_dev_id (NM_PLATFORM_GET, priv->ifindex); + priv->mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex); } /* Indicate software device in capabilities. */ if (priv->is_software) priv->capabilities |= NM_DEVICE_CAP_IS_SOFTWARE; /* Enslave ourselves */ - master = nm_platform_link_get_master (priv->ifindex); + master = nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex); if (master) device_set_master (self, master); @@ -8581,9 +8582,9 @@ set_property (GObject *object, guint prop_id, if (g_value_get_string (value)) { g_free (priv->iface); priv->iface = g_value_dup_string (value); - priv->ifindex = nm_platform_link_get_ifindex (priv->iface); + priv->ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->iface); if (priv->ifindex > 0) - priv->up = nm_platform_link_is_up (priv->ifindex); + priv->up = nm_platform_link_is_up (NM_PLATFORM_GET, priv->ifindex); } break; case PROP_DRIVER: diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 84d2241cc6..3f31244ec2 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -638,7 +638,8 @@ enslave_slave (NMDevice *device, } } } - success = nm_platform_link_enslave (nm_device_get_ip_ifindex (device), + success = nm_platform_link_enslave (NM_PLATFORM_GET, + nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); @@ -663,7 +664,8 @@ release_slave (NMDevice *device, gboolean success = TRUE, no_firmware = FALSE; if (configure) { - success = nm_platform_link_release (nm_device_get_ip_ifindex (device), + success = nm_platform_link_release (NM_PLATFORM_GET, + nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) @@ -715,14 +717,14 @@ nm_device_team_new_for_connection (NMConnection *connection, GError **error) iface = nm_connection_get_interface_name (connection); g_return_val_if_fail (iface != NULL, NULL); - if ( !nm_platform_team_add (iface) - && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) { + if ( !nm_platform_team_add (NM_PLATFORM_GET, iface) + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "failed to create team master interface '%s' for connection '%s': %s", iface, nm_connection_get_id (connection), - nm_platform_get_error_msg ()); + nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index dc3dfbc659..f8bf2f7d97 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -197,8 +197,8 @@ _mesh_set_channel (NMDeviceOlpcMesh *self, guint32 channel) { int ifindex = nm_device_get_ifindex (NM_DEVICE (self)); - if (nm_platform_mesh_get_channel (ifindex) != channel) { - if (nm_platform_mesh_set_channel (ifindex, channel)) + if (nm_platform_mesh_get_channel (NM_PLATFORM_GET, ifindex) != channel) { + if (nm_platform_mesh_set_channel (NM_PLATFORM_GET, ifindex, channel)) g_object_notify (G_OBJECT (self), NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL); } } @@ -224,7 +224,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason) _mesh_set_channel (self, channel); ssid = nm_setting_olpc_mesh_get_ssid (s_mesh); - nm_platform_mesh_set_ssid (nm_device_get_ifindex (device), + nm_platform_mesh_set_ssid (NM_PLATFORM_GET, + nm_device_get_ifindex (device), g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); @@ -453,7 +454,7 @@ constructor (GType type, self = NM_DEVICE_OLPC_MESH (object); - if (!nm_platform_wifi_get_capabilities (nm_device_get_ifindex (NM_DEVICE (self)), &caps)) { + if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) { _LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver"); g_object_unref (object); return NULL; @@ -482,7 +483,7 @@ get_property (GObject *object, guint prop_id, g_value_set_boxed (value, "/"); break; case PROP_ACTIVE_CHANNEL: - g_value_set_uint (value, nm_platform_mesh_get_channel (nm_device_get_ifindex (NM_DEVICE (device)))); + g_value_set_uint (value, nm_platform_mesh_get_channel (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (device)))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index ce9a3f7539..3aec4a06d4 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -213,7 +213,8 @@ constructor (GType type, self = NM_DEVICE_WIFI (object); priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - if (!nm_platform_wifi_get_capabilities (nm_device_get_ifindex (NM_DEVICE (self)), + if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, + nm_device_get_ifindex (NM_DEVICE (self)), &priv->capabilities)) { _LOGW (LOGD_HW | LOGD_WIFI, "failed to initialize WiFi driver"); g_object_unref (object); @@ -362,21 +363,21 @@ find_active_ap (NMDeviceWifi *self, NM80211Mode devmode; guint32 devfreq; - nm_platform_wifi_get_bssid (ifindex, bssid); + nm_platform_wifi_get_bssid (NM_PLATFORM_GET, ifindex, bssid); _LOGD (LOGD_WIFI, "active BSSID: %02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); if (!nm_ethernet_address_is_valid (bssid, ETH_ALEN)) return NULL; - ssid = nm_platform_wifi_get_ssid (ifindex); + ssid = nm_platform_wifi_get_ssid (NM_PLATFORM_GET, ifindex); _LOGD (LOGD_WIFI, "active SSID: %s%s%s", ssid ? "'" : "", ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", ssid ? "'" : ""); - devmode = nm_platform_wifi_get_mode (ifindex); - devfreq = nm_platform_wifi_get_frequency (ifindex); + devmode = nm_platform_wifi_get_mode (NM_PLATFORM_GET, ifindex); + devfreq = nm_platform_wifi_get_frequency (NM_PLATFORM_GET, ifindex); /* When matching hidden APs, do a second pass that ignores the SSID check, * because NM might not yet know the SSID of the hidden AP in the scan list @@ -591,7 +592,7 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap) if (priv->current_ap && (nm_ap_get_mode (priv->current_ap) == NM_802_11_MODE_ADHOC)) { guint8 bssid[ETH_ALEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; - nm_platform_wifi_get_bssid (ifindex, bssid); + nm_platform_wifi_get_bssid (NM_PLATFORM_GET, ifindex, bssid); /* 0x02 means "locally administered" and should be OR-ed into * the first byte of IBSS BSSIDs. */ @@ -607,7 +608,7 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap) /* Try to smooth out the strength. Atmel cards, for example, will give no strength * one second and normal strength the next. */ - percent = nm_platform_wifi_get_quality (ifindex); + percent = nm_platform_wifi_get_quality (NM_PLATFORM_GET, ifindex); if (percent >= 0 || ++priv->invalid_strength_counter > 3) { nm_ap_set_strength (new_ap, (gint8) percent); priv->invalid_strength_counter = 0; @@ -639,7 +640,7 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap) set_current_ap (self, new_ap, TRUE, FALSE); } - new_rate = nm_platform_wifi_get_rate (ifindex); + new_rate = nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex); if (new_rate != priv->rate) { priv->rate = new_rate; g_object_notify (G_OBJECT (self), NM_DEVICE_WIFI_BITRATE); @@ -738,7 +739,7 @@ deactivate (NMDevice *device) set_current_ap (self, NULL, TRUE, FALSE); /* Clear any critical protocol notification in the Wi-Fi stack */ - nm_platform_wifi_indicate_addressing_running (ifindex, FALSE); + nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, ifindex, FALSE); /* Reset MAC address back to initial address */ if (priv->initial_hw_addr) @@ -747,9 +748,9 @@ deactivate (NMDevice *device) /* Ensure we're in infrastructure mode after deactivation; some devices * (usually older ones) don't scan well in adhoc mode. */ - if (nm_platform_wifi_get_mode (ifindex) != NM_802_11_MODE_INFRA) { + if (nm_platform_wifi_get_mode (NM_PLATFORM_GET, ifindex) != NM_802_11_MODE_INFRA) { nm_device_take_down (NM_DEVICE (self), TRUE); - nm_platform_wifi_set_mode (ifindex, NM_802_11_MODE_INFRA); + nm_platform_wifi_set_mode (NM_PLATFORM_GET, ifindex, NM_802_11_MODE_INFRA); nm_device_bring_up (NM_DEVICE (self), TRUE, NULL); } @@ -2687,9 +2688,9 @@ ensure_hotspot_frequency (NMDeviceWifi *self, return; if (g_strcmp0 (band, "a") == 0) - freq = nm_platform_wifi_find_frequency (nm_device_get_ifindex (NM_DEVICE (self)), a_freqs); + freq = nm_platform_wifi_find_frequency (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), a_freqs); else - freq = nm_platform_wifi_find_frequency (nm_device_get_ifindex (NM_DEVICE (self)), bg_freqs); + freq = nm_platform_wifi_find_frequency (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), bg_freqs); if (!freq) freq = (g_strcmp0 (band, "a") == 0) ? 5180 : 2462; @@ -2823,7 +2824,7 @@ act_stage3_ip4_config_start (NMDevice *device, /* Indicate that a critical protocol is about to start */ if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) - nm_platform_wifi_indicate_addressing_running (nm_device_get_ifindex (device), TRUE); + nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), TRUE); return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip4_config_start (device, out_config, reason); } @@ -2846,7 +2847,7 @@ act_stage3_ip6_config_start (NMDevice *device, /* Indicate that a critical protocol is about to start */ if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) - nm_platform_wifi_indicate_addressing_running (nm_device_get_ifindex (device), TRUE); + nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), TRUE); return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip6_config_start (device, out_config, reason); } @@ -2998,7 +2999,7 @@ activation_success_handler (NMDevice *device) g_assert (connection); /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (ifindex, FALSE); + nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, ifindex, FALSE); /* Clear wireless secrets tries on success */ g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, NULL); @@ -3017,16 +3018,16 @@ activation_success_handler (NMDevice *device) * But if activation was successful, the card will know the BSSID. Grab * the BSSID off the card and fill in the BSSID of the activation AP. */ - nm_platform_wifi_get_bssid (ifindex, bssid); + nm_platform_wifi_get_bssid (NM_PLATFORM_GET, ifindex, bssid); if (!nm_ap_get_address (ap)) { char *bssid_str = nm_utils_hwaddr_ntoa (bssid, ETH_ALEN); nm_ap_set_address (ap, bssid_str); g_free (bssid_str); } if (!nm_ap_get_freq (ap)) - nm_ap_set_freq (ap, nm_platform_wifi_get_frequency (ifindex)); + nm_ap_set_freq (ap, nm_platform_wifi_get_frequency (NM_PLATFORM_GET, ifindex)); if (!nm_ap_get_max_bitrate (ap)) - nm_ap_set_max_bitrate (ap, nm_platform_wifi_get_rate (ifindex)); + nm_ap_set_max_bitrate (ap, nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex)); tmp_ap = find_active_ap (self, ap, TRUE); if (tmp_ap) { @@ -3076,7 +3077,7 @@ activation_failure_handler (NMDevice *device) g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, NULL); /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (nm_device_get_ifindex (device), FALSE); + nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), FALSE); } static void @@ -3126,7 +3127,7 @@ device_state_changed (NMDevice *device, break; case NM_DEVICE_STATE_IP_CHECK: /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (nm_device_get_ifindex (device), FALSE); + nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), FALSE); break; case NM_DEVICE_STATE_ACTIVATED: activation_success_handler (device); diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 69eaddf3c0..800e01617e 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -615,7 +615,7 @@ nm_modem_ip4_pre_commit (NMModem *modem, g_assert (address); if (address->plen == 32) - nm_platform_link_set_noarp (nm_device_get_ip_ifindex (device)); + nm_platform_link_set_noarp (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device)); } } @@ -912,9 +912,9 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip6_method == NM_MODEM_IP_METHOD_AUTO) { ifindex = nm_device_get_ip_ifindex (device); if (ifindex > 0) { - nm_platform_route_flush (ifindex); - nm_platform_address_flush (ifindex); - nm_platform_link_set_down (ifindex); + nm_platform_route_flush (NM_PLATFORM_GET, ifindex); + nm_platform_address_flush (NM_PLATFORM_GET, ifindex); + nm_platform_link_set_down (NM_PLATFORM_GET, ifindex); } } } diff --git a/src/main.c b/src/main.c index 0569c11a73..32ed099909 100644 --- a/src/main.c +++ b/src/main.c @@ -512,7 +512,7 @@ main (int argc, char *argv[]) * physical interfaces. */ nm_log_dbg (LOGD_CORE, "setting up local loopback"); - nm_platform_link_set_up (1); + nm_platform_link_set_up (NM_PLATFORM_GET, 1); success = TRUE; diff --git a/src/nm-dcb.c b/src/nm-dcb.c index 6faec5c532..34b9246fb8 100644 --- a/src/nm-dcb.c +++ b/src/nm-dcb.c @@ -355,7 +355,7 @@ carrier_wait (const char *iface, guint secs, gboolean up) g_return_if_fail (iface != NULL); - ifindex = nm_platform_link_get_ifindex (iface); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, iface); if (ifindex > 0) { /* To work around driver quirks and lldpad handling of carrier status, * we must wait a short period of time to see if the carrier goes @@ -366,9 +366,9 @@ carrier_wait (const char *iface, guint secs, gboolean up) nm_log_dbg (LOGD_DCB, "(%s): cleanup waiting for carrier %s", iface, up ? "up" : "down"); g_usleep (G_USEC_PER_SEC / 4); - while (nm_platform_link_is_connected (ifindex) != up && count-- > 0) { + while (nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex) != up && count-- > 0) { g_usleep (G_USEC_PER_SEC / 10); - nm_platform_link_refresh (ifindex); + nm_platform_link_refresh (NM_PLATFORM_GET, ifindex); } } } diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index 153c1de6bb..a55ad5b00f 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -256,7 +256,8 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g return FALSE; if (vtable->vt->is_ip4) { - success = nm_platform_ip4_route_add (entry->route.rx.ifindex, + success = nm_platform_ip4_route_add (NM_PLATFORM_GET, + entry->route.rx.ifindex, entry->route.rx.source, 0, 0, @@ -265,7 +266,8 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g entry->effective_metric, entry->route.rx.mss); } else { - success = nm_platform_ip6_route_add (entry->route.rx.ifindex, + success = nm_platform_ip6_route_add (NM_PLATFORM_GET, + entry->route.rx.ifindex, entry->route.rx.source, in6addr_any, 0, @@ -290,7 +292,7 @@ _platform_route_sync_flush (const VTableIP *vtable, NMDefaultRouteManager *self, gboolean changed = FALSE; /* prune all other default routes from this device. */ - routes = vtable->vt->route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); + routes = vtable->vt->route_get_all (NM_PLATFORM_GET, 0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); for (i = 0; i < routes->len; i++) { const NMPlatformIPRoute *route; @@ -322,7 +324,7 @@ _platform_route_sync_flush (const VTableIP *vtable, NMDefaultRouteManager *self, */ if ( !entry && (has_ifindex_synced || ifindex_to_flush == route->ifindex)) { - vtable->vt->route_delete_default (route->ifindex, route->metric); + vtable->vt->route_delete_default (NM_PLATFORM_GET, route->ifindex, route->metric); changed = TRUE; } } @@ -452,7 +454,7 @@ _resync_all (const VTableIP *vtable, NMDefaultRouteManager *self, const Entry *c entries = vtable->get_entries (priv); - routes = vtable->vt->route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); + routes = vtable->vt->route_get_all (NM_PLATFORM_GET, 0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); assumed_metrics = _get_assumed_interface_metrics (vtable, self, routes); diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 1e32524356..d46ba1e8c3 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -145,7 +145,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da * from adding a prefix route for this address. **/ system_support = nm_platform_check_support_libnl_extended_ifa_flags () && - nm_platform_check_support_kernel_extended_ifa_flags (); + nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET); } if (system_support) @@ -227,13 +227,13 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da } if (changed & NM_RDISC_CONFIG_HOP_LIMIT) - nm_platform_sysctl_set_ip6_hop_limit_safe (global_opt.ifname, rdisc->hop_limit); + nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, global_opt.ifname, rdisc->hop_limit); if (changed & NM_RDISC_CONFIG_MTU) { char val[16]; g_snprintf (val, sizeof (val), "%d", rdisc->mtu); - nm_platform_sysctl_set (nm_utils_ip6_property_path (global_opt.ifname, "mtu"), val); + nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "mtu"), val); } existing = nm_ip6_config_capture (ifindex, FALSE, global_opt.tempaddr); @@ -424,7 +424,7 @@ main (int argc, char *argv[]) /* Set up platform interaction layer */ nm_linux_platform_setup (); - tmp = nm_platform_link_get_address (ifindex, &hwaddr_len); + tmp = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddr_len); if (tmp) { hwaddr = g_byte_array_sized_new (hwaddr_len); g_byte_array_append (hwaddr, tmp, hwaddr_len); @@ -443,7 +443,7 @@ main (int argc, char *argv[]) } if (global_opt.dhcp4_address) { - nm_platform_sysctl_set (nm_utils_ip4_property_path (global_opt.ifname, "promote_secondaries"), "1"); + nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip4_property_path (global_opt.ifname, "promote_secondaries"), "1"); /* Initialize DHCP manager */ dhcp_mgr = nm_dhcp_manager_get (); @@ -469,7 +469,7 @@ main (int argc, char *argv[]) } if (global_opt.slaac) { - nm_platform_link_set_user_ipv6ll_enabled (ifindex, TRUE); + nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, ifindex, TRUE); rdisc = nm_lndp_rdisc_new (ifindex, global_opt.ifname); g_assert (rdisc); @@ -477,10 +477,10 @@ main (int argc, char *argv[]) if (iid) nm_rdisc_set_iid (rdisc, *iid); - nm_platform_sysctl_set (nm_utils_ip6_property_path (global_opt.ifname, "accept_ra"), "1"); - nm_platform_sysctl_set (nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_defrtr"), "0"); - nm_platform_sysctl_set (nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_pinfo"), "0"); - nm_platform_sysctl_set (nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_rtr_pref"), "0"); + nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra"), "1"); + nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_defrtr"), "0"); + nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_pinfo"), "0"); + nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_rtr_pref"), "0"); g_signal_connect (rdisc, NM_RDISC_CONFIG_CHANGED, diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 0b6fc49ff5..8dee29e81c 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -186,7 +186,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) gboolean has_gateway = FALSE; /* Slaves have no IP configuration */ - if (nm_platform_link_get_master (ifindex) > 0) + if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0) return NULL; config = nm_ip4_config_new (); @@ -195,8 +195,8 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) g_array_unref (priv->addresses); g_array_unref (priv->routes); - priv->addresses = nm_platform_ip4_address_get_all (ifindex); - priv->routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + priv->addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); + priv->routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); /* Extract gateway from default route */ old_gateway = priv->gateway; @@ -260,7 +260,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, guint32 default_ro g_return_val_if_fail (config != NULL, FALSE); /* Addresses */ - nm_platform_ip4_address_sync (ifindex, priv->addresses, default_route_metric); + nm_platform_ip4_address_sync (NM_PLATFORM_GET, ifindex, priv->addresses, default_route_metric); /* Routes */ { @@ -282,7 +282,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, guint32 default_ro g_array_append_vals (routes, route, 1); } - success = nm_platform_ip4_route_sync (ifindex, routes); + success = nm_platform_ip4_route_sync (NM_PLATFORM_GET, ifindex, routes); g_array_unref (routes); if (!success) return FALSE; diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index cf8d74bebd..40fdcb1999 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -298,7 +298,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co gboolean notify_nameservers = FALSE; /* Slaves have no IP configuration */ - if (nm_platform_link_get_master (ifindex) > 0) + if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0) return NULL; config = nm_ip6_config_new (); @@ -307,8 +307,8 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co g_array_unref (priv->addresses); g_array_unref (priv->routes); - priv->addresses = nm_platform_ip6_address_get_all (ifindex); - priv->routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + priv->addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex); + priv->routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); /* Extract gateway from default route */ old_gateway = priv->gateway; @@ -375,7 +375,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex) g_return_val_if_fail (config != NULL, FALSE); /* Addresses */ - nm_platform_ip6_address_sync (ifindex, priv->addresses, TRUE); + nm_platform_ip6_address_sync (NM_PLATFORM_GET, ifindex, priv->addresses, TRUE); /* Routes */ { @@ -396,7 +396,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex) g_array_append_vals (routes, route, 1); } - success = nm_platform_ip6_route_sync (ifindex, routes); + success = nm_platform_ip6_route_sync (NM_PLATFORM_GET, ifindex, routes); g_array_unref (routes); } diff --git a/src/nm-manager.c b/src/nm-manager.c index e6fd1e55d7..1a94479ae7 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1096,7 +1096,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection, GError */ priv->ignore_link_added_cb++; - nm_owned = !nm_platform_link_exists (iface); + nm_owned = !nm_platform_link_exists (NM_PLATFORM_GET, iface); for (iter = priv->factories; iter; iter = iter->next) { device = nm_device_factory_create_virtual_device_for_connection (NM_DEVICE_FACTORY (iter->data), @@ -1579,13 +1579,13 @@ get_existing_connection (NMManager *manager, NMDevice *device, gboolean *out_gen nm_device_capture_initial_config (device); if (ifindex) { - int master_ifindex = nm_platform_link_get_master (ifindex); + int master_ifindex = nm_platform_link_get_master (NM_PLATFORM_GET, ifindex); if (master_ifindex) { master = nm_manager_get_device_by_ifindex (manager, master_ifindex); if (!master) { nm_log_dbg (LOGD_DEVICE, "(%s): cannot generate connection for slave before its master (%s/%d)", - nm_device_get_iface (device), nm_platform_link_get_name (master_ifindex), master_ifindex); + nm_device_get_iface (device), nm_platform_link_get_name (NM_PLATFORM_GET, master_ifindex), master_ifindex); return NULL; } if (!nm_device_get_act_request (master)) { @@ -1877,7 +1877,7 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume) user_unmanaged = nm_device_spec_match_list (device, unmanaged_specs); nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_USER, user_unmanaged); - if (nm_platform_link_get_unmanaged (nm_device_get_ifindex (device), &platform_unmanaged)) + if (nm_platform_link_get_unmanaged (NM_PLATFORM_GET, nm_device_get_ifindex (device), &platform_unmanaged)) nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_DEFAULT, platform_unmanaged); sleeping = manager_sleeping (self); @@ -3673,7 +3673,7 @@ done: static gboolean device_is_wake_on_lan (NMDevice *device) { - return nm_platform_link_get_wake_on_lan (nm_device_get_ip_ifindex (device)); + return nm_platform_link_get_wake_on_lan (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device)); } static void @@ -4268,7 +4268,7 @@ nm_manager_start (NMManager *self) for (iter = priv->factories; iter; iter = iter->next) nm_device_factory_start (iter->data); - nm_platform_query_devices (); + nm_platform_query_devices (NM_PLATFORM_GET); /* * Connections added before the manager is started do not emit diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index ff3034493e..f8678576b2 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -917,7 +917,7 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, const char NMPlatformTunProperties props; guint flags; - if (nm_platform_tun_get_properties (rtnl_link_get_ifindex (rtnllink), &props)) { + if (nm_platform_tun_get_properties (platform, rtnl_link_get_ifindex (rtnllink), &props)) { if (!g_strcmp0 (props.mode, "tap")) return_type (NM_LINK_TYPE_TAP, "tap"); if (!g_strcmp0 (props.mode, "tun")) @@ -2630,7 +2630,7 @@ supports_mii_carrier_detect (const char *ifname) static gboolean link_supports_carrier_detect (NMPlatform *platform, int ifindex) { - const char *name = nm_platform_link_get_name (ifindex); + const char *name = nm_platform_link_get_name (platform, ifindex); if (!name) return FALSE; @@ -2646,7 +2646,7 @@ static gboolean link_supports_vlans (NMPlatform *platform, int ifindex) { auto_nl_object struct rtnl_link *rtnllink = link_get (platform, ifindex); - const char *name = nm_platform_link_get_name (ifindex); + const char *name = nm_platform_link_get_name (platform, ifindex); gs_free struct ethtool_gfeatures *features = NULL; int idx, block, bit, size; @@ -2744,7 +2744,7 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex) const char *ifname; char *path, *id; - ifname = nm_platform_link_get_name (ifindex); + ifname = nm_platform_link_get_name (platform, ifindex); if (!ifname) return NULL; @@ -2764,7 +2764,7 @@ link_get_dev_id (NMPlatform *platform, int ifindex) gs_free char *path = NULL, *id = NULL; gint64 int_val; - ifname = nm_platform_link_get_name (ifindex); + ifname = nm_platform_link_get_name (platform, ifindex); if (!ifname) return 0; @@ -2877,10 +2877,10 @@ link_get_master (NMPlatform *platform, int slave) } static char * -link_option_path (int master, const char *category, const char *option) +link_option_path (NMPlatform *platform, int master, const char *category, const char *option) { - const char *name = nm_platform_link_get_name (master); - + const char *name = nm_platform_link_get_name (platform, master); + if (!name || !category || !option) return NULL; @@ -2891,19 +2891,19 @@ link_option_path (int master, const char *category, const char *option) } static gboolean -link_set_option (int master, const char *category, const char *option, const char *value) +link_set_option (NMPlatform *platform, int master, const char *category, const char *option, const char *value) { - gs_free char *path = link_option_path (master, category, option); + gs_free char *path = link_option_path (platform, master, category, option); - return path && nm_platform_sysctl_set (path, value); + return path && nm_platform_sysctl_set (platform, path, value); } static char * -link_get_option (int master, const char *category, const char *option) +link_get_option (NMPlatform *platform, int master, const char *category, const char *option) { - gs_free char *path = link_option_path (master, category, option); + gs_free char *path = link_option_path (platform, master, category, option); - return path ? nm_platform_sysctl_get (path) : NULL; + return path ? nm_platform_sysctl_get (platform, path) : NULL; } static const char * @@ -2942,25 +2942,25 @@ slave_category (NMPlatform *platform, int slave) static gboolean master_set_option (NMPlatform *platform, int master, const char *option, const char *value) { - return link_set_option (master, master_category (platform, master), option, 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 (master, master_category (platform, master), 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 (slave, slave_category (platform, slave), option, 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 (slave, slave_category (platform, slave), option); + return link_get_option (platform, slave, slave_category (platform, slave), option); } static gboolean @@ -2970,12 +2970,12 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key) char *path, *id; gboolean success; - parent_name = nm_platform_link_get_name (parent); + parent_name = nm_platform_link_get_name (platform, parent); g_return_val_if_fail (parent_name != NULL, FALSE); path = g_strdup_printf ("/sys/class/net/%s/create_child", ASSERT_VALID_PATH_COMPONENT (parent_name)); id = g_strdup_printf ("0x%04x", p_key); - success = nm_platform_sysctl_set (path, id); + success = nm_platform_sysctl_set (platform, path, id); g_free (id); g_free (path); @@ -2996,7 +2996,7 @@ veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties gs_free struct ethtool_stats *stats = NULL; int peer_ifindex_stat; - ifname = nm_platform_link_get_name (ifindex); + ifname = nm_platform_link_get_name (platform, ifindex); if (!ifname) return FALSE; @@ -3029,13 +3029,13 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties * props->owner = -1; props->group = -1; - ifname = nm_platform_link_get_name (ifindex); + ifname = nm_platform_link_get_name (platform, ifindex); if (!ifname || !nm_utils_iface_valid_name (ifname)) return FALSE; ifname = ASSERT_VALID_PATH_COMPONENT (ifname); path = g_strdup_printf ("/sys/class/net/%s/owner", ifname); - val = nm_platform_sysctl_get (path); + val = nm_platform_sysctl_get (platform, path); g_free (path); if (val) { props->owner = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1); @@ -3046,7 +3046,7 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties * success = FALSE; path = g_strdup_printf ("/sys/class/net/%s/group", ifname); - val = nm_platform_sysctl_get (path); + val = nm_platform_sysctl_get (platform, path); g_free (path); if (val) { props->group = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1); @@ -3057,7 +3057,7 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties * success = FALSE; path = g_strdup_printf ("/sys/class/net/%s/tun_flags", ifname); - val = nm_platform_sysctl_get (path); + val = nm_platform_sysctl_get (platform, path); g_free (path); if (val) { gint64 flags; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 6b3b963eab..5bdbe5ffff 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -58,8 +58,27 @@ static guint signals[LAST_SIGNAL] = { 0 }; /******************************************************************/ /* Singleton NMPlatform subclass instance and cached class object */ -static NMPlatform *platform = NULL; -static NMPlatformClass *klass = NULL; +static NMPlatform *singleton_instance = NULL; + +/* Just always initialize a @klass instance. NM_PLATFORM_GET_CLASS() + * is only a plain read on the self instance, which the compiler + * like can optimize out. + */ +#define _CHECK_SELF_VOID(self, klass) \ + NMPlatformClass *klass; \ + do { \ + g_return_if_fail (NM_IS_PLATFORM (self)); \ + klass = NM_PLATFORM_GET_CLASS (self); \ + (void) klass; \ + } while (0) + +#define _CHECK_SELF(self, klass, err_val) \ + NMPlatformClass *klass; \ + do { \ + g_return_val_if_fail (NM_IS_PLATFORM (self), err_val); \ + klass = NM_PLATFORM_GET_CLASS (self); \ + (void) klass; \ + } while (0) /** * nm_platform_setup: @@ -82,16 +101,17 @@ void nm_platform_setup (GType type) { gboolean status; + NMPlatformClass *klass; - g_assert (platform == NULL); + g_assert (singleton_instance == NULL); - platform = g_object_new (type, NULL); - g_assert (NM_IS_PLATFORM (platform)); + singleton_instance = g_object_new (type, NULL); + g_assert (NM_IS_PLATFORM (singleton_instance)); - klass = NM_PLATFORM_GET_CLASS (platform); + klass = NM_PLATFORM_GET_CLASS (singleton_instance); g_assert (klass->setup); - status = klass->setup (platform); + status = klass->setup (singleton_instance); g_assert (status); } @@ -103,14 +123,15 @@ nm_platform_setup (GType type) void nm_platform_free (void) { - g_assert (platform); + g_assert (singleton_instance); - g_object_unref (platform); - platform = NULL; + g_object_unref (singleton_instance); + singleton_instance = NULL; } /** * nm_platform_get: + * @self: platform instance * * Retrieve #NMPlatform singleton. Use this whenever you want to connect to * #NMPlatform signals. It is an error to call it before nm_*_platform_setup() @@ -119,30 +140,34 @@ nm_platform_free (void) * Returns: (transfer none): The #NMPlatform singleton reference. */ NMPlatform * -nm_platform_get (void) +nm_platform_get () { - g_assert (platform); + g_assert (singleton_instance); - return platform; + return singleton_instance; } /******************************************************************/ /** * nm_platform_set_error: + * @self: platform instance * @error: The error code * - * Convenience function to falsify platform->error. It can be used for example + * Convenience function to falsify self->error. It can be used for example * by functions that want to save the error, execute some operations and * restore it. */ -void nm_platform_set_error (NMPlatformError error) +void nm_platform_set_error (NMPlatform *self, NMPlatformError error) { - platform->error = error; + _CHECK_SELF_VOID (self, klass); + + self->error = error; } /** * nm_platform_get_error: + * @self: platform instance * * Convenience function to quickly retrieve the error code of the last * operation. @@ -150,24 +175,25 @@ void nm_platform_set_error (NMPlatformError error) * Returns: Integer error code. */ NMPlatformError -nm_platform_get_error (void) +nm_platform_get_error (NMPlatform *self) { - g_assert (platform); + _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_NONE); - return platform->error; + return self->error; } /** * nm_platform_get_error_message: + * @self: platform instance * * Returns: Static human-readable string for the error. Don't free. */ const char * -nm_platform_get_error_msg (void) +nm_platform_get_error_msg (NMPlatform *self) { - g_assert (platform); + _CHECK_SELF (self, klass, NULL); - switch (platform->error) { + switch (self->error) { case NM_PLATFORM_ERROR_NONE: return "unknown error"; case NM_PLATFORM_ERROR_NOT_FOUND: @@ -186,10 +212,10 @@ nm_platform_get_error_msg (void) } static void -reset_error (void) +reset_error (NMPlatform *self) { - g_assert (platform); - platform->error = NM_PLATFORM_ERROR_NONE; + g_assert (self); + self->error = NM_PLATFORM_ERROR_NONE; } #define IFA_F_MANAGETEMPADDR_STR "mngtmpaddr" @@ -209,28 +235,28 @@ nm_platform_check_support_libnl_extended_ifa_flags () } gboolean -nm_platform_check_support_kernel_extended_ifa_flags () +nm_platform_check_support_kernel_extended_ifa_flags (NMPlatform *self) { - g_return_val_if_fail (NM_IS_PLATFORM (platform), FALSE); + _CHECK_SELF (self, klass, FALSE); if (!klass->check_support_kernel_extended_ifa_flags) return FALSE; - return klass->check_support_kernel_extended_ifa_flags (platform); + return klass->check_support_kernel_extended_ifa_flags (self); } gboolean -nm_platform_check_support_user_ipv6ll (void) +nm_platform_check_support_user_ipv6ll (NMPlatform *self) { static int supported = -1; - g_return_val_if_fail (NM_IS_PLATFORM (platform), FALSE); + _CHECK_SELF (self, klass, FALSE); if (!klass->check_support_user_ipv6ll) return FALSE; if (supported < 0) - supported = klass->check_support_user_ipv6ll (platform) ? 1 : 0; + supported = klass->check_support_user_ipv6ll (self) ? 1 : 0; return !!supported; } @@ -238,6 +264,7 @@ nm_platform_check_support_user_ipv6ll (void) /** * nm_platform_sysctl_set: + * @self: platform instance * @path: Absolute option path * @value: Value to write * @@ -248,23 +275,27 @@ nm_platform_check_support_user_ipv6ll (void) * Returns: %TRUE on success. */ gboolean -nm_platform_sysctl_set (const char *path, const char *value) +nm_platform_sysctl_set (NMPlatform *self, const char *path, const char *value) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); 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 (platform, path, value); + reset_error (self); + + return klass->sysctl_set (self, path, value); } gboolean -nm_platform_sysctl_set_ip6_hop_limit_safe (const char *iface, int value) +nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char *iface, int value) { const char *path; gint64 cur; + _CHECK_SELF (self, klass, FALSE); + /* the hop-limit provided via RA is uint8. */ if (value > 0xFF) return FALSE; @@ -274,7 +305,7 @@ nm_platform_sysctl_set_ip6_hop_limit_safe (const char *iface, int value) return FALSE; path = nm_utils_ip6_property_path (iface, "hop_limit"); - cur = nm_platform_sysctl_get_int_checked (path, 10, 1, G_MAXINT32, -1); + cur = nm_platform_sysctl_get_int_checked (self, path, 10, 1, G_MAXINT32, -1); /* only allow increasing the hop-limit to avoid DOS by an attacker * setting a low hop-limit (CVE-2015-2924, rh#1209902) */ @@ -285,7 +316,7 @@ nm_platform_sysctl_set_ip6_hop_limit_safe (const char *iface, int value) char svalue[20]; sprintf (svalue, "%d", value); - nm_platform_sysctl_set (path, svalue); + nm_platform_sysctl_set (self, path, svalue); } return TRUE; @@ -293,23 +324,27 @@ nm_platform_sysctl_set_ip6_hop_limit_safe (const char *iface, int value) /** * nm_platform_sysctl_get: + * @self: platform instance * @path: Absolute path to sysctl * * Returns: (transfer full): Contents of the virtual sysctl file. */ char * -nm_platform_sysctl_get (const char *path) +nm_platform_sysctl_get (NMPlatform *self, const char *path) { - reset_error (); + _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 (platform, path); + reset_error (self); + + return klass->sysctl_get (self, path); } /** * nm_platform_sysctl_get_int32: + * @self: platform instance * @path: Absolute path to sysctl * @fallback: default value, if the content of path could not be read * as decimal integer. @@ -319,13 +354,14 @@ nm_platform_sysctl_get (const char *path) * value, on success %errno will be set to zero. */ gint32 -nm_platform_sysctl_get_int32 (const char *path, gint32 fallback) +nm_platform_sysctl_get_int32 (NMPlatform *self, const char *path, gint32 fallback) { - return nm_platform_sysctl_get_int_checked (path, 10, G_MININT32, G_MAXINT32, fallback); + return nm_platform_sysctl_get_int_checked (self, path, 10, G_MININT32, G_MAXINT32, fallback); } /** * nm_platform_sysctl_get_int_checked: + * @self: platform instance * @path: Absolute path to sysctl * @base: base of numeric conversion * @min: minimal value that is still valid @@ -340,15 +376,17 @@ nm_platform_sysctl_get_int32 (const char *path, gint32 fallback) * (inclusive) or @fallback. */ gint64 -nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gint64 max, gint64 fallback) +nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *path, guint base, gint64 min, gint64 max, gint64 fallback) { char *value = NULL; gint32 ret; + _CHECK_SELF (self, klass, fallback); + g_return_val_if_fail (path, fallback); if (path) - value = nm_platform_sysctl_get (path); + value = nm_platform_sysctl_get (self, path); if (!value) { errno = EINVAL; @@ -364,21 +402,24 @@ nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gi /** * nm_platform_query_devices: + * self: platform instance * * Emit #NMPlatform:link-changed ADDED signals for all currently-known links. * Should only be called at startup. */ void -nm_platform_query_devices (void) +nm_platform_query_devices (NMPlatform *self) { GArray *links_array; NMPlatformLink *links; int i; - links_array = nm_platform_link_get_all (); + _CHECK_SELF_VOID (self, klass); + + links_array = nm_platform_link_get_all (self); links = (NMPlatformLink *) links_array->data; for (i = 0; i < links_array->len; i++) { - g_signal_emit (platform, signals[SIGNAL_LINK_CHANGED], 0, + g_signal_emit (self, signals[SIGNAL_LINK_CHANGED], 0, links[i].ifindex, &links[i], NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL); } @@ -387,23 +428,25 @@ nm_platform_query_devices (void) /** * nm_platform_link_get_all: + * self: platform instance * * Retrieve a snapshot of configuration for all links at once. The result is * owned by the caller and should be freed with g_array_unref(). */ GArray * -nm_platform_link_get_all (void) +nm_platform_link_get_all (NMPlatform *self) { GArray *links, *result; guint i, j, nresult; GHashTable *unseen; NMPlatformLink *item; - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (klass->link_get_all, NULL); - links = klass->link_get_all (platform); + links = klass->link_get_all (self); if (!links || links->len == 0) return links; @@ -492,6 +535,7 @@ nm_platform_link_get_all (void) /** * nm_platform_link_get: + * @self: platform instance * @ifindex: ifindex of the link * @link: (out): output NMPlatformLink structure. * @@ -502,121 +546,135 @@ nm_platform_link_get_all (void) * If the link does not exist, the content of @link is undefined. **/ gboolean -nm_platform_link_get (int ifindex, NMPlatformLink *link) +nm_platform_link_get (NMPlatform *self, int ifindex, NMPlatformLink *link) { + _CHECK_SELF (self, klass, FALSE); + g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (link, FALSE); g_return_val_if_fail (klass->link_get, FALSE); - return !!klass->link_get (platform, ifindex, link); + return !!klass->link_get (self, ifindex, link); } /** * nm_platform_link_add: + * @self: platform instance * @name: Interface name * @type: Interface type * @address: (allow-none): set the mac address of the link * @address_len: the length of the @address * - * Add a software interface. Sets platform->error to NM_PLATFORM_ERROR_EXISTS + * Add a software interface. Sets self->error to NM_PLATFORM_ERROR_EXISTS * if interface is already already exists. Any link-changed ADDED signal will be * emitted directly, before this function finishes. */ static gboolean -nm_platform_link_add (const char *name, NMLinkType type, const void *address, size_t address_len) +nm_platform_link_add (NMPlatform *self, const char *name, NMLinkType type, const void *address, size_t address_len) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (name, FALSE); g_return_val_if_fail (klass->link_add, FALSE); g_return_val_if_fail ( (address != NULL) ^ (address_len == 0) , FALSE); - if (nm_platform_link_exists (name)) { + if (nm_platform_link_exists (self, name)) { debug ("link: already exists"); - platform->error = NM_PLATFORM_ERROR_EXISTS; + self->error = NM_PLATFORM_ERROR_EXISTS; return FALSE; } - return klass->link_add (platform, name, type, address, address_len); + return klass->link_add (self, name, type, address, address_len); } /** * nm_platform_dummy_add: + * @self: platform instance * @name: New interface name * * Create a software ethernet-like interface */ gboolean -nm_platform_dummy_add (const char *name) +nm_platform_dummy_add (NMPlatform *self, const char *name) { g_return_val_if_fail (name, FALSE); debug ("link: adding dummy '%s'", name); - return nm_platform_link_add (name, NM_LINK_TYPE_DUMMY, NULL, 0); + return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0); } /** * nm_platform_link_exists: + * @self: platform instance * @name: Interface name * * Returns: %TRUE if an interface of this name exists, %FALSE otherwise. */ gboolean -nm_platform_link_exists (const char *name) +nm_platform_link_exists (NMPlatform *self, const char *name) { - int ifindex = nm_platform_link_get_ifindex (name); + int ifindex; - reset_error(); + _CHECK_SELF (self, klass, FALSE); + + ifindex = nm_platform_link_get_ifindex (self, name); + + reset_error (self); return ifindex > 0; } /** * nm_platform_link_delete: + * @self: platform instance * @ifindex: Interface index * - * Delete a software interface. Sets platform->error to + * Delete a software interface. Sets self->error to * NM_PLATFORM_ERROR_NOT_FOUND if ifindex not available. */ gboolean -nm_platform_link_delete (int ifindex) +nm_platform_link_delete (NMPlatform *self, int ifindex) { const char *name; - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (klass->link_delete, FALSE); - name = nm_platform_link_get_name (ifindex); + name = nm_platform_link_get_name (self, ifindex); if (!name) return FALSE; debug ("link: deleting '%s' (%d)", name, ifindex); - return klass->link_delete (platform, ifindex); + return klass->link_delete (self, ifindex); } /** * nm_platform_link_get_index: + * @self: platform instance * @name: Interface name * * Returns: The interface index corresponding to the given interface name * or 0. Inteface name is owned by #NMPlatform, don't free it. */ int -nm_platform_link_get_ifindex (const char *name) +nm_platform_link_get_ifindex (NMPlatform *self, const char *name) { int ifindex; - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (name, 0); g_return_val_if_fail (klass->link_get_ifindex, 0); - ifindex = klass->link_get_ifindex (platform, name); + ifindex = klass->link_get_ifindex (self, name); if (!ifindex) { debug ("link not found: %s", name); - platform->error = NM_PLATFORM_ERROR_NOT_FOUND; + self->error = NM_PLATFORM_ERROR_NOT_FOUND; } return ifindex; @@ -624,25 +682,27 @@ nm_platform_link_get_ifindex (const char *name) /** * nm_platform_link_get_name: + * @self: platform instance * @name: Interface name * * Returns: The interface name corresponding to the given interface index * or %NULL. */ const char * -nm_platform_link_get_name (int ifindex) +nm_platform_link_get_name (NMPlatform *self, int ifindex) { const char *name; - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (klass->link_get_name, NULL); - name = klass->link_get_name (platform, ifindex); + name = klass->link_get_name (self, ifindex); if (!name) { debug ("link not found: %d", ifindex); - platform->error = NM_PLATFORM_ERROR_NOT_FOUND; + self->error = NM_PLATFORM_ERROR_NOT_FOUND; return FALSE; } @@ -651,23 +711,26 @@ nm_platform_link_get_name (int ifindex) /** * nm_platform_link_get_type: + * @self: platform instance * @ifindex: Interface index. * * Returns: Link type constant as defined in nm-platform.h. On error, * NM_LINK_TYPE_NONE is returned. */ NMLinkType -nm_platform_link_get_type (int ifindex) +nm_platform_link_get_type (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NM_LINK_TYPE_NONE); + reset_error (self); g_return_val_if_fail (klass->link_get_type, NM_LINK_TYPE_NONE); - return klass->link_get_type (platform, ifindex); + return klass->link_get_type (self, ifindex); } /** * nm_platform_link_get_type_name: + * @self: platform instance * @ifindex: Interface index. * * Returns: A string describing the type of link. In some cases this @@ -675,17 +738,19 @@ nm_platform_link_get_type (int ifindex) * other cases it may not. On error, %NULL is returned. */ const char * -nm_platform_link_get_type_name (int ifindex) +nm_platform_link_get_type_name (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (klass->link_get_type_name, NULL); - return klass->link_get_type_name (platform, ifindex); + return klass->link_get_type_name (self, ifindex); } /** * nm_platform_link_get_unmanaged: + * @self: platform instance * @ifindex: Interface index. * @managed: Management status in case %TRUE is returned * @@ -694,113 +759,125 @@ nm_platform_link_get_type_name (int ifindex) * otherwise. */ gboolean -nm_platform_link_get_unmanaged (int ifindex, gboolean *managed) +nm_platform_link_get_unmanaged (NMPlatform *self, int ifindex, gboolean *managed) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (klass->link_get_unmanaged, FALSE); - return klass->link_get_unmanaged (platform, ifindex, managed); + return klass->link_get_unmanaged (self, ifindex, managed); } /** * nm_platform_link_is_software: + * @self: platform instance * @ifindex: Interface index. * * Returns: %TRUE if ifindex belongs to a software interface, not backed by * a physical device. */ gboolean -nm_platform_link_is_software (int ifindex) +nm_platform_link_is_software (NMPlatform *self, int ifindex) { - return (nm_platform_link_get_type (ifindex) & 0x10000); + return (nm_platform_link_get_type (self, ifindex) & 0x10000); } /** * nm_platform_link_supports_slaves: + * @self: platform instance * @ifindex: Interface index. * * Returns: %TRUE if ifindex belongs to an interface capable of enslaving * other interfaces. */ gboolean -nm_platform_link_supports_slaves (int ifindex) +nm_platform_link_supports_slaves (NMPlatform *self, int ifindex) { - return (nm_platform_link_get_type (ifindex) & 0x20000); + return (nm_platform_link_get_type (self, ifindex) & 0x20000); } /** * nm_platform_link_refresh: + * @self: platform instance * @ifindex: Interface index * * Reload the cache for ifindex synchronously. */ gboolean -nm_platform_link_refresh (int ifindex) +nm_platform_link_refresh (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); if (klass->link_refresh) - return klass->link_refresh (platform, ifindex); + return klass->link_refresh (self, ifindex); return TRUE; } /** * nm_platform_link_is_up: + * @self: platform instance * @ifindex: Interface index * * Check if the interface is up. */ gboolean -nm_platform_link_is_up (int ifindex) +nm_platform_link_is_up (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->link_is_up, FALSE); - return klass->link_is_up (platform, ifindex); + return klass->link_is_up (self, ifindex); } /** * nm_platform_link_is_connected: + * @self: platform instance * @ifindex: Interface index * * Check if the interface is connected. */ gboolean -nm_platform_link_is_connected (int ifindex) +nm_platform_link_is_connected (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->link_is_connected, FALSE); - return klass->link_is_connected (platform, ifindex); + return klass->link_is_connected (self, ifindex); } /** * nm_platform_link_uses_arp: + * @self: platform instance * @ifindex: Interface index * * Check if the interface is configured to use ARP. */ gboolean -nm_platform_link_uses_arp (int ifindex) +nm_platform_link_uses_arp (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->link_uses_arp, FALSE); - return klass->link_uses_arp (platform, ifindex); + return klass->link_uses_arp (self, ifindex); } /** * nm_platform_link_get_ipv6_token: + * @self: platform instance * @ifindex: Interface index * @iid: Tokenized interface identifier * @@ -811,21 +888,23 @@ nm_platform_link_uses_arp (int ifindex) * Returns: %TRUE a tokenized identifier was available */ gboolean -nm_platform_link_get_ipv6_token (int ifindex, NMUtilsIPv6IfaceId *iid) +nm_platform_link_get_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId *iid) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (iid, FALSE); if (klass->link_get_ipv6_token) - return klass->link_get_ipv6_token (platform, ifindex, iid); + return klass->link_get_ipv6_token (self, ifindex, iid); return FALSE; } /** * nm_platform_link_get_user_ip6vll_enabled: + * @self: platform instance * @ifindex: Interface index * * Check whether NM handles IPv6LL address creation for the link. If the @@ -835,20 +914,22 @@ nm_platform_link_get_ipv6_token (int ifindex, NMUtilsIPv6IfaceId *iid) * Returns: %TRUE if NM handles the IPv6LL address for @ifindex */ gboolean -nm_platform_link_get_user_ipv6ll_enabled (int ifindex) +nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->check_support_user_ipv6ll, FALSE); if (klass->link_get_user_ipv6ll_enabled) - return klass->link_get_user_ipv6ll_enabled (platform, ifindex); + return klass->link_get_user_ipv6ll_enabled (self, ifindex); return FALSE; } /** * nm_platform_link_set_user_ip6vll_enabled: + * @self: platform instance * @ifindex: Interface index * * Set whether NM handles IPv6LL address creation for the link. If the @@ -858,50 +939,55 @@ nm_platform_link_get_user_ipv6ll_enabled (int ifindex) * Returns: %TRUE if the operation was successful, %FALSE if it failed. */ gboolean -nm_platform_link_set_user_ipv6ll_enabled (int ifindex, gboolean enabled) +nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); 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 (platform, ifindex, enabled); + return klass->link_set_user_ipv6ll_enabled (self, ifindex, enabled); return FALSE; } /** * nm_platform_link_set_address: + * @self: platform instance * @ifindex: Interface index * @address: The new MAC address * * Set interface MAC address. */ gboolean -nm_platform_link_set_address (int ifindex, gconstpointer address, size_t length) +nm_platform_link_set_address (NMPlatform *self, int ifindex, gconstpointer address, size_t length) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); 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); - debug ("link: setting '%s' (%d) hardware address", nm_platform_link_get_name (ifindex), ifindex); - return klass->link_set_address (platform, ifindex, address, length); + debug ("link: setting '%s' (%d) hardware address", nm_platform_link_get_name (self, ifindex), ifindex); + return klass->link_set_address (self, ifindex, address, length); } /** * nm_platform_link_get_address: + * @self: platform instance * @ifindex: Interface index * @length: Pointer to a variable to store address length * * Saves interface hardware address to @address. */ gconstpointer -nm_platform_link_get_address (int ifindex, size_t *length) +nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); if (length) *length = 0; @@ -909,138 +995,155 @@ nm_platform_link_get_address (int ifindex, size_t *length) g_return_val_if_fail (ifindex > 0, NULL); g_return_val_if_fail (klass->link_get_address, NULL); - return klass->link_get_address (platform, ifindex, length); + return klass->link_get_address (self, ifindex, length); } gboolean -nm_platform_link_supports_carrier_detect (int ifindex) +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 (platform, ifindex); + return klass->link_supports_carrier_detect (self, ifindex); } gboolean -nm_platform_link_supports_vlans (int ifindex) +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 (platform, ifindex); + return klass->link_supports_vlans (self, ifindex); } /** * nm_platform_link_set_up: + * @self: platform instance * @ifindex: Interface index * * Bring the interface up. */ gboolean -nm_platform_link_set_up (int ifindex) +nm_platform_link_set_up (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (klass->link_set_up, FALSE); - debug ("link: setting up '%s' (%d)", nm_platform_link_get_name (ifindex), ifindex); - return klass->link_set_up (platform, ifindex); + debug ("link: setting up '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); + return klass->link_set_up (self, ifindex); } /** * nm_platform_link_set_down: + * @self: platform instance * @ifindex: Interface index * * Take the interface down. */ gboolean -nm_platform_link_set_down (int ifindex) +nm_platform_link_set_down (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (klass->link_set_down, FALSE); - debug ("link: setting down '%s' (%d)", nm_platform_link_get_name (ifindex), ifindex); - return klass->link_set_down (platform, ifindex); + debug ("link: setting down '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); + return klass->link_set_down (self, ifindex); } /** * nm_platform_link_set_arp: + * @self: platform instance * @ifindex: Interface index * * Enable ARP on the interface. */ gboolean -nm_platform_link_set_arp (int ifindex) +nm_platform_link_set_arp (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->link_set_arp, FALSE); - debug ("link: setting arp '%s' (%d)", nm_platform_link_get_name (ifindex), ifindex); - return klass->link_set_arp (platform, ifindex); + debug ("link: setting arp '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); + return klass->link_set_arp (self, ifindex); } /** * nm_platform_link_set_noarp: + * @self: platform instance * @ifindex: Interface index * * Disable ARP on the interface. */ gboolean -nm_platform_link_set_noarp (int ifindex) +nm_platform_link_set_noarp (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->link_set_noarp, FALSE); - debug ("link: setting noarp '%s' (%d)", nm_platform_link_get_name (ifindex), ifindex); - return klass->link_set_noarp (platform, ifindex); + debug ("link: setting noarp '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex); + return klass->link_set_noarp (self, ifindex); } /** * nm_platform_link_set_mtu: + * @self: platform instance * @ifindex: Interface index * @mtu: The new MTU value * * Set interface MTU. */ gboolean -nm_platform_link_set_mtu (int ifindex, guint32 mtu) +nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); 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); - debug ("link: setting '%s' (%d) mtu %"G_GUINT32_FORMAT, nm_platform_link_get_name (ifindex), ifindex, mtu); - return klass->link_set_mtu (platform, ifindex, mtu); + debug ("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); } /** * nm_platform_link_get_mtu: + * @self: platform instance * @ifindex: Interface index * * Returns: MTU value for the interface or 0 on error. */ guint32 -nm_platform_link_get_mtu (int ifindex) +nm_platform_link_get_mtu (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex >= 0, 0); g_return_val_if_fail (klass->link_get_mtu, 0); - return klass->link_get_mtu (platform, ifindex); + return klass->link_get_mtu (self, ifindex); } /** * nm_platform_link_get_physical_port_id: + * @self: platform instance * @ifindex: Interface index * * The physical port ID, if present, indicates some unique identifier of @@ -1053,18 +1156,20 @@ nm_platform_link_get_mtu (int ifindex) * or if the interface has no physical port ID. */ char * -nm_platform_link_get_physical_port_id (int ifindex) +nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (ifindex >= 0, NULL); g_return_val_if_fail (klass->link_get_physical_port_id, NULL); - return klass->link_get_physical_port_id (platform, ifindex); + return klass->link_get_physical_port_id (self, ifindex); } /** * nm_platform_link_get_dev_id: + * @self: platform instance * @ifindex: Interface index * * In contrast to the physical device ID (which indicates which parent a @@ -1075,108 +1180,115 @@ nm_platform_link_get_physical_port_id (int ifindex) * interface has no device ID. */ guint -nm_platform_link_get_dev_id (int ifindex) +nm_platform_link_get_dev_id (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex >= 0, 0); g_return_val_if_fail (klass->link_get_dev_id, 0); - return klass->link_get_dev_id (platform, ifindex); + return klass->link_get_dev_id (self, ifindex); } /** * nm_platform_link_get_wake_onlan: + * @self: platform instance * @ifindex: Interface index * * Returns: the "Wake-on-LAN" status for @ifindex. */ gboolean -nm_platform_link_get_wake_on_lan (int ifindex) +nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex >= 0, FALSE); g_return_val_if_fail (klass->link_get_wake_on_lan, FALSE); - return klass->link_get_wake_on_lan (platform, ifindex); + return klass->link_get_wake_on_lan (self, ifindex); } /** * nm_platform_link_enslave: + * @self: platform instance * @master: Interface index of the master * @slave: Interface index of the slave * * Enslave @slave to @master. */ gboolean -nm_platform_link_enslave (int master, int slave) +nm_platform_link_enslave (NMPlatform *self, int master, int slave) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_assert (platform); 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); debug ("link: enslaving '%s' (%d) to master '%s' (%d)", - nm_platform_link_get_name (slave), slave, - nm_platform_link_get_name (master), master); - return klass->link_enslave (platform, master, slave); + nm_platform_link_get_name (self, slave), slave, + nm_platform_link_get_name (self, master), master); + return klass->link_enslave (self, master, slave); } /** * nm_platform_link_release: + * @self: platform instance * @master: Interface index of the master * @slave: Interface index of the slave * * Release @slave from @master. */ gboolean -nm_platform_link_release (int master, int slave) +nm_platform_link_release (NMPlatform *self, int master, int slave) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_assert (platform); 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 (slave) != master) { - platform->error = NM_PLATFORM_ERROR_NOT_SLAVE; + if (nm_platform_link_get_master (self, slave) != master) { + self->error = NM_PLATFORM_ERROR_NOT_SLAVE; return FALSE; } debug ("link: releasing '%s' (%d) from master '%s' (%d)", - nm_platform_link_get_name (slave), slave, - nm_platform_link_get_name (master), master); - return klass->link_release (platform, master, slave); + nm_platform_link_get_name (self, slave), slave, + nm_platform_link_get_name (self, master), master); + return klass->link_release (self, master, slave); } /** * nm_platform_link_get_master: + * @self: platform instance * @slave: Interface index of the slave. * * Returns: Interfase index of the slave's master. */ int -nm_platform_link_get_master (int slave) +nm_platform_link_get_master (NMPlatform *self, int slave) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); - g_assert (platform); g_return_val_if_fail (slave >= 0, FALSE); g_return_val_if_fail (klass->link_get_master, FALSE); - if (!nm_platform_link_get_name (slave)) { - platform->error = NM_PLATFORM_ERROR_NOT_FOUND; + if (!nm_platform_link_get_name (self, slave)) { + self->error = NM_PLATFORM_ERROR_NOT_FOUND; return 0; } - return klass->link_get_master (platform, slave); + return klass->link_get_master (self, slave); } /** * nm_platform_bridge_add: + * @self: platform instance * @name: New interface name * @address: (allow-none): set the mac address of the new bridge * @address_len: the length of the @address @@ -1184,40 +1296,43 @@ nm_platform_link_get_master (int slave) * Create a software bridge. */ gboolean -nm_platform_bridge_add (const char *name, const void *address, size_t address_len) +nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len) { debug ("link: adding bridge '%s'", name); - return nm_platform_link_add (name, NM_LINK_TYPE_BRIDGE, address, address_len); + return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len); } /** * nm_platform_bond_add: + * @self: platform instance * @name: New interface name * * Create a software bonding device. */ gboolean -nm_platform_bond_add (const char *name) +nm_platform_bond_add (NMPlatform *self, const char *name) { debug ("link: adding bond '%s'", name); - return nm_platform_link_add (name, NM_LINK_TYPE_BOND, NULL, 0); + return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0); } /** * nm_platform_team_add: + * @self: platform instance * @name: New interface name * * Create a software teaming device. */ gboolean -nm_platform_team_add (const char *name) +nm_platform_team_add (NMPlatform *self, const char *name) { debug ("link: adding team '%s'", name); - return nm_platform_link_add (name, NM_LINK_TYPE_TEAM, NULL, 0); + return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0); } /** * nm_platform_vlan_add: + * @self: platform instance * @name: New interface name * @vlanid: VLAN identifier * @vlanflags: VLAN flags from libnm @@ -1225,83 +1340,87 @@ nm_platform_team_add (const char *name) * Create a software VLAN device. */ gboolean -nm_platform_vlan_add (const char *name, int parent, int vlanid, guint32 vlanflags) +nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_assert (platform); g_return_val_if_fail (parent >= 0, FALSE); g_return_val_if_fail (vlanid >= 0, FALSE); g_return_val_if_fail (name, FALSE); g_return_val_if_fail (klass->vlan_add, FALSE); - if (nm_platform_link_exists (name)) { + if (nm_platform_link_exists (self, name)) { debug ("link already exists: %s", name); - platform->error = NM_PLATFORM_ERROR_EXISTS; + self->error = NM_PLATFORM_ERROR_EXISTS; return FALSE; } debug ("link: adding vlan '%s' parent %d vlanid %d vlanflags %x", name, parent, vlanid, vlanflags); - return klass->vlan_add (platform, name, parent, vlanid, vlanflags); + return klass->vlan_add (self, name, parent, vlanid, vlanflags); } gboolean -nm_platform_master_set_option (int ifindex, const char *option, const char *value) +nm_platform_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); 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 (platform, ifindex, option, value); + return klass->master_set_option (self, ifindex, option, value); } char * -nm_platform_master_get_option (int ifindex, const char *option) +nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *option) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); 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 (platform, ifindex, option); + return klass->master_get_option (self, ifindex, option); } gboolean -nm_platform_slave_set_option (int ifindex, const char *option, const char *value) +nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); 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 (platform, ifindex, option, value); + return klass->slave_set_option (self, ifindex, option, value); } char * -nm_platform_slave_get_option (int ifindex, const char *option) +nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *option) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); 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 (platform, ifindex, option); + return klass->slave_get_option (self, ifindex, option); } gboolean -nm_platform_vlan_get_info (int ifindex, int *parent, int *vlanid) +nm_platform_vlan_get_info (NMPlatform *self, int ifindex, int *parent, int *vlanid) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_assert (platform); g_return_val_if_fail (klass->vlan_get_info, FALSE); if (parent) @@ -1309,261 +1428,280 @@ nm_platform_vlan_get_info (int ifindex, int *parent, int *vlanid) if (vlanid) *vlanid = 0; - if (nm_platform_link_get_type (ifindex) != NM_LINK_TYPE_VLAN) + if (nm_platform_link_get_type (self, ifindex) != NM_LINK_TYPE_VLAN) return FALSE; - return klass->vlan_get_info (platform, ifindex, parent, vlanid); + return klass->vlan_get_info (self, ifindex, parent, vlanid); } gboolean -nm_platform_vlan_set_ingress_map (int ifindex, int from, int to) +nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_assert (platform); g_return_val_if_fail (klass->vlan_set_ingress_map, FALSE); debug ("link: setting vlan ingress map for %d from %d to %d", ifindex, from, to); - return klass->vlan_set_ingress_map (platform, ifindex, from, to); + return klass->vlan_set_ingress_map (self, ifindex, from, to); } gboolean -nm_platform_vlan_set_egress_map (int ifindex, int from, int to) +nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_assert (platform); g_return_val_if_fail (klass->vlan_set_egress_map, FALSE); debug ("link: setting vlan egress map for %d from %d to %d", ifindex, from, to); - return klass->vlan_set_egress_map (platform, ifindex, from, to); + return klass->vlan_set_egress_map (self, ifindex, from, to); } gboolean -nm_platform_infiniband_partition_add (int parent, int p_key) +nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key) { const char *parent_name; char *name; - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (parent >= 0, FALSE); g_return_val_if_fail (p_key >= 0, FALSE); g_return_val_if_fail (klass->infiniband_partition_add, FALSE); - if (nm_platform_link_get_type (parent) != NM_LINK_TYPE_INFINIBAND) { - platform->error = NM_PLATFORM_ERROR_WRONG_TYPE; + if (nm_platform_link_get_type (self, parent) != NM_LINK_TYPE_INFINIBAND) { + self->error = NM_PLATFORM_ERROR_WRONG_TYPE; return FALSE; } - parent_name = nm_platform_link_get_name (parent); + parent_name = nm_platform_link_get_name (self, parent); name = g_strdup_printf ("%s.%04x", parent_name, p_key); - if (nm_platform_link_exists (name)) { + if (nm_platform_link_exists (self, name)) { debug ("infiniband: already exists"); - platform->error = NM_PLATFORM_ERROR_EXISTS; + self->error = NM_PLATFORM_ERROR_EXISTS; g_free (name); return FALSE; } g_free (name); - return klass->infiniband_partition_add (platform, parent, p_key); + return klass->infiniband_partition_add (self, parent, p_key); } gboolean -nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *props) +nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethProperties *props) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (props != NULL, FALSE); - return klass->veth_get_properties (platform, ifindex, props); + return klass->veth_get_properties (self, ifindex, props); } gboolean -nm_platform_tun_get_properties (int ifindex, NMPlatformTunProperties *props) +nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (props != NULL, FALSE); - return klass->tun_get_properties (platform, ifindex, props); + return klass->tun_get_properties (self, ifindex, props); } gboolean -nm_platform_macvlan_get_properties (int ifindex, NMPlatformMacvlanProperties *props) +nm_platform_macvlan_get_properties (NMPlatform *self, int ifindex, NMPlatformMacvlanProperties *props) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (props != NULL, FALSE); - return klass->macvlan_get_properties (platform, ifindex, props); + return klass->macvlan_get_properties (self, ifindex, props); } gboolean -nm_platform_vxlan_get_properties (int ifindex, NMPlatformVxlanProperties *props) +nm_platform_vxlan_get_properties (NMPlatform *self, int ifindex, NMPlatformVxlanProperties *props) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (props != NULL, FALSE); - return klass->vxlan_get_properties (platform, ifindex, props); + return klass->vxlan_get_properties (self, ifindex, props); } gboolean -nm_platform_gre_get_properties (int ifindex, NMPlatformGreProperties *props) +nm_platform_gre_get_properties (NMPlatform *self, int ifindex, NMPlatformGreProperties *props) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (props != NULL, FALSE); - return klass->gre_get_properties (platform, ifindex, props); + return klass->gre_get_properties (self, ifindex, props); } gboolean -nm_platform_wifi_get_capabilities (int ifindex, NMDeviceWifiCapabilities *caps) +nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); - return klass->wifi_get_capabilities (platform, ifindex, caps); + return klass->wifi_get_capabilities (self, ifindex, caps); } gboolean -nm_platform_wifi_get_bssid (int ifindex, guint8 *bssid) +nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); - return klass->wifi_get_bssid (platform, ifindex, bssid); + return klass->wifi_get_bssid (self, ifindex, bssid); } GByteArray * -nm_platform_wifi_get_ssid (int ifindex) +nm_platform_wifi_get_ssid (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (ifindex > 0, NULL); - return klass->wifi_get_ssid (platform, ifindex); + return klass->wifi_get_ssid (self, ifindex); } guint32 -nm_platform_wifi_get_frequency (int ifindex) +nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex > 0, 0); - return klass->wifi_get_frequency (platform, ifindex); + return klass->wifi_get_frequency (self, ifindex); } int -nm_platform_wifi_get_quality (int ifindex) +nm_platform_wifi_get_quality (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex > 0, 0); - return klass->wifi_get_quality (platform, ifindex); + return klass->wifi_get_quality (self, ifindex); } guint32 -nm_platform_wifi_get_rate (int ifindex) +nm_platform_wifi_get_rate (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex > 0, 0); - return klass->wifi_get_rate (platform, ifindex); + return klass->wifi_get_rate (self, ifindex); } NM80211Mode -nm_platform_wifi_get_mode (int ifindex) +nm_platform_wifi_get_mode (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NM_802_11_MODE_UNKNOWN); + reset_error (self); g_return_val_if_fail (ifindex > 0, NM_802_11_MODE_UNKNOWN); - return klass->wifi_get_mode (platform, ifindex); + return klass->wifi_get_mode (self, ifindex); } void -nm_platform_wifi_set_mode (int ifindex, NM80211Mode mode) +nm_platform_wifi_set_mode (NMPlatform *self, int ifindex, NM80211Mode mode) { - reset_error (); + _CHECK_SELF_VOID (self, klass); + reset_error (self); g_return_if_fail (ifindex > 0); - klass->wifi_set_mode (platform, ifindex, mode); + klass->wifi_set_mode (self, ifindex, mode); } guint32 -nm_platform_wifi_find_frequency (int ifindex, const guint32 *freqs) +nm_platform_wifi_find_frequency (NMPlatform *self, int ifindex, const guint32 *freqs) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex > 0, 0); g_return_val_if_fail (freqs != NULL, 0); - return klass->wifi_find_frequency (platform, ifindex, freqs); + return klass->wifi_find_frequency (self, ifindex, freqs); } void -nm_platform_wifi_indicate_addressing_running (int ifindex, gboolean running) +nm_platform_wifi_indicate_addressing_running (NMPlatform *self, int ifindex, gboolean running) { - reset_error (); + _CHECK_SELF_VOID (self, klass); + reset_error (self); g_return_if_fail (ifindex > 0); - klass->wifi_indicate_addressing_running (platform, ifindex, running); + klass->wifi_indicate_addressing_running (self, ifindex, running); } guint32 -nm_platform_mesh_get_channel (int ifindex) +nm_platform_mesh_get_channel (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, 0); + reset_error (self); g_return_val_if_fail (ifindex > 0, 0); - return klass->mesh_get_channel (platform, ifindex); + return klass->mesh_get_channel (self, ifindex); } gboolean -nm_platform_mesh_set_channel (int ifindex, guint32 channel) +nm_platform_mesh_set_channel (NMPlatform *self, int ifindex, guint32 channel) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); - return klass->mesh_set_channel (platform, ifindex, channel); + return klass->mesh_set_channel (self, ifindex, channel); } gboolean -nm_platform_mesh_set_ssid (int ifindex, const guint8 *ssid, gsize len) +nm_platform_mesh_set_ssid (NMPlatform *self, int ifindex, const guint8 *ssid, gsize len) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (ssid != NULL, FALSE); - return klass->mesh_set_ssid (platform, ifindex, ssid, len); + return klass->mesh_set_ssid (self, ifindex, ssid, len); } #define TO_STRING_DEV_BUF_SIZE (5+15+1) static const char * -_to_string_dev (int ifindex, char *buf, size_t size) +_to_string_dev (NMPlatform *self, int ifindex, char *buf, size_t size) { g_assert (buf && size >= TO_STRING_DEV_BUF_SIZE); if (ifindex) { - const char *name = ifindex > 0 ? nm_platform_link_get_name (ifindex) : NULL; + const char *name = ifindex > 0 && self ? nm_platform_link_get_name (self, ifindex) : NULL; char *buf2; strcpy (buf, " dev "); @@ -1583,29 +1721,32 @@ _to_string_dev (int ifindex, char *buf, size_t size) /******************************************************************/ GArray * -nm_platform_ip4_address_get_all (int ifindex) +nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); 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 (platform, ifindex); + return klass->ip4_address_get_all (self, ifindex); } GArray * -nm_platform_ip6_address_get_all (int ifindex) +nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); 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 (platform, ifindex); + return klass->ip6_address_get_all (self, ifindex); } gboolean -nm_platform_ip4_address_add (int ifindex, +nm_platform_ip4_address_add (NMPlatform *self, + int ifindex, in_addr_t address, in_addr_t peer_address, int plen, @@ -1613,7 +1754,8 @@ nm_platform_ip4_address_add (int ifindex, guint32 preferred, const char *label) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (plen > 0, FALSE); @@ -1637,11 +1779,12 @@ nm_platform_ip4_address_add (int ifindex, debug ("address: adding or updating IPv4 address: %s", nm_platform_ip4_address_to_string (&addr)); } - return klass->ip4_address_add (platform, ifindex, address, peer_address, plen, lifetime, preferred, label); + return klass->ip4_address_add (self, ifindex, address, peer_address, plen, lifetime, preferred, label); } gboolean -nm_platform_ip6_address_add (int ifindex, +nm_platform_ip6_address_add (NMPlatform *self, + int ifindex, struct in6_addr address, struct in6_addr peer_address, int plen, @@ -1649,7 +1792,8 @@ nm_platform_ip6_address_add (int ifindex, guint32 preferred, guint flags) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (plen > 0, FALSE); @@ -1671,16 +1815,17 @@ nm_platform_ip6_address_add (int ifindex, debug ("address: adding or updating IPv6 address: %s", nm_platform_ip6_address_to_string (&addr)); } - return klass->ip6_address_add (platform, ifindex, address, peer_address, plen, lifetime, preferred, flags); + return klass->ip6_address_add (self, ifindex, address, peer_address, plen, lifetime, preferred, flags); } gboolean -nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen, in_addr_t peer_address) +nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address) { char str_dev[TO_STRING_DEV_BUF_SIZE]; char str_peer[NM_UTILS_INET_ADDRSTRLEN]; - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (plen > 0, FALSE); @@ -1692,16 +1837,17 @@ nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen, in_add peer_address ? nm_utils_inet4_ntop (peer_address, str_peer) : "", peer_address ? ", " : "", ifindex, - _to_string_dev (ifindex, str_dev, sizeof (str_dev))); - return klass->ip4_address_delete (platform, ifindex, address, plen, peer_address); + _to_string_dev (self, ifindex, str_dev, sizeof (str_dev))); + return klass->ip4_address_delete (self, ifindex, address, plen, peer_address); } gboolean -nm_platform_ip6_address_delete (int ifindex, struct in6_addr address, int plen) +nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, int plen) { char str_dev[TO_STRING_DEV_BUF_SIZE]; - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (plen > 0, FALSE); @@ -1709,30 +1855,32 @@ nm_platform_ip6_address_delete (int ifindex, struct in6_addr address, int plen) debug ("address: deleting IPv6 address %s/%d, ifindex %d%s", nm_utils_inet6_ntop (&address, NULL), plen, ifindex, - _to_string_dev (ifindex, str_dev, sizeof (str_dev))); - return klass->ip6_address_delete (platform, ifindex, address, plen); + _to_string_dev (self, ifindex, str_dev, sizeof (str_dev))); + return klass->ip6_address_delete (self, ifindex, address, plen); } gboolean -nm_platform_ip4_address_exists (int ifindex, in_addr_t address, int plen) +nm_platform_ip4_address_exists (NMPlatform *self, int ifindex, in_addr_t address, int plen) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (plen > 0, FALSE); g_return_val_if_fail (klass->ip4_address_exists, FALSE); - return klass->ip4_address_exists (platform, ifindex, address, plen); + return klass->ip4_address_exists (self, ifindex, address, plen); } gboolean -nm_platform_ip6_address_exists (int ifindex, struct in6_addr address, int plen) +nm_platform_ip6_address_exists (NMPlatform *self, int ifindex, struct in6_addr address, int plen) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); g_return_val_if_fail (plen > 0, FALSE); g_return_val_if_fail (klass->ip6_address_exists, FALSE); - return klass->ip6_address_exists (platform, ifindex, address, plen); + return klass->ip6_address_exists (self, ifindex, address, plen); } static gboolean @@ -1838,9 +1986,10 @@ _address_get_lifetime (const NMPlatformIPAddress *address, guint32 now, guint32 } gboolean -nm_platform_ip4_check_reinstall_device_route (int ifindex, const NMPlatformIP4Address *address, guint32 device_route_metric) +nm_platform_ip4_check_reinstall_device_route (NMPlatform *self, int ifindex, const NMPlatformIP4Address *address, guint32 device_route_metric) { - g_return_val_if_fail (address, FALSE); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); if ( ifindex <= 0 || address->plen <= 0 @@ -1853,11 +2002,12 @@ nm_platform_ip4_check_reinstall_device_route (int ifindex, const NMPlatformIP4Ad return FALSE; } - return klass->ip4_check_reinstall_device_route (platform, ifindex, address, device_route_metric); + return klass->ip4_check_reinstall_device_route (self, ifindex, address, device_route_metric); } /** * nm_platform_ip4_address_sync: + * @self: platform instance * @ifindex: Interface index * @known_addresses: List of addresses * @device_route_metric: the route metric for adding subnet routes (replaces @@ -1870,20 +2020,22 @@ nm_platform_ip4_check_reinstall_device_route (int ifindex, const NMPlatformIP4Ad * Returns: %TRUE on success. */ gboolean -nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint32 device_route_metric) +nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, guint32 device_route_metric) { GArray *addresses; NMPlatformIP4Address *address; guint32 now = nm_utils_get_monotonic_timestamp_s (); int i; + _CHECK_SELF (self, klass, FALSE); + /* Delete unknown addresses */ - addresses = nm_platform_ip4_address_get_all (ifindex); + addresses = nm_platform_ip4_address_get_all (self, ifindex); for (i = 0; i < addresses->len; i++) { address = &g_array_index (addresses, NMPlatformIP4Address, i); if (!array_contains_ip4_address (known_addresses, address)) - nm_platform_ip4_address_delete (ifindex, address->address, address->plen, address->peer_address); + nm_platform_ip4_address_delete (self, ifindex, address->address, address->plen, address->peer_address); } g_array_free (addresses, TRUE); @@ -1901,10 +2053,10 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint3 if (!_address_get_lifetime ((NMPlatformIPAddress *) known_address, now, 5, &lifetime, &preferred)) continue; - if (nm_platform_ip4_check_reinstall_device_route (ifindex, known_address, device_route_metric)) + if (nm_platform_ip4_check_reinstall_device_route (self, ifindex, known_address, device_route_metric)) reinstall_device_route = TRUE; - if (!nm_platform_ip4_address_add (ifindex, known_address->address, known_address->peer_address, known_address->plen, lifetime, preferred, known_address->label)) + if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->peer_address, known_address->plen, lifetime, preferred, known_address->label)) return FALSE; if (reinstall_device_route) { @@ -1917,9 +2069,9 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint3 * by the above nm_platform_ip4_check_reinstall_device_route() check. */ network = nm_utils_ip4_address_clear_host_address (known_address->address, known_address->plen); - (void) nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_KERNEL, network, known_address->plen, + (void) nm_platform_ip4_route_add (self, ifindex, NM_IP_CONFIG_SOURCE_KERNEL, network, known_address->plen, 0, known_address->address, device_route_metric, 0); - (void) nm_platform_ip4_route_delete (ifindex, network, known_address->plen, + (void) nm_platform_ip4_route_delete (self, ifindex, network, known_address->plen, NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE); } } @@ -1929,6 +2081,7 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint3 /** * nm_platform_ip6_address_sync: + * @self: platform instance * @ifindex: Interface index * @known_addresses: List of addresses * @keep_link_local: Don't remove link-local address @@ -1940,7 +2093,7 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint3 * Returns: %TRUE on success. */ gboolean -nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses, gboolean keep_link_local) +nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, gboolean keep_link_local) { GArray *addresses; NMPlatformIP6Address *address; @@ -1948,7 +2101,7 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses, gboole int i; /* Delete unknown addresses */ - addresses = nm_platform_ip6_address_get_all (ifindex); + addresses = nm_platform_ip6_address_get_all (self, ifindex); for (i = 0; i < addresses->len; i++) { address = &g_array_index (addresses, NMPlatformIP6Address, i); @@ -1957,7 +2110,7 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses, gboole continue; if (!array_contains_ip6_address (known_addresses, address)) - nm_platform_ip6_address_delete (ifindex, address->address, address->plen); + nm_platform_ip6_address_delete (self, ifindex, address->address, address->plen); } g_array_free (addresses, TRUE); @@ -1973,7 +2126,7 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses, gboole if (!_address_get_lifetime ((NMPlatformIPAddress *) known_address, now, 5, &lifetime, &preferred)) continue; - if (!nm_platform_ip6_address_add (ifindex, known_address->address, + if (!nm_platform_ip6_address_add (self, ifindex, known_address->address, known_address->peer_address, known_address->plen, lifetime, preferred, known_address->flags)) return FALSE; @@ -1983,45 +2136,50 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses, gboole } gboolean -nm_platform_address_flush (int ifindex) +nm_platform_address_flush (NMPlatform *self, int ifindex) { - return nm_platform_ip4_address_sync (ifindex, NULL, 0) - && nm_platform_ip6_address_sync (ifindex, NULL, FALSE); + _CHECK_SELF (self, klass, FALSE); + + return nm_platform_ip4_address_sync (self, ifindex, NULL, 0) + && nm_platform_ip6_address_sync (self, ifindex, NULL, FALSE); } /******************************************************************/ GArray * -nm_platform_ip4_route_get_all (int ifindex, NMPlatformGetRouteMode mode) +nm_platform_ip4_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteMode mode) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (ifindex >= 0, NULL); g_return_val_if_fail (klass->ip4_route_get_all, NULL); - return klass->ip4_route_get_all (platform, ifindex, mode); + return klass->ip4_route_get_all (self, ifindex, mode); } GArray * -nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode) +nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteMode mode) { - reset_error (); + _CHECK_SELF (self, klass, NULL); + reset_error (self); g_return_val_if_fail (ifindex >= 0, NULL); g_return_val_if_fail (klass->ip6_route_get_all, NULL); - return klass->ip6_route_get_all (platform, ifindex, mode); + return klass->ip6_route_get_all (self, ifindex, mode); } gboolean -nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source, +nm_platform_ip4_route_add (NMPlatform *self, + int ifindex, NMIPConfigSource source, in_addr_t network, int plen, in_addr_t gateway, guint32 pref_src, guint32 metric, guint32 mss) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_return_val_if_fail (platform, FALSE); g_return_val_if_fail (0 <= plen && plen <= 32, FALSE); g_return_val_if_fail (klass->ip4_route_add, FALSE); @@ -2042,15 +2200,18 @@ nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source, pref_src ? nm_utils_inet4_ntop (pref_src, pref_src_buf) : "", pref_src ? ")" : ""); } - return klass->ip4_route_add (platform, ifindex, source, network, plen, gateway, pref_src, metric, mss); + return klass->ip4_route_add (self, ifindex, source, network, plen, gateway, pref_src, metric, mss); } gboolean -nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source, +nm_platform_ip6_route_add (NMPlatform *self, + int ifindex, NMIPConfigSource source, struct in6_addr network, int plen, struct in6_addr gateway, guint32 metric, guint32 mss) { - g_return_val_if_fail (platform, FALSE); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); + g_return_val_if_fail (0 <= plen && plen <= 128, FALSE); g_return_val_if_fail (klass->ip6_route_add, FALSE); @@ -2067,61 +2228,61 @@ nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source, debug ("route: adding or updating IPv6 route: %s", nm_platform_ip6_route_to_string (&route)); } - return klass->ip6_route_add (platform, ifindex, source, network, plen, gateway, metric, mss); + return klass->ip6_route_add (self, ifindex, source, network, plen, gateway, metric, mss); } gboolean -nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, guint32 metric) +nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, int plen, guint32 metric) { char str_dev[TO_STRING_DEV_BUF_SIZE]; - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_return_val_if_fail (platform, FALSE); g_return_val_if_fail (klass->ip4_route_delete, FALSE); debug ("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 (ifindex, str_dev, sizeof (str_dev))); - return klass->ip4_route_delete (platform, ifindex, network, plen, metric); + _to_string_dev (self, ifindex, str_dev, sizeof (str_dev))); + return klass->ip4_route_delete (self, ifindex, network, plen, metric); } gboolean -nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, guint32 metric) +nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, int plen, guint32 metric) { char str_dev[TO_STRING_DEV_BUF_SIZE]; - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_return_val_if_fail (platform, FALSE); g_return_val_if_fail (klass->ip6_route_delete, FALSE); debug ("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 (ifindex, str_dev, sizeof (str_dev))); - return klass->ip6_route_delete (platform, ifindex, network, plen, metric); + _to_string_dev (self, ifindex, str_dev, sizeof (str_dev))); + return klass->ip6_route_delete (self, ifindex, network, plen, metric); } gboolean -nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, guint32 metric) +nm_platform_ip4_route_exists (NMPlatform *self, int ifindex, in_addr_t network, int plen, guint32 metric) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_return_val_if_fail (platform, FALSE); g_return_val_if_fail (klass->ip4_route_exists, FALSE); - return klass->ip4_route_exists (platform,ifindex, network, plen, metric); + return klass->ip4_route_exists (self ,ifindex, network, plen, metric); } gboolean -nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, guint32 metric) +nm_platform_ip6_route_exists (NMPlatform *self, int ifindex, struct in6_addr network, int plen, guint32 metric) { - reset_error (); + _CHECK_SELF (self, klass, FALSE); + reset_error (self); - g_return_val_if_fail (platform, FALSE); g_return_val_if_fail (klass->ip6_route_exists, FALSE); - return klass->ip6_route_exists (platform, ifindex, network, plen, metric); + return klass->ip6_route_exists (self, ifindex, network, plen, metric); } static gboolean @@ -2164,6 +2325,7 @@ array_contains_ip6_route (const GArray *routes, const NMPlatformIP6Route *route) /** * nm_platform_ip4_route_sync: + * @self: platform instance * @ifindex: Interface index * @known_routes: List of routes * @@ -2176,7 +2338,7 @@ array_contains_ip6_route (const GArray *routes, const NMPlatformIP6Route *route) * Returns: %TRUE on success. */ gboolean -nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes) +nm_platform_ip4_route_sync (NMPlatform *self, int ifindex, const GArray *known_routes) { GArray *routes; NMPlatformIP4Route *route; @@ -2184,13 +2346,15 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes) gboolean success; int i, i_type; + _CHECK_SELF (self, klass, FALSE); + /* Delete unknown routes */ - routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT); + routes = nm_platform_ip4_route_get_all (self, ifindex, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT); for (i = 0; i < routes->len; i++) { route = &g_array_index (routes, NMPlatformIP4Route, i); if (!array_contains_ip4_route (known_routes, route)) - (void) nm_platform_ip4_route_delete (ifindex, route->network, route->plen, route->metric); + (void) nm_platform_ip4_route_delete (self, ifindex, route->network, route->plen, route->metric); } if (!known_routes) { @@ -2215,7 +2379,8 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes) /* Ignore routes that already exist */ if (!array_contains_ip4_route (routes, known_route)) { - success = nm_platform_ip4_route_add (ifindex, + success = nm_platform_ip4_route_add (self, + ifindex, known_route->source, known_route->network, known_route->plen, @@ -2238,6 +2403,7 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes) /** * nm_platform_ip6_route_sync: + * @self: platform instance * @ifindex: Interface index * @known_routes: List of routes * @@ -2250,7 +2416,7 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes) * Returns: %TRUE on success. */ gboolean -nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes) +nm_platform_ip6_route_sync (NMPlatform *self, int ifindex, const GArray *known_routes) { GArray *routes; NMPlatformIP6Route *route; @@ -2258,14 +2424,16 @@ nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes) gboolean success; int i, i_type; + _CHECK_SELF (self, klass, FALSE); + /* Delete unknown routes */ - routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT); + routes = nm_platform_ip6_route_get_all (self, ifindex, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT); for (i = 0; i < routes->len; i++) { route = &g_array_index (routes, NMPlatformIP6Route, i); route->ifindex = 0; if (!array_contains_ip6_route (known_routes, route)) - nm_platform_ip6_route_delete (ifindex, route->network, route->plen, route->metric); + nm_platform_ip6_route_delete (self, ifindex, route->network, route->plen, route->metric); } if (!known_routes) { @@ -2290,7 +2458,8 @@ nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes) /* Ignore routes that already exist */ if (!array_contains_ip6_route (routes, known_route)) { - success = nm_platform_ip6_route_add (ifindex, + success = nm_platform_ip6_route_add (self, + ifindex, known_route->source, known_route->network, known_route->plen, @@ -2311,10 +2480,10 @@ nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes) } gboolean -nm_platform_route_flush (int ifindex) +nm_platform_route_flush (NMPlatform *self, int ifindex) { - return nm_platform_ip4_route_sync (ifindex, NULL) - && nm_platform_ip6_route_sync (ifindex, NULL); + return nm_platform_ip4_route_sync (self, ifindex, NULL) + && nm_platform_ip6_route_sync (self, ifindex, NULL); } /******************************************************************/ @@ -2448,7 +2617,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address) str_peer = g_strconcat (" ptp ", s_peer, NULL); } - _to_string_dev (address->ifindex, str_dev, sizeof (str_dev)); + _to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev)); if (*address->label) g_snprintf (str_label, sizeof (str_label), " label %s", address->label); @@ -2533,7 +2702,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address) str_peer = g_strconcat (" ptp ", s_peer, NULL); } - _to_string_dev (address->ifindex, str_dev, sizeof (str_dev)); + _to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev)); nm_platform_addr_flags2str (address->flags, s_flags, sizeof (s_flags)); @@ -2583,7 +2752,7 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route) inet_ntop (AF_INET, &route->network, s_network, sizeof(s_network)); inet_ntop (AF_INET, &route->gateway, s_gateway, sizeof(s_gateway)); - _to_string_dev (route->ifindex, str_dev, sizeof (str_dev)); + _to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev)); g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %"G_GUINT32_FORMAT" mss %"G_GUINT32_FORMAT" src %s", s_network, route->plen, s_gateway, @@ -2616,7 +2785,7 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route) inet_ntop (AF_INET6, &route->network, s_network, sizeof(s_network)); inet_ntop (AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway)); - _to_string_dev (route->ifindex, str_dev, sizeof (str_dev)); + _to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev)); g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %"G_GUINT32_FORMAT" mss %"G_GUINT32_FORMAT" src %s", s_network, route->plen, s_gateway, @@ -2848,9 +3017,10 @@ log_ip6_route (NMPlatform *p, int ifindex, NMPlatformIP6Route *route, NMPlatform /******************************************************************/ static gboolean -_vtr_v4_route_add (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) +_vtr_v4_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) { - return nm_platform_ip4_route_add (ifindex > 0 ? ifindex : route->rx.ifindex, + return nm_platform_ip4_route_add (self, + ifindex > 0 ? ifindex : route->rx.ifindex, route->rx.source, route->r4.network, route->rx.plen, @@ -2861,9 +3031,10 @@ _vtr_v4_route_add (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref } static gboolean -_vtr_v6_route_add (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) +_vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) { - return nm_platform_ip6_route_add (ifindex > 0 ? ifindex : route->rx.ifindex, + return nm_platform_ip6_route_add (self, + ifindex > 0 ? ifindex : route->rx.ifindex, route->rx.source, route->r6.network, route->rx.plen, @@ -2873,18 +3044,20 @@ _vtr_v6_route_add (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref } static gboolean -_vtr_v4_route_delete (int ifindex, const NMPlatformIPXRoute *route) +_vtr_v4_route_delete (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route) { - return nm_platform_ip4_route_delete (ifindex > 0 ? ifindex : route->rx.ifindex, + return nm_platform_ip4_route_delete (self, + ifindex > 0 ? ifindex : route->rx.ifindex, route->r4.network, route->rx.plen, route->rx.metric); } static gboolean -_vtr_v6_route_delete (int ifindex, const NMPlatformIPXRoute *route) +_vtr_v6_route_delete (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route) { - return nm_platform_ip6_route_delete (ifindex > 0 ? ifindex : route->rx.ifindex, + return nm_platform_ip6_route_delete (self, + ifindex > 0 ? ifindex : route->rx.ifindex, route->r6.network, route->rx.plen, route->rx.metric); @@ -2897,15 +3070,15 @@ _vtr_v4_metric_normalize (guint32 metric) } static gboolean -_vtr_v4_route_delete_default (int ifindex, guint32 metric) +_vtr_v4_route_delete_default (NMPlatform *self, int ifindex, guint32 metric) { - return nm_platform_ip4_route_delete (ifindex, 0, 0, metric); + return nm_platform_ip4_route_delete (self, ifindex, 0, 0, metric); } static gboolean -_vtr_v6_route_delete_default (int ifindex, guint32 metric) +_vtr_v6_route_delete_default (NMPlatform *self, int ifindex, guint32 metric) { - return nm_platform_ip6_route_delete (ifindex, in6addr_any, 0, metric); + return nm_platform_ip6_route_delete (self, ifindex, in6addr_any, 0, metric); } /******************************************************************/ diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index e23ddf03dd..21df64f58c 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -39,6 +39,8 @@ /******************************************************************/ +typedef struct _NMPlatform NMPlatform; + /* workaround for older libnl version, that does not define these flags. */ #ifndef IFA_F_MANAGETEMPADDR #define IFA_F_MANAGETEMPADDR 0x100 @@ -252,10 +254,10 @@ typedef struct { gsize sizeof_route; int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b); const char *(*route_to_string) (const NMPlatformIPXRoute *route); - GArray *(*route_get_all) (int ifindex, NMPlatformGetRouteMode mode); - gboolean (*route_add) (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src); - gboolean (*route_delete) (int ifindex, const NMPlatformIPXRoute *route); - gboolean (*route_delete_default) (int ifindex, guint32 metric); + GArray *(*route_get_all) (NMPlatform *self, int ifindex, NMPlatformGetRouteMode mode); + gboolean (*route_add) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src); + gboolean (*route_delete) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route); + gboolean (*route_delete_default) (NMPlatform *self, int ifindex, guint32 metric); guint32 (*metric_normalize) (guint32 metric); } NMPlatformVTableRoute; @@ -346,11 +348,11 @@ typedef struct { * network configuration daemons stopped. Look at the code first. */ -typedef struct { +struct _NMPlatform { GObject parent; NMPlatformError error; -} NMPlatform; +}; typedef struct { GObjectClass parent; @@ -491,134 +493,136 @@ void nm_platform_setup (GType type); NMPlatform *nm_platform_get (void); void nm_platform_free (void); +#define NM_PLATFORM_GET (nm_platform_get ()) + /******************************************************************/ -void nm_platform_set_error (NMPlatformError error); -NMPlatformError nm_platform_get_error (void); -const char *nm_platform_get_error_msg (void); +void nm_platform_set_error (NMPlatform *self, NMPlatformError error); +NMPlatformError nm_platform_get_error (NMPlatform *self); +const char *nm_platform_get_error_msg (NMPlatform *self); -void nm_platform_query_devices (void); +void nm_platform_query_devices (NMPlatform *self); -gboolean nm_platform_sysctl_set (const char *path, const char *value); -char *nm_platform_sysctl_get (const char *path); -gint32 nm_platform_sysctl_get_int32 (const char *path, gint32 fallback); -gint64 nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gint64 max, gint64 fallback); +gboolean nm_platform_sysctl_set (NMPlatform *self, const char *path, const char *value); +char *nm_platform_sysctl_get (NMPlatform *self, const char *path); +gint32 nm_platform_sysctl_get_int32 (NMPlatform *self, const char *path, gint32 fallback); +gint64 nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *path, guint base, gint64 min, gint64 max, gint64 fallback); -gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (const char *iface, int value); +gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char *iface, int value); -gboolean nm_platform_link_get (int ifindex, NMPlatformLink *link); -GArray *nm_platform_link_get_all (void); -gboolean nm_platform_dummy_add (const char *name); -gboolean nm_platform_bridge_add (const char *name, const void *address, size_t address_len); -gboolean nm_platform_bond_add (const char *name); -gboolean nm_platform_team_add (const char *name); -gboolean nm_platform_link_exists (const char *name); -gboolean nm_platform_link_delete (int ifindex); -int nm_platform_link_get_ifindex (const char *name); -const char *nm_platform_link_get_name (int ifindex); -NMLinkType nm_platform_link_get_type (int ifindex); -const char *nm_platform_link_get_type_name (int ifindex); -gboolean nm_platform_link_get_unmanaged (int ifindex, gboolean *managed); -gboolean nm_platform_link_is_software (int ifindex); -gboolean nm_platform_link_supports_slaves (int ifindex); +gboolean nm_platform_link_get (NMPlatform *self, int ifindex, NMPlatformLink *link); +GArray *nm_platform_link_get_all (NMPlatform *self); +gboolean nm_platform_dummy_add (NMPlatform *self, const char *name); +gboolean nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len); +gboolean nm_platform_bond_add (NMPlatform *self, const char *name); +gboolean nm_platform_team_add (NMPlatform *self, const char *name); +gboolean nm_platform_link_exists (NMPlatform *self, const char *name); +gboolean nm_platform_link_delete (NMPlatform *self, int ifindex); +int nm_platform_link_get_ifindex (NMPlatform *self, const char *name); +const char *nm_platform_link_get_name (NMPlatform *self, int ifindex); +NMLinkType nm_platform_link_get_type (NMPlatform *self, int ifindex); +const char *nm_platform_link_get_type_name (NMPlatform *self, int ifindex); +gboolean nm_platform_link_get_unmanaged (NMPlatform *self, int ifindex, gboolean *managed); +gboolean nm_platform_link_is_software (NMPlatform *self, int ifindex); +gboolean nm_platform_link_supports_slaves (NMPlatform *self, int ifindex); -gboolean nm_platform_link_refresh (int ifindex); +gboolean nm_platform_link_refresh (NMPlatform *self, int ifindex); -gboolean nm_platform_link_set_up (int ifindex); -gboolean nm_platform_link_set_down (int ifindex); -gboolean nm_platform_link_set_arp (int ifindex); -gboolean nm_platform_link_set_noarp (int ifindex); -gboolean nm_platform_link_is_up (int ifindex); -gboolean nm_platform_link_is_connected (int ifindex); -gboolean nm_platform_link_uses_arp (int ifindex); +gboolean nm_platform_link_set_up (NMPlatform *self, int ifindex); +gboolean nm_platform_link_set_down (NMPlatform *self, int ifindex); +gboolean nm_platform_link_set_arp (NMPlatform *self, int ifindex); +gboolean nm_platform_link_set_noarp (NMPlatform *self, int ifindex); +gboolean nm_platform_link_is_up (NMPlatform *self, int ifindex); +gboolean nm_platform_link_is_connected (NMPlatform *self, int ifindex); +gboolean nm_platform_link_uses_arp (NMPlatform *self, int ifindex); -gboolean nm_platform_link_get_ipv6_token (int ifindex, NMUtilsIPv6IfaceId *iid); +gboolean nm_platform_link_get_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId *iid); -gboolean nm_platform_link_get_user_ipv6ll_enabled (int ifindex); -gboolean nm_platform_link_set_user_ipv6ll_enabled (int ifindex, gboolean enabled); +gboolean nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex); +gboolean nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled); -gconstpointer nm_platform_link_get_address (int ifindex, size_t *length); -gboolean nm_platform_link_set_address (int ifindex, const void *address, size_t length); -guint32 nm_platform_link_get_mtu (int ifindex); -gboolean nm_platform_link_set_mtu (int ifindex, guint32 mtu); +gconstpointer nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length); +gboolean nm_platform_link_set_address (NMPlatform *self, int ifindex, const void *address, size_t length); +guint32 nm_platform_link_get_mtu (NMPlatform *self, int ifindex); +gboolean nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu); -char *nm_platform_link_get_physical_port_id (int ifindex); -guint nm_platform_link_get_dev_id (int ifindex); -gboolean nm_platform_link_get_wake_on_lan (int ifindex); +char *nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex); +guint nm_platform_link_get_dev_id (NMPlatform *self, int ifindex); +gboolean nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex); -gboolean nm_platform_link_supports_carrier_detect (int ifindex); -gboolean nm_platform_link_supports_vlans (int ifindex); +gboolean nm_platform_link_supports_carrier_detect (NMPlatform *self, int ifindex); +gboolean nm_platform_link_supports_vlans (NMPlatform *self, int ifindex); -gboolean nm_platform_link_enslave (int master, int slave); -gboolean nm_platform_link_release (int master, int slave); -int nm_platform_link_get_master (int slave); -gboolean nm_platform_master_set_option (int ifindex, const char *option, const char *value); -char *nm_platform_master_get_option (int ifindex, const char *option); -gboolean nm_platform_slave_set_option (int ifindex, const char *option, const char *value); -char *nm_platform_slave_get_option (int ifindex, const char *option); +gboolean nm_platform_link_enslave (NMPlatform *self, int master, int slave); +gboolean nm_platform_link_release (NMPlatform *self, int master, int slave); +int nm_platform_link_get_master (NMPlatform *self, 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_vlan_add (const char *name, int parent, int vlanid, guint32 vlanflags); -gboolean nm_platform_vlan_get_info (int ifindex, int *parent, int *vlanid); -gboolean nm_platform_vlan_set_ingress_map (int ifindex, int from, int to); -gboolean nm_platform_vlan_set_egress_map (int ifindex, int from, int to); +gboolean nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags); +gboolean nm_platform_vlan_get_info (NMPlatform *self, int ifindex, int *parent, int *vlanid); +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_infiniband_partition_add (int parent, int p_key); +gboolean nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key); -gboolean nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *properties); -gboolean nm_platform_tun_get_properties (int ifindex, NMPlatformTunProperties *properties); -gboolean nm_platform_macvlan_get_properties (int ifindex, NMPlatformMacvlanProperties *props); -gboolean nm_platform_vxlan_get_properties (int ifindex, NMPlatformVxlanProperties *props); -gboolean nm_platform_gre_get_properties (int ifindex, NMPlatformGreProperties *props); +gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethProperties *properties); +gboolean nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *properties); +gboolean nm_platform_macvlan_get_properties (NMPlatform *self, int ifindex, NMPlatformMacvlanProperties *props); +gboolean nm_platform_vxlan_get_properties (NMPlatform *self, int ifindex, NMPlatformVxlanProperties *props); +gboolean nm_platform_gre_get_properties (NMPlatform *self, int ifindex, NMPlatformGreProperties *props); -gboolean nm_platform_wifi_get_capabilities (int ifindex, NMDeviceWifiCapabilities *caps); -gboolean nm_platform_wifi_get_bssid (int ifindex, guint8 *bssid); -GByteArray *nm_platform_wifi_get_ssid (int ifindex); -guint32 nm_platform_wifi_get_frequency (int ifindex); -int nm_platform_wifi_get_quality (int ifindex); -guint32 nm_platform_wifi_get_rate (int ifindex); -NM80211Mode nm_platform_wifi_get_mode (int ifindex); -void nm_platform_wifi_set_mode (int ifindex, NM80211Mode mode); -guint32 nm_platform_wifi_find_frequency (int ifindex, const guint32 *freqs); -void nm_platform_wifi_indicate_addressing_running (int ifindex, gboolean running); +gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps); +gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid); +GByteArray *nm_platform_wifi_get_ssid (NMPlatform *self, int ifindex); +guint32 nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex); +int nm_platform_wifi_get_quality (NMPlatform *self, int ifindex); +guint32 nm_platform_wifi_get_rate (NMPlatform *self, int ifindex); +NM80211Mode nm_platform_wifi_get_mode (NMPlatform *self, int ifindex); +void nm_platform_wifi_set_mode (NMPlatform *self, int ifindex, NM80211Mode mode); +guint32 nm_platform_wifi_find_frequency (NMPlatform *self, int ifindex, const guint32 *freqs); +void nm_platform_wifi_indicate_addressing_running (NMPlatform *self, int ifindex, gboolean running); -guint32 nm_platform_mesh_get_channel (int ifindex); -gboolean nm_platform_mesh_set_channel (int ifindex, guint32 channel); -gboolean nm_platform_mesh_set_ssid (int ifindex, const guint8 *ssid, gsize len); +guint32 nm_platform_mesh_get_channel (NMPlatform *self, int ifindex); +gboolean nm_platform_mesh_set_channel (NMPlatform *self, int ifindex, guint32 channel); +gboolean nm_platform_mesh_set_ssid (NMPlatform *self, int ifindex, const guint8 *ssid, gsize len); -GArray *nm_platform_ip4_address_get_all (int ifindex); -GArray *nm_platform_ip6_address_get_all (int ifindex); -gboolean nm_platform_ip4_address_add (int ifindex, +GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex); +GArray *nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex); +gboolean nm_platform_ip4_address_add (NMPlatform *self, int ifindex, in_addr_t address, in_addr_t peer_address, int plen, guint32 lifetime, guint32 preferred_lft, const char *label); -gboolean nm_platform_ip6_address_add (int ifindex, +gboolean nm_platform_ip6_address_add (NMPlatform *self, int ifindex, struct in6_addr address, struct in6_addr peer_address, int plen, guint32 lifetime, guint32 preferred_lft, guint flags); -gboolean nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen, in_addr_t peer_address); -gboolean nm_platform_ip6_address_delete (int ifindex, struct in6_addr address, int plen); -gboolean nm_platform_ip4_address_exists (int ifindex, in_addr_t address, int plen); -gboolean nm_platform_ip6_address_exists (int ifindex, struct in6_addr address, int plen); -gboolean nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint32 device_route_metric); -gboolean nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses, gboolean keep_link_local); -gboolean nm_platform_address_flush (int ifindex); +gboolean nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); +gboolean nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, int plen); +gboolean nm_platform_ip4_address_exists (NMPlatform *self, int ifindex, in_addr_t address, int plen); +gboolean nm_platform_ip6_address_exists (NMPlatform *self, int ifindex, struct in6_addr address, int plen); +gboolean nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, guint32 device_route_metric); +gboolean nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, gboolean keep_link_local); +gboolean nm_platform_address_flush (NMPlatform *self, int ifindex); -gboolean nm_platform_ip4_check_reinstall_device_route (int ifindex, const NMPlatformIP4Address *address, guint32 device_route_metric); +gboolean nm_platform_ip4_check_reinstall_device_route (NMPlatform *self, int ifindex, const NMPlatformIP4Address *address, guint32 device_route_metric); -GArray *nm_platform_ip4_route_get_all (int ifindex, NMPlatformGetRouteMode mode); -GArray *nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode); -gboolean nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source, +GArray *nm_platform_ip4_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteMode mode); +GArray *nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteMode mode); +gboolean nm_platform_ip4_route_add (NMPlatform *self, int ifindex, NMIPConfigSource source, in_addr_t network, int plen, in_addr_t gateway, guint32 pref_src, guint32 metric, guint32 mss); -gboolean nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source, +gboolean nm_platform_ip6_route_add (NMPlatform *self, int ifindex, NMIPConfigSource source, struct in6_addr network, int plen, struct in6_addr gateway, guint32 metric, guint32 mss); -gboolean nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, guint32 metric); -gboolean nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, guint32 metric); -gboolean nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, guint32 metric); -gboolean nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, guint32 metric); -gboolean nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes); -gboolean nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes); -gboolean nm_platform_route_flush (int ifindex); +gboolean nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, int plen, guint32 metric); +gboolean nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, int plen, guint32 metric); +gboolean nm_platform_ip4_route_exists (NMPlatform *self, int ifindex, in_addr_t network, int plen, guint32 metric); +gboolean nm_platform_ip6_route_exists (NMPlatform *self, int ifindex, struct in6_addr network, int plen, guint32 metric); +gboolean nm_platform_ip4_route_sync (NMPlatform *self, int ifindex, const GArray *known_routes); +gboolean nm_platform_ip6_route_sync (NMPlatform *self, int ifindex, const GArray *known_routes); +gboolean nm_platform_route_flush (NMPlatform *self, int ifindex); const char *nm_platform_link_to_string (const NMPlatformLink *link); const char *nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address); @@ -633,8 +637,8 @@ int nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4R int nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b); gboolean nm_platform_check_support_libnl_extended_ifa_flags (void); -gboolean nm_platform_check_support_kernel_extended_ifa_flags (void); -gboolean nm_platform_check_support_user_ipv6ll (void); +gboolean nm_platform_check_support_kernel_extended_ifa_flags (NMPlatform *self); +gboolean nm_platform_check_support_user_ipv6ll (NMPlatform *self); void nm_platform_addr_flags2str (int flags, char *buf, size_t size); diff --git a/src/platform/tests/dump.c b/src/platform/tests/dump.c index 3bb61da415..e356df0b45 100644 --- a/src/platform/tests/dump.c +++ b/src/platform/tests/dump.c @@ -44,21 +44,21 @@ dump_interface (NMPlatformLink *link) if (link->driver) printf (" driver: %s\n", link->driver); printf (" UDI: %s\n", link->udi); - if (!nm_platform_vlan_get_info (link->ifindex, &vlan_parent, &vlan_id)) + if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, link->ifindex, &vlan_parent, &vlan_id)) g_assert_not_reached (); if (vlan_parent) printf (" vlan parent %d id %d\n", vlan_parent, vlan_id); - if (nm_platform_link_is_software (link->ifindex)) + if (nm_platform_link_is_software (NM_PLATFORM_GET, link->ifindex)) printf (" class software\n"); - if (nm_platform_link_supports_slaves (link->ifindex)) + if (nm_platform_link_supports_slaves (NM_PLATFORM_GET, link->ifindex)) printf (" class supports-slaves\n"); - if (nm_platform_link_supports_carrier_detect (link->ifindex)) + if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, link->ifindex)) printf (" feature carrier-detect\n"); - if (nm_platform_link_supports_vlans (link->ifindex)) + if (nm_platform_link_supports_vlans (NM_PLATFORM_GET, link->ifindex)) printf (" feature vlans\n"); - address = nm_platform_link_get_address (link->ifindex, &addrlen); + address = nm_platform_link_get_address (NM_PLATFORM_GET, link->ifindex, &addrlen); if (address) { printf (" link-address "); for (i = 0; i < addrlen; i++) @@ -66,8 +66,8 @@ dump_interface (NMPlatformLink *link) printf ("\n"); } - ip4_addresses = nm_platform_ip4_address_get_all (link->ifindex); - ip6_addresses = nm_platform_ip6_address_get_all (link->ifindex); + ip4_addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, link->ifindex); + ip6_addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, link->ifindex); g_assert (ip4_addresses); g_assert (ip6_addresses); @@ -85,8 +85,8 @@ dump_interface (NMPlatformLink *link) g_array_unref (ip4_addresses); g_array_unref (ip6_addresses); - ip4_routes = nm_platform_ip4_route_get_all (link->ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); - ip6_routes = nm_platform_ip6_route_get_all (link->ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + ip4_routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, link->ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + ip6_routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, link->ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); g_assert (ip4_routes); g_assert (ip6_routes); @@ -112,7 +112,7 @@ dump_interface (NMPlatformLink *link) static void dump_all (void) { - GArray *links = nm_platform_link_get_all (); + GArray *links = nm_platform_link_get_all (NM_PLATFORM_GET); int i; for (i = 0; i < links->len; i++) diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index eea6610d37..07ca8f9108 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -44,13 +44,13 @@ typedef const char *string_t; static gboolean do_sysctl_set (char **argv) { - return nm_platform_sysctl_set (argv[0], argv[1]); + return nm_platform_sysctl_set (NM_PLATFORM_GET, argv[0], argv[1]); } static gboolean do_sysctl_get (char **argv) { - gs_free char *value = nm_platform_sysctl_get (argv[0]); + gs_free char *value = nm_platform_sysctl_get (NM_PLATFORM_GET, argv[0]); printf ("%s\n", value); @@ -66,7 +66,7 @@ parse_ifindex (const char *str) ifindex = strtol (str, &endptr, 10); if (*endptr) { - ifindex = nm_platform_link_get_ifindex (str); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, str); } return ifindex; @@ -79,7 +79,7 @@ do_link_get_all (char **argv) NMPlatformLink *device; int i; - links = nm_platform_link_get_all (); + links = nm_platform_link_get_all (NM_PLATFORM_GET); for (i = 0; i < links->len; i++) { device = &g_array_index (links, NMPlatformLink, i); @@ -93,25 +93,25 @@ do_link_get_all (char **argv) static gboolean do_dummy_add (char **argv) { - return nm_platform_dummy_add (argv[0]); + return nm_platform_dummy_add (NM_PLATFORM_GET, argv[0]); } static gboolean do_bridge_add (char **argv) { - return nm_platform_bridge_add (argv[0], NULL, 0); + return nm_platform_bridge_add (NM_PLATFORM_GET, argv[0], NULL, 0); } static gboolean do_bond_add (char **argv) { - return nm_platform_bond_add (argv[0]); + return nm_platform_bond_add (NM_PLATFORM_GET, argv[0]); } static gboolean do_team_add (char **argv) { - return nm_platform_team_add (argv[0]); + return nm_platform_team_add (NM_PLATFORM_GET, argv[0]); } static gboolean @@ -122,13 +122,13 @@ do_vlan_add (char **argv) int vlanid = strtol (*argv++, NULL, 10); guint32 vlan_flags = strtol (*argv++, NULL, 10); - return nm_platform_vlan_add (name, parent, vlanid, vlan_flags); + return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent, vlanid, vlan_flags); } static gboolean do_link_exists (char **argv) { - gboolean value = nm_platform_link_exists (argv[0]); + gboolean value = nm_platform_link_exists (NM_PLATFORM_GET, argv[0]); print_boolean (value); @@ -140,7 +140,7 @@ do_link_exists (char **argv) do_link_##cmdname (char **argv) \ { \ int ifindex = parse_ifindex (argv[0]); \ - return ifindex ? nm_platform_link_##cmdname (ifindex) : FALSE; \ + return ifindex ? nm_platform_link_##cmdname (NM_PLATFORM_GET, ifindex) : FALSE; \ } #define LINK_CMD_GET_FULL(cmdname, type, cond) \ @@ -149,7 +149,7 @@ do_link_exists (char **argv) { \ int ifindex = parse_ifindex (argv[0]); \ if (ifindex) { \ - type##_t value = nm_platform_link_##cmdname (ifindex); \ + type##_t value = nm_platform_link_##cmdname (NM_PLATFORM_GET, ifindex); \ if (cond) { \ print_##type (value); \ return TRUE; \ @@ -169,7 +169,7 @@ LINK_CMD (delete) static gboolean do_link_get_ifindex (char **argv) { - int ifindex = nm_platform_link_get_ifindex (argv[0]); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, argv[0]); if (ifindex) printf ("%d\n", ifindex); @@ -213,7 +213,7 @@ do_link_set_address (char **argv) g_assert (!*endptr); } - return nm_platform_link_set_address (ifindex, address, sizeof (address)); + return nm_platform_link_set_address (NM_PLATFORM_GET, ifindex, address, sizeof (address)); } static gboolean @@ -224,7 +224,7 @@ do_link_get_address (char **argv) size_t length; int i; - address = nm_platform_link_get_address (ifindex, &length); + address = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &length); if (!address || length <= 0) return FALSE; @@ -242,7 +242,7 @@ do_link_set_mtu (char **argv) int ifindex = parse_ifindex (*argv++); int mtu = strtoul (*argv++, NULL, 10); - return nm_platform_link_set_mtu (ifindex, mtu); + return nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, mtu); } LINK_CMD_GET (get_mtu, decimal); @@ -255,7 +255,7 @@ do_link_enslave (char **argv) int master = parse_ifindex (*argv++); int slave = parse_ifindex (*argv++); - return nm_platform_link_enslave (master, slave); + return nm_platform_link_enslave (NM_PLATFORM_GET, master, slave); } static gboolean @@ -264,7 +264,7 @@ do_link_release (char **argv) int master = parse_ifindex (*argv++); int slave = parse_ifindex (*argv++); - return nm_platform_link_release (master, slave); + return nm_platform_link_release (NM_PLATFORM_GET, master, slave); } LINK_CMD_GET (get_master, decimal) @@ -276,7 +276,7 @@ do_master_set_option (char **argv) const char *option = *argv++; const char *value = *argv++; - return nm_platform_master_set_option (ifindex, option, value); + return nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, option, value); } static gboolean @@ -284,7 +284,7 @@ do_master_get_option (char **argv) { int ifindex = parse_ifindex (*argv++); const char *option = *argv++; - gs_free char *value = nm_platform_master_get_option (ifindex, option); + gs_free char *value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, option); printf ("%s\n", value); @@ -298,7 +298,7 @@ do_slave_set_option (char **argv) const char *option = *argv++; const char *value = *argv++; - return nm_platform_slave_set_option (ifindex, option, value); + return nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, option, value); } static gboolean @@ -306,7 +306,7 @@ do_slave_get_option (char **argv) { int ifindex = parse_ifindex (*argv++); const char *option = *argv++; - gs_free char *value = nm_platform_slave_get_option (ifindex, option); + gs_free char *value = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex, option); printf ("%s\n", value); @@ -320,7 +320,7 @@ do_vlan_get_info (char **argv) int parent; int vlanid; - if (!nm_platform_vlan_get_info (ifindex, &parent, &vlanid)) + if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent, &vlanid)) return FALSE; printf ("%d %d\n", parent, vlanid); @@ -335,7 +335,7 @@ do_vlan_set_ingress_map (char **argv) int from = strtol (*argv++, NULL, 10); int to = strtol (*argv++, NULL, 10); - return nm_platform_vlan_set_ingress_map (ifindex, from, to); + return nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, ifindex, from, to); } static gboolean @@ -345,7 +345,7 @@ do_vlan_set_egress_map (char **argv) int from = strtol (*argv++, NULL, 10); int to = strtol (*argv++, NULL, 10); - return nm_platform_vlan_set_egress_map (ifindex, from, to); + return nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, from, to); } static gboolean @@ -354,7 +354,7 @@ do_veth_get_properties (char **argv) int ifindex = parse_ifindex (*argv++); NMPlatformVethProperties props; - if (!nm_platform_veth_get_properties (ifindex, &props)) + if (!nm_platform_veth_get_properties (NM_PLATFORM_GET, ifindex, &props)) return FALSE; printf ("peer: %d\n", props.peer); @@ -368,7 +368,7 @@ do_tun_get_properties (char **argv) int ifindex = parse_ifindex (*argv++); NMPlatformTunProperties props; - if (!nm_platform_tun_get_properties (ifindex, &props)) + if (!nm_platform_tun_get_properties (NM_PLATFORM_GET, ifindex, &props)) return FALSE; printf ("mode: %s\n", props.mode); @@ -396,7 +396,7 @@ do_macvlan_get_properties (char **argv) int ifindex = parse_ifindex (*argv++); NMPlatformMacvlanProperties props; - if (!nm_platform_macvlan_get_properties (ifindex, &props)) + if (!nm_platform_macvlan_get_properties (NM_PLATFORM_GET, ifindex, &props)) return FALSE; printf ("parent: %d\n", props.parent_ifindex); @@ -413,7 +413,7 @@ do_vxlan_get_properties (char **argv) NMPlatformVxlanProperties props; char addrstr[INET6_ADDRSTRLEN]; - if (!nm_platform_vxlan_get_properties (ifindex, &props)) + if (!nm_platform_vxlan_get_properties (NM_PLATFORM_GET, ifindex, &props)) return FALSE; printf ("parent-ifindex: %u\n", props.parent_ifindex); @@ -460,7 +460,7 @@ do_gre_get_properties (char **argv) NMPlatformGreProperties props; char addrstr[INET_ADDRSTRLEN]; - if (!nm_platform_gre_get_properties (ifindex, &props)) + if (!nm_platform_gre_get_properties (NM_PLATFORM_GET, ifindex, &props)) return FALSE; printf ("parent-ifindex: %u\n", props.parent_ifindex); @@ -496,7 +496,7 @@ do_ip4_address_get_all (char **argv) int i; if (ifindex) { - addresses = nm_platform_ip4_address_get_all (ifindex); + addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); for (i = 0; i < addresses->len; i++) { address = &g_array_index (addresses, NMPlatformIP4Address, i); inet_ntop (AF_INET, &address->address, addrstr, sizeof (addrstr)); @@ -518,7 +518,7 @@ do_ip6_address_get_all (char **argv) int i; if (ifindex) { - addresses = nm_platform_ip6_address_get_all (ifindex); + addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex); for (i = 0; i < addresses->len; i++) { address = &g_array_index (addresses, NMPlatformIP6Address, i); inet_ntop (AF_INET6, &address->address, addrstr, sizeof (addrstr)); @@ -576,7 +576,7 @@ do_ip4_address_add (char **argv) guint32 lifetime = strtol (*argv++, NULL, 10); guint32 preferred = strtol (*argv++, NULL, 10); - gboolean value = nm_platform_ip4_address_add (ifindex, address, 0, plen, lifetime, preferred, NULL); + gboolean value = nm_platform_ip4_address_add (NM_PLATFORM_GET, ifindex, address, 0, plen, lifetime, preferred, NULL); return value; } else return FALSE; @@ -594,7 +594,7 @@ do_ip6_address_add (char **argv) guint32 preferred = strtol (*argv++, NULL, 10); guint flags = (*argv) ? rtnl_addr_str2flags (*argv++) : 0; - gboolean value = nm_platform_ip6_address_add (ifindex, address, in6addr_any, plen, lifetime, preferred, flags); + gboolean value = nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, address, in6addr_any, plen, lifetime, preferred, flags); return value; } else return FALSE; @@ -608,7 +608,7 @@ do_ip6_address_add (char **argv) v##_t address; \ int plen; \ if (ifindex && parse_##v##_address (*argv++, &address, &plen)) { \ - gboolean value = nm_platform_##v##_address_##cmdname (ifindex, address, plen, ##__VA_ARGS__); \ + gboolean value = nm_platform_##v##_address_##cmdname (NM_PLATFORM_GET, ifindex, address, plen, ##__VA_ARGS__); \ if (print) { \ print_boolean (value); \ return TRUE; \ @@ -633,7 +633,7 @@ do_ip4_route_get_all (char **argv) int i; if (ifindex) { - routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); for (i = 0; i < routes->len; i++) { route = &g_array_index (routes, NMPlatformIP4Route, i); inet_ntop (AF_INET, &route->network, networkstr, sizeof (networkstr)); @@ -657,7 +657,7 @@ do_ip6_route_get_all (char **argv) int i; if (ifindex) { - routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); for (i = 0; i < routes->len; i++) { route = &g_array_index (routes, NMPlatformIP6Route, i); inet_ntop (AF_INET6, &route->network, networkstr, sizeof (networkstr)); @@ -683,7 +683,7 @@ do_ip4_route_add (char **argv) metric = strtol (*argv++, NULL, 10); mss = strtol (*argv++, NULL, 10); - return nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, + return nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss); } @@ -699,7 +699,7 @@ do_ip6_route_add (char **argv) parse_ip6_address (*argv++, &gateway, NULL); metric = strtol (*argv++, NULL, 10); mss = strtol (*argv++, NULL, 10); - return nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, + return nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss); } @@ -714,7 +714,7 @@ do_ip4_route_delete (char **argv) parse_ip4_address (*argv++, &network, &plen); metric = strtol (*argv++, NULL, 10); - return nm_platform_ip4_route_delete (ifindex, network, plen, metric); + return nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric); } static gboolean @@ -727,7 +727,7 @@ do_ip6_route_delete (char **argv) parse_ip6_address (*argv++, &network, &plen); metric = strtol (*argv++, NULL, 10); - return nm_platform_ip6_route_delete (ifindex, network, plen, metric); + return nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric); } static gboolean @@ -740,7 +740,7 @@ do_ip4_route_exists (char **argv) parse_ip4_address (*argv++, &network, &plen); metric = strtol (*argv++, NULL, 10); - print_boolean (nm_platform_ip4_route_exists (ifindex, network, plen, metric)); + print_boolean (nm_platform_ip4_route_exists (NM_PLATFORM_GET, ifindex, network, plen, metric)); return TRUE; } @@ -754,7 +754,7 @@ do_ip6_route_exists (char **argv) parse_ip6_address (*argv++, &network, &plen); metric = strtol (*argv++, NULL, 10); - print_boolean (nm_platform_ip6_route_exists (ifindex, network, plen, metric)); + print_boolean (nm_platform_ip6_route_exists (NM_PLATFORM_GET, ifindex, network, plen, metric)); return TRUE; } @@ -892,9 +892,9 @@ main (int argc, char **argv) error ("\n"); } - error = nm_platform_get_error (); + error = nm_platform_get_error (NM_PLATFORM_GET); if (error) { - const char *msg = nm_platform_get_error_msg (); + const char *msg = nm_platform_get_error_msg (NM_PLATFORM_GET); error ("nm-platform: %s\n", msg); } diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c index 08f2f1f250..0354795d47 100644 --- a/src/platform/tests/test-address.c +++ b/src/platform/tests/test-address.c @@ -51,7 +51,7 @@ ip6_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Address *r static void test_ip4_address (void) { - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); SignalData *address_added = add_signal_ifindex (NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_address_callback, ifindex); SignalData *address_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip4_address_callback, ifindex); SignalData *address_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_address_callback, ifindex); @@ -64,21 +64,21 @@ test_ip4_address (void) inet_pton (AF_INET, IP4_ADDRESS, &addr); /* Add address */ - g_assert (!nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (!nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); no_error (); - g_assert (nm_platform_ip4_address_add (ifindex, addr, 0, IP4_PLEN, lifetime, preferred, NULL)); + g_assert (nm_platform_ip4_address_add (NM_PLATFORM_GET, ifindex, addr, 0, IP4_PLEN, lifetime, preferred, NULL)); no_error (); - g_assert (nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); no_error (); accept_signal (address_added); /* Add address again (aka update) */ - g_assert (nm_platform_ip4_address_add (ifindex, addr, 0, IP4_PLEN, lifetime, preferred, NULL)); + g_assert (nm_platform_ip4_address_add (NM_PLATFORM_GET, ifindex, addr, 0, IP4_PLEN, lifetime, preferred, NULL)); no_error (); accept_signal (address_changed); /* Test address listing */ - addresses = nm_platform_ip4_address_get_all (ifindex); + addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); g_assert (addresses); no_error (); g_assert_cmpint (addresses->len, ==, 1); @@ -89,13 +89,13 @@ test_ip4_address (void) g_array_unref (addresses); /* Remove address */ - g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN, 0)); + g_assert (nm_platform_ip4_address_delete (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, 0)); no_error (); - g_assert (!nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (!nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); accept_signal (address_removed); /* Remove address again */ - g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN, 0)); + g_assert (nm_platform_ip4_address_delete (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, 0)); no_error (); free_signal (address_added); @@ -106,7 +106,7 @@ test_ip4_address (void) static void test_ip6_address (void) { - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); SignalData *address_added = add_signal_ifindex (NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip6_address_callback, ifindex); SignalData *address_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip6_address_callback, ifindex); SignalData *address_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip6_address_callback, ifindex); @@ -120,21 +120,21 @@ test_ip6_address (void) inet_pton (AF_INET6, IP6_ADDRESS, &addr); /* Add address */ - g_assert (!nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (!nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); no_error (); - g_assert (nm_platform_ip6_address_add (ifindex, addr, in6addr_any, IP6_PLEN, lifetime, preferred, flags)); + g_assert (nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, addr, in6addr_any, IP6_PLEN, lifetime, preferred, flags)); no_error (); - g_assert (nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); no_error (); accept_signal (address_added); /* Add address again (aka update) */ - g_assert (nm_platform_ip6_address_add (ifindex, addr, in6addr_any, IP6_PLEN, lifetime, preferred, flags)); + g_assert (nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, addr, in6addr_any, IP6_PLEN, lifetime, preferred, flags)); no_error (); accept_signal (address_changed); /* Test address listing */ - addresses = nm_platform_ip6_address_get_all (ifindex); + addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex); g_assert (addresses); no_error (); g_assert_cmpint (addresses->len, ==, 1); @@ -145,13 +145,13 @@ test_ip6_address (void) g_array_unref (addresses); /* Remove address */ - g_assert (nm_platform_ip6_address_delete (ifindex, addr, IP6_PLEN)); + g_assert (nm_platform_ip6_address_delete (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); no_error (); - g_assert (!nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (!nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); accept_signal (address_removed); /* Remove address again */ - g_assert (nm_platform_ip6_address_delete (ifindex, addr, IP6_PLEN)); + g_assert (nm_platform_ip6_address_delete (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); no_error (); free_signal (address_added); @@ -164,7 +164,7 @@ test_ip4_address_external (void) { SignalData *address_added = add_signal (NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_address_callback); SignalData *address_removed = add_signal (NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_address_callback); - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); in_addr_t addr; guint32 lifetime = 2000; guint32 preferred = 1000; @@ -175,28 +175,28 @@ test_ip4_address_external (void) /* Looks like addresses are not announced by kerenl when the interface * is down. Link-local IPv6 address is automatically added. */ - g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME))); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME))); /* Add/delete notification */ run_command ("ip address add %s/%d dev %s valid_lft %d preferred_lft %d", IP4_ADDRESS, IP4_PLEN, DEVICE_NAME, lifetime, preferred); wait_signal (address_added); - g_assert (nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); run_command ("ip address delete %s/%d dev %s", IP4_ADDRESS, IP4_PLEN, DEVICE_NAME); wait_signal (address_removed); - g_assert (!nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (!nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); /* Add/delete conflict */ run_command ("ip address add %s/%d dev %s valid_lft %d preferred_lft %d", IP4_ADDRESS, IP4_PLEN, DEVICE_NAME, lifetime, preferred); - g_assert (nm_platform_ip4_address_add (ifindex, addr, 0, IP4_PLEN, lifetime, preferred, NULL)); + g_assert (nm_platform_ip4_address_add (NM_PLATFORM_GET, ifindex, addr, 0, IP4_PLEN, lifetime, preferred, NULL)); no_error (); - g_assert (nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); accept_signal (address_added); /*run_command ("ip address delete %s/%d dev %s", IP4_ADDRESS, IP4_PLEN, DEVICE_NAME); g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN, 0)); no_error (); - g_assert (!nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN)); + g_assert (!nm_platform_ip4_address_exists (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN)); accept_signal (address_removed);*/ free_signal (address_added); @@ -208,7 +208,7 @@ test_ip6_address_external (void) { SignalData *address_added = add_signal (NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip6_address_callback); SignalData *address_removed = add_signal (NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip6_address_callback); - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); struct in6_addr addr; guint32 lifetime = 2000; guint32 preferred = 1000; @@ -220,22 +220,22 @@ test_ip6_address_external (void) run_command ("ip address add %s/%d dev %s valid_lft %d preferred_lft %d", IP6_ADDRESS, IP6_PLEN, DEVICE_NAME, lifetime, preferred); wait_signal (address_added); - g_assert (nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); run_command ("ip address delete %s/%d dev %s", IP6_ADDRESS, IP6_PLEN, DEVICE_NAME); wait_signal (address_removed); - g_assert (!nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (!nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); /* Add/delete conflict */ run_command ("ip address add %s/%d dev %s valid_lft %d preferred_lft %d", IP6_ADDRESS, IP6_PLEN, DEVICE_NAME, lifetime, preferred); - g_assert (nm_platform_ip6_address_add (ifindex, addr, in6addr_any, IP6_PLEN, lifetime, preferred, flags)); + g_assert (nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, addr, in6addr_any, IP6_PLEN, lifetime, preferred, flags)); no_error (); - g_assert (nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); accept_signal (address_added); /*run_command ("ip address delete %s/%d dev %s", IP6_ADDRESS, IP6_PLEN, DEVICE_NAME); - g_assert (nm_platform_ip6_address_delete (ifindex, addr, IP6_PLEN)); + g_assert (nm_platform_ip6_address_delete (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); no_error (); - g_assert (!nm_platform_ip6_address_exists (ifindex, addr, IP6_PLEN)); + g_assert (!nm_platform_ip6_address_exists (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN)); wait_signal (address_removed);*/ free_signal (address_added); @@ -253,9 +253,9 @@ setup_tests (void) { SignalData *link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME); - nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME)); - g_assert (!nm_platform_link_exists (DEVICE_NAME)); - g_assert (nm_platform_dummy_add (DEVICE_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); + g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME)); wait_signal (link_added); free_signal (link_added); diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c index 796ca874e5..29892c9c83 100644 --- a/src/platform/tests/test-cleanup.c +++ b/src/platform/tests/test-cleanup.c @@ -35,27 +35,27 @@ 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 (DEVICE_NAME)); + g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME)); wait_signal (link_added); free_signal (link_added); - g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME))); - ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME))); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); g_assert (ifindex > 0); /* Add routes and addresses */ - g_assert (nm_platform_ip4_address_add (ifindex, addr4, 0, plen4, lifetime, preferred, NULL)); - g_assert (nm_platform_ip6_address_add (ifindex, addr6, in6addr_any, plen6, lifetime, preferred, flags)); - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, 0, metric, mss)); - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, 0, metric, mss)); - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, 0, metric, mss)); - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, metric, mss)); - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, metric, mss)); - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, metric, mss)); + g_assert (nm_platform_ip4_address_add (NM_PLATFORM_GET, ifindex, addr4, 0, plen4, lifetime, preferred, NULL)); + g_assert (nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, addr6, in6addr_any, plen6, lifetime, preferred, flags)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, 0, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, metric, mss)); - addresses4 = nm_platform_ip4_address_get_all (ifindex); - addresses6 = nm_platform_ip6_address_get_all (ifindex); - routes4 = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); - routes6 = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + addresses4 = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); + addresses6 = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex); + routes4 = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + routes6 = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); g_assert_cmpint (addresses4->len, ==, 1); g_assert_cmpint (addresses6->len, ==, 1); @@ -68,12 +68,12 @@ test_cleanup_internal (void) g_array_unref (routes6); /* Delete interface with all addresses and routes */ - g_assert (nm_platform_link_delete (ifindex)); + g_assert (nm_platform_link_delete (NM_PLATFORM_GET, ifindex)); - addresses4 = nm_platform_ip4_address_get_all (ifindex); - addresses6 = nm_platform_ip6_address_get_all (ifindex); - routes4 = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); - routes6 = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + addresses4 = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); + addresses6 = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex); + routes4 = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + routes6 = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); g_assert_cmpint (addresses4->len, ==, 0); g_assert_cmpint (addresses6->len, ==, 0); @@ -95,8 +95,8 @@ init_tests (int *argc, char ***argv) void setup_tests (void) { - nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME)); - g_assert (!nm_platform_link_exists (DEVICE_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); g_test_add_func ("/internal", test_cleanup_internal); /* FIXME: add external cleanup check */ diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index 2c5958cadb..2e02ce6c46 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -113,7 +113,7 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl if (data->ifindex && data->ifindex != received->ifindex) return; - if (data->ifname && g_strcmp0 (data->ifname, nm_platform_link_get_name (ifindex)) != 0) + if (data->ifname && g_strcmp0 (data->ifname, nm_platform_link_get_name (NM_PLATFORM_GET, ifindex)) != 0) return; if (change_type != data->change_type) return; @@ -127,13 +127,13 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl debug ("Received signal '%s-%s' ifindex %d ifname '%s' %dth time.", data->name, _change_type_to_string (data->change_type), ifindex, received->name, data->received_count); if (change_type == NM_PLATFORM_SIGNAL_REMOVED) - g_assert (!nm_platform_link_get_name (ifindex)); + g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, ifindex)); else - g_assert (nm_platform_link_get_name (ifindex)); + g_assert (nm_platform_link_get_name (NM_PLATFORM_GET, ifindex)); /* Check the data */ g_assert (received->ifindex > 0); - links = nm_platform_link_get_all (); + links = nm_platform_link_get_all (NM_PLATFORM_GET); for (i = 0; i < links->len; i++) { cached = &g_array_index (links, NMPlatformLink, i); if (cached->ifindex == received->ifindex) { @@ -247,9 +247,9 @@ _assert_ip4_route_exists (const char *file, guint line, const char *func, gboole exists ? "doesn't" : "does"); } - ifindex = nm_platform_link_get_ifindex (ifname); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, ifname); g_assert (ifindex > 0); - if (!nm_platform_ip4_route_exists (ifindex, network, plen, metric) != !exists) { + if (!nm_platform_ip4_route_exists (NM_PLATFORM_GET, ifindex, network, plen, metric) != !exists) { g_error ("[%s:%u] %s(): The ip4 route %s/%d metric %u %s, but platform thinks %s", file, line, func, nm_utils_inet4_ntop (network, NULL), plen, metric, @@ -302,7 +302,7 @@ main (int argc, char **argv) result = g_test_run (); - nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); nm_platform_free (); return result; diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index a44b5f9c91..56e27f6581 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -15,7 +15,7 @@ #define debug(...) nm_log_dbg (LOGD_PLATFORM, __VA_ARGS__) -#define error(err) g_assert (nm_platform_get_error () == err) +#define error(err) g_assert (nm_platform_get_error (NM_PLATFORM_GET) == err) #define no_error() error (NM_PLATFORM_ERROR_NONE) typedef struct { diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 8a2f2a84d1..6dddfc0d59 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -21,68 +21,68 @@ test_bogus(void) { size_t addrlen; - g_assert (!nm_platform_link_exists (BOGUS_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, BOGUS_NAME)); no_error (); - g_assert (!nm_platform_link_delete (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_delete (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_ifindex (BOGUS_NAME)); + g_assert (!nm_platform_link_get_ifindex (NM_PLATFORM_GET, BOGUS_NAME)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_name (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_type (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_get_type (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_type_name (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_get_type_name (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_set_up (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_set_up (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_set_down (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_set_down (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_set_arp (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_set_arp (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_set_noarp (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_set_noarp (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_is_up (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_is_connected (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_uses_arp (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_uses_arp (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_address (BOGUS_IFINDEX, &addrlen)); + g_assert (!nm_platform_link_get_address (NM_PLATFORM_GET, BOGUS_IFINDEX, &addrlen)); g_assert (!addrlen); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_address (BOGUS_IFINDEX, NULL)); + g_assert (!nm_platform_link_get_address (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_set_mtu (BOGUS_IFINDEX, MTU)); + g_assert (!nm_platform_link_set_mtu (NM_PLATFORM_GET, BOGUS_IFINDEX, MTU)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_mtu (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_get_mtu (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_supports_carrier_detect (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_supports_vlans (BOGUS_IFINDEX)); + g_assert (!nm_platform_link_supports_vlans (NM_PLATFORM_GET, BOGUS_IFINDEX)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_vlan_get_info (BOGUS_IFINDEX, NULL, NULL)); + g_assert (!nm_platform_vlan_get_info (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL, NULL)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_vlan_set_ingress_map (BOGUS_IFINDEX, 0, 0)); + g_assert (!nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0)); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_vlan_set_egress_map (BOGUS_IFINDEX, 0, 0)); + g_assert (!nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0)); error (NM_PLATFORM_ERROR_NOT_FOUND); } static void test_loopback (void) { - g_assert (nm_platform_link_exists (LO_NAME)); - g_assert_cmpint (nm_platform_link_get_type (LO_INDEX), ==, NM_LINK_TYPE_LOOPBACK); - g_assert_cmpint (nm_platform_link_get_ifindex (LO_NAME), ==, LO_INDEX); - g_assert_cmpstr (nm_platform_link_get_name (LO_INDEX), ==, LO_NAME); - g_assert_cmpstr (nm_platform_link_get_type_name (LO_INDEX), ==, LO_TYPEDESC); + g_assert (nm_platform_link_exists (NM_PLATFORM_GET, LO_NAME)); + g_assert_cmpint (nm_platform_link_get_type (NM_PLATFORM_GET, LO_INDEX), ==, NM_LINK_TYPE_LOOPBACK); + g_assert_cmpint (nm_platform_link_get_ifindex (NM_PLATFORM_GET, LO_NAME), ==, LO_INDEX); + g_assert_cmpstr (nm_platform_link_get_name (NM_PLATFORM_GET, LO_INDEX), ==, LO_NAME); + g_assert_cmpstr (nm_platform_link_get_type_name (NM_PLATFORM_GET, LO_INDEX), ==, LO_TYPEDESC); - g_assert (nm_platform_link_supports_carrier_detect (LO_INDEX)); - g_assert (!nm_platform_link_supports_vlans (LO_INDEX)); + g_assert (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, LO_INDEX)); + g_assert (!nm_platform_link_supports_vlans (NM_PLATFORM_GET, LO_INDEX)); } static int @@ -90,43 +90,43 @@ software_add (NMLinkType link_type, const char *name) { switch (link_type) { case NM_LINK_TYPE_DUMMY: - return nm_platform_dummy_add (name); + return nm_platform_dummy_add (NM_PLATFORM_GET, name); case NM_LINK_TYPE_BRIDGE: - return nm_platform_bridge_add (name, NULL, 0); + return nm_platform_bridge_add (NM_PLATFORM_GET, name, NULL, 0); case NM_LINK_TYPE_BOND: { - gboolean bond0_exists = nm_platform_link_exists ("bond0"); - gboolean result = nm_platform_bond_add (name); - NMPlatformError error = nm_platform_get_error (); + gboolean bond0_exists = nm_platform_link_exists (NM_PLATFORM_GET, "bond0"); + gboolean result = nm_platform_bond_add (NM_PLATFORM_GET, name); + NMPlatformError error = nm_platform_get_error (NM_PLATFORM_GET); /* Check that bond0 is *not* automatically created. */ if (!bond0_exists) - g_assert (!nm_platform_link_exists ("bond0")); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, "bond0")); - nm_platform_set_error (error); + nm_platform_set_error (NM_PLATFORM_GET, error); return result; } case NM_LINK_TYPE_TEAM: - return nm_platform_team_add (name); + return nm_platform_team_add (NM_PLATFORM_GET, name); 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 (PARENT_NAME, NULL, 0)) + if (nm_platform_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0)) wait_signal (parent_added); free_signal (parent_added); { - int parent_ifindex = nm_platform_link_get_ifindex (PARENT_NAME); + int parent_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, PARENT_NAME); parent_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, parent_ifindex); - g_assert (nm_platform_link_set_up (parent_ifindex)); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, parent_ifindex)); accept_signal (parent_changed); free_signal (parent_changed); - return nm_platform_vlan_add (name, parent_ifindex, VLAN_ID, 0); + return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0); } } default: @@ -144,7 +144,7 @@ test_slave (int master, int type, SignalData *master_changed) char *value; g_assert (software_add (type, SLAVE_NAME)); - ifindex = nm_platform_link_get_ifindex (SLAVE_NAME); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, SLAVE_NAME); g_assert (ifindex > 0); link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex); link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex); @@ -154,19 +154,19 @@ test_slave (int master, int type, SignalData *master_changed) * * See https://bugzilla.redhat.com/show_bug.cgi?id=910348 */ - g_assert (nm_platform_link_set_down (ifindex)); - g_assert (!nm_platform_link_is_up (ifindex)); + g_assert (nm_platform_link_set_down (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); /* Enslave */ link_changed->ifindex = ifindex; - g_assert (nm_platform_link_enslave (master, ifindex)); no_error (); - g_assert_cmpint (nm_platform_link_get_master (ifindex), ==, master); no_error (); + g_assert (nm_platform_link_enslave (NM_PLATFORM_GET, master, ifindex)); no_error (); + g_assert_cmpint (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex), ==, master); no_error (); accept_signal (link_changed); accept_signal (master_changed); /* Set master up */ - g_assert (nm_platform_link_set_up (master)); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, master)); accept_signal (master_changed); /* Master with a disconnected slave is disconnected @@ -174,26 +174,26 @@ test_slave (int master, int type, SignalData *master_changed) * For some reason, bonding and teaming slaves are automatically set up. We * need to set them back down for this test. */ - switch (nm_platform_link_get_type (master)) { + switch (nm_platform_link_get_type (NM_PLATFORM_GET, master)) { case NM_LINK_TYPE_BOND: case NM_LINK_TYPE_TEAM: - g_assert (nm_platform_link_set_down (ifindex)); + g_assert (nm_platform_link_set_down (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); accept_signal (master_changed); break; default: break; } - g_assert (!nm_platform_link_is_up (ifindex)); - g_assert (!nm_platform_link_is_connected (ifindex)); - if (nm_platform_link_is_connected (master)) { - if (nm_platform_link_get_type (master) == NM_LINK_TYPE_TEAM) { + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); + if (nm_platform_link_is_connected (NM_PLATFORM_GET, master)) { + if (nm_platform_link_get_type (NM_PLATFORM_GET, master) == NM_LINK_TYPE_TEAM) { /* Older team versions (e.g. Fedora 17) have a bug that team master stays * IFF_LOWER_UP even if its slave is down. Double check it with iproute2 and if * `ip link` also claims master to be up, accept it. */ char *stdout_str = NULL; - nmtst_spawn_sync (NULL, &stdout_str, NULL, 0, "/sbin/ip", "link", "show", "dev", nm_platform_link_get_name (master)); + nmtst_spawn_sync (NULL, &stdout_str, NULL, 0, "/sbin/ip", "link", "show", "dev", nm_platform_link_get_name (NM_PLATFORM_GET, master)); g_assert (strstr (stdout_str, "LOWER_UP")); g_free (stdout_str); @@ -202,9 +202,9 @@ test_slave (int master, int type, SignalData *master_changed) } /* Set slave up and see if master gets up too */ - g_assert (nm_platform_link_set_up (ifindex)); no_error (); - g_assert (nm_platform_link_is_connected (ifindex)); - g_assert (nm_platform_link_is_connected (master)); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_is_connected (NM_PLATFORM_GET, master)); accept_signal (link_changed); accept_signal (master_changed); @@ -212,16 +212,16 @@ test_slave (int master, int type, SignalData *master_changed) * * Gracefully succeed if already enslaved. */ - g_assert (nm_platform_link_enslave (master, ifindex)); no_error (); + g_assert (nm_platform_link_enslave (NM_PLATFORM_GET, master, ifindex)); no_error (); accept_signal (link_changed); accept_signal (master_changed); /* Set slave option */ switch (type) { case NM_LINK_TYPE_BRIDGE: - g_assert (nm_platform_slave_set_option (ifindex, "priority", "789")); + g_assert (nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, "priority", "789")); no_error (); - value = nm_platform_slave_get_option (ifindex, "priority"); + value = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex, "priority"); no_error (); g_assert_cmpstr (value, ==, "789"); g_free (value); @@ -231,17 +231,17 @@ test_slave (int master, int type, SignalData *master_changed) } /* Release */ - g_assert (nm_platform_link_release (master, ifindex)); - g_assert_cmpint (nm_platform_link_get_master (ifindex), ==, 0); no_error (); + g_assert (nm_platform_link_release (NM_PLATFORM_GET, master, ifindex)); + g_assert_cmpint (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex), ==, 0); no_error (); accept_signal (link_changed); accept_signal (master_changed); /* Release again */ - g_assert (!nm_platform_link_release (master, ifindex)); + g_assert (!nm_platform_link_release (NM_PLATFORM_GET, master, ifindex)); error (NM_PLATFORM_ERROR_NOT_SLAVE); /* Remove */ - g_assert (nm_platform_link_delete (ifindex)); + g_assert (nm_platform_link_delete (NM_PLATFORM_GET, ifindex)); no_error (); accept_signal (link_removed); @@ -264,16 +264,16 @@ test_software (NMLinkType link_type, const char *link_typename) g_assert (software_add (link_type, DEVICE_NAME)); no_error (); wait_signal (link_added); - g_assert (nm_platform_link_exists (DEVICE_NAME)); - ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + g_assert (nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); g_assert (ifindex >= 0); - g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, link_type); - g_assert_cmpstr (nm_platform_link_get_type_name (ifindex), ==, link_typename); + g_assert_cmpint (nm_platform_link_get_type (NM_PLATFORM_GET, ifindex), ==, link_type); + g_assert_cmpstr (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex), ==, link_typename); link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex); link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex); if (link_type == NM_LINK_TYPE_VLAN) { - g_assert (nm_platform_vlan_get_info (ifindex, &vlan_parent, &vlan_id)); - g_assert_cmpint (vlan_parent, ==, nm_platform_link_get_ifindex (PARENT_NAME)); + g_assert (nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &vlan_parent, &vlan_id)); + g_assert_cmpint (vlan_parent, ==, nm_platform_link_get_ifindex (NM_PLATFORM_GET, PARENT_NAME)); g_assert_cmpint (vlan_id, ==, VLAN_ID); no_error (); } @@ -283,28 +283,28 @@ test_software (NMLinkType link_type, const char *link_typename) error (NM_PLATFORM_ERROR_EXISTS); /* Set ARP/NOARP */ - g_assert (nm_platform_link_uses_arp (ifindex)); - g_assert (nm_platform_link_set_noarp (ifindex)); - g_assert (!nm_platform_link_uses_arp (ifindex)); + g_assert (nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_set_noarp (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); - g_assert (nm_platform_link_set_arp (ifindex)); - g_assert (nm_platform_link_uses_arp (ifindex)); + g_assert (nm_platform_link_set_arp (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); /* Set master option */ switch (link_type) { case NM_LINK_TYPE_BRIDGE: - g_assert (nm_platform_master_set_option (ifindex, "forward_delay", "789")); + g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "789")); no_error (); - value = nm_platform_master_get_option (ifindex, "forward_delay"); + value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay"); no_error (); g_assert_cmpstr (value, ==, "789"); g_free (value); break; case NM_LINK_TYPE_BOND: - g_assert (nm_platform_master_set_option (ifindex, "mode", "active-backup")); + g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup")); no_error (); - value = nm_platform_master_get_option (ifindex, "mode"); + value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "mode"); no_error (); /* When reading back, the output looks slightly different. */ g_assert (g_str_has_prefix (value, "active-backup")); @@ -328,24 +328,24 @@ test_software (NMLinkType link_type, const char *link_typename) } /* Delete */ - g_assert (nm_platform_link_delete (ifindex)); + g_assert (nm_platform_link_delete (NM_PLATFORM_GET, ifindex)); no_error (); - g_assert (!nm_platform_link_exists (DEVICE_NAME)); no_error (); - g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, NM_LINK_TYPE_NONE); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); no_error (); + g_assert_cmpint (nm_platform_link_get_type (NM_PLATFORM_GET, ifindex), ==, NM_LINK_TYPE_NONE); error (NM_PLATFORM_ERROR_NOT_FOUND); - g_assert (!nm_platform_link_get_type (ifindex)); + g_assert (!nm_platform_link_get_type (NM_PLATFORM_GET, ifindex)); error (NM_PLATFORM_ERROR_NOT_FOUND); accept_signal (link_removed); /* Delete again */ - g_assert (!nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME))); + g_assert (!nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME))); error (NM_PLATFORM_ERROR_NOT_FOUND); /* VLAN: Delete parent */ if (link_type == NM_LINK_TYPE_VLAN) { SignalData *link_removed_parent = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, vlan_parent); - g_assert (nm_platform_link_delete (vlan_parent)); + g_assert (nm_platform_link_delete (NM_PLATFORM_GET, vlan_parent)); accept_signal (link_removed_parent); free_signal (link_removed_parent); } @@ -398,75 +398,75 @@ test_internal (void) int ifindex; /* Check the functions for non-existent devices */ - g_assert (!nm_platform_link_exists (DEVICE_NAME)); no_error (); - g_assert (!nm_platform_link_get_ifindex (DEVICE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); no_error (); + g_assert (!nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); error (NM_PLATFORM_ERROR_NOT_FOUND); /* Add device */ - g_assert (nm_platform_dummy_add (DEVICE_NAME)); + g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME)); no_error (); wait_signal (link_added); /* Try to add again */ - g_assert (!nm_platform_dummy_add (DEVICE_NAME)); + g_assert (!nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME)); error (NM_PLATFORM_ERROR_EXISTS); /* Check device index, name and type */ - ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); g_assert (ifindex > 0); - g_assert_cmpstr (nm_platform_link_get_name (ifindex), ==, DEVICE_NAME); - g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, NM_LINK_TYPE_DUMMY); - g_assert_cmpstr (nm_platform_link_get_type_name (ifindex), ==, DUMMY_TYPEDESC); + g_assert_cmpstr (nm_platform_link_get_name (NM_PLATFORM_GET, ifindex), ==, DEVICE_NAME); + g_assert_cmpint (nm_platform_link_get_type (NM_PLATFORM_GET, ifindex), ==, NM_LINK_TYPE_DUMMY); + g_assert_cmpstr (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex), ==, DUMMY_TYPEDESC); link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex); link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex); /* Up/connected */ - g_assert (!nm_platform_link_is_up (ifindex)); no_error (); - g_assert (!nm_platform_link_is_connected (ifindex)); no_error (); - g_assert (nm_platform_link_set_up (ifindex)); no_error (); - g_assert (nm_platform_link_is_up (ifindex)); no_error (); - g_assert (nm_platform_link_is_connected (ifindex)); no_error (); + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); no_error (); accept_signal (link_changed); - g_assert (nm_platform_link_set_down (ifindex)); no_error (); - g_assert (!nm_platform_link_is_up (ifindex)); no_error (); - g_assert (!nm_platform_link_is_connected (ifindex)); no_error (); + g_assert (nm_platform_link_set_down (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); no_error (); + g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); no_error (); accept_signal (link_changed); /* arp/noarp */ - g_assert (!nm_platform_link_uses_arp (ifindex)); - g_assert (nm_platform_link_set_arp (ifindex)); - g_assert (nm_platform_link_uses_arp (ifindex)); + g_assert (!nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_set_arp (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); - g_assert (nm_platform_link_set_noarp (ifindex)); - g_assert (!nm_platform_link_uses_arp (ifindex)); + g_assert (nm_platform_link_set_noarp (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); /* Features */ - g_assert (!nm_platform_link_supports_carrier_detect (ifindex)); - g_assert (nm_platform_link_supports_vlans (ifindex)); + g_assert (!nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_supports_vlans (NM_PLATFORM_GET, ifindex)); /* Set MAC address */ - g_assert (nm_platform_link_set_address (ifindex, mac, sizeof (mac))); - address = nm_platform_link_get_address (ifindex, &addrlen); + g_assert (nm_platform_link_set_address (NM_PLATFORM_GET, ifindex, mac, sizeof (mac))); + address = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addrlen); g_assert (addrlen == sizeof(mac)); g_assert (!memcmp (address, mac, addrlen)); - address = nm_platform_link_get_address (ifindex, NULL); + address = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, NULL); g_assert (!memcmp (address, mac, addrlen)); accept_signal (link_changed); /* Set MTU */ - g_assert (nm_platform_link_set_mtu (ifindex, MTU)); + g_assert (nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, MTU)); no_error (); - g_assert_cmpint (nm_platform_link_get_mtu (ifindex), ==, MTU); + g_assert_cmpint (nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex), ==, MTU); accept_signal (link_changed); /* Delete device */ - g_assert (nm_platform_link_delete (ifindex)); + g_assert (nm_platform_link_delete (NM_PLATFORM_GET, ifindex)); no_error (); accept_signal (link_removed); /* Try to delete again */ - g_assert (!nm_platform_link_delete (ifindex)); + g_assert (!nm_platform_link_delete (NM_PLATFORM_GET, ifindex)); error (NM_PLATFORM_ERROR_NOT_FOUND); free_signal (link_added); @@ -485,16 +485,16 @@ test_external (void) run_command ("ip link add %s type %s", DEVICE_NAME, "dummy"); wait_signal (link_added); - g_assert (nm_platform_link_exists (DEVICE_NAME)); - ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + g_assert (nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); g_assert (ifindex > 0); - g_assert_cmpstr (nm_platform_link_get_name (ifindex), ==, DEVICE_NAME); - g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, NM_LINK_TYPE_DUMMY); - g_assert_cmpstr (nm_platform_link_get_type_name (ifindex), ==, DUMMY_TYPEDESC); + g_assert_cmpstr (nm_platform_link_get_name (NM_PLATFORM_GET, ifindex), ==, DEVICE_NAME); + g_assert_cmpint (nm_platform_link_get_type (NM_PLATFORM_GET, ifindex), ==, NM_LINK_TYPE_DUMMY); + g_assert_cmpstr (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex), ==, DUMMY_TYPEDESC); link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex); link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex); - success = nm_platform_link_get (ifindex, &link); + success = nm_platform_link_get (NM_PLATFORM_GET, ifindex, &link); g_assert (success); if (!link.driver) { /* we still lack the notification via UDEV. Expect another link changed signal. */ @@ -502,17 +502,17 @@ test_external (void) } /* Up/connected/arp */ - g_assert (!nm_platform_link_is_up (ifindex)); - g_assert (!nm_platform_link_is_connected (ifindex)); - g_assert (!nm_platform_link_uses_arp (ifindex)); + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); run_command ("ip link set %s up", DEVICE_NAME); wait_signal (link_changed); - g_assert (nm_platform_link_is_up (ifindex)); - g_assert (nm_platform_link_is_connected (ifindex)); + g_assert (nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); + g_assert (nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); run_command ("ip link set %s down", DEVICE_NAME); wait_signal (link_changed); - g_assert (!nm_platform_link_is_up (ifindex)); - g_assert (!nm_platform_link_is_connected (ifindex)); + g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); + g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); /* This test doesn't trigger a netlink event at least on * 3.8.2-206.fc18.x86_64. Disabling the waiting and checking code * because of that. @@ -530,7 +530,7 @@ test_external (void) run_command ("ip link del %s", DEVICE_NAME); wait_signal (link_removed); - g_assert (!nm_platform_link_exists (DEVICE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); free_signal (link_added); free_signal (link_changed); @@ -546,12 +546,12 @@ init_tests (int *argc, char ***argv) void setup_tests (void) { - nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME)); - nm_platform_link_delete (nm_platform_link_get_ifindex (SLAVE_NAME)); - nm_platform_link_delete (nm_platform_link_get_ifindex (PARENT_NAME)); - g_assert (!nm_platform_link_exists (DEVICE_NAME)); - g_assert (!nm_platform_link_exists (SLAVE_NAME)); - g_assert (!nm_platform_link_exists (PARENT_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, SLAVE_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, PARENT_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, SLAVE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, PARENT_NAME)); g_test_add_func ("/link/bogus", test_bogus); g_test_add_func ("/link/loopback", test_loopback); diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index 6289d1994c..e644816e11 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -49,7 +49,7 @@ ip6_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Route *recei static void test_ip4_route_metric0 (void) { - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); SignalData *route_added = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_route_callback); SignalData *route_changed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip4_route_callback); SignalData *route_removed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_route_callback); @@ -63,7 +63,7 @@ test_ip4_route_metric0 (void) assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric); /* add the first route */ - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, metric, mss)); no_error (); accept_signal (route_added); @@ -71,7 +71,7 @@ test_ip4_route_metric0 (void) assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric); /* Deleting route with metric 0 does nothing */ - g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, 0)); + g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0)); no_error (); ensure_no_signal (route_removed); @@ -79,7 +79,7 @@ test_ip4_route_metric0 (void) assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric); /* add the second route */ - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, 0, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, 0, mss)); no_error (); accept_signal (route_added); @@ -87,7 +87,7 @@ test_ip4_route_metric0 (void) assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric); /* Delete route with metric 0 */ - g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, 0)); + g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0)); no_error (); accept_signal (route_removed); @@ -95,7 +95,7 @@ test_ip4_route_metric0 (void) assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric); /* Delete route with metric 0 again (we expect nothing to happen) */ - g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, 0)); + g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0)); no_error (); ensure_no_signal (route_removed); @@ -103,7 +103,7 @@ test_ip4_route_metric0 (void) assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric); /* Delete the other route */ - g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, metric)); + g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); accept_signal (route_removed); @@ -118,7 +118,7 @@ test_ip4_route_metric0 (void) static void test_ip4_route (void) { - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); SignalData *route_added = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_route_callback); SignalData *route_changed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip4_route_callback); SignalData *route_removed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_route_callback); @@ -135,40 +135,40 @@ test_ip4_route (void) inet_pton (AF_INET, "198.51.100.1", &gateway); /* Add route to gateway */ - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, 0, metric, mss)); no_error (); accept_signal (route_added); /* Add route */ assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric); no_error (); - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss)); no_error (); assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric); no_error (); accept_signal (route_added); /* Add route again */ - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss)); no_error (); accept_signal (route_changed); /* Add default route */ assert_ip4_route_exists (FALSE, DEVICE_NAME, 0, 0, metric); no_error (); - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss)); no_error (); assert_ip4_route_exists (TRUE, DEVICE_NAME, 0, 0, metric); no_error (); accept_signal (route_added); /* Add default route again */ - g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss)); + g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss)); no_error (); accept_signal (route_changed); /* Test route listing */ - routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); memset (rts, 0, sizeof (rts)); rts[0].source = NM_IP_CONFIG_SOURCE_USER; rts[0].network = gateway; @@ -197,13 +197,13 @@ test_ip4_route (void) g_array_unref (routes); /* Remove route */ - g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, metric)); + g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric); accept_signal (route_removed); /* Remove route again */ - g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, metric)); + g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); free_signal (route_added); @@ -214,7 +214,7 @@ test_ip4_route (void) static void test_ip6_route (void) { - int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); SignalData *route_added = add_signal (NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip6_route_callback); SignalData *route_changed = add_signal (NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip6_route_callback); SignalData *route_removed = add_signal (NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip6_route_callback); @@ -231,40 +231,40 @@ test_ip6_route (void) inet_pton (AF_INET6, "2001:db8:c:d:1:2:3:4", &gateway); /* Add route to gateway */ - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, metric, mss)); no_error (); accept_signal (route_added); /* Add route */ - g_assert (!nm_platform_ip6_route_exists (ifindex, network, plen, metric)); + g_assert (!nm_platform_ip6_route_exists (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss)); no_error (); - g_assert (nm_platform_ip6_route_exists (ifindex, network, plen, metric)); + g_assert (nm_platform_ip6_route_exists (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); accept_signal (route_added); /* Add route again */ - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss)); no_error (); accept_signal (route_changed); /* Add default route */ - g_assert (!nm_platform_ip6_route_exists (ifindex, in6addr_any, 0, metric)); + g_assert (!nm_platform_ip6_route_exists (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric)); no_error (); - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss)); no_error (); - g_assert (nm_platform_ip6_route_exists (ifindex, in6addr_any, 0, metric)); + g_assert (nm_platform_ip6_route_exists (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric)); no_error (); accept_signal (route_added); /* Add default route again */ - g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss)); + g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss)); no_error (); accept_signal (route_changed); /* Test route listing */ - routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); + routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL); memset (rts, 0, sizeof (rts)); rts[0].source = NM_IP_CONFIG_SOURCE_USER; rts[0].network = gateway; @@ -293,13 +293,13 @@ test_ip6_route (void) g_array_unref (routes); /* Remove route */ - g_assert (nm_platform_ip6_route_delete (ifindex, network, plen, metric)); + g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); - g_assert (!nm_platform_ip6_route_exists (ifindex, network, plen, metric)); + g_assert (!nm_platform_ip6_route_exists (NM_PLATFORM_GET, ifindex, network, plen, metric)); accept_signal (route_removed); /* Remove route again */ - g_assert (nm_platform_ip6_route_delete (ifindex, network, plen, metric)); + g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric)); no_error (); free_signal (route_added); @@ -318,13 +318,13 @@ setup_tests (void) { SignalData *link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME); - nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME)); - g_assert (!nm_platform_link_exists (DEVICE_NAME)); - g_assert (nm_platform_dummy_add (DEVICE_NAME)); + nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)); + g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME)); + g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME)); wait_signal (link_added); free_signal (link_added); - g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME))); + g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME))); g_test_add_func ("/route/ip4", test_ip4_route); g_test_add_func ("/route/ip6", test_ip6_route); diff --git a/src/rdisc/nm-lndp-rdisc.c b/src/rdisc/nm-lndp-rdisc.c index cadbfdfabc..46f814767f 100644 --- a/src/rdisc/nm-lndp-rdisc.c +++ b/src/rdisc/nm-lndp-rdisc.c @@ -298,7 +298,7 @@ start (NMRDisc *rdisc) static inline gint32 ipv6_sysctl_get (const char *ifname, const char *property, gint32 defval) { - return nm_platform_sysctl_get_int32 (nm_utils_ip6_property_path (ifname, property), defval); + return nm_platform_sysctl_get_int32 (NM_PLATFORM_GET, nm_utils_ip6_property_path (ifname, property), defval); } NMRDisc * diff --git a/src/rdisc/tests/test-rdisc-fake.c b/src/rdisc/tests/test-rdisc-fake.c index 8b7bd37a34..3b525203a2 100644 --- a/src/rdisc/tests/test-rdisc-fake.c +++ b/src/rdisc/tests/test-rdisc-fake.c @@ -36,7 +36,7 @@ rdisc_new (void) { NMRDisc *rdisc; const int ifindex = 1; - const char *ifname = nm_platform_link_get_name (ifindex); + const char *ifname = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex); rdisc = nm_fake_rdisc_new (ifindex, ifname); g_assert (rdisc); diff --git a/src/rdisc/tests/test-rdisc-linux.c b/src/rdisc/tests/test-rdisc-linux.c index 9b2ccafd67..eddb3b0eb4 100644 --- a/src/rdisc/tests/test-rdisc-linux.c +++ b/src/rdisc/tests/test-rdisc-linux.c @@ -54,7 +54,7 @@ main (int argc, char **argv) if (argv[1]) { ifname = argv[1]; - ifindex = nm_platform_link_get_ifindex (ifname); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, ifname); } else { g_print ("Missing command line argument \"interface-name\"\n"); return EXIT_FAILURE; diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index 94d2225820..06a7f21039 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -164,7 +164,7 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self) if (!devtimeout) return; - if (nm_platform_link_get_ifindex (ifname) != 0) + if (nm_platform_link_get_ifindex (NM_PLATFORM_GET, ifname) != 0) return; /* ONBOOT=yes, DEVICE and DEVTIMEOUT are set, but device is not present */ diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 8c9352d428..2ef2617f92 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -4335,11 +4335,11 @@ is_wifi_device (const char *name, shvarFile *parsed) g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (parsed != NULL, FALSE); - ifindex = nm_platform_link_get_ifindex (name); + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, name); if (ifindex == 0) return FALSE; - return nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_WIFI; + return nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) == NM_LINK_TYPE_WIFI; } static void diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c index 755767e296..8f528d0f4d 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/net_parser.c @@ -174,9 +174,9 @@ init_block_by_line (gchar * buf) /* ignored connection */ conn = add_new_connection_config ("ignore", pos); } else { - int ifindex = nm_platform_link_get_ifindex (pos); + int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, pos); - if (ifindex && nm_platform_link_get_type (ifindex) != NM_LINK_TYPE_WIFI) + if (ifindex && nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) != NM_LINK_TYPE_WIFI) /* wired connection */ conn = add_new_connection_config ("wired", pos); else diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index d79bd1c8f5..6cfe7f80fe 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -232,9 +232,9 @@ vpn_cleanup (NMVpnConnection *connection, NMDevice *parent_dev) NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); if (priv->ip_ifindex) { - nm_platform_link_set_down (priv->ip_ifindex); - nm_platform_route_flush (priv->ip_ifindex); - nm_platform_address_flush (priv->ip_ifindex); + nm_platform_link_set_down (NM_PLATFORM_GET, priv->ip_ifindex); + nm_platform_route_flush (NM_PLATFORM_GET, priv->ip_ifindex); + nm_platform_address_flush (NM_PLATFORM_GET, priv->ip_ifindex); } nm_device_set_vpn4_config (parent_dev, NULL); @@ -933,7 +933,7 @@ nm_vpn_connection_apply_config (NMVpnConnection *connection) NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); if (priv->ip_ifindex > 0) { - nm_platform_link_set_up (priv->ip_ifindex); + nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex); if (priv->ip4_config) { if (!nm_ip4_config_commit (priv->ip4_config, priv->ip_ifindex, @@ -1027,7 +1027,7 @@ process_generic_config (NMVpnConnection *connection, if (priv->ip_iface) { /* Grab the interface index for address/routing operations */ - priv->ip_ifindex = nm_platform_link_get_ifindex (priv->ip_iface); + priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface); if (!priv->ip_ifindex) { nm_log_err (LOGD_VPN, "(%s): failed to look up VPN interface index", priv->ip_iface); nm_vpn_connection_config_maybe_complete (connection, FALSE);