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 Import dhcpcd-8.0.3 With the fo...



details:   https://anonhg.NetBSD.org/src/rev/5b3b46894a65
branches:  trunk
changeset: 453659:5b3b46894a65
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Aug 21 17:10:29 2019 +0000

description:
Import dhcpcd-8.0.3 With the following changes:

 *  DHCP: Work with IP headers with options
 *  script: Assert that env string are correctly terminated
 *  script: Terminate env strings with no value
 *  script: Don't attempt to use an invalid env string
 *  route: Fix NULL deference error when using static routes
 *  ARP: Respect IFF_NOARP
 *  DHCP: Allow full DHCP support for PtP interfaces, but not by default
 *  control: sends correct buffer to listeners

dhcpcd-ui now correctly reports SSD association and all the addresses obtained (regression from dhcpcd-7)

diffstat:

 external/bsd/dhcpcd/dist/src/control.c     |  152 +++++++++++++++++-----------
 external/bsd/dhcpcd/dist/src/control.h     |   15 ++-
 external/bsd/dhcpcd/dist/src/defs.h        |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp-common.c |   59 ++++++----
 external/bsd/dhcpcd/dist/src/duid.c        |   10 +-
 external/bsd/dhcpcd/dist/src/if-linux.c    |   16 ++-
 external/bsd/dhcpcd/dist/src/if-options.h  |    2 +-
 external/bsd/dhcpcd/dist/src/if.c          |   29 ++++-
 external/bsd/dhcpcd/dist/src/ipv4.c        |   19 ++-
 external/bsd/dhcpcd/dist/src/route.c       |   27 ++++-
 external/bsd/dhcpcd/dist/src/route.h       |    1 +
 external/bsd/dhcpcd/dist/src/sa.c          |    4 +-
 external/bsd/dhcpcd/dist/src/script.c      |   45 +++++---
 13 files changed, 239 insertions(+), 142 deletions(-)

diffs (truncated from 836 to 300 lines):

diff -r f093d611066d -r 5b3b46894a65 external/bsd/dhcpcd/dist/src/control.c
--- a/external/bsd/dhcpcd/dist/src/control.c    Wed Aug 21 17:06:36 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/control.c    Wed Aug 21 17:10:29 2019 +0000
@@ -53,41 +53,26 @@
 #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);
+               if (fdp->data_size != 0)
+                       free(fdp->data);
                free(fdp);
        }
+       fd->queue_len = 0;
+
+#ifdef CTL_FREE_LIST
        while ((fdp = TAILQ_FIRST(&fd->free_queue))) {
                TAILQ_REMOVE(&fd->free_queue, fdp, next);
+               if (fdp->data_size != 0)
+                       free(fdp->data);
                free(fdp);
        }
+#endif
 }
 
 static void
@@ -161,29 +146,33 @@
 
        len = sizeof(run);
        if ((fd = accept(lfd, (struct sockaddr *)&run, &len)) == -1)
-               return;
+               goto error;
        if ((flags = fcntl(fd, F_GETFD, 0)) == -1 ||
            fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
-       {
-               close(fd);
-               return;
-       }
+               goto error;
        if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
            fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
-       {
-               close(fd);
-               return;
-       }
+               goto error;
+
        l = malloc(sizeof(*l));
-       if (l) {
-               l->ctx = ctx;
-               l->fd = fd;
-               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);
-       } else
+       if (l == NULL)
+               goto error;
+
+       l->ctx = ctx;
+       l->fd = fd;
+       l->flags = fd_flags;
+       TAILQ_INIT(&l->queue);
+       l->queue_len = 0;
+#ifdef CTL_FREE_LIST
+       TAILQ_INIT(&l->free_queue);
+#endif
+       TAILQ_INSERT_TAIL(&ctx->control_fds, l, next);
+       eloop_event_add(ctx->eloop, l->fd, control_handle_data, l);
+       return;
+
+error:
+       logerr(__func__);
+       if (fd != -1)
                close(fd);
 }
 
@@ -374,40 +363,85 @@
        }
 
        TAILQ_REMOVE(&fd->queue, data, next);
-       if (data->freeit)
-               control_queue_purge(fd->ctx, data->data);
-       data->data = NULL; /* safety */
-       data->data_len = 0;
+       fd->queue_len--;
+#ifdef CTL_FREE_LIST
        TAILQ_INSERT_TAIL(&fd->free_queue, data, next);
+#else
+       if (data->data_size != 0)
+               free(data->data);
+       free(data);
+#endif
 
        if (TAILQ_FIRST(&fd->queue) == NULL)
                eloop_event_remove_writecb(fd->ctx->eloop, fd->fd);
 }
 
 int
-control_queue(struct fd_list *fd, char *data, size_t data_len, uint8_t fit)
+control_queue(struct fd_list *fd, void *data, size_t data_len, bool fit)
 {
        struct fd_data *d;
-       size_t n;
+
+#ifdef CTL_FREE_LIST
+       struct fd_data *df;
 
-       d = TAILQ_FIRST(&fd->free_queue);
-       if (d) {
+       d = NULL;
+       TAILQ_FOREACH(df, &fd->free_queue, next) {
+               if (!fit) {
+                       if (df->data_size == 0) {
+                               d = df;
+                               break;
+                       }
+                       continue;
+               }
+               if (d == NULL || d->data_size < df->data_size) {
+                       d = df;
+                       if (d->data_size <= data_len)
+                               break;
+               }
+       }
+       if (d != NULL)
                TAILQ_REMOVE(&fd->free_queue, d, next);
-       } else {
-               n = 0;
-               TAILQ_FOREACH(d, &fd->queue, next) {
-                       if (++n == CONTROL_QUEUE_MAX) {
-                               errno = ENOBUFS;
-                               return -1;
-                       }
+       else
+#endif
+       {
+               if (fd->queue_len == CONTROL_QUEUE_MAX) {
+                       errno = ENOBUFS;
+                       return -1;
                }
-               d = malloc(sizeof(*d));
+               fd->queue_len++;
+               d = calloc(1, sizeof(*d));
                if (d == NULL)
                        return -1;
        }
-       d->data = data;
+
+       if (!fit) {
+#ifdef CTL_FREE_LIST
+               if (d->data_size != 0) {
+                       free(d->data);
+                       d->data_size = 0;
+               }
+#endif
+               d->data = data;
+               d->data_len = data_len;
+               goto queue;
+       }
+
+       if (d->data_size == 0)
+               d->data = NULL;
+       if (d->data_size < data_len) {
+               void *nbuf = realloc(d->data, data_len);
+               if (nbuf == NULL) {
+                       free(d->data);
+                       free(d);
+                       return -1;
+               }
+               d->data = nbuf;
+               d->data_size = data_len;
+       }
+       memcpy(d->data, data, data_len);
        d->data_len = data_len;
-       d->freeit = fit;
+
+queue:
        TAILQ_INSERT_TAIL(&fd->queue, d, next);
        eloop_event_add_w(fd->ctx->eloop, fd->fd, control_writeone, fd);
        return 0;
diff -r f093d611066d -r 5b3b46894a65 external/bsd/dhcpcd/dist/src/control.h
--- a/external/bsd/dhcpcd/dist/src/control.h    Wed Aug 21 17:06:36 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/control.h    Wed Aug 21 17:10:29 2019 +0000
@@ -31,14 +31,20 @@
 
 #include "dhcpcd.h"
 
+#if !defined(CTL_FREE_LIST)
+#define        CTL_FREE_LIST 1
+#elif CTL_FREE_LIST == 0
+#undef CTL_FREE_LIST
+#endif
+
 /* Limit queue size per fd */
 #define CONTROL_QUEUE_MAX      100
 
 struct fd_data {
        TAILQ_ENTRY(fd_data) next;
-       char *data;
+       void *data;
+       size_t data_size;
        size_t data_len;
-       uint8_t freeit;
 };
 TAILQ_HEAD(fd_data_head, fd_data);
 
@@ -48,7 +54,10 @@
        int fd;
        unsigned int flags;
        struct fd_data_head queue;
+       size_t queue_len;
+#ifdef CTL_FREE_LIST
        struct fd_data_head free_queue;
+#endif
 };
 TAILQ_HEAD(fd_list_head, fd_list);
 
@@ -59,7 +68,7 @@
 int control_stop(struct dhcpcd_ctx *);
 int control_open(const char *);
 ssize_t control_send(struct dhcpcd_ctx *, int, char * const *);
-int control_queue(struct fd_list *fd, char *data, size_t data_len, uint8_t fit);
+int control_queue(struct fd_list *, void *, size_t, bool);
 void control_close(struct dhcpcd_ctx *ctx);
 
 #endif
diff -r f093d611066d -r 5b3b46894a65 external/bsd/dhcpcd/dist/src/defs.h
--- a/external/bsd/dhcpcd/dist/src/defs.h       Wed Aug 21 17:06:36 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/defs.h       Wed Aug 21 17:10:29 2019 +0000
@@ -29,7 +29,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "8.0.2"
+#define VERSION                        "8.0.3"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r f093d611066d -r 5b3b46894a65 external/bsd/dhcpcd/dist/src/dhcp-common.c
--- a/external/bsd/dhcpcd/dist/src/dhcp-common.c        Wed Aug 21 17:06:36 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp-common.c        Wed Aug 21 17:10:29 2019 +0000
@@ -622,6 +622,7 @@
     int vname,
     const uint8_t *data, size_t dl, const char *ifname)
 {
+       fpos_t fp_pos;
        const uint8_t *e, *t;
        uint16_t u16;
        int16_t s16;
@@ -636,25 +637,32 @@
        if ((ssize_t)dl == -1)
                return 0;
 
+       if (fgetpos(fp, &fp_pos) == -1)
+               return -1;
        if (fprintf(fp, "%s", prefix) == -1)
-               return -1;
+               goto err;
+
+       /* We printed something, so always goto err from now-on
+        * to terminate the string. */
        if (vname) {
                if (fprintf(fp, "_%s", opt->var) == -1)
-                       return -1;
+                       goto err;
        }
        if (fputc('=', fp) == EOF)
-               return -1;
+               goto err;
        if (dl == 0)
-               return 1;



Home | Main Index | Thread Index | Old Index