platform: refactor signals by combining added/changed/removed
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>
This commit is contained in:
@@ -155,13 +155,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)
|
||||
{
|
||||
@@ -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[N_TYPES] = {
|
||||
[LINK] = NM_PLATFORM_SIGNAL_LINK_CHANGED,
|
||||
[IP4_ADDRESS] = NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED,
|
||||
[IP6_ADDRESS] = NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED,
|
||||
[IP4_ROUTE] = NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED,
|
||||
[IP6_ROUTE] = NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED,
|
||||
};
|
||||
|
||||
static struct nl_cache *
|
||||
@@ -1178,11 +1171,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:
|
||||
@@ -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,7 +1222,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:
|
||||
@@ -1242,15 +1235,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:
|
||||
@@ -1259,7 +1252,7 @@ announce_object (NMPlatform *platform, const struct nl_object *object, ObjectSta
|
||||
|
||||
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:
|
||||
@@ -1267,7 +1260,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:
|
||||
@@ -1275,7 +1268,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:
|
||||
@@ -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,7 +1315,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) {
|
||||
@@ -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:
|
||||
@@ -3407,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
|
||||
@@ -3443,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user