]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: also check multicast group to find suitable match callback
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 21 Sep 2021 07:22:29 +0000 (16:22 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 29 Sep 2021 06:36:42 +0000 (15:36 +0900)
src/libsystemd/sd-netlink/netlink-internal.h
src/libsystemd/sd-netlink/netlink-message.c
src/libsystemd/sd-netlink/netlink-socket.c
src/libsystemd/sd-netlink/sd-netlink.c

index 299b7d660bca5bd7f9e14d8fbfb8618e5c64e7bc..80d28258e2434fcbd1ddaba5fbc22818c49d061c 100644 (file)
@@ -123,8 +123,8 @@ struct sd_netlink_message {
         struct nlmsghdr *hdr;
         struct netlink_container containers[NETLINK_CONTAINER_DEPTH];
         unsigned n_containers; /* number of containers */
+        uint32_t multicast_group;
         bool sealed:1;
-        bool broadcast:1;
 
         sd_netlink_message *next; /* next in a chain of multi-part messages */
 };
index 735018e12b7aa20ef166ba5215074066aa96c3c3..27c7910566e7c9bc18bc84b3050a8162b31f8423 100644 (file)
@@ -166,7 +166,7 @@ int sd_netlink_message_set_flags(sd_netlink_message *m, uint16_t flags) {
 int sd_netlink_message_is_broadcast(sd_netlink_message *m) {
         assert_return(m, -EINVAL);
 
-        return m->broadcast;
+        return m->multicast_group != 0;
 }
 
 /* If successful the updated message will be correctly aligned, if
index 4edd7d8f85b94eeceb1f42bd6c875d775c8b7795..718073bb8fea2601371321265e1f10b59f679d51 100644 (file)
@@ -363,8 +363,7 @@ int socket_read_message(sd_netlink *nl) {
                 if (r < 0)
                         return r;
 
-                m->broadcast = group != 0;
-
+                m->multicast_group = group;
                 m->hdr = memdup(new_msg, new_msg->nlmsg_len);
                 if (!m->hdr)
                         return -ENOMEM;
index 4218a385f3009563e3f893de9830c65d7e0ad386..2bf26523bdeafbd3b9a003b86e08ae42efa3d9e9 100644 (file)
@@ -445,12 +445,22 @@ static int process_match(sd_netlink *nl, sd_netlink_message *m) {
 
         LIST_FOREACH(match_callbacks, c, nl->match_callbacks) {
                 sd_netlink_slot *slot;
+                bool found = false;
 
                 if (c->type != type)
                         continue;
                 if (c->cmd != 0 && c->cmd != cmd)
                         continue;
 
+                for (size_t i = 0; i < c->n_groups; i++)
+                        if (c->groups[i] == m->multicast_group) {
+                                found = true;
+                                break;
+                        }
+
+                if (!found)
+                        continue;
+
                 slot = container_of(c, sd_netlink_slot, match_callback);
 
                 r = c->callback(nl, m, slot->userdata);