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 Sync



details:   https://anonhg.NetBSD.org/src/rev/da217d14a6d4
branches:  trunk
changeset: 336886:da217d14a6d4
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Mar 26 10:26:37 2015 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/arp.c                  |   39 +-
 external/bsd/dhcpcd/dist/auth.c                 |    3 +-
 external/bsd/dhcpcd/dist/common.c               |  178 +++++-
 external/bsd/dhcpcd/dist/common.h               |  108 +++-
 external/bsd/dhcpcd/dist/config.h               |    4 +-
 external/bsd/dhcpcd/dist/control.c              |    9 +-
 external/bsd/dhcpcd/dist/defs.h                 |    8 +-
 external/bsd/dhcpcd/dist/dhcp-common.c          |   83 ++-
 external/bsd/dhcpcd/dist/dhcp-common.h          |   14 +-
 external/bsd/dhcpcd/dist/dhcp.c                 |  554 ++++++++++---------
 external/bsd/dhcpcd/dist/dhcp.h                 |    5 +-
 external/bsd/dhcpcd/dist/dhcp6.c                |  531 ++++++++++---------
 external/bsd/dhcpcd/dist/dhcp6.h                |    7 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.c      |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind |   15 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in    |   40 +-
 external/bsd/dhcpcd/dist/dhcpcd.8.in            |   31 +-
 external/bsd/dhcpcd/dist/dhcpcd.c               |  376 +++++++------
 external/bsd/dhcpcd/dist/dhcpcd.conf            |    4 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in       |   16 +-
 external/bsd/dhcpcd/dist/dhcpcd.h               |   26 +-
 external/bsd/dhcpcd/dist/duid.c                 |   20 +-
 external/bsd/dhcpcd/dist/eloop.c                |  380 +++++++++++--
 external/bsd/dhcpcd/dist/eloop.h                |   27 +-
 external/bsd/dhcpcd/dist/if-bsd.c               |  657 ++++++++++++++++-------
 external/bsd/dhcpcd/dist/if-options.c           |  441 ++++++++--------
 external/bsd/dhcpcd/dist/if-options.h           |    8 +-
 external/bsd/dhcpcd/dist/if.c                   |  120 +++-
 external/bsd/dhcpcd/dist/if.h                   |   52 +-
 external/bsd/dhcpcd/dist/ipv4.c                 |  388 ++++++++------
 external/bsd/dhcpcd/dist/ipv4.h                 |   11 +-
 external/bsd/dhcpcd/dist/ipv4ll.c               |   18 +-
 external/bsd/dhcpcd/dist/ipv4ll.h               |    4 +-
 external/bsd/dhcpcd/dist/ipv6.c                 |  360 +++++++-----
 external/bsd/dhcpcd/dist/ipv6.h                 |   46 +-
 external/bsd/dhcpcd/dist/ipv6nd.c               |  267 +++++----
 external/bsd/dhcpcd/dist/ipv6nd.h               |    6 +-
 external/bsd/dhcpcd/dist/script.c               |   40 +-
 external/bsd/dhcpcd/dist/script.h               |    4 +-
 39 files changed, 3045 insertions(+), 1861 deletions(-)

diffs (truncated from 11742 to 300 lines):

diff -r f705591c15c1 -r da217d14a6d4 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Thu Mar 26 10:20:41 2015 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Thu Mar 26 10:26:37 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: arp.c,v 1.9 2015/01/30 09:47:05 roy Exp $");
+ __RCSID("$NetBSD: arp.c,v 1.10 2015/03/26 10:26:37 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -39,7 +39,6 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 5
@@ -102,7 +101,7 @@
 {
        char buf[HWADDR_LEN * 3];
 
-       syslog(LOG_ERR, "%s: hardware address %s claims %s",
+       logger(astate->iface->ctx, LOG_ERR, "%s: hardware address %s claims %s",
            astate->iface->name,
            hwaddr_ntoa(amsg->sha, astate->iface->hwlen, buf, sizeof(buf)),
            inet_ntoa(astate->failed));
@@ -128,8 +127,8 @@
                bytes = if_readrawpacket(ifp, ETHERTYPE_ARP,
                    arp_buffer, sizeof(arp_buffer), &flags);
                if (bytes == -1) {
-                       syslog(LOG_ERR, "%s: arp if_readrawpacket: %m",
-                           ifp->name);
+                       logger(ifp->ctx, LOG_ERR,
+                           "%s: arp if_readrawpacket: %m", ifp->name);
                        dhcp_close(ifp);
                        return;
                }
@@ -187,7 +186,8 @@
        if (state->arp_fd == -1) {
                state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
                if (state->arp_fd == -1) {
-                       syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+                       logger(ifp->ctx, LOG_ERR, "%s: %s: %m",
+                           __func__, ifp->name);
                        return;
                }
                eloop_event_add(ifp->ctx->eloop, state->arp_fd,
@@ -216,19 +216,19 @@
        struct interface *ifp = astate->iface;
 
        if (++astate->claims < ANNOUNCE_NUM)
-               syslog(LOG_DEBUG,
+               logger(ifp->ctx, LOG_DEBUG,
                    "%s: ARP announcing %s (%d of %d), "
                    "next in %d.0 seconds",
                    ifp->name, inet_ntoa(astate->addr),
                    astate->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
        else
-               syslog(LOG_DEBUG,
+               logger(ifp->ctx, LOG_DEBUG,
                    "%s: ARP announcing %s (%d of %d)",
                    ifp->name, inet_ntoa(astate->addr),
                    astate->claims, ANNOUNCE_NUM);
        if (arp_send(ifp, ARPOP_REQUEST,
                astate->addr.s_addr, astate->addr.s_addr) == -1)
-               syslog(LOG_ERR, "send_arp: %m");
+               logger(ifp->ctx, LOG_ERR, "send_arp: %m");
        eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
            astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
            astate);
@@ -256,26 +256,26 @@
 {
        struct arp_state *astate = arg;
        struct interface *ifp = astate->iface;
-       struct timeval tv;
+       struct timespec tv;
 
        if (++astate->probes < PROBE_NUM) {
                tv.tv_sec = PROBE_MIN;
-               tv.tv_usec = (suseconds_t)arc4random_uniform(
-                   (PROBE_MAX - PROBE_MIN) * 1000000);
-               timernorm(&tv);
+               tv.tv_nsec = (suseconds_t)arc4random_uniform(
+                   (PROBE_MAX - PROBE_MIN) * NSEC_PER_SEC);
+               timespecnorm(&tv);
                eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probe1, astate);
        } else {
                tv.tv_sec = ANNOUNCE_WAIT;
-               tv.tv_usec = 0;
+               tv.tv_nsec = 0;
                eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate);
        }
-       syslog(LOG_DEBUG,
+       logger(ifp->ctx, LOG_DEBUG,
            "%s: ARP probing %s (%d of %d), next in %0.1f seconds",
            ifp->name, inet_ntoa(astate->addr),
            astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM,
-           timeval_to_double(&tv));
+           timespec_to_double(&tv));
        if (arp_send(ifp, ARPOP_REQUEST, 0, astate->addr.s_addr) == -1)
-               syslog(LOG_ERR, "send_arp: %m");
+               logger(ifp->ctx, LOG_ERR, "send_arp: %m");
 }
 
 void
@@ -284,12 +284,11 @@
 
        arp_open(astate->iface);
        astate->probes = 0;
-       syslog(LOG_DEBUG, "%s: probing for %s",
+       logger(astate->iface->ctx, LOG_DEBUG, "%s: probing for %s",
            astate->iface->name, inet_ntoa(astate->addr));
        arp_probe1(astate);
 }
 
-
 struct arp_state *
 arp_new(struct interface *ifp) {
        struct arp_state *astate;
@@ -297,7 +296,7 @@
 
        astate = calloc(1, sizeof(*astate));
        if (astate == NULL) {
-               syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+               logger(ifp->ctx, LOG_ERR, "%s: %s: %m", ifp->name, __func__);
                return NULL;
        }
 
diff -r f705591c15c1 -r da217d14a6d4 external/bsd/dhcpcd/dist/auth.c
--- a/external/bsd/dhcpcd/dist/auth.c   Thu Mar 26 10:20:41 2015 +0000
+++ b/external/bsd/dhcpcd/dist/auth.c   Thu Mar 26 10:26:37 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: auth.c,v 1.8 2015/01/30 09:47:05 roy Exp $");
+ __RCSID("$NetBSD: auth.c,v 1.9 2015/03/26 10:26:37 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -35,7 +35,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
diff -r f705591c15c1 -r da217d14a6d4 external/bsd/dhcpcd/dist/common.c
--- a/external/bsd/dhcpcd/dist/common.c Thu Mar 26 10:20:41 2015 +0000
+++ b/external/bsd/dhcpcd/dist/common.c Thu Mar 26 10:26:37 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: common.c,v 1.8 2015/01/30 09:47:05 roy Exp $");
+ __RCSID("$NetBSD: common.c,v 1.9 2015/03/26 10:26:37 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -42,12 +42,14 @@
 #include <sys/time.h>
 
 #include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #ifdef BSD
 #  include <paths.h>
 #endif
+#include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -57,6 +59,8 @@
 #include <unistd.h>
 
 #include "common.h"
+#include "dhcpcd.h"
+#include "if-options.h"
 
 #ifndef _PATH_DEVNULL
 #  define _PATH_DEVNULL "/dev/null"
@@ -92,18 +96,12 @@
  */
 #define NO_MONOTONIC "host does not support a monotonic clock - timing can skew"
 int
-get_monotonic(struct timeval *tp)
+get_monotonic(struct timespec *ts)
 {
-#if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC)
-       struct timespec ts;
 
-       if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
-               tp->tv_sec = ts.tv_sec;
-               tp->tv_usec = (suseconds_t)(ts.tv_nsec / 1000);
-               return 0;
-       }
+#if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC)
+       return clock_gettime(CLOCK_MONOTONIC, ts);
 #elif defined(__APPLE__)
-#define NSEC_PER_SEC 1000000000
        /* We can use mach kernel functions here.
         * This is crap though - why can't they implement clock_gettime?*/
        static struct mach_timebase_info info = { 0, 0 };
@@ -121,13 +119,12 @@
                nano = mach_absolute_time();
                if ((info.denom != 1 || info.numer != 1) && factor != 0.0)
                        nano *= factor;
-               tp->tv_sec = nano / NSEC_PER_SEC;
-               rem = nano % NSEC_PER_SEC;
-               if (rem < 0) {
-                       tp->tv_sec--;
-                       rem += NSEC_PER_SEC;
+               ts->tv_sec = nano / NSEC_PER_SEC;
+               ts->tv_nsec = nano % NSEC_PER_SEC;
+               if (ts->tv_nsec < 0) {
+                       ts->tv_sec--;
+                       ts->tv_nsec += NSEC_PER_SEC;
                }
-               tp->tv_usec = rem / 1000;
                return 0;
        }
 #endif
@@ -135,15 +132,149 @@
 #if 0
        /* Something above failed, so fall back to gettimeofday */
        if (!posix_clock_set) {
-               syslog(LOG_WARNING, NO_MONOTONIC);
+               logger(NULL, LOG_WARNING, NO_MONOTONIC);
                posix_clock_set = 1;
        }
 #endif
-       return gettimeofday(tp, NULL);
+       {
+               struct timeval tv;
+               if (gettimeofday(&tv, NULL) == 0) {
+                       TIMEVAL_TO_TIMESPEC(&tv, ts);
+                       return 0;
+               }
+       }
+
+       return -1;
+}
+
+#if USE_LOGFILE
+void
+logger_open(struct dhcpcd_ctx *ctx)
+{
+
+       if (ctx->logfile) {
+               int f = O_CREAT | O_APPEND | O_TRUNC;
+
+#ifdef O_CLOEXEC
+               f |= O_CLOEXEC;
+#endif
+               ctx->log_fd = open(ctx->logfile, O_WRONLY | f, 0644);
+               if (ctx->log_fd == -1)
+                       warn("open: %s", ctx->logfile);
+#ifndef O_CLOEXEC
+               else {
+                       if (fcntl(ctx->log_fd, F_GETFD, &f) == -1 ||
+                           fcntl(ctx->log_fd, F_SETFD, f | FD_CLOEXEC) == -1)
+                               warn("fcntl: %s", ctx->logfile);
+               }
+#endif
+       } else
+               openlog(PACKAGE, LOG_PID, LOG_DAEMON);
+}
+
+void
+logger_close(struct dhcpcd_ctx *ctx)
+{
+
+       if (ctx->log_fd != -1) {
+               close(ctx->log_fd);
+               ctx->log_fd = -1;
+       }
+       closelog();
 }
 
+void
+logger(struct dhcpcd_ctx *ctx, int pri, const char *fmt, ...)
+{
+       va_list va;
+       int serrno;
+#ifndef HAVE_PRINTF_M
+       char fmt_cpy[1024];
+#endif
+
+       serrno = errno;
+       va_start(va, fmt);
+
+       if (pri >= LOG_DEBUG && ctx && !(ctx->options & DHCPCD_DEBUG))
+               return;
+
+#ifndef HAVE_PRINTF_M
+       /* Print strerrno(errno) in place of %m */
+       if (ctx == NULL || !(ctx->options & DHCPCD_QUIET) || ctx->log_fd != -1)
+       {
+               const char *p;
+               char *fp = fmt_cpy, *serr = NULL;



Home | Main Index | Thread Index | Old Index