]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/ndisc: constify several arguments and add several assertions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Nov 2024 16:21:28 +0000 (01:21 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 02:21:14 +0000 (11:21 +0900)
Follow-up for 0f8afaf94dd29126981219b3ea2b3bc315cc2dd0.

No functional change, just for safety.

src/network/networkd-ndisc.c

index 33e86fb04e409abd0466f349f5ec0ed1b482d7b1..e778300c70cc2e331e343a66034f46ce7ca4439c 100644 (file)
@@ -215,7 +215,7 @@ static int ndisc_remove_unused_nexthops(Link *link) {
 
 #define NDISC_NEXTHOP_APP_ID SD_ID128_MAKE(76,d2,0f,1f,76,1e,44,d1,97,3a,52,5c,05,68,b5,0d)
 
-static uint32_t ndisc_generate_nexthop_id(NextHop *nexthop, Link *link, sd_id128_t app_id, uint64_t trial) {
+static uint32_t ndisc_generate_nexthop_id(const NextHop *nexthop, Link *link, sd_id128_t app_id, uint64_t trial) {
         assert(nexthop);
         assert(link);
 
@@ -232,7 +232,7 @@ static uint32_t ndisc_generate_nexthop_id(NextHop *nexthop, Link *link, sd_id128
         return (uint32_t) ((result & 0xffffffff) ^ (result >> 32));
 }
 
-static bool ndisc_nexthop_equal(NextHop *a, NextHop *b) {
+static bool ndisc_nexthop_equal(const NextHop *a, const NextHop *b) {
         assert(a);
         assert(b);
 
@@ -250,9 +250,11 @@ static bool ndisc_nexthop_equal(NextHop *a, NextHop *b) {
         return true;
 }
 
-static bool ndisc_take_nexthop_id(NextHop *nexthop, NextHop *existing, Manager *manager) {
+static bool ndisc_take_nexthop_id(NextHop *nexthop, const NextHop *existing, Manager *manager) {
         assert(nexthop);
+        assert(nexthop->id == 0);
         assert(existing);
+        assert(existing->id > 0);
         assert(manager);
 
         if (!ndisc_nexthop_equal(nexthop, existing))
@@ -300,7 +302,7 @@ static int ndisc_nexthop_find_id(NextHop *nexthop, Link *link) {
         return false;
 }
 
-static int ndisc_nexthop_new(Route *route, Link *link, NextHop **ret) {
+static int ndisc_nexthop_new(const Route *route, Link *link, NextHop **ret) {
         _cleanup_(nexthop_unrefp) NextHop *nexthop = NULL;
         int r;