summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-03-07 19:04:38 +0100
committerThomas Haller <thaller@redhat.com>2014-03-07 21:38:03 +0100
commitc965fc1616783963fff8df66496a4943a83d994a (patch)
tree024034d62730b143d317268d9c5d360a40b76978
parentbdb44ba39a71a6e4fe47c3b3abcc762aae70b010 (diff)
downloadNetworkManager-th/platform_combine_signals.tar.gz
platform: refactor signals by combining added/changed/removedth/platform_combine_signals
Before platform raised 3 signals for each object type. Combine them into one and add a new parameter @change_type to distinguish between the change type. Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/devices/atm/nm-device-adsl.c14
-rw-r--r--src/devices/nm-device.c45
-rw-r--r--src/nm-manager.c65
-rw-r--r--src/platform/nm-fake-platform.c30
-rw-r--r--src/platform/nm-linux-platform.c63
-rw-r--r--src/platform/nm-platform.c172
-rw-r--r--src/platform/nm-platform.h26
-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.c40
-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.c26
13 files changed, 243 insertions, 315 deletions
diff --git a/src/devices/atm/nm-device-adsl.c b/src/devices/atm/nm-device-adsl.c
index 7fe626e7ca..981e74ab6c 100644
--- a/src/devices/atm/nm-device-adsl.c
+++ b/src/devices/atm/nm-device-adsl.c
@@ -320,10 +320,16 @@ error:
}
static void
-lost_link (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlatformReason reason, NMDeviceAdsl *device_adsl)
+lost_link (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);
+ NMDeviceAdslPrivate *priv;
+ NMDevice *device;
+
+ if (change_type != NM_PLATFORM_SIGNAL_REMOVED)
+ return;
+
+ priv = NM_DEVICE_ADSL_GET_PRIVATE (device_adsl);
+ device = NM_DEVICE (device_adsl);
/* This only gets called for PPPoE connections and "nas" interfaces */
@@ -370,7 +376,7 @@ 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,
+ priv->lost_link_id = g_signal_connect (nm_platform_get (), NM_PLATFORM_LINK,
G_CALLBACK (lost_link),
self);
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 2169a2778a..2d3d8d84c0 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -344,34 +344,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)
{
@@ -491,7 +475,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,
@@ -524,12 +507,12 @@ 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_IP4_ADDRESS, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_IP6_ADDRESS, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_IP4_ROUTE, G_CALLBACK (device_ip_changed), dev);
+ g_signal_connect (platform, NM_PLATFORM_IP6_ROUTE, G_CALLBACK (device_ip_changed), dev);
- g_signal_connect (platform, NM_PLATFORM_LINK_CHANGED,
+ g_signal_connect (platform, NM_PLATFORM_LINK,
G_CALLBACK (link_changed_cb), dev);
priv->initialized = TRUE;
@@ -1111,10 +1094,13 @@ 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);
+ NMDeviceClass *klass;
+ NMDevicePrivate *priv;
+
+ if (change_type != NM_PLATFORM_SIGNAL_CHANGED)
+ return;
/* Ignore other devices. */
if (ifindex != nm_device_get_ifindex (device))
@@ -1126,6 +1112,9 @@ link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMPlat
* and it results in also setting IFF_LOWER_UP.
*/
+ klass = NM_DEVICE_GET_CLASS (device);
+ priv = NM_DEVICE_GET_PRIVATE (device);
+
if (info->udi && g_strcmp0 (info->udi, priv->udi)) {
/* Update UDI to what udev gives us */
g_free (priv->udi);
@@ -6821,7 +6810,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-manager.c b/src/nm-manager.c
index 26e65d84fe..16f1bb281d 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;
@@ -1105,7 +1100,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);
@@ -1125,7 +1120,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);
@@ -2065,13 +2060,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;
@@ -2079,6 +2072,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;
@@ -2189,18 +2185,29 @@ platform_link_added_cb (NMPlatform *platform,
}
static void
-platform_link_removed_cb (NMPlatform *platform,
- int ifindex,
- NMPlatformLink *plink,
- NMPlatformReason reason,
- gpointer user_data)
+platform_link_cb (NMPlatform *platform,
+ int ifindex,
+ NMPlatformLink *plink,
+ NMPlatformSignalChangeType change_type,
+ NMPlatformReason reason,
+ gpointer user_data)
{
- NMManager *self = NM_MANAGER (user_data);
- NMDevice *device;
+ 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
@@ -4671,12 +4678,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_LINK,
+ 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 90d181bb8f..c17e662de5 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_LINK, 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_LINK, 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_LINK, 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);
@@ -764,12 +764,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_IP4_ADDRESS, 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_IP4_ADDRESS, ifindex, &address, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -804,12 +804,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_IP6_ADDRESS, 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_IP6_ADDRESS, ifindex, &address, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -828,7 +828,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_IP4_ADDRESS, ifindex, &deleted_address, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
}
@@ -851,7 +851,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_IP6_ADDRESS, ifindex, &deleted_address, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
}
@@ -979,12 +979,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_IP4_ROUTE, 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_IP4_ROUTE, ifindex, &route, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -1016,12 +1016,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_IP6_ROUTE, 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_IP6_ROUTE, ifindex, &route, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
return TRUE;
}
@@ -1073,7 +1073,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_IP4_ROUTE, ifindex, &deleted_route, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);
}
return TRUE;
@@ -1088,7 +1088,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_IP6_ROUTE, 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 ef519c8415..4afffc2af2 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -150,13 +150,6 @@ typedef enum {
N_TYPES,
} ObjectType;
-typedef enum {
- ADDED,
- CHANGED,
- REMOVED,
- N_STATUSES
-} ObjectStatus;
-
static ObjectType
object_type_from_nl_object (const struct nl_object *object)
{
@@ -969,12 +962,12 @@ init_ip6_route (NMPlatformIP6Route *route, struct rtnl_route *rtnlroute)
/* 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[N_TYPES] = {
+ [LINK] = NM_PLATFORM_LINK,
+ [IP4_ADDRESS] = NM_PLATFORM_IP4_ADDRESS,
+ [IP6_ADDRESS] = NM_PLATFORM_IP6_ADDRESS,
+ [IP4_ROUTE] = NM_PLATFORM_IP4_ROUTE,
+ [IP6_ROUTE] = NM_PLATFORM_IP6_ROUTE,
};
static struct nl_cache *
@@ -1043,11 +1036,11 @@ 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:
@@ -1063,9 +1056,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;
@@ -1079,12 +1072,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);
break;
@@ -1092,7 +1085,7 @@ 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:
@@ -1104,15 +1097,15 @@ 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:
@@ -1120,7 +1113,7 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
NMPlatformIP6Address address;
init_ip6_address (&address, (struct rtnl_addr *) object);
- 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:
@@ -1128,7 +1121,7 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
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:
@@ -1136,7 +1129,7 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
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:
@@ -1167,7 +1160,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)
@@ -1183,7 +1176,7 @@ 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) {
@@ -1379,7 +1372,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:
@@ -1400,7 +1393,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
@@ -1417,7 +1410,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:
@@ -3061,7 +3054,7 @@ udev_device_added (NMPlatform *platform,
return;
}
- announce_object (platform, (struct nl_object *) rtnllink, ADDED, NM_PLATFORM_REASON_EXTERNAL);
+ announce_object (platform, (struct nl_object *) rtnllink, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_EXTERNAL);
}
static void
@@ -3097,7 +3090,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 6f7ec5e545..576d5d7feb 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,
+ LINK,
+ IP4_ADDRESS,
+ IP6_ADDRESS,
+ IP4_ROUTE,
+ IP6_ROUTE,
LAST_SIGNAL
};
@@ -316,8 +306,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[LINK], 0,
+ links[i].ifindex, &links[i], NM_PLATFORM_SIGNAL_ADDED,
+ NM_PLATFORM_REASON_INTERNAL);
}
g_array_unref (links_array);
}
@@ -2108,128 +2099,51 @@ nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route
#undef _CMP_FIELD_MEMCMP
-static void
-log_link (NMPlatformLink *device, const char *change_type)
-{
- debug ("signal: link %s: %s (%d)", change_type, device->name, device->ifindex);
-}
-
-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)
-{
- 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));
-}
-
-static void
-log_ip4_address_added (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, gpointer user_data)
-{
- log_ip4_address (address, "added ");
-}
-
-static void
-log_ip4_address_changed (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, gpointer user_data)
-{
- log_ip4_address (address, "changed");
-}
-
-static void
-log_ip4_address_removed (NMPlatform *p, int ifindex, NMPlatformIP4Address *address, gpointer user_data)
-{
- log_ip4_address (address, "removed");
-}
-
-static void
-log_ip6_address (NMPlatformIP6Address *address, const char *change_type)
-{
- const char *name = nm_platform_link_get_name (address->ifindex);
-
- debug ("(%s) signal: address 6 %s: %s", name, change_type, nm_platform_ip6_address_to_string (address));
-}
-
-static void
-log_ip6_address_added (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, gpointer user_data)
-{
- log_ip6_address (address, "added ");
-}
-
-static void
-log_ip6_address_changed (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, gpointer user_data)
-{
- log_ip6_address (address, "changed");
-}
-
-static void
-log_ip6_address_removed (NMPlatform *p, int ifindex, NMPlatformIP6Address *address, gpointer user_data)
-{
- log_ip6_address (address, "removed");
-}
-
-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));
-}
-
-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 (%d)", _change_type_to_string (change_type), device->name, device->ifindex);
}
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));
}
/******************************************************************/
@@ -2245,7 +2159,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)
@@ -2253,19 +2167,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 (LINK, log_link)
+ SIGNAL (IP4_ADDRESS, log_ip4_address)
+ SIGNAL (IP6_ADDRESS, log_ip6_address)
+ SIGNAL (IP4_ROUTE, log_ip4_route)
+ SIGNAL (IP6_ROUTE, log_ip6_route)
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 1a7a44d319..2e4f308d64 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -127,6 +127,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 {
@@ -380,21 +386,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_LINK "link"
+#define NM_PLATFORM_IP4_ADDRESS "ip4-address"
+#define NM_PLATFORM_IP6_ADDRESS "ip6-address"
+#define NM_PLATFORM_IP4_ROUTE "ip4-route"
+#define NM_PLATFORM_IP6_ROUTE "ip6-route"
/******************************************************************/
diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c
index 20f1bd9ed6..806590db1f 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_IP4_ADDRESS);
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_IP6_ADDRESS);
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_IP4_ADDRESS, NM_PLATFORM_SIGNAL_ADDED, ip4_address_callback, ifindex);
+ SignalData *address_changed = add_signal_ifindex (NM_PLATFORM_IP4_ADDRESS, NM_PLATFORM_SIGNAL_CHANGED, ip4_address_callback, ifindex);
+ SignalData *address_removed = add_signal_ifindex (NM_PLATFORM_IP4_ADDRESS, 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_IP6_ADDRESS, NM_PLATFORM_SIGNAL_ADDED, ip6_address_callback, ifindex);
+ SignalData *address_changed = add_signal_ifindex (NM_PLATFORM_IP6_ADDRESS, NM_PLATFORM_SIGNAL_CHANGED, ip6_address_callback, ifindex);
+ SignalData *address_removed = add_signal_ifindex (NM_PLATFORM_IP6_ADDRESS, 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_IP4_ADDRESS, NM_PLATFORM_SIGNAL_ADDED, ip4_address_callback);
+ SignalData *address_removed = add_signal (NM_PLATFORM_IP4_ADDRESS, 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_IP6_ADDRESS, NM_PLATFORM_SIGNAL_ADDED, ip6_address_callback);
+ SignalData *address_removed = add_signal (NM_PLATFORM_IP6_ADDRESS, 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_LINK, 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 d94b359559..5c5c61db33 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_LINK, 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..bc72c92880 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_LINK);
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 */
@@ -81,16 +102,15 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
cached = &g_array_index (links, NMPlatformLink, i);
if (cached->ifindex == received->ifindex) {
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..85fde90b15 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_LINK, 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_LINK, 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_LINK, 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_LINK, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
+ link_removed = add_signal_ifindex (NM_PLATFORM_LINK, 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_LINK, 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_LINK, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
+ link_removed = add_signal_ifindex (NM_PLATFORM_LINK, 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_LINK, 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_LINK, 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_LINK, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
+ link_removed = add_signal_ifindex (NM_PLATFORM_LINK, 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_LINK, 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_LINK, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
+ link_removed = add_signal_ifindex (NM_PLATFORM_LINK, 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..1f1d57a83b 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_IP4_ROUTE);
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_IP6_ROUTE);
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,9 +50,9 @@ 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_IP4_ROUTE, NM_PLATFORM_SIGNAL_ADDED, ip4_route_callback);
+ SignalData *route_changed = add_signal (NM_PLATFORM_IP4_ROUTE, NM_PLATFORM_SIGNAL_CHANGED, ip4_route_callback);
+ SignalData *route_removed = add_signal (NM_PLATFORM_IP4_ROUTE, NM_PLATFORM_SIGNAL_REMOVED, ip4_route_callback);
GArray *routes;
NMPlatformIP4Route rts[4];
in_addr_t network;
@@ -125,9 +133,9 @@ 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_IP6_ROUTE, NM_PLATFORM_SIGNAL_ADDED, ip6_route_callback);
+ SignalData *route_changed = add_signal (NM_PLATFORM_IP6_ROUTE, NM_PLATFORM_SIGNAL_CHANGED, ip6_route_callback);
+ SignalData *route_removed = add_signal (NM_PLATFORM_IP6_ROUTE, NM_PLATFORM_SIGNAL_REMOVED, ip6_route_callback);
GArray *routes;
NMPlatformIP6Route rts[4];
struct in6_addr network;
@@ -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_LINK, 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));