]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: drop NextHop::oif and always use link ifindex
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Sep 2020 13:20:23 +0000 (22:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Oct 2020 17:39:51 +0000 (02:39 +0900)
src/network/networkd-nexthop.c
src/network/networkd-nexthop.h

index 03e4bd152a38359f5f4ca8bb13f1233b455a6dc9..48f00b218b545a06efc436154bb9cee1effdc9dc 100644 (file)
@@ -95,7 +95,6 @@ static void nexthop_hash_func(const NextHop *nexthop, struct siphash *state) {
         assert(nexthop);
 
         siphash24_compress(&nexthop->id, sizeof(nexthop->id), state);
-        siphash24_compress(&nexthop->oif, sizeof(nexthop->oif), state);
         siphash24_compress(&nexthop->family, sizeof(nexthop->family), state);
 
         switch (nexthop->family) {
@@ -117,10 +116,6 @@ static int nexthop_compare_func(const NextHop *a, const NextHop *b) {
         if (r != 0)
                 return r;
 
-        r = CMP(a->oif, b->oif);
-        if (r != 0)
-                return r;
-
         r = CMP(a->family, b->family);
         if (r != 0)
                 return r;
@@ -174,7 +169,6 @@ static int nexthop_add_internal(Link *link, Set **nexthops, NextHop *in, NextHop
                 return r;
 
         nexthop->id = in->id;
-        nexthop->oif = in->oif;
         nexthop->family = in->family;
         nexthop->gw = in->gw;
 
@@ -343,8 +337,9 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
         _cleanup_(nexthop_freep) NextHop *tmp = NULL;
         _cleanup_free_ char *gateway = NULL;
         NextHop *nexthop = NULL;
-        Link *link = NULL;
+        uint32_t ifindex;
         uint16_t type;
+        Link *link;
         int r;
 
         assert(rtnl);
@@ -368,6 +363,25 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
                 return 0;
         }
 
+        r = sd_netlink_message_read_u32(message, NHA_OIF, &ifindex);
+        if (r == -ENODATA) {
+                log_warning_errno(r, "rtnl: received nexthop message without NHA_OIF attribute, ignoring: %m");
+                return 0;
+        } else if (r < 0) {
+                log_warning_errno(r, "rtnl: could not get NHA_OIF attribute, ignoring: %m");
+                return 0;
+        } else if (ifindex <= 0) {
+                log_warning("rtnl: received nexthop message with invalid ifindex %"PRIu32", ignoring.", ifindex);
+                return 0;
+        }
+
+        r = link_get(m, ifindex, &link);
+        if (r < 0 || !link) {
+                if (!m->enumerating)
+                        log_warning("rtnl: received nexthop message for link (%"PRIu32") we do not know about, ignoring", ifindex);
+                return 0;
+        }
+
         r = nexthop_new(&tmp);
         if (r < 0)
                 return log_oom();
@@ -408,22 +422,6 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
                 return 0;
         }
 
-        r = sd_netlink_message_read_u32(message, NHA_OIF, &tmp->oif);
-        if (r < 0 && r != -ENODATA) {
-                log_warning_errno(r, "rtnl: could not get NHA_OIF attribute, ignoring: %m");
-                return 0;
-        } else if (tmp->oif <= 0) {
-                log_warning("rtnl: received nexthop message with invalid ifindex %d, ignoring.", tmp->oif);
-                return 0;
-        }
-
-        r = link_get(m, tmp->oif, &link);
-        if (r < 0 || !link) {
-                if (!m->enumerating)
-                        log_warning("rtnl: received nexthop message for link (%d) we do not know about, ignoring", tmp->oif);
-                return 0;
-        }
-
         (void) nexthop_get(link, tmp, &nexthop);
 
         if (DEBUG_LOGGING)
@@ -432,9 +430,9 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
         switch (type) {
         case RTM_NEWNEXTHOP:
                 if (nexthop)
-                        log_link_debug(link, "Received remembered nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
+                        log_link_debug(link, "Received remembered nexthop: %s, id: %d", strna(gateway), tmp->id);
                 else {
-                        log_link_debug(link, "Remembering foreign nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
+                        log_link_debug(link, "Remembering foreign nexthop: %s, id: %d", strna(gateway), tmp->id);
                         r = nexthop_add_foreign(link, tmp, &nexthop);
                         if (r < 0) {
                                 log_link_warning_errno(link, r, "Could not remember foreign nexthop, ignoring: %m");
@@ -444,11 +442,11 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
                 break;
         case RTM_DELNEXTHOP:
                 if (nexthop) {
-                        log_link_debug(link, "Forgetting nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
+                        log_link_debug(link, "Forgetting nexthop: %s, id: %d", strna(gateway), tmp->id);
                         nexthop_free(nexthop);
                 } else
-                        log_link_debug(link, "Kernel removed a nexthop we don't remember: %s, oif: %d, id: %d, ignoring.",
-                                       strna(gateway), tmp->oif, tmp->id);
+                        log_link_debug(link, "Kernel removed a nexthop we don't remember: %s, id: %d, ignoring.",
+                                       strna(gateway), tmp->id);
                 break;
 
         default:
index 7d1705904ff9ac575c7e6eb6449aecab09c184d2..8f4686d864d7239bcf126187bdda5039886dc36c 100644 (file)
@@ -24,10 +24,8 @@ typedef struct NextHop {
 
         unsigned char protocol;
 
-        int family;
-        uint32_t oif;
         uint32_t id;
-
+        int family;
         union in_addr_union gw;
 } NextHop;