From: Yu Watanabe Date: Mon, 22 Feb 2021 18:10:16 +0000 (+0900) Subject: network: nexthop: read protocol in received netlink message X-Git-Tag: v248-rc3~129^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e9d129c1603a0768adcb4e6b8218c16a07ac82f;p=thirdparty%2Fsystemd.git network: nexthop: read protocol in received netlink message Preparation of later commits. --- diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c index 0b598823f65..29ed5b5ef98 100644 --- a/src/network/networkd-nexthop.c +++ b/src/network/networkd-nexthop.c @@ -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"); diff --git a/src/network/networkd-nexthop.h b/src/network/networkd-nexthop.h index 9ead5fc95ca..3c4e560c409 100644 --- a/src/network/networkd-nexthop.h +++ b/src/network/networkd-nexthop.h @@ -23,7 +23,7 @@ typedef struct NextHop { Manager *manager; Link *link; - unsigned char protocol; + uint8_t protocol; uint32_t id; bool blackhole;