summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-05-03 01:15:22 +0200
committerThomas Haller <thaller@redhat.com>2014-05-03 03:45:10 +0200
commitc30fd99f6f5dcdf9d12491974ba156e1930518b1 (patch)
tree7498025a60665c410c359244ad986387abb002a5
parent9ef23947cc8f074767bd63b984b73740766377b0 (diff)
parentd16761d939d2c996c53a489b50eeeb91c1b9c8cc (diff)
downloadNetworkManager-c30fd99f6f5dcdf9d12491974ba156e1930518b1.tar.gz
platform: merge branch 'th/bgo726275_div_refact_platform'
https://bugzilla.gnome.org/show_bug.cgi?id=726275 Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/devices/adsl/nm-device-adsl.c47
-rw-r--r--src/devices/nm-device.c40
-rw-r--r--src/nm-ip4-config.c28
-rw-r--r--src/nm-ip6-config.c23
-rw-r--r--src/nm-manager.c67
-rw-r--r--src/platform/nm-fake-platform.c30
-rw-r--r--src/platform/nm-linux-platform.c289
-rw-r--r--src/platform/nm-platform.c227
-rw-r--r--src/platform/nm-platform.h118
-rw-r--r--src/platform/tests/test-address.c34
-rw-r--r--src/platform/tests/test-cleanup.c2
-rw-r--r--src/platform/tests/test-common.c41
-rw-r--r--src/platform/tests/test-common.h11
-rw-r--r--src/platform/tests/test-link.c30
-rw-r--r--src/platform/tests/test-route.c30
15 files changed, 514 insertions, 503 deletions
diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c
index 4163988c6a..5f90c2acc2 100644
--- a/src/devices/adsl/nm-device-adsl.c
+++ b/src/devices/adsl/nm-device-adsl.c
@@ -69,9 +69,6 @@ typedef struct {
guint carrier_poll_id;
int atm_index;
- /* Watch for 'nas' interfaces going away */
- guint lost_link_id;
-
/* PPP */
NMPPPManager *ppp_manager;
@@ -320,20 +317,22 @@ error:
}
static void
-lost_link (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformReason reason, NMDeviceAdsl *device_adsl)
+link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformSignalChangeType change_type, NMPlatformReason reason, NMDeviceAdsl *device_adsl)
{
- NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device_adsl);
- NMDevice *device = NM_DEVICE (device_adsl);
-
- /* This only gets called for PPPoE connections and "nas" interfaces */
-
- if (priv->nas_ifindex >= 0 && ifindex == priv->nas_ifindex) {
- /* NAS device went away for some reason; kill the connection */
- nm_log_dbg (LOGD_ADSL, "(%s): NAS interface disappeared",
- nm_device_get_iface (device));
- nm_device_state_changed (device,
- NM_DEVICE_STATE_FAILED,
- NM_DEVICE_STATE_REASON_BR2684_FAILED);
+ if (change_type == NM_PLATFORM_SIGNAL_REMOVED) {
+ NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device_adsl);
+ NMDevice *device = NM_DEVICE (device_adsl);
+
+ /* This only gets called for PPPoE connections and "nas" interfaces */
+
+ if (priv->nas_ifindex >= 0 && ifindex == priv->nas_ifindex) {
+ /* NAS device went away for some reason; kill the connection */
+ nm_log_dbg (LOGD_ADSL, "(%s): NAS interface disappeared",
+ nm_device_get_iface (device));
+ nm_device_state_changed (device,
+ NM_DEVICE_STATE_FAILED,
+ NM_DEVICE_STATE_REASON_BR2684_FAILED);
+ }
}
}
@@ -370,9 +369,9 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_reason)
}
/* Watch for the 'nas' interface going away */
- priv->lost_link_id = g_signal_connect (nm_platform_get (), NM_PLATFORM_LINK_REMOVED,
- G_CALLBACK (lost_link),
- self);
+ g_signal_connect (nm_platform_get (), NM_PLATFORM_SIGNAL_LINK_CHANGED,
+ G_CALLBACK (link_changed_cb),
+ self);
nm_log_dbg (LOGD_ADSL, "(%s): ATM setup successful", nm_device_get_iface (device));
@@ -493,10 +492,7 @@ deactivate (NMDevice *device)
priv->ppp_manager = NULL;
}
- if (priv->lost_link_id) {
- g_signal_handler_disconnect (nm_platform_get (), priv->lost_link_id);
- priv->lost_link_id = 0;
- }
+ g_signal_handlers_disconnect_by_func (nm_platform_get (), G_CALLBACK (link_changed_cb), device);
if (priv->brfd >= 0) {
close (priv->brfd);
@@ -629,10 +625,7 @@ dispose (GObject *object)
priv->carrier_poll_id = 0;
}
- if (priv->lost_link_id) {
- g_signal_handler_disconnect (nm_platform_get (), priv->lost_link_id);
- priv->lost_link_id = 0;
- }
+ g_signal_handlers_disconnect_by_func (nm_platform_get (), G_CALLBACK (link_changed_cb), self);
g_free (priv->nas_ifname);
priv->nas_ifname = NULL;
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 384460ecd7..a93acb298a 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -355,34 +355,18 @@ static void cp_connection_updated (NMConnectionProvider *cp, NMConnection *conne
static const char *state_to_string (NMDeviceState state);
-static void link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformReason reason, NMDevice *device);
+static void link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformSignalChangeType change_type, NMPlatformReason reason, NMDevice *device);
static void check_carrier (NMDevice *device);
static void nm_device_queued_ip_config_change_clear (NMDevice *self);
static void update_ip_config (NMDevice *self, gboolean initial);
-static void device_ip_changed (NMPlatform *platform, int ifindex, gpointer platform_object, NMPlatformReason reason, gpointer user_data);
+static void device_ip_changed (NMPlatform *platform, int ifindex, gpointer platform_object, NMPlatformSignalChangeType change_type, NMPlatformReason reason, gpointer user_data);
static void nm_device_slave_notify_enslave (NMDevice *dev, gboolean success);
static void nm_device_slave_notify_release (NMDevice *dev, NMDeviceStateReason reason);
static void addrconf6_start_with_link_ready (NMDevice *self);
-static const char const *platform_ip_signals[] = {
- NM_PLATFORM_IP4_ADDRESS_ADDED,
- NM_PLATFORM_IP4_ADDRESS_CHANGED,
- NM_PLATFORM_IP4_ADDRESS_REMOVED,
- NM_PLATFORM_IP4_ROUTE_ADDED,
- NM_PLATFORM_IP4_ROUTE_CHANGED,
- NM_PLATFORM_IP4_ROUTE_REMOVED,
- NM_PLATFORM_IP6_ADDRESS_ADDED,
- NM_PLATFORM_IP6_ADDRESS_CHANGED,
- NM_PLATFORM_IP6_ADDRESS_REMOVED,
- NM_PLATFORM_IP6_ROUTE_ADDED,
- NM_PLATFORM_IP6_ROUTE_CHANGED,
- NM_PLATFORM_IP6_ROUTE_REMOVED,
-};
-static const int n_platform_ip_signals = G_N_ELEMENTS (platform_ip_signals);
-
static void
nm_device_init (NMDevice *self)
{
@@ -502,7 +486,6 @@ constructor (GType type,
NMDevice *dev;
NMDevicePrivate *priv;
NMPlatform *platform;
- int i;
static guint32 id = 0;
object = G_OBJECT_CLASS (nm_device_parent_class)->constructor (type,
@@ -535,13 +518,11 @@ constructor (GType type,
/* Watch for external IP config changes */
platform = nm_platform_get ();
- for (i = 0; i < n_platform_ip_signals; i++) {
- g_signal_connect (platform, platform_ip_signals[i],
- G_CALLBACK (device_ip_changed), dev);
- }
-
- g_signal_connect (platform, NM_PLATFORM_LINK_CHANGED,
- G_CALLBACK (link_changed_cb), dev);
+ g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), dev);
priv->initialized = TRUE;
return object;
@@ -1142,13 +1123,16 @@ nm_device_set_carrier (NMDevice *device, gboolean carrier)
}
static void
-link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformReason reason, NMDevice *device)
+link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformSignalChangeType change_type, NMPlatformReason reason, NMDevice *device)
{
NMDeviceClass *klass = NM_DEVICE_GET_CLASS (device);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
int my_ifindex = nm_device_get_ifindex (device);
gboolean change_ip_ifname = FALSE;
+ if (change_type != NM_PLATFORM_SIGNAL_CHANGED)
+ return;
+
/* Ignore other devices. */
if (ifindex == my_ifindex) {
@@ -7107,7 +7091,7 @@ queued_ip_config_change (gpointer user_data)
}
static void
-device_ip_changed (NMPlatform *platform, int ifindex, gpointer platform_object, NMPlatformReason reason, gpointer user_data)
+device_ip_changed (NMPlatform *platform, int ifindex, gpointer platform_object, NMPlatformSignalChangeType change_type, NMPlatformReason reason, gpointer user_data)
{
NMDevice *self = user_data;
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 505bc851ff..12aac78519 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -1018,7 +1018,7 @@ void
nm_ip4_config_add_address (NMIP4Config *config, const NMPlatformIP4Address *new)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
- NMPlatformSource old_source;
+ NMPlatformIP4Address item_old;
int i;
g_return_if_fail (new != NULL);
@@ -1029,10 +1029,28 @@ nm_ip4_config_add_address (NMIP4Config *config, const NMPlatformIP4Address *new)
if (addresses_are_duplicate (item, new, FALSE)) {
if (nm_platform_ip4_address_cmp (item, new) == 0)
return;
- old_source = item->source;
- memcpy (item, new, sizeof (*item));
- /* Restore highest priority source */
- item->source = MAX (old_source, new->source);
+
+ /* remember the old values. */
+ item_old = *item;
+ /* Copy over old item to get new lifetime, timestamp, preferred */
+ *item = *new;
+
+ /* But restore highest priority source */
+ item->source = MAX (item_old.source, new->source);
+
+ /* for addresses that we read from the kernel, we keep the timestamps as defined
+ * by the previous source (item_old). The reason is, that the other source configured the lifetimes
+ * with "what should be" and the kernel values are "what turned out after configuring it".
+ *
+ * For other sources, the longer lifetime wins. */
+ if ( (new->source == NM_PLATFORM_SOURCE_KERNEL && new->source != item_old.source)
+ || nm_platform_ip_address_cmp_expiry ((const NMPlatformIPAddress *) &item_old, (const NMPlatformIPAddress *) new) > 0) {
+ item->timestamp = item_old.timestamp;
+ item->lifetime = item_old.lifetime;
+ item->preferred = item_old.preferred;
+ }
+ if (nm_platform_ip4_address_cmp (&item_old, item) == 0)
+ return;
goto NOTIFY;
}
}
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index 0a7cf26a3b..fd791a5f90 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -1021,7 +1021,7 @@ void
nm_ip6_config_add_address (NMIP6Config *config, const NMPlatformIP6Address *new)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
- NMPlatformSource old_source;
+ NMPlatformIP6Address item_old;
int i;
g_return_if_fail (new != NULL);
@@ -1032,11 +1032,28 @@ nm_ip6_config_add_address (NMIP6Config *config, const NMPlatformIP6Address *new)
if (IN6_ARE_ADDR_EQUAL (&item->address, &new->address)) {
if (nm_platform_ip6_address_cmp (item, new) == 0)
return;
- old_source = item->source;
+
+ /* remember the old values. */
+ item_old = *item;
/* Copy over old item to get new lifetime, timestamp, preferred */
*item = *new;
+
/* But restore highest priority source */
- item->source = MAX (old_source, new->source);
+ item->source = MAX (item_old.source, new->source);
+
+ /* for addresses that we read from the kernel, we keep the timestamps as defined
+ * by the previous source (item_old). The reason is, that the other source configured the lifetimes
+ * with "what should be" and the kernel values are "what turned out after configuring it".
+ *
+ * For other sources, the longer lifetime wins. */
+ if ( (new->source == NM_PLATFORM_SOURCE_KERNEL && new->source != item_old.source)
+ || nm_platform_ip_address_cmp_expiry ((const NMPlatformIPAddress *) &item_old, (const NMPlatformIPAddress *) new) > 0) {
+ item->timestamp = item_old.timestamp;
+ item->lifetime = item_old.lifetime;
+ item->preferred = item_old.preferred;
+ }
+ if (nm_platform_ip6_address_cmp (&item_old, item) == 0)
+ return;
goto NOTIFY;
}
}
diff --git a/src/nm-manager.c b/src/nm-manager.c
index fb9716d9bd..79c0518c5a 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -148,13 +148,6 @@ static NMDevice *find_device_by_ip_iface (NMManager *self, const gchar *iface);
static void rfkill_change_wifi (const char *desc, gboolean enabled);
-static void
-platform_link_added_cb (NMPlatform *platform,
- int ifindex,
- NMPlatformLink *plink,
- NMPlatformReason reason,
- gpointer user_data);
-
static gboolean find_master (NMManager *self,
NMConnection *connection,
NMDevice *device,
@@ -194,6 +187,8 @@ typedef struct {
NMState state;
NMConnectivity *connectivity;
+ int ignore_link_added_cb;
+
NMPolicy *policy;
NMDBusManager *dbus_mgr;
@@ -1102,7 +1097,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
* explicitly here, otherwise adding the platform/kernel device would
* create it before this function can do the rest of the setup.
*/
- g_signal_handlers_block_by_func (nm_platform_get (), G_CALLBACK (platform_link_added_cb), self);
+ priv->ignore_link_added_cb++;
if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) {
device = nm_device_bond_new_for_connection (connection);
@@ -1122,7 +1117,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
g_object_unref (device);
}
- g_signal_handlers_unblock_by_func (nm_platform_get (), G_CALLBACK (platform_link_added_cb), self);
+ priv->ignore_link_added_cb--;
out:
g_free (iface);
@@ -2078,13 +2073,11 @@ load_device_factories (NMManager *self)
}
static void
-platform_link_added_cb (NMPlatform *platform,
- int ifindex,
- NMPlatformLink *plink,
- NMPlatformReason reason,
- gpointer user_data)
+platform_link_added (NMManager *self,
+ int ifindex,
+ NMPlatformLink *plink,
+ NMPlatformReason reason)
{
- NMManager *self = NM_MANAGER (user_data);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMDevice *device = NULL;
GSList *iter;
@@ -2092,6 +2085,9 @@ platform_link_added_cb (NMPlatform *platform,
g_return_if_fail (ifindex > 0);
+ if (priv->ignore_link_added_cb > 0)
+ return;
+
if (find_device_by_ifindex (self, ifindex))
return;
@@ -2202,18 +2198,29 @@ platform_link_added_cb (NMPlatform *platform,
}
static void
-platform_link_removed_cb (NMPlatform *platform,
- int ifindex,
- NMPlatformLink *plink,
- NMPlatformReason reason,
- gpointer user_data)
-{
- NMManager *self = NM_MANAGER (user_data);
- NMDevice *device;
+platform_link_cb (NMPlatform *platform,
+ int ifindex,
+ NMPlatformLink *plink,
+ NMPlatformSignalChangeType change_type,
+ NMPlatformReason reason,
+ gpointer user_data)
+{
+ switch (change_type) {
+ case NM_PLATFORM_SIGNAL_ADDED:
+ platform_link_added (NM_MANAGER (user_data), ifindex, plink, reason);
+ break;
+ case NM_PLATFORM_SIGNAL_REMOVED: {
+ NMManager *self = NM_MANAGER (user_data);
+ NMDevice *device;
- device = find_device_by_ifindex (self, ifindex);
- if (device)
- remove_device (self, device, FALSE);
+ device = find_device_by_ifindex (self, ifindex);
+ if (device)
+ remove_device (self, device, FALSE);
+ break;
+ }
+ default:
+ break;
+ }
}
static void
@@ -4738,12 +4745,8 @@ nm_manager_new (NMSettings *settings,
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH, singleton);
g_signal_connect (nm_platform_get (),
- NM_PLATFORM_LINK_ADDED,
- G_CALLBACK (platform_link_added_cb),
- singleton);
- g_signal_connect (nm_platform_get (),
- NM_PLATFORM_LINK_REMOVED,
- G_CALLBACK (platform_link_removed_cb),
+ NM_PLATFORM_SIGNAL_LINK_CHANGED,
+ G_CALLBACK (platform_link_cb),
singleton);
priv->rfkill_mgr = nm_rfkill_manager_new ();
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 9dfab56dd3..2da3181fe0 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -180,7 +180,7 @@ link_added_emit (gpointer user_data)
device = link_get (info->platform, info->ifindex);
g_assert (device);
- g_signal_emit_by_name (info->platform, NM_PLATFORM_LINK_ADDED, info->ifindex, &device->link, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (info->platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, info->ifindex, &device->link, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return FALSE;
}
@@ -250,7 +250,7 @@ link_delete (NMPlatform *platform, int ifindex)
memset (route, 0, sizeof (*route));
}
- g_signal_emit_by_name (platform, NM_PLATFORM_LINK_REMOVED, ifindex, &deleted_device, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, ifindex, &deleted_device, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -299,7 +299,7 @@ link_changed (NMPlatform *platform, NMFakePlatformLink *device)
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
int i;
- g_signal_emit_by_name (platform, NM_PLATFORM_LINK_CHANGED, device->link.ifindex, &device->link, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, device->link.ifindex, &device->link, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_REASON_INTERNAL);
if (device->link.master) {
NMFakePlatformLink *master = link_get (platform, device->link.master);
@@ -871,12 +871,12 @@ ip4_address_add (NMPlatform *platform, int ifindex,
continue;
memcpy (item, &address, sizeof (address));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ADDRESS_CHANGED, ifindex, &address, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, ifindex, &address, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
g_array_append_val (priv->ip4_addresses, address);
- g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ADDRESS_ADDED, ifindex, &address, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, ifindex, &address, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -911,12 +911,12 @@ ip6_address_add (NMPlatform *platform, int ifindex,
continue;
memcpy (item, &address, sizeof (address));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ADDRESS_CHANGED, ifindex, &address, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, ifindex, &address, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
g_array_append_val (priv->ip6_addresses, address);
- g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ADDRESS_ADDED, ifindex, &address, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, ifindex, &address, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -935,7 +935,7 @@ ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen)
memcpy (&deleted_address, address, sizeof (deleted_address));
memset (address, 0, sizeof (*address));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ADDRESS_REMOVED, ifindex, &deleted_address, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, ifindex, &deleted_address, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
}
@@ -958,7 +958,7 @@ ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int
memcpy (&deleted_address, address, sizeof (deleted_address));
memset (address, 0, sizeof (*address));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ADDRESS_REMOVED, ifindex, &deleted_address, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, ifindex, &deleted_address, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
}
@@ -1086,12 +1086,12 @@ ip4_route_add (NMPlatform *platform, int ifindex, in_addr_t network, int plen,
continue;
memcpy (item, &route, sizeof (route));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_CHANGED, ifindex, &route, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, ifindex, &route, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
g_array_append_val (priv->ip4_routes, route);
- g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_ADDED, ifindex, &route, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, ifindex, &route, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -1123,12 +1123,12 @@ ip6_route_add (NMPlatform *platform, int ifindex, struct in6_addr network, int p
continue;
memcpy (item, &route, sizeof (route));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_CHANGED, ifindex, &route, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, ifindex, &route, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
g_array_append_val (priv->ip6_routes, route);
- g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_ADDED, ifindex, &route, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, ifindex, &route, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -1180,7 +1180,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
if (route) {
memcpy (&deleted_route, route, sizeof (deleted_route));
memset (route, 0, sizeof (*route));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_REMOVED, ifindex, &deleted_route, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, ifindex, &deleted_route, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
}
return TRUE;
@@ -1195,7 +1195,7 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
if (route) {
memcpy (&deleted_route, route, sizeof (deleted_route));
memset (route, 0, sizeof (*route));
- g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_REMOVED, ifindex, &deleted_route, NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, ifindex, &deleted_route, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
}
return TRUE;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 46430d6cbd..82c2fed26c 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -146,58 +146,51 @@ nm_rtnl_addr_set_prefixlen (struct rtnl_addr *rtnladdr, int plen)
#define rtnl_addr_set_prefixlen nm_rtnl_addr_set_prefixlen
typedef enum {
- UNKNOWN_OBJECT_TYPE,
- LINK,
- IP4_ADDRESS,
- IP6_ADDRESS,
- IP4_ROUTE,
- IP6_ROUTE,
- N_TYPES,
+ OBJECT_TYPE_UNKNOWN,
+ OBJECT_TYPE_LINK,
+ OBJECT_TYPE_IP4_ADDRESS,
+ OBJECT_TYPE_IP6_ADDRESS,
+ OBJECT_TYPE_IP4_ROUTE,
+ OBJECT_TYPE_IP6_ROUTE,
+ __OBJECT_TYPE_LAST,
} ObjectType;
-typedef enum {
- ADDED,
- CHANGED,
- REMOVED,
- N_STATUSES
-} ObjectStatus;
-
static ObjectType
object_type_from_nl_object (const struct nl_object *object)
{
const char *type_str;
if (!object || !(type_str = nl_object_get_type (object)))
- return UNKNOWN_OBJECT_TYPE;
+ return OBJECT_TYPE_UNKNOWN;
if (!strcmp (type_str, "route/link"))
- return LINK;
+ return OBJECT_TYPE_LINK;
else if (!strcmp (type_str, "route/addr")) {
switch (rtnl_addr_get_family ((struct rtnl_addr *) object)) {
case AF_INET:
- return IP4_ADDRESS;
+ return OBJECT_TYPE_IP4_ADDRESS;
case AF_INET6:
- return IP6_ADDRESS;
+ return OBJECT_TYPE_IP6_ADDRESS;
default:
- return UNKNOWN_OBJECT_TYPE;
+ return OBJECT_TYPE_UNKNOWN;
}
} else if (!strcmp (type_str, "route/route")) {
switch (rtnl_route_get_family ((struct rtnl_route *) object)) {
case AF_INET:
- return IP4_ROUTE;
+ return OBJECT_TYPE_IP4_ROUTE;
case AF_INET6:
- return IP6_ROUTE;
+ return OBJECT_TYPE_IP6_ROUTE;
default:
- return UNKNOWN_OBJECT_TYPE;
+ return OBJECT_TYPE_UNKNOWN;
}
} else
- return UNKNOWN_OBJECT_TYPE;
+ return OBJECT_TYPE_UNKNOWN;
}
static void
_nl_link_family_unset (struct nl_object *obj, int *family)
{
- if (!obj || object_type_from_nl_object (obj) != LINK)
+ if (!obj || object_type_from_nl_object (obj) != OBJECT_TYPE_LINK)
*family = AF_UNSPEC;
else {
*family = rtnl_link_get_family ((struct rtnl_link *) obj);
@@ -243,7 +236,7 @@ get_kernel_object (struct nl_sock *sock, struct nl_object *needle)
ObjectType type = object_type_from_nl_object (needle);
switch (type) {
- case LINK:
+ case OBJECT_TYPE_LINK:
{
int ifindex = rtnl_link_get_ifindex ((struct rtnl_link *) needle);
const char *name = rtnl_link_get_name ((struct rtnl_link *) needle);
@@ -272,10 +265,10 @@ get_kernel_object (struct nl_sock *sock, struct nl_object *needle)
return NULL;
}
}
- case IP4_ADDRESS:
- case IP6_ADDRESS:
- case IP4_ROUTE:
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP4_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
+ case OBJECT_TYPE_IP4_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
/* Fallback to a one-time cache allocation. */
{
struct nl_cache *cache;
@@ -311,13 +304,13 @@ static int
add_kernel_object (struct nl_sock *sock, struct nl_object *object)
{
switch (object_type_from_nl_object (object)) {
- case LINK:
+ case OBJECT_TYPE_LINK:
return rtnl_link_add (sock, (struct rtnl_link *) object, NLM_F_CREATE);
- case IP4_ADDRESS:
- case IP6_ADDRESS:
+ case OBJECT_TYPE_IP4_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
return rtnl_addr_add (sock, (struct rtnl_addr *) object, NLM_F_CREATE | NLM_F_REPLACE);
- case IP4_ROUTE:
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP4_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
return rtnl_route_add (sock, (struct rtnl_route *) object, NLM_F_CREATE | NLM_F_REPLACE);
default:
g_return_val_if_reached (-NLE_INVAL);
@@ -1077,15 +1070,15 @@ static const char *
to_string_object_with_type (NMPlatform *platform, struct nl_object *obj, ObjectType type)
{
switch (type) {
- case LINK:
+ case OBJECT_TYPE_LINK:
return to_string_link (platform, (struct rtnl_link *) obj);
- case IP4_ADDRESS:
+ case OBJECT_TYPE_IP4_ADDRESS:
return to_string_ip4_address ((struct rtnl_addr *) obj);
- case IP6_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
return to_string_ip6_address ((struct rtnl_addr *) obj);
- case IP4_ROUTE:
+ case OBJECT_TYPE_IP4_ROUTE:
return to_string_ip4_route ((struct rtnl_route *) obj);
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
return to_string_ip6_route ((struct rtnl_route *) obj);
default:
SET_AND_RETURN_STRING_BUFFER ("(unknown netlink object %p)", obj);
@@ -1104,12 +1097,12 @@ to_string_object (NMPlatform *platform, struct nl_object *obj)
/* Object and cache manipulation */
-static const char *signal_by_type_and_status[N_TYPES][N_STATUSES] = {
- [LINK] = { NM_PLATFORM_LINK_ADDED, NM_PLATFORM_LINK_CHANGED, NM_PLATFORM_LINK_REMOVED },
- [IP4_ADDRESS] = { NM_PLATFORM_IP4_ADDRESS_ADDED, NM_PLATFORM_IP4_ADDRESS_CHANGED, NM_PLATFORM_IP4_ADDRESS_REMOVED },
- [IP6_ADDRESS] = { NM_PLATFORM_IP6_ADDRESS_ADDED, NM_PLATFORM_IP6_ADDRESS_CHANGED, NM_PLATFORM_IP6_ADDRESS_REMOVED },
- [IP4_ROUTE] = { NM_PLATFORM_IP4_ROUTE_ADDED, NM_PLATFORM_IP4_ROUTE_CHANGED, NM_PLATFORM_IP4_ROUTE_REMOVED },
- [IP6_ROUTE] = { NM_PLATFORM_IP6_ROUTE_ADDED, NM_PLATFORM_IP6_ROUTE_CHANGED, NM_PLATFORM_IP6_ROUTE_REMOVED }
+static const char *signal_by_type_and_status[__OBJECT_TYPE_LAST] = {
+ [OBJECT_TYPE_LINK] = NM_PLATFORM_SIGNAL_LINK_CHANGED,
+ [OBJECT_TYPE_IP4_ADDRESS] = NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED,
+ [OBJECT_TYPE_IP6_ADDRESS] = NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED,
+ [OBJECT_TYPE_IP4_ROUTE] = NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED,
+ [OBJECT_TYPE_IP6_ROUTE] = NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED,
};
static struct nl_cache *
@@ -1118,13 +1111,13 @@ choose_cache_by_type (NMPlatform *platform, ObjectType object_type)
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
switch (object_type) {
- case LINK:
+ case OBJECT_TYPE_LINK:
return priv->link_cache;
- case IP4_ADDRESS:
- case IP6_ADDRESS:
+ case OBJECT_TYPE_IP4_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
return priv->address_cache;
- case IP4_ROUTE:
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP4_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
return priv->route_cache;
default:
g_return_val_if_reached (NULL);
@@ -1142,11 +1135,11 @@ static gboolean
object_has_ifindex (struct nl_object *object, int ifindex)
{
switch (object_type_from_nl_object (object)) {
- case IP4_ADDRESS:
- case IP6_ADDRESS:
+ case OBJECT_TYPE_IP4_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
return ifindex == rtnl_addr_get_ifindex ((struct rtnl_addr *) object);
- case IP4_ROUTE:
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP4_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
{
struct rtnl_route *rtnlroute = (struct rtnl_route *) object;
struct rtnl_nexthop *nexthop;
@@ -1178,14 +1171,14 @@ check_cache_items (NMPlatform *platform, struct nl_cache *cache, int ifindex)
}
static void
-announce_object (NMPlatform *platform, const struct nl_object *object, ObjectStatus status, NMPlatformReason reason)
+announce_object (NMPlatform *platform, const struct nl_object *object, NMPlatformSignalChangeType change_type, NMPlatformReason reason)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
ObjectType object_type = object_type_from_nl_object (object);
- const char *sig = signal_by_type_and_status[object_type][status];
+ const char *sig = signal_by_type_and_status[object_type];
switch (object_type) {
- case LINK:
+ case OBJECT_TYPE_LINK:
{
NMPlatformLink device;
struct rtnl_link *rtnl_link = (struct rtnl_link *) object;
@@ -1199,9 +1192,9 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
* event_notification() or link_delete() which block the announcment
* themselves when appropriate.
*/
- switch (status) {
- case ADDED:
- case CHANGED:
+ switch (change_type) {
+ case NM_PLATFORM_SIGNAL_ADDED:
+ case NM_PLATFORM_SIGNAL_CHANGED:
if (!link_is_software (rtnl_link) && !device.driver)
return;
break;
@@ -1215,12 +1208,12 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
* More precisely, kernel removes routes when interface goes !IFF_UP and
* removes both addresses and routes when interface is removed.
*/
- switch (status) {
- case CHANGED:
+ switch (change_type) {
+ case NM_PLATFORM_SIGNAL_CHANGED:
if (!device.connected)
check_cache_items (platform, priv->route_cache, device.ifindex);
break;
- case REMOVED:
+ case NM_PLATFORM_SIGNAL_REMOVED:
check_cache_items (platform, priv->address_cache, device.ifindex);
check_cache_items (platform, priv->route_cache, device.ifindex);
g_hash_table_remove (priv->wifi_data, GINT_TO_POINTER (device.ifindex));
@@ -1229,10 +1222,10 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
break;
}
- g_signal_emit_by_name (platform, sig, device.ifindex, &device, reason);
+ g_signal_emit_by_name (platform, sig, device.ifindex, &device, change_type, reason);
}
return;
- case IP4_ADDRESS:
+ case OBJECT_TYPE_IP4_ADDRESS:
{
NMPlatformIP4Address address;
@@ -1242,40 +1235,40 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
/* Address deletion is sometimes accompanied by route deletion. We need to
* check all routes belonging to the same interface.
*/
- switch (status) {
- case REMOVED:
+ switch (change_type) {
+ case NM_PLATFORM_SIGNAL_REMOVED:
check_cache_items (platform, priv->route_cache, address.ifindex);
break;
default:
break;
}
- g_signal_emit_by_name (platform, sig, address.ifindex, &address, reason);
+ g_signal_emit_by_name (platform, sig, address.ifindex, &address, change_type, reason);
}
return;
- case IP6_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
{
NMPlatformIP6Address address;
if (!init_ip6_address (&address, (struct rtnl_addr *) object))
return;
- g_signal_emit_by_name (platform, sig, address.ifindex, &address, reason);
+ g_signal_emit_by_name (platform, sig, address.ifindex, &address, change_type, reason);
}
return;
- case IP4_ROUTE:
+ case OBJECT_TYPE_IP4_ROUTE:
{
NMPlatformIP4Route route;
if (init_ip4_route (&route, (struct rtnl_route *) object))
- g_signal_emit_by_name (platform, sig, route.ifindex, &route, reason);
+ g_signal_emit_by_name (platform, sig, route.ifindex, &route, change_type, reason);
}
return;
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
{
NMPlatformIP6Route route;
if (init_ip6_route (&route, (struct rtnl_route *) object))
- g_signal_emit_by_name (platform, sig, route.ifindex, &route, reason);
+ g_signal_emit_by_name (platform, sig, route.ifindex, &route, change_type, reason);
}
return;
default:
@@ -1306,7 +1299,7 @@ refresh_object (NMPlatform *platform, struct nl_object *object, gboolean removed
if (cached_object) {
nl_cache_remove (cached_object);
- announce_object (platform, cached_object, REMOVED, reason);
+ announce_object (platform, cached_object, NM_PLATFORM_SIGNAL_REMOVED, reason);
}
} else {
if (!kernel_object)
@@ -1322,10 +1315,10 @@ refresh_object (NMPlatform *platform, struct nl_object *object, gboolean removed
return FALSE;
}
- announce_object (platform, kernel_object, cached_object ? CHANGED : ADDED, reason);
+ announce_object (platform, kernel_object, cached_object ? NM_PLATFORM_SIGNAL_CHANGED : NM_PLATFORM_SIGNAL_ADDED, reason);
/* Refresh the master device (even on enslave/release) */
- if (object_type_from_nl_object (kernel_object) == LINK) {
+ if (object_type_from_nl_object (kernel_object) == OBJECT_TYPE_LINK) {
int kernel_master = rtnl_link_get_master ((struct rtnl_link *) kernel_object);
int cached_master = cached_object ? rtnl_link_get_master ((struct rtnl_link *) cached_object) : 0;
struct nl_object *master_object;
@@ -1391,21 +1384,21 @@ delete_object (NMPlatform *platform, struct nl_object *obj)
int nle;
object_type = object_type_from_nl_object (obj);
- g_return_val_if_fail (object_type != UNKNOWN_OBJECT_TYPE, FALSE);
+ g_return_val_if_fail (object_type != OBJECT_TYPE_UNKNOWN, FALSE);
cached_object = nm_nl_cache_search (choose_cache_by_type (platform, object_type), obj);
object = cached_object ? cached_object : obj;
switch (object_type) {
- case LINK:
+ case OBJECT_TYPE_LINK:
nle = rtnl_link_delete (priv->nlh, (struct rtnl_link *) object);
break;
- case IP4_ADDRESS:
- case IP6_ADDRESS:
+ case OBJECT_TYPE_IP4_ADDRESS:
+ case OBJECT_TYPE_IP6_ADDRESS:
nle = rtnl_addr_delete (priv->nlh, (struct rtnl_addr *) object, 0);
break;
- case IP4_ROUTE:
- case IP6_ROUTE:
+ case OBJECT_TYPE_IP4_ROUTE:
+ case OBJECT_TYPE_IP6_ROUTE:
nle = rtnl_route_delete (priv->nlh, (struct rtnl_route *) object, 0);
break;
default:
@@ -1420,7 +1413,7 @@ delete_object (NMPlatform *platform, struct nl_object *obj)
nl_geterror (nle), nle);
break;
case -NLE_NOADDR:
- if (object_type == IP4_ADDRESS || object_type == IP6_ADDRESS) {
+ if (object_type == OBJECT_TYPE_IP4_ADDRESS || object_type == OBJECT_TYPE_IP6_ADDRESS) {
debug("delete_object for address failed with \"%s\" (%d), meaning the address was already removed",
nl_geterror (nle), nle);
break;
@@ -1476,7 +1469,7 @@ event_notification (struct nl_msg *msg, gpointer user_data)
g_return_val_if_fail (object, NL_OK);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
- if (object_type_from_nl_object (object) == LINK) {
+ if (object_type_from_nl_object (object) == OBJECT_TYPE_LINK) {
const char *name = rtnl_link_get_name ((struct rtnl_link *) object);
debug ("netlink event (type %d) for link: %s (%d, family %d)",
@@ -1518,7 +1511,7 @@ event_notification (struct nl_msg *msg, gpointer user_data)
if (!link_is_announceable (platform, (struct rtnl_link *) cached_object))
return NL_OK;
}
- announce_object (platform, cached_object, REMOVED, NM_PLATFORM_REASON_EXTERNAL);
+ announce_object (platform, cached_object, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_EXTERNAL);
return NL_OK;
case RTM_NEWLINK:
@@ -1539,7 +1532,7 @@ event_notification (struct nl_msg *msg, gpointer user_data)
error ("netlink cache error: %s", nl_geterror (nle));
return NL_OK;
}
- announce_object (platform, kernel_object, ADDED, NM_PLATFORM_REASON_EXTERNAL);
+ announce_object (platform, kernel_object, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_EXTERNAL);
return NL_OK;
}
/* Ignore non-change
@@ -1556,7 +1549,7 @@ event_notification (struct nl_msg *msg, gpointer user_data)
error ("netlink cache error: %s", nl_geterror (nle));
return NL_OK;
}
- announce_object (platform, kernel_object, CHANGED, NM_PLATFORM_REASON_EXTERNAL);
+ announce_object (platform, kernel_object, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_REASON_EXTERNAL);
return NL_OK;
default:
@@ -1735,7 +1728,7 @@ static GArray *
link_get_all (NMPlatform *platform)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
- GArray *links = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformLink), nl_cache_nitems (priv->link_cache));
+ GArray *links = g_array_sized_new (FALSE, FALSE, sizeof (NMPlatformLink), nl_cache_nitems (priv->link_cache));
NMPlatformLink device;
struct nl_object *object;
@@ -2900,24 +2893,13 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
/******************************************************************/
-static int
-ip_address_mark_all (NMPlatform *platform, int family, int ifindex)
+static gboolean
+_address_match (struct rtnl_addr *addr, int family, int ifindex)
{
- NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
- struct nl_object *object;
- int count = 0;
-
- for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) {
- nl_object_unmark (object);
- if (rtnl_addr_get_family ((struct rtnl_addr *) object) != family)
- continue;
- if (rtnl_addr_get_ifindex ((struct rtnl_addr *) object) != ifindex)
- continue;
- nl_object_mark (object);
- count++;
- }
+ g_return_val_if_fail (addr, FALSE);
- return count;
+ return rtnl_addr_get_family (addr) == family &&
+ rtnl_addr_get_ifindex (addr) == ifindex;
}
static GArray *
@@ -2927,18 +2909,15 @@ ip4_address_get_all (NMPlatform *platform, int ifindex)
GArray *addresses;
NMPlatformIP4Address address;
struct nl_object *object;
- int count;
- count = ip_address_mark_all (platform, AF_INET, ifindex);
- addresses = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP4Address), count);
+ addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address));
for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) {
- if (nl_object_is_marked (object)) {
+ if (_address_match ((struct rtnl_addr *) object, AF_INET, ifindex)) {
if (init_ip4_address (&address, (struct rtnl_addr *) object)) {
address.source = NM_PLATFORM_SOURCE_KERNEL;
g_array_append_val (addresses, address);
}
- nl_object_unmark (object);
}
}
@@ -2952,43 +2931,21 @@ ip6_address_get_all (NMPlatform *platform, int ifindex)
GArray *addresses;
NMPlatformIP6Address address;
struct nl_object *object;
- int count;
- count = ip_address_mark_all (platform, AF_INET6, ifindex);
- addresses = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP6Address), count);
+ addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP6Address));
for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) {
- if (nl_object_is_marked (object)) {
+ if (_address_match ((struct rtnl_addr *) object, AF_INET6, ifindex)) {
if (init_ip6_address (&address, (struct rtnl_addr *) object)) {
address.source = NM_PLATFORM_SOURCE_KERNEL;
g_array_append_val (addresses, address);
}
- nl_object_unmark (object);
}
}
return addresses;
}
-static void
-addr4_to_broadcast (struct in_addr *dst, const struct in_addr *src, guint8 plen)
-{
- guint nbytes = plen / 8;
- guint nbits = plen % 8;
-
- g_return_if_fail (plen <= 32);
- g_assert (src);
- g_assert (dst);
-
- if (plen >= 32)
- *dst = *src;
- else {
- dst->s_addr = 0xFFFFFFFF;
- memcpy (dst, src, nbytes);
- ((guint8 *) dst)[nbytes] = (((const guint8 *) src)[nbytes] | (0xFF >> nbits));
- }
-}
-
#define IPV4LL_NETWORK (htonl (0xA9FE0000L))
#define IPV4LL_NETMASK (htonl (0xFFFF0000L))
@@ -3027,10 +2984,10 @@ build_rtnl_addr (int family,
/* IPv4 Broadcast address */
if (family == AF_INET) {
- struct in_addr bcast;
+ in_addr_t bcast;
auto_nl_addr struct nl_addr *bcaddr = NULL;
- addr4_to_broadcast (&bcast, addr, plen);
+ bcast = *((in_addr_t *) addr) | ~nm_utils_ip4_prefix_to_netmask (plen);
bcaddr = nl_addr_build (family, &bcast, addrlen);
g_assert (bcaddr);
rtnl_addr_set_broadcast (rtnladdr, bcaddr);
@@ -3136,36 +3093,22 @@ ip6_address_exists (NMPlatform *platform, int ifindex, struct in6_addr addr, int
/******************************************************************/
-static int
-ip_route_mark_all (NMPlatform *platform, int family, int ifindex)
+static gboolean
+_route_match (struct rtnl_route *rtnlroute, int family, int ifindex)
{
- NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
- struct nl_object *object;
- int count = 0;
+ struct rtnl_nexthop *nexthop;
- for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
- struct rtnl_route *rtnlroute = (struct rtnl_route *) object;
- struct rtnl_nexthop *nexthop;
-
- nl_object_unmark (object);
- if (rtnl_route_get_type (rtnlroute) != RTN_UNICAST)
- continue;
- if (rtnl_route_get_table (rtnlroute) != RT_TABLE_MAIN)
- continue;
- if (rtnl_route_get_protocol (rtnlroute) == RTPROT_KERNEL)
- continue;
- if (rtnl_route_get_family (rtnlroute) != family)
- continue;
- if (rtnl_route_get_nnexthops (rtnlroute) != 1)
- continue;
- nexthop = rtnl_route_nexthop_n (rtnlroute, 0);
- if (rtnl_route_nh_get_ifindex (nexthop) != ifindex)
- continue;
- nl_object_mark (object);
- count++;
- }
-
- return count;
+ g_return_val_if_fail (rtnlroute, FALSE);
+
+ if (rtnl_route_get_type (rtnlroute) != RTN_UNICAST ||
+ rtnl_route_get_table (rtnlroute) != RT_TABLE_MAIN ||
+ rtnl_route_get_protocol (rtnlroute) == RTPROT_KERNEL ||
+ rtnl_route_get_family (rtnlroute) != family ||
+ rtnl_route_get_nnexthops (rtnlroute) != 1)
+ return FALSE;
+
+ nexthop = rtnl_route_nexthop_n (rtnlroute, 0);
+ return rtnl_route_nh_get_ifindex (nexthop) == ifindex;
}
static GArray *
@@ -3175,19 +3118,16 @@ ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
GArray *routes;
NMPlatformIP4Route route;
struct nl_object *object;
- int count = 0;
- count = ip_route_mark_all (platform, AF_INET, ifindex);
- routes = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP4Route), count);
+ routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route));
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
- if (nl_object_is_marked (object)) {
+ if (_route_match ((struct rtnl_route *) object, AF_INET, ifindex)) {
if (init_ip4_route (&route, (struct rtnl_route *) object)) {
route.source = NM_PLATFORM_SOURCE_KERNEL;
if (route.plen != 0 || include_default)
g_array_append_val (routes, route);
}
- nl_object_unmark (object);
}
}
@@ -3201,19 +3141,16 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
GArray *routes;
NMPlatformIP6Route route;
struct nl_object *object;
- int count;
- count = ip_route_mark_all (platform, AF_INET6, ifindex);
- routes = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP6Route), count);
+ routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP6Route));
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
- if (nl_object_is_marked (object)) {
+ if (_route_match ((struct rtnl_route *) object, AF_INET6, ifindex)) {
if (init_ip6_route (&route, (struct rtnl_route *) object)) {
route.source = NM_PLATFORM_SOURCE_KERNEL;
if (route.plen != 0 || include_default)
g_array_append_val (routes, route);
}
- nl_object_unmark (object);
}
}
@@ -3463,7 +3400,7 @@ udev_device_added (NMPlatform *platform,
return;
}
- announce_object (platform, (struct nl_object *) rtnllink, is_changed ? CHANGED : ADDED, NM_PLATFORM_REASON_EXTERNAL);
+ announce_object (platform, (struct nl_object *) rtnllink, is_changed ? NM_PLATFORM_SIGNAL_CHANGED : NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_EXTERNAL);
}
static void
@@ -3499,7 +3436,7 @@ udev_device_removed (NMPlatform *platform,
auto_nl_object struct rtnl_link *device = rtnl_link_get (priv->link_cache, ifindex);
if (device)
- announce_object (platform, (struct nl_object *) device, REMOVED, NM_PLATFORM_REASON_EXTERNAL);
+ announce_object (platform, (struct nl_object *) device, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_EXTERNAL);
}
}
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index d2e45753fa..64802212ec 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -41,21 +41,11 @@ G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
/* NMPlatform signals */
enum {
- LINK_ADDED,
- LINK_CHANGED,
- LINK_REMOVED,
- IP4_ADDRESS_ADDED,
- IP4_ADDRESS_CHANGED,
- IP4_ADDRESS_REMOVED,
- IP6_ADDRESS_ADDED,
- IP6_ADDRESS_CHANGED,
- IP6_ADDRESS_REMOVED,
- IP4_ROUTE_ADDED,
- IP4_ROUTE_CHANGED,
- IP4_ROUTE_REMOVED,
- IP6_ROUTE_ADDED,
- IP6_ROUTE_CHANGED,
- IP6_ROUTE_REMOVED,
+ SIGNAL_LINK_CHANGED,
+ SIGNAL_IP4_ADDRESS_CHANGED,
+ SIGNAL_IP6_ADDRESS_CHANGED,
+ SIGNAL_IP4_ROUTE_CHANGED,
+ SIGNAL_IP6_ROUTE_CHANGED,
LAST_SIGNAL
};
@@ -337,8 +327,9 @@ nm_platform_query_devices (void)
links_array = nm_platform_link_get_all ();
links = (NMPlatformLink *) links_array->data;
for (i = 0; i < links_array->len; i++) {
- g_signal_emit (platform, signals[LINK_ADDED], 0,
- links[i].ifindex, &links[i], NM_PLATFORM_REASON_INTERNAL);
+ g_signal_emit (platform, signals[SIGNAL_LINK_CHANGED], 0,
+ links[i].ifindex, &links[i], NM_PLATFORM_SIGNAL_ADDED,
+ NM_PLATFORM_REASON_INTERNAL);
}
g_array_unref (links_array);
}
@@ -2280,6 +2271,13 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
return c < 0 ? -1 : 1; \
} G_STMT_END
+#define _CMP_FIELD_STR0(a, b, field) \
+ G_STMT_START { \
+ int c = g_strcmp0 ((a)->field, (b)->field); \
+ if (c != 0) \
+ return c < 0 ? -1 : 1; \
+ } G_STMT_END
+
#define _CMP_FIELD_MEMCMP(a, b, field) \
G_STMT_START { \
int c = memcmp (&((a)->field), &((b)->field), \
@@ -2289,6 +2287,24 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
} G_STMT_END
int
+nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
+{
+ _CMP_POINTER (a, b);
+ _CMP_FIELD (a, b, type);
+ _CMP_FIELD_STR (a, b, name);
+ _CMP_FIELD (a, b, master);
+ _CMP_FIELD (a, b, parent);
+ _CMP_FIELD (a, b, up);
+ _CMP_FIELD (a, b, connected);
+ _CMP_FIELD (a, b, arp);
+ _CMP_FIELD (a, b, mtu);
+ _CMP_FIELD_STR0 (a, b, type_name);
+ _CMP_FIELD_STR0 (a, b, udi);
+ _CMP_FIELD_STR0 (a, b, driver);
+ return 0;
+}
+
+int
nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b)
{
_CMP_POINTER (a, b);
@@ -2348,133 +2364,106 @@ nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route
return 0;
}
-#undef _CMP_POINTER
#undef _CMP_FIELD
#undef _CMP_FIELD_MEMCMP
-
-static void
-log_link (NMPlatformLink *device, const char *change_type)
-{
- debug ("signal: link %s: %s", change_type, nm_platform_link_to_string (device));
-}
-
-static void
-log_link_added (NMPlatform *p, int ifindex, NMPlatformLink *device, gpointer user_data)
-{
- log_link (device, "added ");
-}
-
-static void
-log_link_changed (NMPlatform *p, int ifindex, NMPlatformLink *device, gpointer user_data)
-{
- log_link (device, "changed");
-}
-
-static void
-log_link_removed (NMPlatform *p, int ifindex, NMPlatformLink *device, gpointer user_data)
-{
- log_link (device, "removed");
-}
-
-static void
-log_ip4_address (NMPlatformIP4Address *address, const char *change_type)
+/**
+ * nm_platform_ip_address_cmp_expiry:
+ * @a: a NMPlatformIPAddress to compare
+ * @b: the other NMPlatformIPAddress to compare
+ *
+ * Compares two addresses and returns which one has a longer remaining lifetime.
+ * If both addresses have the same lifetime, look at the remaining preferred time.
+ *
+ * For comparison, only the timestamp, lifetime and preferred fields are considered.
+ * If they compare equal (== 0), their other fields were not considered.
+ *
+ * Returns: -1, 0, or 1 according to the comparison
+ **/
+int
+nm_platform_ip_address_cmp_expiry (const NMPlatformIPAddress *a, const NMPlatformIPAddress *b)
{
- const char *name = nm_platform_link_get_name (address->ifindex);
-
- debug ("(%s) signal: address 4 %s: %s", name, change_type, nm_platform_ip4_address_to_string (address));
-}
+ gint64 ta, tb;
-static void
-log_ip4_address_added (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, gpointer user_data)
-{
- log_ip4_address (address, "added ");
-}
+ _CMP_POINTER (a, b);
-static void
-log_ip4_address_changed (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, gpointer user_data)
-{
- log_ip4_address (address, "changed");
-}
+ if (a->lifetime == NM_PLATFORM_LIFETIME_PERMANENT || a->lifetime == 0)
+ ta = G_MAXINT64;
+ else
+ ta = ((gint64) a->timestamp) + a->lifetime;
-static void
-log_ip4_address_removed (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, gpointer user_data)
-{
- log_ip4_address (address, "removed");
-}
+ if (b->lifetime == NM_PLATFORM_LIFETIME_PERMANENT || b->lifetime == 0)
+ tb = G_MAXINT64;
+ else
+ tb = ((gint64) b->timestamp) + b->lifetime;
-static void
-log_ip6_address (NMPlatformIP6Address *address, const char *change_type)
-{
- const char *name = nm_platform_link_get_name (address->ifindex);
+ if (ta == tb) {
+ /* if the lifetime is equal, compare the preferred time. */
- debug ("(%s) signal: address 6 %s: %s", name, change_type, nm_platform_ip6_address_to_string (address));
-}
+ if (a->preferred == NM_PLATFORM_LIFETIME_PERMANENT || a->lifetime == 0 /* liftime==0 means permanent! */)
+ ta = G_MAXINT64;
+ else
+ ta = ((gint64) a->timestamp) + a->preferred;
-static void
-log_ip6_address_added (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, gpointer user_data)
-{
- log_ip6_address (address, "added ");
-}
+ if (b->preferred == NM_PLATFORM_LIFETIME_PERMANENT|| b->lifetime == 0)
+ tb = G_MAXINT64;
+ else
+ tb = ((gint64) b->timestamp) + b->preferred;
-static void
-log_ip6_address_changed (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, gpointer user_data)
-{
- log_ip6_address (address, "changed");
-}
+ if (ta == tb)
+ return 0;
+ }
-static void
-log_ip6_address_removed (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, gpointer user_data)
-{
- log_ip6_address (address, "removed");
+ return ta < tb ? -1 : 1;
}
-static void
-log_ip4_route (NMPlatformIP4Route *route, const char *change_type)
-{
- debug ("signal: route 4 %s: %s", change_type, nm_platform_ip4_route_to_string (route));
-}
+#undef _CMP_POINTER
-static void
-log_ip4_route_added (NMPlatform *p, int ifindex, NMPlatformIP4Route *route, gpointer user_data)
-{
- log_ip4_route (route, "added ");
+static const char *
+_change_type_to_string (NMPlatformSignalChangeType change_type)
+{
+ switch (change_type) {
+ case NM_PLATFORM_SIGNAL_ADDED:
+ return "added";
+ case NM_PLATFORM_SIGNAL_CHANGED:
+ return "changed";
+ case NM_PLATFORM_SIGNAL_REMOVED:
+ return "removed";
+ default:
+ g_return_val_if_reached ("UNKNOWN");
+ return "UNKNOWN";
+ }
}
static void
-log_ip4_route_changed (NMPlatform *p, int ifindex, NMPlatformIP4Route *route, gpointer user_data)
+log_link (NMPlatform *p, int ifindex, NMPlatformLink *device, NMPlatformSignalChangeType change_type, gpointer user_data)
{
- log_ip4_route (route, "changed");
-}
-static void
-log_ip4_route_removed (NMPlatform *p, int ifindex, NMPlatformIP4Route *route, gpointer user_data)
-{
- log_ip4_route (route, "removed");
+ debug ("signal: link %7s: %s", _change_type_to_string (change_type), nm_platform_link_to_string (device));
}
static void
-log_ip6_route (NMPlatformIP6Route *route, const char *change_type)
+log_ip4_address (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, NMPlatformSignalChangeType change_type, gpointer user_data)
{
- debug ("signal: route 6 %s: %s", change_type, nm_platform_ip6_route_to_string (route));
+ debug ("signal: address 4 %7s: %s", _change_type_to_string (change_type), nm_platform_ip4_address_to_string (address));
}
static void
-log_ip6_route_added (NMPlatform *p, int ifindex, NMPlatformIP6Route *route, gpointer user_data)
+log_ip6_address (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, NMPlatformSignalChangeType change_type, gpointer user_data)
{
- log_ip6_route (route, "added ");
+ debug ("signal: address 6 %7s: %s", _change_type_to_string (change_type), nm_platform_ip6_address_to_string (address));
}
static void
-log_ip6_route_changed (NMPlatform *p, int ifindex, NMPlatformIP6Route *route, gpointer user_data)
+log_ip4_route (NMPlatform *p, int ifindex, NMPlatformIP4Route *route, NMPlatformSignalChangeType change_type, gpointer user_data)
{
- log_ip6_route (route, "changed");
+ debug ("signal: route 4 %7s: %s", _change_type_to_string (change_type), nm_platform_ip4_route_to_string (route));
}
static void
-log_ip6_route_removed (NMPlatform *p, int ifindex, NMPlatformIP6Route *route, gpointer user_data)
+log_ip6_route (NMPlatform *p, int ifindex, NMPlatformIP6Route *route, NMPlatformSignalChangeType change_type, gpointer user_data)
{
- log_ip6_route (route, "removed");
+ debug ("signal: route 6 %7s: %s", _change_type_to_string (change_type), nm_platform_ip6_route_to_string (route));
}
/******************************************************************/
@@ -2490,7 +2479,7 @@ nm_platform_init (NMPlatform *object)
G_SIGNAL_RUN_FIRST, \
G_CALLBACK (method), \
NULL, NULL, NULL, \
- G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_POINTER, NM_TYPE_PLATFORM_REASON);
+ G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_POINTER, NM_TYPE_PLATFORM_SIGNAL_CHANGE_TYPE, NM_TYPE_PLATFORM_REASON);
static void
nm_platform_class_init (NMPlatformClass *platform_class)
@@ -2498,19 +2487,9 @@ nm_platform_class_init (NMPlatformClass *platform_class)
GObjectClass *object_class = G_OBJECT_CLASS (platform_class);
/* Signals */
- SIGNAL (LINK_ADDED, log_link_added)
- SIGNAL (LINK_CHANGED, log_link_changed)
- SIGNAL (LINK_REMOVED, log_link_removed)
- SIGNAL (IP4_ADDRESS_ADDED, log_ip4_address_added)
- SIGNAL (IP4_ADDRESS_CHANGED, log_ip4_address_changed)
- SIGNAL (IP4_ADDRESS_REMOVED, log_ip4_address_removed)
- SIGNAL (IP6_ADDRESS_ADDED, log_ip6_address_added)
- SIGNAL (IP6_ADDRESS_CHANGED, log_ip6_address_changed)
- SIGNAL (IP6_ADDRESS_REMOVED, log_ip6_address_removed)
- SIGNAL (IP4_ROUTE_ADDED, log_ip4_route_added)
- SIGNAL (IP4_ROUTE_CHANGED, log_ip4_route_changed)
- SIGNAL (IP4_ROUTE_REMOVED, log_ip4_route_removed)
- SIGNAL (IP6_ROUTE_ADDED, log_ip6_route_added)
- SIGNAL (IP6_ROUTE_CHANGED, log_ip6_route_changed)
- SIGNAL (IP6_ROUTE_REMOVED, log_ip6_route_removed)
+ SIGNAL (SIGNAL_LINK_CHANGED, log_link)
+ SIGNAL (SIGNAL_IP4_ADDRESS_CHANGED, log_ip4_address)
+ SIGNAL (SIGNAL_IP6_ADDRESS_CHANGED, log_ip6_address)
+ SIGNAL (SIGNAL_IP4_ROUTE_CHANGED, log_ip4_route)
+ SIGNAL (SIGNAL_IP6_ROUTE_CHANGED, log_ip6_route)
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index e817f337c5..28800f895e 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -115,8 +115,12 @@ typedef enum {
NM_LINK_TYPE_TEAM,
} NMLinkType;
+#define __NMPlatformObject_COMMON \
+ int ifindex; \
+ ;
+
typedef struct {
- int ifindex;
+ __NMPlatformObject_COMMON;
char name[IFNAMSIZ];
NMLinkType type;
const char *type_name;
@@ -130,6 +134,12 @@ typedef struct {
guint mtu;
} NMPlatformLink;
+typedef enum {
+ NM_PLATFORM_SIGNAL_ADDED,
+ NM_PLATFORM_SIGNAL_CHANGED,
+ NM_PLATFORM_SIGNAL_REMOVED,
+} NMPlatformSignalChangeType;
+
#define NM_PLATFORM_LIFETIME_PERMANENT G_MAXUINT32
typedef enum {
@@ -146,59 +156,98 @@ typedef enum {
NM_PLATFORM_SOURCE_USER,
} NMPlatformSource;
+
+typedef struct {
+ __NMPlatformObject_COMMON;
+} NMPlatformObject;
+
+
+#define __NMPlatformIPAddress_COMMON \
+ __NMPlatformObject_COMMON; \
+ NMPlatformSource source; \
+ guint32 timestamp; /* nm_utils_get_monotonic_timestamp_s() */ \
+ guint32 lifetime; /* seconds */ \
+ guint32 preferred; /* seconds */ \
+ int plen; \
+ ;
+
+/**
+ * NMPlatformIPAddress:
+ *
+ * Common parts of NMPlatformIP4Address and NMPlatformIP6Address.
+ **/
+typedef struct {
+ __NMPlatformIPAddress_COMMON;
+ union {
+ guint8 address_ptr[1];
+ guint32 __dummy_for_32bit_alignment;
+ };
+} NMPlatformIPAddress;
+
/**
* NMPlatformIP4Address:
* @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s()
**/
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPAddress_COMMON;
in_addr_t address;
in_addr_t peer_address; /* PTP peer address */
- int plen;
- guint32 timestamp;
- guint32 lifetime; /* seconds */
- guint32 preferred; /* seconds */
char label[IFNAMSIZ];
} NMPlatformIP4Address;
+G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_OFFSET (NMPlatformIP4Address, address));
/**
* NMPlatformIP6Address:
* @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s()
**/
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPAddress_COMMON;
struct in6_addr address;
struct in6_addr peer_address;
- int plen;
- guint32 timestamp; /* seconds */
- guint32 lifetime; /* seconds */
- guint32 preferred;
guint flags; /* ifa_flags from <linux/if_addr.h>, field type "unsigned int" is as used in rtnl_addr_get_flags. */
} NMPlatformIP6Address;
+G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_OFFSET (NMPlatformIP6Address, address));
+
+#undef __NMPlatformIPAddress_COMMON
+
#define NM_PLATFORM_ROUTE_METRIC_DEFAULT 1024
+#define __NMPlatformIPRoute_COMMON \
+ __NMPlatformObject_COMMON; \
+ NMPlatformSource source; \
+ int plen; \
+ guint metric; \
+ guint mss; \
+ ;
+
+typedef struct {
+ __NMPlatformIPRoute_COMMON;
+ union {
+ guint8 network_ptr[1];
+ guint32 __dummy_for_32bit_alignment;
+ };
+} NMPlatformIPRoute;
+
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPRoute_COMMON;
in_addr_t network;
- int plen;
in_addr_t gateway;
- guint metric;
- guint mss;
} NMPlatformIP4Route;
+G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OFFSET (NMPlatformIP4Route, network));
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPRoute_COMMON;
struct in6_addr network;
- int plen;
struct in6_addr gateway;
- guint metric;
- guint mss;
} NMPlatformIP6Route;
+G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OFFSET (NMPlatformIP6Route, network));
+
+#undef __NMPlatformIPRoute_COMMON
+
+
+#undef __NMPlatformObject_COMMON
+
typedef struct {
int peer;
@@ -401,21 +450,11 @@ typedef struct {
* but you are free to copy the provided information and use it for later
* reference.
*/
-#define NM_PLATFORM_LINK_ADDED "link-added"
-#define NM_PLATFORM_LINK_CHANGED "link-changed"
-#define NM_PLATFORM_LINK_REMOVED "link-removed"
-#define NM_PLATFORM_IP4_ADDRESS_ADDED "ip4-address-added"
-#define NM_PLATFORM_IP4_ADDRESS_CHANGED "ip4-address-changed"
-#define NM_PLATFORM_IP4_ADDRESS_REMOVED "ip4-address-removed"
-#define NM_PLATFORM_IP6_ADDRESS_ADDED "ip6-address-added"
-#define NM_PLATFORM_IP6_ADDRESS_CHANGED "ip6-address-changed"
-#define NM_PLATFORM_IP6_ADDRESS_REMOVED "ip6-address-removed"
-#define NM_PLATFORM_IP4_ROUTE_ADDED "ip4-route-added"
-#define NM_PLATFORM_IP4_ROUTE_CHANGED "ip4-route-changed"
-#define NM_PLATFORM_IP4_ROUTE_REMOVED "ip4-route-removed"
-#define NM_PLATFORM_IP6_ROUTE_ADDED "ip6-route-added"
-#define NM_PLATFORM_IP6_ROUTE_CHANGED "ip6-route-changed"
-#define NM_PLATFORM_IP6_ROUTE_REMOVED "ip6-route-removed"
+#define NM_PLATFORM_SIGNAL_LINK_CHANGED "link-changed"
+#define NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED "ip4-address-changed"
+#define NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED "ip6-address-changed"
+#define NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED "ip4-route-changed"
+#define NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED "ip6-route-changed"
/******************************************************************/
@@ -547,6 +586,7 @@ const char *nm_platform_ip6_address_to_string (const NMPlatformIP6Address *addre
const char *nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route);
const char *nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route);
+int nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b);
int nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b);
int nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6Address *b);
int nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b);
@@ -557,6 +597,8 @@ gboolean nm_platform_check_support_kernel_extended_ifa_flags (void);
void nm_platform_addr_flags2str (int flags, char *buf, size_t size);
+int nm_platform_ip_address_cmp_expiry (const NMPlatformIPAddress *a, const NMPlatformIPAddress *b);
+
#define auto_g_free __attribute__((cleanup(put_g_free)))
static void __attribute__((unused))
put_g_free (void *ptr)
diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c
index a81b108171..ed50157ab5 100644
--- a/src/platform/tests/test-address.c
+++ b/src/platform/tests/test-address.c
@@ -7,13 +7,17 @@
#define IP6_PLEN 64
static void
-ip4_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Address *received, NMPlatformReason reason, SignalData *data)
+ip4_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Address *received, NMPlatformSignalChangeType change_type, NMPlatformReason reason, SignalData *data)
{
g_assert (received);
g_assert_cmpint (received->ifindex, ==, ifindex);
+ g_assert (data && data->name);
+ g_assert_cmpstr (data->name, ==, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED);
if (data->ifindex && data->ifindex != received->ifindex)
return;
+ if (data->change_type != change_type)
+ return;
if (data->loop)
g_main_loop_quit (data->loop);
@@ -25,13 +29,17 @@ ip4_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Address *r
}
static void
-ip6_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Address *received, NMPlatformReason reason, SignalData *data)
+ip6_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Address *received, NMPlatformSignalChangeType change_type, NMPlatformReason reason, SignalData *data)
{
g_assert (received);
g_assert_cmpint (received->ifindex, ==, ifindex);
+ g_assert (data && data->name);
+ g_assert_cmpstr (data->name, ==, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED);
if (data->ifindex && data->ifindex != received->ifindex)
return;
+ if (data->change_type != change_type)
+ return;
if (data->loop)
g_main_loop_quit (data->loop);
@@ -46,9 +54,9 @@ static void
test_ip4_address (void)
{
int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
- SignalData *address_added = add_signal_ifindex (NM_PLATFORM_IP4_ADDRESS_ADDED, ip4_address_callback, ifindex);
- SignalData *address_changed = add_signal_ifindex (NM_PLATFORM_IP4_ADDRESS_CHANGED, ip4_address_callback, ifindex);
- SignalData *address_removed = add_signal_ifindex (NM_PLATFORM_IP4_ADDRESS_REMOVED, ip4_address_callback, ifindex);
+ 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);
GArray *addresses;
NMPlatformIP4Address *address;
in_addr_t addr;
@@ -101,9 +109,9 @@ static void
test_ip6_address (void)
{
int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
- SignalData *address_added = add_signal_ifindex (NM_PLATFORM_IP6_ADDRESS_ADDED, ip6_address_callback, ifindex);
- SignalData *address_changed = add_signal_ifindex (NM_PLATFORM_IP6_ADDRESS_CHANGED, ip6_address_callback, ifindex);
- SignalData *address_removed = add_signal_ifindex (NM_PLATFORM_IP6_ADDRESS_REMOVED, ip6_address_callback, ifindex);
+ 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);
GArray *addresses;
NMPlatformIP6Address *address;
struct in6_addr addr;
@@ -156,8 +164,8 @@ test_ip6_address (void)
static void
test_ip4_address_external (void)
{
- SignalData *address_added = add_signal (NM_PLATFORM_IP4_ADDRESS_ADDED, ip4_address_callback);
- SignalData *address_removed = add_signal (NM_PLATFORM_IP4_ADDRESS_REMOVED, ip4_address_callback);
+ 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);
in_addr_t addr;
guint32 lifetime = 2000;
@@ -200,8 +208,8 @@ test_ip4_address_external (void)
static void
test_ip6_address_external (void)
{
- SignalData *address_added = add_signal (NM_PLATFORM_IP6_ADDRESS_ADDED, ip6_address_callback);
- SignalData *address_removed = add_signal (NM_PLATFORM_IP6_ADDRESS_REMOVED, ip6_address_callback);
+ 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);
struct in6_addr addr;
guint32 lifetime = 2000;
@@ -239,7 +247,7 @@ test_ip6_address_external (void)
void
setup_tests (void)
{
- SignalData *link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, DEVICE_NAME);
+ 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));
diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c
index d8e8a7d513..c35dafb21d 100644
--- a/src/platform/tests/test-cleanup.c
+++ b/src/platform/tests/test-cleanup.c
@@ -5,7 +5,7 @@
static void
test_cleanup_internal ()
{
- SignalData *link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, DEVICE_NAME);
+ SignalData *link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME);
int ifindex;
GArray *addresses4;
GArray *addresses6;
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index 8d54e7ae8c..fc5bfaf23a 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -2,11 +2,12 @@
#include "nm-glib-compat.h"
SignalData *
-add_signal_full (const char *name, GCallback callback, int ifindex, const char *ifname)
+add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCallback callback, int ifindex, const char *ifname)
{
SignalData *data = g_new0 (SignalData, 1);
data->name = name;
+ data->change_type = change_type;
data->received = FALSE;
data->handler_id = g_signal_connect (nm_platform_get (), name, callback, data);
data->ifindex = ifindex;
@@ -17,12 +18,28 @@ add_signal_full (const char *name, GCallback callback, int ifindex, const char *
return data;
}
+static const char *
+_change_type_to_string (NMPlatformSignalChangeType change_type)
+{
+ switch (change_type) {
+ case NM_PLATFORM_SIGNAL_ADDED:
+ return "added";
+ case NM_PLATFORM_SIGNAL_CHANGED:
+ return "changed";
+ case NM_PLATFORM_SIGNAL_REMOVED:
+ return "removed";
+ default:
+ g_return_val_if_reached ("UNKNOWN");
+ return "UNKNOWN";
+ }
+}
+
void
accept_signal (SignalData *data)
{
- debug ("Accepting signal '%s' ifindex %d ifname %s.", data->name, data->ifindex, data->ifname);
+ debug ("Accepting signal '%s-%s' ifindex %d ifname %s.", data->name, _change_type_to_string (data->change_type), data->ifindex, data->ifname);
if (!data->received)
- g_error ("Attemted to accept a non-received signal '%s'.", data->name);
+ g_error ("Attemted to accept a non-received signal '%s-%s'.", data->name, _change_type_to_string (data->change_type));
data->received = FALSE;
}
@@ -41,14 +58,14 @@ void
free_signal (SignalData *data)
{
if (data->received)
- g_error ("Attempted to free received but not accepted signal '%s'.", data->name);
+ g_error ("Attempted to free received but not accepted signal '%s-%s'.", data->name, _change_type_to_string (data->change_type));
g_signal_handler_disconnect (nm_platform_get (), data->handler_id);
g_free (data);
}
void
-link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPlatformReason reason, SignalData *data)
+link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPlatformSignalChangeType change_type, NMPlatformReason reason, SignalData *data)
{
GArray *links;
@@ -57,11 +74,15 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
g_assert (received);
g_assert_cmpint (received->ifindex, ==, ifindex);
+ g_assert (data && data->name);
+ g_assert_cmpstr (data->name, ==, NM_PLATFORM_SIGNAL_LINK_CHANGED);
if (data->ifindex && data->ifindex != received->ifindex)
return;
if (data->ifname && g_strcmp0 (data->ifname, nm_platform_link_get_name (ifindex)) != 0)
return;
+ if (change_type != data->change_type)
+ return;
if (data->loop) {
debug ("Quitting main loop.");
@@ -69,9 +90,9 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
}
if (data->received)
- g_error ("Received signal '%s' a second time.", data->name);
+ g_error ("Received signal '%s-%s' a second time.", data->name, _change_type_to_string (data->change_type));
- debug ("Received signal '%s' ifindex %d ifname '%s'.", data->name, ifindex, received->name);
+ debug ("Received signal '%s-%s' ifindex %d ifname '%s'.", data->name, _change_type_to_string (data->change_type), ifindex, received->name);
data->received = TRUE;
/* Check the data */
@@ -80,17 +101,17 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
for (i = 0; i < links->len; i++) {
cached = &g_array_index (links, NMPlatformLink, i);
if (cached->ifindex == received->ifindex) {
+ g_assert_cmpint (nm_platform_link_cmp (cached, received), ==, 0);
g_assert (!memcmp (cached, received, sizeof (*cached)));
- if (!g_strcmp0 (data->name, NM_PLATFORM_LINK_REMOVED)) {
+ if (data->change_type == NM_PLATFORM_SIGNAL_REMOVED)
g_error ("Deleted link still found in the local cache.");
- }
g_array_unref (links);
return;
}
}
g_array_unref (links);
- if (g_strcmp0 (data->name, NM_PLATFORM_LINK_REMOVED))
+ if (data->change_type != NM_PLATFORM_SIGNAL_REMOVED)
g_error ("Added/changed link not found in the local cache.");
}
diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h
index 48342dda0c..8f6b391266 100644
--- a/src/platform/tests/test-common.h
+++ b/src/platform/tests/test-common.h
@@ -19,21 +19,22 @@
typedef struct {
int handler_id;
const char *name;
+ NMPlatformSignalChangeType change_type;
gboolean received;
GMainLoop *loop;
int ifindex;
const char *ifname;
} SignalData;
-SignalData *add_signal_full (const char *name, GCallback callback, int ifindex, const char *ifname);
-#define add_signal(name, callback) add_signal_full (name, (GCallback) callback, 0, NULL)
-#define add_signal_ifindex(name, callback, ifindex) add_signal_full (name, (GCallback) callback, ifindex, NULL)
-#define add_signal_ifname(name, callback, ifname) add_signal_full (name, (GCallback) callback, 0, ifname)
+SignalData *add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCallback callback, int ifindex, const char *ifname);
+#define add_signal(name, change_type, callback) add_signal_full (name, change_type, (GCallback) callback, 0, NULL)
+#define add_signal_ifindex(name, change_type, callback, ifindex) add_signal_full (name, change_type, (GCallback) callback, ifindex, NULL)
+#define add_signal_ifname(name, change_type, callback, ifname) add_signal_full (name, change_type, (GCallback) callback, 0, ifname)
void accept_signal (SignalData *data);
void wait_signal (SignalData *data);
void free_signal (SignalData *data);
-void link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPlatformReason reason, SignalData *data);
+void link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPlatformSignalChangeType change_type, NMPlatformReason reason, SignalData *data);
void run_command (const char *format, ...);
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c
index b4bd6917e1..2be4b5f19f 100644
--- a/src/platform/tests/test-link.c
+++ b/src/platform/tests/test-link.c
@@ -110,7 +110,7 @@ software_add (NMLinkType link_type, const char *name)
SignalData *parent_changed;
/* Don't call link_callback for the bridge interface */
- parent_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, PARENT_NAME);
+ 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))
wait_signal (parent_added);
free_signal (parent_added);
@@ -118,7 +118,7 @@ software_add (NMLinkType link_type, const char *name)
{
int parent_ifindex = nm_platform_link_get_ifindex (PARENT_NAME);
- parent_changed = add_signal_ifindex (NM_PLATFORM_LINK_CHANGED, link_callback, parent_ifindex);
+ 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));
accept_signal (parent_changed);
free_signal (parent_changed);
@@ -135,15 +135,15 @@ static void
test_slave (int master, int type, SignalData *master_changed)
{
int ifindex;
- SignalData *link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, SLAVE_NAME);
+ SignalData *link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, SLAVE_NAME);
SignalData *link_changed, *link_removed;
char *value;
g_assert (software_add (type, SLAVE_NAME));
ifindex = nm_platform_link_get_ifindex (SLAVE_NAME);
g_assert (ifindex > 0);
- link_changed = add_signal_ifindex (NM_PLATFORM_LINK_CHANGED, link_callback, ifindex);
- link_removed = add_signal_ifindex (NM_PLATFORM_LINK_REMOVED, link_callback, ifindex);
+ 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);
wait_signal (link_added);
/* Set the slave up to see whether master's IFF_LOWER_UP is set correctly.
@@ -243,7 +243,7 @@ test_software (NMLinkType link_type, const char *link_typename)
SignalData *link_added, *link_changed, *link_removed;
/* Add */
- link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, DEVICE_NAME);
+ link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME);
g_assert (software_add (link_type, DEVICE_NAME));
no_error ();
wait_signal (link_added);
@@ -252,8 +252,8 @@ test_software (NMLinkType link_type, const char *link_typename)
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);
- link_changed = add_signal_ifindex (NM_PLATFORM_LINK_CHANGED, link_callback, ifindex);
- link_removed = add_signal_ifindex (NM_PLATFORM_LINK_REMOVED, link_callback, ifindex);
+ 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));
@@ -326,7 +326,7 @@ test_software (NMLinkType link_type, const char *link_typename)
/* VLAN: Delete parent */
if (link_type == NM_LINK_TYPE_VLAN) {
- SignalData *link_removed_parent = add_signal_ifindex (NM_PLATFORM_LINK_REMOVED, link_callback, vlan_parent);
+ 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));
accept_signal (link_removed_parent);
@@ -366,7 +366,7 @@ test_vlan ()
static void
test_internal (void)
{
- SignalData *link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, DEVICE_NAME);
+ SignalData *link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME);
SignalData *link_changed, *link_removed;
const char mac[6] = { 0x00, 0xff, 0x11, 0xee, 0x22, 0xdd };
const char *address;
@@ -393,8 +393,8 @@ test_internal (void)
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);
- link_changed = add_signal_ifindex (NM_PLATFORM_LINK_CHANGED, link_callback, ifindex);
- link_removed = add_signal_ifindex (NM_PLATFORM_LINK_REMOVED, link_callback, ifindex);
+ 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 ();
@@ -453,7 +453,7 @@ test_internal (void)
static void
test_external (void)
{
- SignalData *link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, DEVICE_NAME);
+ SignalData *link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME);
SignalData *link_changed, *link_removed;
int ifindex;
@@ -465,8 +465,8 @@ test_external (void)
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);
- link_changed = add_signal_ifindex (NM_PLATFORM_LINK_CHANGED, link_callback, ifindex);
- link_removed = add_signal_ifindex (NM_PLATFORM_LINK_REMOVED, link_callback, ifindex);
+ 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/arp */
g_assert (!nm_platform_link_is_up (ifindex));
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index f333ffc3c1..a332474265 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -3,13 +3,17 @@
#define DEVICE_NAME "nm-test-device"
static void
-ip4_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Route *received, NMPlatformReason reason, SignalData *data)
+ip4_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Route *received, NMPlatformSignalChangeType change_type, NMPlatformReason reason, SignalData *data)
{
g_assert (received);
g_assert_cmpint (received->ifindex, ==, ifindex);
+ g_assert (data && data->name);
+ g_assert_cmpstr (data->name, ==, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED);
if (data->ifindex && data->ifindex != received->ifindex)
return;
+ if (data->change_type != change_type)
+ return;
if (data->loop)
g_main_loop_quit (data->loop);
@@ -21,13 +25,17 @@ ip4_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Route *recei
}
static void
-ip6_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Route *received, NMPlatformReason reason, SignalData *data)
+ip6_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Route *received, NMPlatformSignalChangeType change_type, NMPlatformReason reason, SignalData *data)
{
g_assert (received);
g_assert_cmpint (received->ifindex, ==, ifindex);
+ g_assert (data && data->name);
+ g_assert_cmpstr (data->name, ==, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED);
if (data->ifindex && data->ifindex != received->ifindex)
return;
+ if (data->change_type != change_type)
+ return;
if (data->loop)
g_main_loop_quit (data->loop);
@@ -42,11 +50,11 @@ static void
test_ip4_route ()
{
int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
- SignalData *route_added = add_signal (NM_PLATFORM_IP4_ROUTE_ADDED, ip4_route_callback);
- SignalData *route_changed = add_signal (NM_PLATFORM_IP4_ROUTE_CHANGED, ip4_route_callback);
- SignalData *route_removed = add_signal (NM_PLATFORM_IP4_ROUTE_REMOVED, ip4_route_callback);
+ 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);
GArray *routes;
- NMPlatformIP4Route rts[4];
+ NMPlatformIP4Route rts[3];
in_addr_t network;
int plen = 24;
in_addr_t gateway;
@@ -125,11 +133,11 @@ static void
test_ip6_route ()
{
int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
- SignalData *route_added = add_signal (NM_PLATFORM_IP6_ROUTE_ADDED, ip6_route_callback);
- SignalData *route_changed = add_signal (NM_PLATFORM_IP6_ROUTE_CHANGED, ip6_route_callback);
- SignalData *route_removed = add_signal (NM_PLATFORM_IP6_ROUTE_REMOVED, ip6_route_callback);
+ 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);
GArray *routes;
- NMPlatformIP6Route rts[4];
+ NMPlatformIP6Route rts[3];
struct in6_addr network;
int plen = 64;
struct in6_addr gateway;
@@ -207,7 +215,7 @@ test_ip6_route ()
void
setup_tests (void)
{
- SignalData *link_added = add_signal_ifname (NM_PLATFORM_LINK_ADDED, link_callback, DEVICE_NAME);
+ 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));