]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: nexthop: read protocol in received netlink message
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Feb 2021 18:10:16 +0000 (03:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 23 Feb 2021 13:47:11 +0000 (22:47 +0900)
Preparation of later commits.

src/network/networkd-nexthop.c
src/network/networkd-nexthop.h

index 0b598823f6535d4888e04360a1e96016e800d917..29ed5b5ef98c41db64217d661147b231cc71a40a 100644 (file)
@@ -102,6 +102,7 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
 static void nexthop_hash_func(const NextHop *nexthop, struct siphash *state) {
         assert(nexthop);
 
+        siphash24_compress(&nexthop->protocol, sizeof(nexthop->protocol), state);
         siphash24_compress(&nexthop->id, sizeof(nexthop->id), state);
         siphash24_compress(&nexthop->blackhole, sizeof(nexthop->blackhole), state);
         siphash24_compress(&nexthop->family, sizeof(nexthop->family), state);
@@ -121,6 +122,10 @@ static void nexthop_hash_func(const NextHop *nexthop, struct siphash *state) {
 static int nexthop_compare_func(const NextHop *a, const NextHop *b) {
         int r;
 
+        r = CMP(a->protocol, b->protocol);
+        if (r != 0)
+                return r;
+
         r = CMP(a->id, b->id);
         if (r != 0)
                 return r;
@@ -152,6 +157,7 @@ static void nexthop_copy(NextHop *dest, const NextHop *src) {
 
         /* This only copies entries used in the above hash and compare functions. */
 
+        dest->protocol = src->protocol;
         dest->id = src->id;
         dest->blackhole = src->blackhole;
         dest->family = src->family;
@@ -530,6 +536,12 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
         } else if (!IN_SET(tmp->family, AF_INET, AF_INET6))
                 return log_link_debug(link, "rtnl: received nexthop message with invalid family %d, ignoring.", tmp->family);
 
+        r = sd_rtnl_message_nexthop_get_protocol(message, &tmp->protocol);
+        if (r < 0) {
+                log_link_warning_errno(link, r, "rtnl: could not get nexthop protocol, ignoring: %m");
+                return 0;
+        }
+
         r = netlink_message_read_in_addr_union(message, NHA_GATEWAY, tmp->family, &tmp->gw);
         if (r < 0 && r != -ENODATA) {
                 log_link_warning_errno(link, r, "rtnl: could not get NHA_GATEWAY attribute, ignoring: %m");
index 9ead5fc95ca41d6704b6e085b534008371130fea..3c4e560c4091a3084d1efdc19237e0e8b67123ac 100644 (file)
@@ -23,7 +23,7 @@ typedef struct NextHop {
         Manager *manager;
         Link *link;
 
-        unsigned char protocol;
+        uint8_t protocol;
 
         uint32_t id;
         bool blackhole;