Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/dhcpcd/dist/src Sync



details:   https://anonhg.NetBSD.org/src/rev/d74ef8032592
branches:  trunk
changeset: 1010746:d74ef8032592
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Jun 04 13:08:13 2020 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/src/dhcp.c      |   37 ++++++++-
 external/bsd/dhcpcd/dist/src/dhcp6.c     |   64 ++++++++++++----
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in |   11 ++-
 external/bsd/dhcpcd/dist/src/dhcpcd.c    |   92 +++++++++++++---------
 external/bsd/dhcpcd/dist/src/if-bsd.c    |    4 +-
 external/bsd/dhcpcd/dist/src/privsep.c   |  123 ++++++++++++++++--------------
 external/bsd/dhcpcd/dist/src/script.c    |   71 ++++++++++++-----
 7 files changed, 260 insertions(+), 142 deletions(-)

diffs (truncated from 778 to 300 lines):

diff -r d1d044e5890c -r d74ef8032592 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Thu Jun 04 13:07:12 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Thu Jun 04 13:08:13 2020 +0000
@@ -1034,7 +1034,7 @@
        auth = NULL;    /* appease GCC */
        auth_len = 0;
        if (ifo->auth.options & DHCPCD_AUTH_SEND) {
-               ssize_t alen = dhcp_auth_encode(&ifo->auth,
+               ssize_t alen = dhcp_auth_encode(ifp->ctx, &ifo->auth,
                    state->auth.token,
                    NULL, 0, 4, type, NULL, 0);
                if (alen != -1 && alen > UINT8_MAX) {
@@ -1129,7 +1129,7 @@
 
 #ifdef AUTH
        if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len != 0)
-               dhcp_auth_encode(&ifo->auth, state->auth.token,
+               dhcp_auth_encode(ifp->ctx, &ifo->auth, state->auth.token,
                    (uint8_t *)bootp, len, 4, type, auth, auth_len);
 #endif
 
@@ -2747,6 +2747,18 @@
 #endif
                }
        }
+#ifdef AUTH
+       else if (state->auth.reconf != NULL) {
+               /*
+                * Drop the lease as the token may only be present
+                * in the initial reply message and not subsequent
+                * renewals.
+                * If dhcpcd is restarted, the token is lost.
+                * XXX persist this in another file?
+                */
+               dhcp_unlink(ifp->ctx, state->leasefile);
+       }
+#endif
 
        eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
 #ifdef AUTH
@@ -4176,3 +4188,24 @@
 
        return ia;
 }
+
+#ifndef SMALL
+int
+dhcp_dump(struct interface *ifp)
+{
+       struct dhcp_state *state;
+
+       ifp->if_data[IF_DATA_DHCP] = state = calloc(1, sizeof(*state));
+       if (state == NULL) {
+               logerr(__func__);
+               return -1;
+       }
+       state->new_len = read_lease(ifp, &state->new);
+       if (state->new == NULL) {
+               logerr("read_lease");
+               return -1;
+       }
+       state->reason = "DUMP";
+       return script_runreason(ifp, state->reason);
+}
+#endif
diff -r d1d044e5890c -r d74ef8032592 external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Thu Jun 04 13:07:12 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Thu Jun 04 13:08:13 2020 +0000
@@ -881,7 +881,7 @@
 #ifdef AUTH
        auth_len = 0;
        if (ifo->auth.options & DHCPCD_AUTH_SEND) {
-               ssize_t alen = dhcp_auth_encode(&ifo->auth,
+               ssize_t alen = dhcp_auth_encode(ifp->ctx, &ifo->auth,
                    state->auth.token, NULL, 0, 6, type, NULL, 0);
                if (alen != -1 && alen > UINT16_MAX) {
                        errno = ERANGE;
@@ -1196,9 +1196,9 @@
                return -1;
 
        state = D6_STATE(ifp);
-       return dhcp_auth_encode(&ifp->options->auth, state->auth.token,
-           (uint8_t *)state->send, state->send_len,
-           6, state->send->type, opt, opt_len);
+       return dhcp_auth_encode(ifp->ctx, &ifp->options->auth,
+           state->auth.token, (uint8_t *)state->send, state->send_len, 6,
+           state->send->type, opt, opt_len);
 }
 #endif
 
@@ -1483,7 +1483,7 @@
        dhcp6_startrenew(ifp);
 }
 
-int
+bool
 dhcp6_dadcompleted(const struct interface *ifp)
 {
        const struct dhcp6_state *state;
@@ -1493,9 +1493,9 @@
        TAILQ_FOREACH(ap, &state->addrs, next) {
                if (ap->flags & IPV6_AF_ADDED &&
                    !(ap->flags & IPV6_AF_DADCOMPLETED))
-                       return 0;
+                       return false;
        }
-       return 1;
+       return true;
 }
 
 static void
@@ -3319,7 +3319,7 @@
                        loginfox("%s: accepted reconfigure key", ifp->name);
        } else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
                if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
-                       logerr("%s: no authentication from %s",
+                       logerrx("%s: no authentication from %s",
                            ifp->name, sfrom);
                        return;
                }
@@ -3595,15 +3595,12 @@
        }
 
        if (r->type == DHCP6_RECONFIGURE) {
-               logdebugx("%s: RECONFIGURE6 recv from %s,"
-                   " sending to all interfaces",
-                   ifp->name, sfrom);
-               TAILQ_FOREACH(ifp, ctx->ifaces, next) {
-                       state = D6_CSTATE(ifp);
-                       if (state != NULL && state->send != NULL)
-                               dhcp6_recvif(ifp, sfrom, r, len);
+               if (!IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) {
+                       logerrx("%s: RECONFIGURE6 recv from %s, not LL",
+                           ifp->name, sfrom);
+                       return;
                }
-               return;
+               goto recvif;
        }
 
        state = D6_CSTATE(ifp);
@@ -3679,6 +3676,7 @@
        len = (size_t)tlen;
 #endif
 
+recvif:
        dhcp6_recvif(ifp, sfrom, r, len);
 }
 
@@ -4041,6 +4039,19 @@
                        }
                        dhcp_unlink(ifp->ctx, state->leasefile);
                }
+#ifdef AUTH
+               else if (state->auth.reconf != NULL) {
+                       /*
+                        * Drop the lease as the token may only be present
+                        * in the initial reply message and not subsequent
+                        * renewals.
+                        * If dhcpcd is restarted, the token is lost.
+                        * XXX persist this in another file?
+                        */
+                       dhcp_unlink(ifp->ctx, state->leasefile);
+               }
+#endif
+
                dhcp6_freedrop_addrs(ifp, drop, NULL);
                free(state->old);
                state->old = state->new;
@@ -4293,3 +4304,24 @@
        return 1;
 }
 #endif
+
+#ifndef SMALL
+int
+dhcp6_dump(struct interface *ifp)
+{
+       struct dhcp6_state *state;
+
+       ifp->if_data[IF_DATA_DHCP6] = state = calloc(1, sizeof(*state));
+       if (state == NULL) {
+               logerr(__func__);
+               return -1;
+       }
+       TAILQ_INIT(&state->addrs);
+       if (dhcp6_readlease(ifp, 0) == -1) {
+               logerr("dhcp6_readlease");
+               return -1;
+       }
+       state->reason = "DUMP6";
+       return script_runreason(ifp, state->reason);
+}
+#endif
diff -r d1d044e5890c -r d74ef8032592 external/bsd/dhcpcd/dist/src/dhcpcd.8.in
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.8.in  Thu Jun 04 13:07:12 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.8.in  Thu Jun 04 13:08:13 2020 +0000
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 21, 2020
+.Dd May 31, 2020
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -72,7 +72,7 @@
 .Op interface
 .Nm
 .Fl U , Fl Fl dumplease
-.Ar interface
+.Op Ar interface
 .Nm
 .Fl Fl version
 .Nm
@@ -685,15 +685,20 @@
 To test INFORM the interface needs to be configured with the desired address
 before starting
 .Nm .
-.It Fl U , Fl Fl dumplease Ar interface
+.It Fl U , Fl Fl dumplease Op Ar interface
 Dumps the current lease for the
 .Ar interface
 to stdout.
+If no
+.Ar interface
+is given then all interfaces are dumped.
 Use the
 .Fl 4
 or
 .Fl 6
 flags to specify an address family.
+If a lease is piped in via standard input then that is dumped.
+In this case, specifying an address family is mandatory.
 .It Fl V , Fl Fl variables
 Display a list of option codes, the associated variable and encoding for use in
 .Xr dhcpcd-run-hooks 8 .
diff -r d1d044e5890c -r d74ef8032592 external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Thu Jun 04 13:07:12 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Thu Jun 04 13:08:13 2020 +0000
@@ -29,6 +29,7 @@
 const char dhcpcd_copyright[] = "Copyright (c) 2006-2020 Roy Marples";
 
 #include <sys/file.h>
+#include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -86,6 +87,7 @@
        SIGHUP,
        SIGUSR1,
        SIGUSR2,
+       SIGCHLD,
 };
 const size_t dhcpcd_signals_len = __arraycount(dhcpcd_signals);
 
@@ -1340,6 +1342,9 @@
        struct interface *ifp;
 
        ctx->options |= DHCPCD_EXITING;
+       if (ctx->ifaces == NULL)
+               return;
+
        /* Drop the last interface first */
        TAILQ_FOREACH_REVERSE(ifp, ctx->ifaces, if_head, next) {
                if (!ifp->active)
@@ -1395,7 +1400,7 @@
        unsigned long long opts;
        int exit_code;
 
-       if (ctx->options & DHCPCD_FORKED) {
+       if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) {
                pid_t pid = pidfile_read(ctx->pidfile);
                if (pid == -1) {
                        if (errno != ENOENT)
@@ -1441,6 +1446,10 @@
                if (logopen(ctx->logfile) == -1)
                        logerr(__func__);
                return;
+       case SIGCHLD:
+               while (waitpid(-1, NULL, WNOHANG) > 0)
+                       ;
+               return;
        default:
                logerrx("received signal %d but don't know what to do with it",
                    sig);
@@ -1663,20 +1672,13 @@
        return 0;
 }
 
-static const char *dumpskip[] = {
-       "PATH=",
-       "pid=",
-       "chroot=",
-};
-
 static int
 dhcpcd_readdump(struct dhcpcd_ctx *ctx)
 {
        int error = 0;



Home | Main Index | Thread Index | Old Index