]> git.decadent.org.uk Git - odhcp6c.git/blobdiff - src/ra.c
React to carrier down events as well
[odhcp6c.git] / src / ra.c
index aa03ff4d3ab8f6235b38aa8f069c785d3486a10e..c8ccb888f8856172ff58f280625b5005b61ab356 100644 (file)
--- a/src/ra.c
+++ b/src/ra.c
@@ -150,6 +150,7 @@ static void update_proc(const char *sect, const char *opt, uint32_t value)
 
 bool ra_link_up(void)
 {
+       static bool firstcall = true;
        struct {
                struct nlmsghdr hdr;
                struct ifinfomsg msg;
@@ -161,19 +162,22 @@ bool ra_link_up(void)
 
        do {
                read = recv(rtnl, &resp, sizeof(resp), MSG_DONTWAIT);
-               if (!NLMSG_OK(&resp.hdr, read) || resp.hdr.nlmsg_type != RTM_NEWLINK ||
+               if (read < 0 || !NLMSG_OK(&resp.hdr, (size_t)read) ||
+                               resp.hdr.nlmsg_type != RTM_NEWLINK ||
                                resp.msg.ifi_index != if_index)
                        continue;
 
                bool hascarrier = resp.msg.ifi_flags & IFF_LOWER_UP;
-               if (nocarrier && hascarrier)
+               if (!firstcall && nocarrier != !hascarrier)
                        ret = true;
 
                nocarrier = !hascarrier;
+               firstcall = false;
        } while (read > 0);
 
        if (ret) {
-               syslog(LOG_NOTICE, "carrier up event on %s", if_name);
+               syslog(LOG_NOTICE, "carrier => %i event on %s", (int)!nocarrier, if_name);
+
                rs_attempt = 0;
                ra_send_rs(SIGALRM);
        }