]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Only spam syslog if something new or unexpected happens, don't spam
authorRoy Marples <roy@marples.name>
Thu, 23 May 2013 21:50:34 +0000 (21:50 +0000)
committerRoy Marples <roy@marples.name>
Thu, 23 May 2013 21:50:34 +0000 (21:50 +0000)
it if we just maintain the status quo.

arp.c
dhcp.c
dhcp6.c
ipv4.c
ipv6.c
ipv6.h
ipv6ns.c
ipv6rs.c

diff --git a/arp.c b/arp.c
index 13a2cc2fd2ec10c5cc6a9335cbf635265aa8d973..f9e49cc525399805e6165c32a7a024f2a76b4134 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -285,10 +285,10 @@ arp_probe(void *arg)
 
        if (state->probes == 0) {
                if (arping)
-                       syslog(LOG_INFO, "%s: searching for %s",
+                       syslog(LOG_DEBUG, "%s: searching for %s",
                            ifp->name, inet_ntoa(addr));
                else
-                       syslog(LOG_INFO, "%s: checking for %s",
+                       syslog(LOG_DEBUG, "%s: checking for %s",
                            ifp->name, inet_ntoa(addr));
        }
        if (++state->probes < PROBE_NUM) {
diff --git a/dhcp.c b/dhcp.c
index 373f439c9cc0c2fd3f85015f0d2f3068981bbf32..0eb5390b3d14d9e34ba5ea83bfcd454ce47b3fd1 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1683,7 +1683,7 @@ dhcp_renew(void *arg)
        struct dhcp_state *state = D_STATE(ifp);
        struct dhcp_lease *lease = &state->lease;
 
-       syslog(LOG_INFO, "%s: renewing lease of %s",
+       syslog(LOG_DEBUG, "%s: renewing lease of %s",
            ifp->name, inet_ntoa(lease->addr));
        syslog(LOG_DEBUG, "%s: rebind in %u seconds, expire in %u seconds",
            ifp->name, lease->rebindtime - lease->renewaltime,
@@ -1700,7 +1700,7 @@ dhcp_rebind(void *arg)
        struct dhcp_state *state = D_STATE(ifp);
        struct dhcp_lease *lease = &state->lease;
 
-       syslog(LOG_ERR, "%s: failed to renew, attempting to rebind",
+       syslog(LOG_WARNING, "%s: failed to renew, attempting to rebind",
            ifp->name);
        syslog(LOG_DEBUG, "%s: expire in %u seconds",
            ifp->name, lease->leasetime - lease->rebindtime);
@@ -1773,7 +1773,7 @@ dhcp_bind(void *arg)
                                lease->rebindtime = lease->leasetime * T2;
                        else if (lease->rebindtime >= lease->leasetime) {
                                lease->rebindtime = lease->leasetime * T2;
-                               syslog(LOG_ERR,
+                               syslog(LOG_WARNING,
                                    "%s: rebind time greater than lease "
                                    "time, forcing to %u seconds",
                                    iface->name, lease->rebindtime);
@@ -1782,12 +1782,13 @@ dhcp_bind(void *arg)
                                lease->renewaltime = lease->leasetime * T1;
                        else if (lease->renewaltime > lease->rebindtime) {
                                lease->renewaltime = lease->leasetime * T1;
-                               syslog(LOG_ERR,
+                               syslog(LOG_WARNING,
                                    "%s: renewal time greater than rebind "
                                    "time, forcing to %u seconds",
                                    iface->name, lease->renewaltime);
                        }
-                       syslog(LOG_INFO,
+                       syslog(lease->addr.s_addr == state->addr.s_addr ?
+                           LOG_DEBUG : LOG_INFO,
                            "%s: leased %s for %u seconds", iface->name,
                            inet_ntoa(lease->addr), lease->leasetime);
                }
@@ -2212,7 +2213,7 @@ dhcp_handle(struct interface *iface, struct dhcp_message **dhcpp,
 
        if (type) {
                if (type == DHCP_OFFER) {
-                       log_dhcp(LOG_INFO, "ignoring offer of",
+                       log_dhcp(LOG_WARNING, "ignoring offer of",
                            iface, dhcp, from);
                        return;
                }
@@ -2225,7 +2226,7 @@ dhcp_handle(struct interface *iface, struct dhcp_message **dhcpp,
                }
 
                if (!(ifo->options & DHCPCD_INFORM))
-                       log_dhcp(LOG_INFO, "acknowledged", iface, dhcp, from);
+                       log_dhcp(LOG_DEBUG, "acknowledged", iface, dhcp, from);
        }
 
        /* BOOTP could have already assigned this above, so check we still
@@ -2266,11 +2267,11 @@ dhcp_handle(struct interface *iface, struct dhcp_message **dhcpp,
 static ssize_t
 get_udp_data(const uint8_t **data, const uint8_t *udp)
 {
-    struct udp_dhcp_packet p;
+       struct udp_dhcp_packet p;
 
-    memcpy(&p, udp, sizeof(p));
-    *data = udp + offsetof(struct udp_dhcp_packet, dhcp);
-    return ntohs(p.ip.ip_len) - sizeof(p.ip) - sizeof(p.udp);
+       memcpy(&p, udp, sizeof(p));
+       *data = udp + offsetof(struct udp_dhcp_packet, dhcp);
+       return ntohs(p.ip.ip_len) - sizeof(p.ip) - sizeof(p.udp);
 }
 
 static int
diff --git a/dhcp6.c b/dhcp6.c
index 81aa6e9c0f4acbbc1a5ad5c36ca690d8ce045e23..7a017bca4b16de13eab2dd32f1f11525491f3b76 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -597,7 +597,6 @@ dhcp6_get_op(uint16_t type)
        return NULL;
 }
 
-
 static void
 dhcp6_freedrop_addrs(struct interface *ifp, int drop)
 {
@@ -816,6 +815,9 @@ dhcp6_startrebind(void *arg)
        ifp = arg;
        eloop_timeout_delete(dhcp6_sendrenew, ifp);
        state = D6_STATE(ifp);
+       if (state->state == DH6S_RENEW)
+               syslog(LOG_WARNING, "%s: failed to renew, rebinding",
+                   ifp->name);
        state->state = DH6S_REBIND;
        state->RTC = 0;
        state->MRC = 0;
@@ -843,6 +845,9 @@ dhcp6_startdiscover(void *arg)
 
        ifp = arg;
        state = D6_STATE(ifp);
+       if (state->state == DH6S_REBIND)
+               syslog(LOG_ERR, "%s: failed to renew, soliciting",
+                   ifp->name);
        state->state = DH6S_DISCOVER;
        state->start_uptime = uptime();
        state->RTC = 0;
@@ -1020,22 +1025,31 @@ static int dhcp6_getstatus(const struct dhcp6_option *o)
        return ntohs(s->status);
 }
 
-int
-dhcp6_addrexists(const struct ipv6_addr *a)
+static struct ipv6_addr *
+dhcp6_findaddr(const struct in6_addr *a, struct interface *ifp)
 {
-       const struct interface *ifp;
        const struct dhcp6_state *state;
-       const struct ipv6_addr *ap;
+       struct ipv6_addr *ap;
 
-       TAILQ_FOREACH(ifp, ifaces, next) {
-               state = D6_CSTATE(ifp);
-               if (state == NULL)
-                       continue;
+       state = D6_CSTATE(ifp);
+       if (state) {
                TAILQ_FOREACH(ap, &state->addrs, next) {
-                       if (memcmp(&ap->addr, &a->addr, sizeof(a->addr)) == 0)
-                               return 1;
+                       if (IN6_ARE_ADDR_EQUAL(&ap->addr, a))
+                               return ap;
                }
        }
+       return NULL;
+}
+
+int
+dhcp6_addrexists(const struct ipv6_addr *a)
+{
+       struct interface *ifp;
+
+       TAILQ_FOREACH(ifp, ifaces, next) {
+               if (dhcp6_findaddr(&a->addr, ifp))
+                       return 1;
+       }
        return 0;
 }
 
@@ -1071,7 +1085,7 @@ dhcp6_dadcallback(void *arg)
                                }
                        }
                        if (!wascompleted) {
-                               syslog(LOG_INFO, "%s: DHCPv6 DAD completed",
+                               syslog(LOG_DEBUG, "%s: DHCPv6 DAD completed",
                                    ifp->name);
                                script_runreason(ifp, state->reason);
                                daemonise();
@@ -1087,6 +1101,7 @@ dhcp6_findna(struct interface *ifp, const uint8_t *iaid,
        struct dhcp6_state *state;
        const struct dhcp6_option *o;
        const uint8_t *p;
+       struct in6_addr in6;
        struct ipv6_addr *a;
        const struct ipv6_addr *pa;
        char iabuf[INET6_ADDRSTRLEN];
@@ -1108,20 +1123,24 @@ dhcp6_findna(struct interface *ifp, const uint8_t *iaid,
                            ifp->name);
                        continue;
                }
-               a = calloc(1, sizeof(*a));
+               p = D6_COPTION_DATA(o);
+               memcpy(&in6.s6_addr, p, sizeof(in6.s6_addr));
+               p += sizeof(in6.s6_addr);
+               a = dhcp6_findaddr(&in6, ifp);
                if (a == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
-                       break;
+                       a = calloc(1, sizeof(*a));
+                       if (a == NULL) {
+                               syslog(LOG_ERR, "%s: %m", __func__);
+                               break;
+                       }
+                       a->iface = ifp;
+                       a->new = 1;
+                       a->onlink = 1; /* XXX: suprised no DHCP opt for this */
+                       a->dadcallback = dhcp6_dadcallback;
+                       memcpy(a->iaid, iaid, sizeof(a->iaid));
+                       memcpy(&a->addr.s6_addr, &in6.s6_addr,
+                           sizeof(in6.s6_addr));
                }
-               a->iface = ifp;
-               a->new = 1;
-               a->onlink = 1; /* XXX: suprised no DHCP opt for this */
-               a->dadcallback = dhcp6_dadcallback;
-               memcpy(a->iaid, iaid, sizeof(a->iaid));
-               p = D6_COPTION_DATA(o);
-               memcpy(&a->addr.s6_addr, p,
-                   sizeof(a->addr.s6_addr));
-               p += sizeof(a->addr.s6_addr);
                pa = ipv6rs_findprefix(a);
                if (pa) {
                        memcpy(&a->prefix, &pa->prefix,
@@ -1148,7 +1167,10 @@ dhcp6_findna(struct interface *ifp, const uint8_t *iaid,
                    iabuf, sizeof(iabuf));
                snprintf(a->saddr, sizeof(a->saddr),
                    "%s/%d", ia, a->prefix_len);
-               TAILQ_INSERT_TAIL(&state->addrs, a, next);
+               if (a->stale)
+                       a->stale = 0;
+               else
+                       TAILQ_INSERT_TAIL(&state->addrs, a, next);
                i++;
        }
        return i;
@@ -1231,10 +1253,10 @@ dhcp6_findia(struct interface *ifp, const uint8_t *d, size_t l,
        uint32_t u32, renew, rebind;
        uint8_t iaid[4];
        size_t ol;
+       struct ipv6_addr *ap, *nap;
 
        ifo = ifp->options;
        i = 0;
-       dhcp6_freedrop_addrs(ifp, 0);
        state = D6_STATE(ifp);
        while ((o = dhcp6_findoption(ifo->ia_type, d, l))) {
                l -= ((const uint8_t *)o - d);
@@ -1284,6 +1306,7 @@ dhcp6_findia(struct interface *ifp, const uint8_t *d, size_t l,
                        return -1;
                }
                if (ifo->ia_type == D6_OPTION_IA_PD) {
+                       dhcp6_freedrop_addrs(ifp, 0);
                        if (dhcp6_findpd(ifp, iaid, p, ol) == 0) {
                                syslog(LOG_ERR,
                                    "%s: %s: DHCPv6 REPLY missing Prefix",
@@ -1291,12 +1314,24 @@ dhcp6_findia(struct interface *ifp, const uint8_t *d, size_t l,
                                return -1;
                        }
                } else {
+                       TAILQ_FOREACH(ap, &state->addrs, next) {
+                               ap->stale = 1;
+                       }
                        if (dhcp6_findna(ifp, iaid, p, ol) == 0) {
                                syslog(LOG_ERR,
                                    "%s: %s: DHCPv6 REPLY missing IA Address",
                                    ifp->name, sfrom);
                                return -1;
                        }
+                       TAILQ_FOREACH_SAFE(ap, &state->addrs, next, nap) {
+                               if (ap->stale) {
+                                       TAILQ_REMOVE(&state->addrs, ap, next);
+                                       if (ap->dadcallback)
+                                               eloop_q_timeout_delete(0, NULL,
+                                                   ap->dadcallback);
+                                       free(ap);
+                               }
+                       }
                }
                i++;
        }
@@ -1495,7 +1530,7 @@ dhcp6_delegate_addr(struct interface *ifp, const struct ipv6_addr *prefix,
 
        /* Remove any exiting address */
        TAILQ_FOREACH(ap, &state->addrs, next) {
-               if (memcmp(&ap->addr, &a->addr, sizeof(ap->addr)) == 0) {
+               if (IN6_ARE_ADDR_EQUAL(&ap->addr, &a->addr)) {
                        TAILQ_REMOVE(&state->addrs, ap, next);
                        free(ap);
                        break;
@@ -1608,6 +1643,7 @@ dhcp6_handledata(__unused void *arg)
        const struct dhcp_opt *opt;
        const struct if_options *ifo;
        const struct ipv6_addr *ap;
+       uint8_t stale;
 
        len = recvmsg(sock, &rcvhdr, 0);
        if (len == -1) {
@@ -1775,7 +1811,15 @@ replyok:
        }
 
 recv:
-       syslog(LOG_INFO, "%s: %s received from %s", ifp->name, op, sfrom);
+       stale = 1;
+       TAILQ_FOREACH(ap, &state->addrs, next) {
+               if (ap->new) {
+                       stale = 0;
+                       break;
+               }
+       }
+       syslog(stale ? LOG_DEBUG : LOG_INFO,
+           "%s: %s received from %s", ifp->name, op, sfrom);
 
        state->reason = NULL;
        eloop_timeout_delete(NULL, ifp);
@@ -1848,7 +1892,7 @@ recv:
                        dhcp6_delegate_prefix(ifp);
                ipv6ns_probeaddrs(&state->addrs);
                if (state->renew || state->rebind)
-                       syslog(LOG_INFO,
+                       syslog(stale ? LOG_DEBUG : LOG_INFO,
                            "%s: renew in %u seconds, rebind in %u seconds",
                            ifp->name, state->renew, state->rebind);
                ipv6_buildroutes();
@@ -1866,8 +1910,8 @@ recv:
                        script_runreason(ifp, state->reason);
                        daemonise();
                } else
-                       syslog(LOG_INFO, "%s: waiting for DHCPv6 DAD"
-                           " to complete",
+                       syslog(LOG_DEBUG,
+                           "%s: waiting for DHCPv6 DAD to complete",
                            ifp->name);
        }
 
@@ -1973,7 +2017,7 @@ dhcp6_start(struct interface *ifp, int manage)
                return 0;
 
        syslog(LOG_INFO, "%s: %s", ifp->name,
-           manage ? "soliciting DHCPv6 address" :
+           manage ? "soliciting DHCPv6 address" :
            "requesting DHCPv6 information");
 
        state->state = manage ? DH6S_INIT : DH6S_INFORM;
diff --git a/ipv4.c b/ipv4.c
index 7692b385b44e427f6930c3fd38bd2cb5439d47da..d937a0bef0022319cede8df39fb0b74f0f59578b 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -223,17 +223,17 @@ desc_route(const char *cmd, const struct rt *rt)
 
        strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr));
        if (rt->gate.s_addr == INADDR_ANY)
-               syslog(LOG_DEBUG, "%s: %s route to %s/%d", ifname, cmd,
+               syslog(LOG_INFO, "%s: %s route to %s/%d", ifname, cmd,
                    addr, inet_ntocidr(rt->net));
        else if (rt->gate.s_addr == rt->dest.s_addr &&
            rt->net.s_addr == INADDR_BROADCAST)
-               syslog(LOG_DEBUG, "%s: %s host route to %s", ifname, cmd,
+               syslog(LOG_INFO, "%s: %s host route to %s", ifname, cmd,
                    addr);
        else if (rt->dest.s_addr == INADDR_ANY && rt->net.s_addr == INADDR_ANY)
-               syslog(LOG_DEBUG, "%s: %s default route via %s", ifname, cmd,
+               syslog(LOG_INFO, "%s: %s default route via %s", ifname, cmd,
                    inet_ntoa(rt->gate));
        else
-               syslog(LOG_DEBUG, "%s: %s route to %s/%d via %s", ifname, cmd,
+               syslog(LOG_INFO, "%s: %s route to %s/%d via %s", ifname, cmd,
                    addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate));
 }
 
diff --git a/ipv6.c b/ipv6.c
index 4312d5a0bfdefbf00d1ea6428afd26dc1d8e3066..a3100d1ddfd7268d0273899c0bc6bdc3c6524c30 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -701,7 +701,8 @@ ipv6_buildroutes(void)
                     d6_state->state == DH6S_DELEGATED))
                {
                        TAILQ_FOREACH(addr, &d6_state->addrs, next) {
-                               if (!addr->onlink)
+                               if (!addr->onlink ||
+                                   IN6_IS_ADDR_UNSPECIFIED(&addr->addr))
                                        continue;
                                rt = make_prefix(ifp, NULL, addr);
                                if (rt)
diff --git a/ipv6.h b/ipv6.h
index ab1ccb6dc246a73da602e4e12583ba8ec8d32c5e..6ef4f6f985c1105e3ad7e6b424895278c8666f36 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -78,6 +78,7 @@ struct ipv6_addr {
        struct in6_addr addr;
        uint8_t onlink;
        uint8_t new;
+       uint8_t stale;
        char saddr[INET6_ADDRSTRLEN];
        uint8_t added;
        uint8_t autoconf;
index a0f238430e96375a4861a8cb20d24505b3191bc4..fd33c9ddfe77d170320c46b8544d51cf398ad08b 100644 (file)
--- a/ipv6ns.c
+++ b/ipv6ns.c
@@ -387,7 +387,8 @@ ipv6ns_probeaddrs(struct ipv6_addrhead *addrs)
                    IN6_IS_ADDR_UNSPECIFIED(&ap->addr))
                        continue;
                ipv6ns_probeaddr(ap);
-               i++;
+               if (ap->new)
+                       i++;
        }
 
        return i;
index 61f8a7ecffe0b511fa69f0c866428f9490cde723..a12925b7b5fca46680add572feee922eb0c68dc1 100644 (file)
--- a/ipv6rs.c
+++ b/ipv6rs.c
@@ -264,7 +264,7 @@ ipv6rs_sendprobe(void *arg)
        cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));
        memcpy(CMSG_DATA(cm), &hoplimit, sizeof(hoplimit));
 
-       syslog(LOG_INFO, "%s: sending Router Solicitation", ifp->name);
+       syslog(LOG_DEBUG, "%s: sending Router Solicitation", ifp->name);
        if (sendmsg(sock, &sndhdr, 0) == -1) {
                syslog(LOG_ERR, "%s: sendmsg: %m", ifp->name);
                ipv6rs_drop(ifp);
@@ -276,7 +276,7 @@ ipv6rs_sendprobe(void *arg)
                eloop_timeout_add_sec(RTR_SOLICITATION_INTERVAL,
                    ipv6rs_sendprobe, ifp);
        else
-               syslog(LOG_INFO, "%s: no IPv6 Routers available", ifp->name);
+               syslog(LOG_WARNING, "%s: no IPv6 Routers available", ifp->name);
 }
 
 static void
@@ -415,7 +415,8 @@ ipv6rs_scriptrun(const struct ra *rap)
        /* If all addresses have completed DAD run the script */
        TAILQ_FOREACH(ap, &rap->addrs, next) {
                if (ap->dadcompleted == 0) {
-                       syslog(LOG_INFO, "%s: waiting for Router Advertisement"
+                       syslog(LOG_DEBUG,
+                           "%s: waiting for Router Advertisement"
                            " DAD to complete",
                            rap->iface->name);
                        return;
@@ -489,7 +490,7 @@ ipv6rs_dadcallback(void *arg)
                        }
 
                        if (wascompleted && found && rap->lifetime) {
-                               syslog(LOG_INFO,
+                               syslog(LOG_DEBUG,
                                    "%s: Router Advertisement DAD completed",
                                    rap->iface->name);
                                ipv6rs_scriptrun(rap);
@@ -1162,7 +1163,7 @@ ipv6rs_expire(void *arg)
                if (timercmp(&now, &expire, >)) {
                        valid = 0;
                        if (!rap->expired) {
-                               syslog(LOG_INFO,
+                               syslog(LOG_WARNING,
                                    "%s: %s: expired default Router",
                                    ifp->name, rap->sfrom);
                                rap->expired = expired = 1;
@@ -1182,7 +1183,7 @@ ipv6rs_expire(void *arg)
                                if (timercmp(&now, &expire, >) &&
                                    ipv6rs_findsameaddr(ap) == NULL)
                                {
-                                       syslog(LOG_INFO,
+                                       syslog(LOG_WARNING,
                                            "%s: %s: expired address",
                                            ifp->name, ap->saddr);
                                        eloop_timeout_delete(NULL, ap);
@@ -1215,7 +1216,7 @@ ipv6rs_expire(void *arg)
                        if (timercmp(&now, &rao->expire, >)) {
                                /* Expired prefixes are logged above */
                                if (rao->type != ND_OPT_PREFIX_INFORMATION)
-                                       syslog(LOG_INFO,
+                                       syslog(LOG_WARNING,
                                            "%s: %s: expired option %d",
                                            ifp->name, rap->sfrom, rao->type);
                                TAILQ_REMOVE(&rap->options, rao, next);
@@ -1249,6 +1250,7 @@ ipv6rs_start(struct interface *ifp)
 {
        struct rs_state *state;
 
+       syslog(LOG_INFO, "%s: soliciting an IPv6 Router", ifp->name);
        if (sock == -1) {
                if (ipv6rs_open() == -1) {
                        syslog(LOG_ERR, "%s: ipv6rs_open: %m", __func__);