]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Linux: Warn if netlink(7) seq number doesn't match expectation.
authorRoy Marples <roy@marples.name>
Mon, 22 Jun 2020 21:09:31 +0000 (22:09 +0100)
committerRoy Marples <roy@marples.name>
Mon, 22 Jun 2020 21:09:31 +0000 (22:09 +0100)
While here, ensure it never goes out of scope.

src/if-linux.c

index 815a06b713fc0f08a7362863e27350098a39a67c..2ff720c6d5f5c70d83cc709412c53c6c9067059b 100644 (file)
@@ -523,8 +523,12 @@ recv_again:
                        terminated = true;
                        break;
                }
-               if (cb != NULL &&
-                  (nlm->nlmsg_seq == (uint32_t)ctx->seq || fd == ctx->link_fd))
+               if (cb == NULL)
+                       continue;
+               if (nlm->nlmsg_seq != (uint32_t)ctx->seq && fd != ctx->link_fd)
+                       logwarnx("%s: received sequence %u, expecting %d",
+                           __func__, nlm->nlmsg_seq, ctx->seq);
+               else
                        r = cb(ctx, cbarg, nlm);
        }
 
@@ -1013,6 +1017,8 @@ if_sendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct nlmsghdr *hdr,
        /* Request a reply */
        hdr->nlmsg_flags |= NLM_F_ACK;
        hdr->nlmsg_seq = (uint32_t)++ctx->seq;
+       if ((unsigned int)ctx->seq > UINT32_MAX)
+               ctx->seq = 0;
 
 #ifdef PRIVSEP
        if (ctx->options & DHCPCD_PRIVSEP && if_netlinkpriv(protocol, hdr))