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 Import dhcpcd-6.4.4 with the follow...



details:   https://anonhg.NetBSD.org/src/rev/569c87ffee26
branches:  trunk
changeset: 332337:569c87ffee26
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Sep 16 22:23:17 2014 +0000

description:
Import dhcpcd-6.4.4 with the following changes:
  *  Many bounds checking fixes from Tobias Stoeckmann
  *  Improve error when the authentication token cannot be found
  *  close the IPv4 specific UDP socket when done sending
  *  Implemented a write queue to the control sockets
  *  Only send interfaces to control sockets when in a BOUND state
  *  Add a sample controlgroup directive to dhcpcd.conf to make setup easier
  *  Add variables if_oneup and if_ipwaited so hook scripts know the overall
     state of dhcpcd better
  *  Pass RC_SVCNAME from enviromment to hooks so that a service hook can
     know it's name (may not be dhcpcd)
  *  Document every variable set for dhcpcd-run-hooks(8)
  *  Allow SSIDs with non printable characters to be used in ssid selection
     in dhcpcd.conf
  *  Add an unprivileged control socket so that normal users can obtain
     dhcpcd running state

diffstat:

 external/bsd/dhcpcd/dist/arp.c                          |   12 +-
 external/bsd/dhcpcd/dist/control.c                      |  307 ++++++++++++---
 external/bsd/dhcpcd/dist/control.h                      |   24 +-
 external/bsd/dhcpcd/dist/defs.h                         |    7 +-
 external/bsd/dhcpcd/dist/dhcp-common.c                  |   26 +-
 external/bsd/dhcpcd/dist/dhcp-common.h                  |    6 +-
 external/bsd/dhcpcd/dist/dhcp.h                         |    5 +-
 external/bsd/dhcpcd/dist/dhcp6.c                        |   52 +-
 external/bsd/dhcpcd/dist/dhcp6.h                        |   11 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/10-wpa_supplicant |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf       |    4 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind         |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd.h                       |   10 +-
 external/bsd/dhcpcd/dist/eloop.c                        |   95 ++--
 external/bsd/dhcpcd/dist/eloop.h                        |   18 +-
 external/bsd/dhcpcd/dist/if.c                           |    4 +-
 external/bsd/dhcpcd/dist/if.h                           |    4 +-
 external/bsd/dhcpcd/dist/ipv6.c                         |    6 +-
 external/bsd/dhcpcd/dist/ipv6nd.h                       |    5 +-
 external/bsd/dhcpcd/dist/script.h                       |    6 +-
 20 files changed, 415 insertions(+), 199 deletions(-)

diffs (truncated from 1292 to 300 lines):

diff -r 57d1573f6224 -r 569c87ffee26 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Tue Sep 16 22:00:22 2014 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Tue Sep 16 22:23:17 2014 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: arp.c,v 1.1.1.13 2014/07/30 15:44:09 roy Exp $");
+ __RCSID("$NetBSD: arp.c,v 1.1.1.14 2014/09/16 22:23:18 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -253,8 +253,8 @@
                        syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
                        return;
                }
-               eloop_event_add(ifp->ctx->eloop,
-                   state->arp_fd, arp_packet, ifp);
+               eloop_event_add(ifp->ctx->eloop, state->arp_fd,
+                   arp_packet, ifp, NULL, NULL);
        }
        if (++state->claims < ANNOUNCE_NUM)
                syslog(LOG_DEBUG,
@@ -289,7 +289,7 @@
                timernorm(&tv);
                eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcp_discover, ifp);
        } else {
-               eloop_event_delete(ifp->ctx->eloop, state->arp_fd);
+               eloop_event_delete(ifp->ctx->eloop, state->arp_fd, 0);
                close(state->arp_fd);
                state->arp_fd = -1;
        }
@@ -311,7 +311,7 @@
                        return;
                }
                eloop_event_add(ifp->ctx->eloop,
-                   state->arp_fd, arp_packet, ifp);
+                   state->arp_fd, arp_packet, ifp, NULL, NULL);
        }
 
        if (state->arping_index < ifp->options->arping_len) {
@@ -381,7 +381,7 @@
                return;
 
        if (state->arp_fd != -1) {
-               eloop_event_delete(ifp->ctx->eloop, state->arp_fd);
+               eloop_event_delete(ifp->ctx->eloop, state->arp_fd, 0);
                close(state->arp_fd);
                state->arp_fd = -1;
        }
diff -r 57d1573f6224 -r 569c87ffee26 external/bsd/dhcpcd/dist/control.c
--- a/external/bsd/dhcpcd/dist/control.c        Tue Sep 16 22:00:22 2014 +0000
+++ b/external/bsd/dhcpcd/dist/control.c        Tue Sep 16 22:23:17 2014 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: control.c,v 1.1.1.7 2014/07/14 11:45:02 roy Exp $");
+ __RCSID("$NetBSD: control.c,v 1.1.1.8 2014/09/16 22:23:17 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -30,6 +30,7 @@
 
 #include <sys/socket.h>
 #include <sys/stat.h>
+#include <sys/uio.h>
 #include <sys/un.h>
 
 #include <errno.h>
@@ -37,6 +38,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -52,32 +54,68 @@
 #endif
 
 static void
+control_queue_purge(struct dhcpcd_ctx *ctx, char *data)
+{
+       int found;
+       struct fd_list *fp;
+       struct fd_data *fpd;
+
+       /* If no other fd queue has the same data, free it */
+       found = 0;
+       TAILQ_FOREACH(fp, &ctx->control_fds, next) {
+               TAILQ_FOREACH(fpd, &fp->queue, next) {
+                       if (fpd->data == data) {
+                               found = 1;
+                               break;
+                       }
+               }
+       }
+       if (!found)
+               free(data);
+}
+
+static void
+control_queue_free(struct fd_list *fd)
+{
+       struct fd_data *fdp;
+
+       while ((fdp = TAILQ_FIRST(&fd->queue))) {
+               TAILQ_REMOVE(&fd->queue, fdp, next);
+               if (fdp->freeit)
+                       control_queue_purge(fd->ctx, fdp->data);
+               free(fdp);
+       }
+       while ((fdp = TAILQ_FIRST(&fd->free_queue))) {
+               TAILQ_REMOVE(&fd->free_queue, fdp, next);
+               free(fdp);
+       }
+}
+
+static void
+control_delete(struct fd_list *fd)
+{
+
+       TAILQ_REMOVE(&fd->ctx->control_fds, fd, next);
+       eloop_event_delete(fd->ctx->eloop, fd->fd, 0);
+       close(fd->fd);
+       control_queue_free(fd);
+       free(fd);
+}
+
+static void
 control_handle_data(void *arg)
 {
-       struct fd_list *l = arg, *lp, *last;
+       struct fd_list *fd = arg;
        char buffer[1024], *e, *p, *argvp[255], **ap, *a;
        ssize_t bytes;
        size_t len;
        int argc;
 
-       bytes = read(l->fd, buffer, sizeof(buffer) - 1);
+       bytes = read(fd->fd, buffer, sizeof(buffer) - 1);
        if (bytes == -1 || bytes == 0) {
                /* Control was closed or there was an error.
                 * Remove it from our list. */
-               last = NULL;
-               for (lp = l->ctx->control_fds; lp; lp = lp->next) {
-                       if (lp == l) {
-                               eloop_event_delete(lp->ctx->eloop, lp->fd);
-                               close(lp->fd);
-                               if (last == NULL)
-                                       lp->ctx->control_fds = lp->next;
-                               else
-                                       last->next = lp->next;
-                               free(lp);
-                               break;
-                       }
-                       last = lp;
-               }
+               control_delete(fd);
                return;
        }
        buffer[bytes] = '\0';
@@ -91,34 +129,39 @@
                ap = argvp;
                while (p < e) {
                        argc++;
-                       if ((size_t)argc > sizeof(argvp)) {
+                       if ((size_t)argc >= sizeof(argvp) / sizeof(argvp[0])) {
                                errno = ENOBUFS;
                                return;
                        }
                        a = *ap++ = p;
                        len = strlen(p);
                        p += len + 1;
-                       if (a[len - 1] == '\n') {
+                       if (len && a[len - 1] == '\n') {
                                a[len - 1] = '\0';
                                break;
                        }
                }
-               dhcpcd_handleargs(l->ctx, l, argc, argvp);
+               *ap = NULL;
+               if (dhcpcd_handleargs(fd->ctx, fd, argc, argvp) == -1) {
+                       syslog(LOG_ERR, "%s: dhcpcd_handleargs: %m", __func__);
+                       if (errno != EINTR && errno != EAGAIN) {
+                               control_delete(fd);
+                               return;
+                       }
+               }
        }
 }
 
 static void
-control_handle(void *arg)
+control_handle1(struct dhcpcd_ctx *ctx, int lfd, unsigned int fd_flags)
 {
-       struct dhcpcd_ctx *ctx;
        struct sockaddr_un run;
        socklen_t len;
        struct fd_list *l;
        int fd, flags;
 
-       ctx = arg;
        len = sizeof(run);
-       if ((fd = accept(ctx->control_fd, (struct sockaddr *)&run, &len)) == -1)
+       if ((fd = accept(lfd, (struct sockaddr *)&run, &len)) == -1)
                return;
        if ((flags = fcntl(fd, F_GETFD, 0)) == -1 ||
            fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
@@ -136,73 +179,119 @@
        if (l) {
                l->ctx = ctx;
                l->fd = fd;
-               l->listener = 0;
-               l->next = ctx->control_fds;
-               ctx->control_fds = l;
-               eloop_event_add(ctx->eloop, l->fd, control_handle_data, l);
+               l->flags = fd_flags;
+               TAILQ_INIT(&l->queue);
+               TAILQ_INIT(&l->free_queue);
+               TAILQ_INSERT_TAIL(&ctx->control_fds, l, next);
+               eloop_event_add(ctx->eloop, l->fd,
+                   control_handle_data, l, NULL, NULL);
        } else
                close(fd);
 }
 
-static socklen_t
-make_sock(struct dhcpcd_ctx *ctx, struct sockaddr_un *sa, const char *ifname)
+static void
+control_handle(void *arg)
 {
+       struct dhcpcd_ctx *ctx = arg;
+
+       control_handle1(ctx, ctx->control_fd, 0);
+}
+
+static void
+control_handle_unpriv(void *arg)
+{
+       struct dhcpcd_ctx *ctx = arg;
+
+       control_handle1(ctx, ctx->control_unpriv_fd, FD_UNPRIV);
+}
+
+static int
+make_sock(struct sockaddr_un *sa, const char *ifname, int unpriv)
+{
+       int fd;
 
 #ifdef SOCK_CLOEXEC
-       if ((ctx->control_fd = socket(AF_UNIX,
+       if ((fd = socket(AF_UNIX,
            SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1)
-               return 0;
+               return -1;
 #else
        int flags;
 
-       if ((ctx->control_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-               return 0;
-       if ((flags = fcntl(ctx->control_fd, F_GETFD, 0)) == -1 ||
-           fcntl(ctx->control_fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+       if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+               return -1;
+       if ((flags = fcntl(fd, F_GETFD, 0)) == -1 ||
+           fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
        {
-               close(ctx->control_fd);
-               ctx->control_fd = -1;
-               return 0;
+               close(fd);
+               return -1;
        }
-       if ((flags = fcntl(ctx->control_fd, F_GETFL, 0)) == -1 ||
-           fcntl(ctx->control_fd, F_SETFL, flags | O_NONBLOCK) == -1)
+       if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
+           fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
        {
-               close(ctx->control_fd);
-               ctx->control_fd = -1;
-               return 0;
+               close(fd);
+               return -1;
        }
 #endif
        memset(sa, 0, sizeof(*sa));
        sa->sun_family = AF_UNIX;
-       snprintf(sa->sun_path, sizeof(sa->sun_path), CONTROLSOCKET,
-           ifname ? "-" : "", ifname ? ifname : "");
-       strlcpy(ctx->control_sock, sa->sun_path, sizeof(ctx->control_sock));
-       return (socklen_t)SUN_LEN(sa);
+       if (unpriv)
+               strlcpy(sa->sun_path, UNPRIVSOCKET, sizeof(sa->sun_path));
+       else {
+               snprintf(sa->sun_path, sizeof(sa->sun_path), CONTROLSOCKET,
+                   ifname ? "-" : "", ifname ? ifname : "");
+       }
+       return fd;
+}
+
+#define S_PRIV (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)
+#define S_UNPRIV (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)



Home | Main Index | Thread Index | Old Index