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-5.1.1



details:   https://anonhg.NetBSD.org/src/rev/4b8f52ba6f2f
branches:  trunk
changeset: 747818:4b8f52ba6f2f
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Oct 02 21:31:01 2009 +0000

description:
Import dhcpcd-5.1.1

Changes from dhcpcd-5.0.7 include
* Only allow hardware families we know by default (over-ridable)
* Fix persistent and timeout 0 options
* Fix parsing of escape code sequencies
* Don't bring up interfaces brought down when handling new interfaces
* Allow un-encapsulated vendor option
* Don't null terminate gratuitously when handling quotes
* Fix various typos and grammatical errors
* dhcpcd.conf simplified a little

diffstat:

 external/bsd/dhcpcd/dist/arp.c            |    1 +
 external/bsd/dhcpcd/dist/bind.c           |    2 +
 external/bsd/dhcpcd/dist/common.c         |  115 +++++------------------------
 external/bsd/dhcpcd/dist/common.h         |   37 +--------
 external/bsd/dhcpcd/dist/compat/getline.c |   75 +++++++++++++++++++
 external/bsd/dhcpcd/dist/compat/getline.h |   36 +++++++++
 external/bsd/dhcpcd/dist/config.h         |   76 +------------------
 external/bsd/dhcpcd/dist/configure.c      |   11 +-
 external/bsd/dhcpcd/dist/control.c        |    1 +
 external/bsd/dhcpcd/dist/defs.h           |   52 +++++++++++++
 external/bsd/dhcpcd/dist/dhcpcd.c         |   38 +++++----
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in |    7 +-
 external/bsd/dhcpcd/dist/duid.c           |    1 +
 external/bsd/dhcpcd/dist/if-options.c     |   35 ++++++++-
 external/bsd/dhcpcd/dist/if-options.h     |    1 +
 external/bsd/dhcpcd/dist/if-pref.c        |    2 +
 external/bsd/dhcpcd/dist/ipv4ll.c         |    1 +
 external/bsd/dhcpcd/dist/net.c            |   43 +++++++++-
 18 files changed, 305 insertions(+), 229 deletions(-)

diffs (truncated from 868 to 300 lines):

diff -r ae05f3a31d20 -r 4b8f52ba6f2f external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Fri Oct 02 21:27:45 2009 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Fri Oct 02 21:31:01 2009 +0000
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <string.h>
 #include <syslog.h>
 #include <unistd.h>
 
diff -r ae05f3a31d20 -r 4b8f52ba6f2f external/bsd/dhcpcd/dist/bind.c
--- a/external/bsd/dhcpcd/dist/bind.c   Fri Oct 02 21:27:45 2009 +0000
+++ b/external/bsd/dhcpcd/dist/bind.c   Fri Oct 02 21:31:01 2009 +0000
@@ -26,6 +26,8 @@
  */
 
 #include <sys/param.h>
+#include <sys/time.h>
+
 #include <fcntl.h>
 #ifdef BSD
 #  include <paths.h>
diff -r ae05f3a31d20 -r 4b8f52ba6f2f external/bsd/dhcpcd/dist/common.c
--- a/external/bsd/dhcpcd/dist/common.c Fri Oct 02 21:27:45 2009 +0000
+++ b/external/bsd/dhcpcd/dist/common.c Fri Oct 02 21:31:01 2009 +0000
@@ -25,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+/* Needed define to get at getline for glibc and FreeBSD */
+#define _GNU_SOURCE
+
 #include <sys/cdefs.h>
 
 #ifdef __APPLE__
@@ -35,7 +38,9 @@
 #include <sys/param.h>
 #include <sys/time.h>
 
+#include <errno.h>
 #include <fcntl.h>
+#include <limits.h>
 #ifdef BSD
 #  include <paths.h>
 #endif
@@ -56,16 +61,19 @@
 int clock_monotonic;
 static char *lbuf;
 static size_t lbuf_len;
+#ifdef DEBUG_MEMORY
+static char lbuf_set;
+#endif
 
 #ifdef DEBUG_MEMORY
 static void
 free_lbuf(void)
 {
        free(lbuf);
+       lbuf = NULL;
 }
 #endif
 
-
 /* Handy routine to read very long lines in text files.
  * This means we read the whole line and avoid any nasty buffer overflows.
  * We strip leading space and avoid comment lines, making the code that calls
@@ -74,107 +82,28 @@
 char *
 get_line(FILE * __restrict fp)
 {
-       char *p, *e;
-       size_t last;
-
-again:
-       if (feof(fp))
-               return NULL;
+       char *p;
+       ssize_t bytes;
 
 #ifdef DEBUG_MEMORY
-       if (lbuf == NULL)
+       if (lbuf_set == 0) {
                atexit(free_lbuf);
+               lbuf_set = 1;
+       }
 #endif
 
-       last = 0;
        do {
-               if (lbuf == NULL || last != 0) {
-                       lbuf_len += BUFSIZ;
-                       lbuf = xrealloc(lbuf, lbuf_len);
-               }
-               p = lbuf + last;
-               memset(p, 0, BUFSIZ);
-               if (fgets(p, BUFSIZ, fp) == NULL)
-                       break;
-               last += strlen(p);
-               if (last != 0 && lbuf[last - 1] == '\n') {
-                       lbuf[last - 1] = '\0';
-                       break;
-               }
-       } while(!feof(fp));
-       if (last == 0)
-               return NULL;
-
-       e = p + last - 1;
-       for (p = lbuf; p < e; p++) {
-               if (*p != ' ' && *p != '\t')
-                       break;
-       }
-       if (p == e || *p == '#' || *p == ';')
-               goto again;
+               bytes = getline(&lbuf, &lbuf_len, fp);
+               if (bytes == -1)
+                       return NULL;
+               for (p = lbuf; *p == ' ' || *p == '\t'; p++)
+                       ;
+       } while (*p == '\0' || *p == '\n' || *p == '#' || *p == ';');
+       if (lbuf[--bytes] == '\n')
+               lbuf[bytes] = '\0';
        return p;
 }
 
-/* Simple hack to return a random number without arc4random */
-#ifndef HAVE_ARC4RANDOM
-uint32_t arc4random(void)
-{
-       int fd;
-       static unsigned long seed;
-
-       if (seed == 0) {
-               fd = open("/dev/urandom", 0);
-               if (fd == -1 || read(fd,  &seed, sizeof(seed)) == -1)
-                       seed = time(0);
-               if (fd >= 0)
-                       close(fd);
-               srandom(seed);
-       }
-
-       return (uint32_t)random();
-}
-#endif
-
-/* strlcpy is nice, shame glibc does not define it */
-#if HAVE_STRLCPY
-#else
-size_t
-strlcpy(char *dst, const char *src, size_t size)
-{
-       const char *s = src;
-       size_t n = size;
-
-       if (n && --n)
-               do {
-                       if (!(*dst++ = *src++))
-                               break;
-               } while (--n);
-
-       if (!n) {
-               if (size)
-                       *dst = '\0';
-               while (*src++);
-       }
-
-       return src - s - 1;
-}
-#endif
-
-#if HAVE_CLOSEFROM
-#else
-int
-closefrom(int fd)
-{
-       int max = getdtablesize();
-       int i;
-       int r = 0;
-
-       for (i = fd; i < max; i++)
-               r += close(i);
-       return r;
-}
-#endif
-
 int
 set_cloexec(int fd)
 {
diff -r ae05f3a31d20 -r 4b8f52ba6f2f external/bsd/dhcpcd/dist/common.h
--- a/external/bsd/dhcpcd/dist/common.h Fri Oct 02 21:27:45 2009 +0000
+++ b/external/bsd/dhcpcd/dist/common.h Fri Oct 02 21:31:01 2009 +0000
@@ -28,12 +28,11 @@
 #ifndef COMMON_H
 #define COMMON_H
 
-/* string.h pulls in features.h so the below define checks work */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <stdint.h>
 #include <stdio.h>
-#include <string.h>
+#include <time.h>
+
+#include "config.h"
+#include "defs.h"
 
 #define UNCONST(a)             ((void *)(unsigned long)(const void *)(a))
 
@@ -68,34 +67,6 @@
 # endif
 #endif
 
-#ifndef HAVE_ARC4RANDOM
-# ifdef __GLIBC__
-uint32_t arc4random(void);
-#else
-# define HAVE_ARC4RANDOM
-# endif
-#endif
-
-#ifndef HAVE_STRLCPY
-#  define HAVE_STRLCPY 1
-#endif
-/* Only GLIBC doesn't support strlcpy */
-#ifdef __GLIBC__
-#  if !defined(__UCLIBC__) && !defined (__dietlibc__)
-#    undef HAVE_STRLCPY
-size_t strlcpy(char *, const char *, size_t);
-#  endif
-#endif
-
-#ifndef HAVE_CLOSEFROM
-# if defined(__NetBSD__) || defined(__OpenBSD__)
-#  define HAVE_CLOSEFROM 1
-# endif
-#endif
-#ifndef HAVE_CLOSEFROM
-int closefrom(int);
-#endif
-
 int set_cloexec(int);
 int set_nonblock(int);
 char *get_line(FILE * __restrict);
diff -r ae05f3a31d20 -r 4b8f52ba6f2f external/bsd/dhcpcd/dist/compat/getline.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/dhcpcd/dist/compat/getline.c Fri Oct 02 21:31:01 2009 +0000
@@ -0,0 +1,75 @@
+/* 
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2009 Roy Marples <roy%marples.name@localhost>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "getline.h"
+
+/* Redefine a small buffer for our simple text config files */
+#undef BUFSIZ
+#define BUFSIZ 128
+
+ssize_t
+getline(char ** __restrict buf, size_t * __restrict buflen,
+    FILE * __restrict fp)
+{
+       size_t bytes, newlen;
+       char *newbuf, *p;
+       
+       if (buf == NULL || buflen == NULL) {
+               errno = EINVAL;
+               return -1;
+       }
+       if (*buf == NULL)
+               *buflen = 0;
+       



Home | Main Index | Thread Index | Old Index