chiark / gitweb /
rtnl: match - only match on one type at a time
authorTom Gundersen <teg@jklm.no>
Fri, 6 Dec 2013 14:20:36 +0000 (15:20 +0100)
committerTom Gundersen <teg@jklm.no>
Mon, 16 Dec 2013 16:28:18 +0000 (17:28 +0100)
src/libsystemd-rtnl/rtnl-internal.h
src/libsystemd-rtnl/sd-rtnl.c
src/libsystemd-rtnl/test-rtnl.c

index 1e40427e58c43ce6ef5d222263f27fe21b5c4f34..2e0b7b8f373f836a6e97b155437eb610849f0cf4 100644 (file)
@@ -39,7 +39,7 @@ struct reply_callback {
 
 struct match_callback {
         sd_rtnl_message_handler_t callback;
-        uint16_t types;
+        uint16_t type;
         void *userdata;
 
         LIST_FIELDS(struct match_callback, match_callbacks);
index c933ac5fb4d9ecdb4ac1625fe79cf7dcdf05d527..08b82ab2a94f3f6dca6bb5e21934d90cbb48cfcc 100644 (file)
@@ -304,7 +304,7 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
                 return r;
 
         LIST_FOREACH(match_callbacks, c, rtnl->match_callbacks) {
-                if (type & c->types) {
+                if (type == c->type) {
                         r = c->callback(rtnl, m, c->userdata);
                         if (r != 0)
                                 return r;
@@ -825,22 +825,22 @@ int sd_rtnl_detach_event(sd_rtnl *rtnl) {
 }
 
 int sd_rtnl_add_match(sd_rtnl *rtnl,
-                      uint16_t types,
+                      uint16_t type,
                       sd_rtnl_message_handler_t callback,
                       void *userdata) {
         struct match_callback *c;
 
         assert_return(rtnl, -EINVAL);
         assert_return(callback, -EINVAL);
-        assert_return(types, -EINVAL);
         assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
+        assert_return(message_type_is_link(type) || message_type_is_addr(type) || message_type_is_route(type), -ENOTSUP);
 
         c = new0(struct match_callback, 1);
         if (!c)
                 return -ENOMEM;
 
         c->callback = callback;
-        c->types = types;
+        c->type = type;
         c->userdata = userdata;
 
         LIST_PREPEND(match_callbacks, rtnl->match_callbacks, c);
@@ -849,7 +849,7 @@ int sd_rtnl_add_match(sd_rtnl *rtnl,
 }
 
 int sd_rtnl_remove_match(sd_rtnl *rtnl,
-                         uint16_t types,
+                         uint16_t type,
                          sd_rtnl_message_handler_t callback,
                          void *userdata) {
         struct match_callback *c;
@@ -859,7 +859,7 @@ int sd_rtnl_remove_match(sd_rtnl *rtnl,
         assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
 
         LIST_FOREACH(match_callbacks, c, rtnl->match_callbacks)
-                if (c->callback == callback && c->types == types && c->userdata == userdata) {
+                if (c->callback == callback && c->type == type && c->userdata == userdata) {
                         LIST_REMOVE(match_callbacks, rtnl->match_callbacks, c);
                         free(c);
 
index a512a7b2f72c7cd343adf33d27fd746fb2fce7e8..6c34a8537f6b7b40437989723a03b5888a608566 100644 (file)
@@ -235,14 +235,12 @@ static void test_match(void) {
 
         assert(sd_rtnl_open(0, &rtnl) >= 0);
 
-        assert(sd_rtnl_add_match(rtnl, 0, &link_handler, NULL) == -EINVAL);
+        assert(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+        assert(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
 
-        assert(sd_rtnl_add_match(rtnl, RTMGRP_LINK, &link_handler, NULL) >= 0);
-        assert(sd_rtnl_add_match(rtnl, RTMGRP_LINK, &link_handler, NULL) >= 0);
-
-        assert(sd_rtnl_remove_match(rtnl, RTMGRP_LINK, &link_handler, NULL) == 1);
-        assert(sd_rtnl_remove_match(rtnl, RTMGRP_LINK, &link_handler, NULL) == 1);
-        assert(sd_rtnl_remove_match(rtnl, RTMGRP_LINK, &link_handler, NULL) == 0);
+        assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+        assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+        assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
 }
 
 int main(void) {