]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP6: don't log when things consitently fail
authorRoy Marples <roy@marples.name>
Fri, 17 Apr 2020 12:25:33 +0000 (13:25 +0100)
committerRoy Marples <roy@marples.name>
Fri, 17 Apr 2020 12:25:33 +0000 (13:25 +0100)
For example, the RA says obtain more inforamtion via DHCPv6 but
there is no DHCPv6 server to service the request.

src/dhcp6.c
src/dhcp6.h

index e59a5aebb3c3dac824fc3d09f41ba0abfede248a..3103e7e034d5974bd66bd4122415668c5542bd03 100644 (file)
@@ -1585,6 +1585,7 @@ dhcp6_startdiscover(void *arg)
 {
        struct interface *ifp;
        struct dhcp6_state *state;
+       int llevel;
 
        ifp = arg;
        state = D6_STATE(ifp);
@@ -1592,7 +1593,11 @@ dhcp6_startdiscover(void *arg)
        if (state->reason == NULL || strcmp(state->reason, "TIMEOUT6") != 0)
                dhcp6_delete_delegates(ifp);
 #endif
-       loginfox("%s: soliciting a DHCPv6 lease", ifp->name);
+       if (state->new == NULL && !state->failed)
+               llevel = LOG_INFO;
+       else
+               llevel = LOG_DEBUG;
+       logmessage(llevel, "%s: soliciting a DHCPv6 lease", ifp->name);
        state->state = DH6S_DISCOVER;
        state->RTC = 0;
        state->IMD = SOL_MAX_DELAY;
@@ -1616,11 +1621,15 @@ dhcp6_startinform(void *arg)
 {
        struct interface *ifp;
        struct dhcp6_state *state;
+       int llevel;
 
        ifp = arg;
        state = D6_STATE(ifp);
-       if (state->new == NULL || ifp->options->options & DHCPCD_DEBUG)
-               loginfox("%s: requesting DHCPv6 information", ifp->name);
+       if (state->new == NULL && !state->failed)
+               llevel = LOG_INFO;
+       else
+               llevel = LOG_DEBUG;
+       logmessage(llevel, "%s: requesting DHCPv6 information", ifp->name);
        state->state = DH6S_INFORM;
        state->RTC = 0;
        state->IMD = INF_MAX_DELAY;
@@ -1677,6 +1686,8 @@ dhcp6_fail(struct interface* ifp)
 {
        struct dhcp6_state *state = D6_STATE(ifp);
 
+       state->failed = true;
+
        /* RFC3315 18.1.2 says that prior addresses SHOULD be used on failure.
         * RFC2131 3.2.3 says that MAY chose to use the prior address.
         * Because dhcpcd was written first for RFC2131, we have the LASTLEASE
@@ -1711,33 +1722,43 @@ dhcp6_fail(struct interface* ifp)
        }
 }
 
+static int
+dhcp6_failloglevel(struct interface *ifp)
+{
+       const struct dhcp6_state *state = D6_CSTATE(ifp);
+
+       return state->failed ? LOG_DEBUG : LOG_ERR;
+}
+
 static void
 dhcp6_failconfirm(void *arg)
 {
-       struct interface *ifp;
+       struct interface *ifp = arg;
+       int llevel = dhcp6_failloglevel(ifp);
 
-       ifp = arg;
-       logerrx("%s: failed to confirm prior address", ifp->name);
+       logmessage(llevel, "%s: failed to confirm prior DHCPv6 address",
+           ifp->name);
        dhcp6_fail(ifp);
 }
 
 static void
 dhcp6_failrequest(void *arg)
 {
-       struct interface *ifp;
+       struct interface *ifp = arg;
+       int llevel = dhcp6_failloglevel(ifp);
 
-       ifp = arg;
-       logerrx("%s: failed to request address", ifp->name);
+       logmessage(llevel, "%s: failed to request DHCPv6 address", ifp->name);
        dhcp6_fail(ifp);
 }
 
 static void
 dhcp6_failinform(void *arg)
 {
-       struct interface *ifp;
+       struct interface *ifp = arg;
+       int llevel = dhcp6_failloglevel(ifp);
 
-       ifp = arg;
-       logerrx("%s: failed to request information", ifp->name);
+       logmessage(llevel, "%s: failed to request DHCPv6 information",
+           ifp->name);
        dhcp6_fail(ifp);
 }
 
@@ -1745,10 +1766,9 @@ dhcp6_failinform(void *arg)
 static void
 dhcp6_failrebind(void *arg)
 {
-       struct interface *ifp;
+       struct interface *ifp = arg;
 
-       ifp = arg;
-       logerrx("%s: failed to rebind prior delegation", ifp->name);
+       logerrx("%s: failed to rebind prior DHCPv6 delegation", ifp->name);
        dhcp6_fail(ifp);
 }
 
@@ -3124,6 +3144,7 @@ dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom)
                        state->state = DH6S_INFORMED;
                else
                        state->state = DH6S_BOUND;
+               state->failed = false;
 
                if (state->renew && state->renew != ND6_INFINITE_LIFETIME)
                        eloop_timeout_add_sec(ifp->ctx->eloop,
@@ -3857,6 +3878,7 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state)
 gogogo:
        state->state = init_state;
        state->lerror = 0;
+       state->failed = false;
        dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
            AF_INET6, ifp);
        if (ipv6_linklocal(ifp) == NULL) {
index c7d118891f4a92739d7327be7e4edb19f2283c18..73341cde459bdbe3cff1ee387991b243ab5f2f49 100644 (file)
@@ -211,7 +211,10 @@ struct dhcp6_state {
        const char *reason;
        uint16_t lerror; /* Last error received from DHCPv6 reply. */
        bool has_no_binding;
+       bool failed; /* Entered the failed state - used to rate limit log. */
+#ifdef AUTH
        struct authstate auth;
+#endif
 };
 
 #define D6_STATE(ifp)                                                         \