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/99390cd1d7f7
branches:  trunk
changeset: 329950:99390cd1d7f7
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Jun 14 20:55:37 2014 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/bpf-filter.h     |    8 +-
 external/bsd/dhcpcd/dist/bpf.c            |  219 --------
 external/bsd/dhcpcd/dist/dhcp.c           |  415 +++++++++------
 external/bsd/dhcpcd/dist/dhcpcd.8.in      |   41 +-
 external/bsd/dhcpcd/dist/dhcpcd.c         |  338 +++++++----
 external/bsd/dhcpcd/dist/dhcpcd.conf      |    5 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in |   53 +-
 external/bsd/dhcpcd/dist/if-bsd.c         |  811 ++++++++++++++++++++++++-----
 external/bsd/dhcpcd/dist/if-options.c     |  253 ++++++--
 external/bsd/dhcpcd/dist/if-pref.c        |  108 ---
 external/bsd/dhcpcd/dist/if-pref.h        |   36 -
 external/bsd/dhcpcd/dist/ipv6nd.c         |  532 ++++++++++--------
 external/bsd/dhcpcd/dist/net.c            |  566 --------------------
 external/bsd/dhcpcd/dist/net.h            |  103 ---
 external/bsd/dhcpcd/dist/platform-bsd.c   |  173 ------
 external/bsd/dhcpcd/dist/platform.h       |   43 -
 external/bsd/dhcpcd/dist/script.c         |  215 ++++---
 17 files changed, 1776 insertions(+), 2143 deletions(-)

diffs (truncated from 6450 to 300 lines):

diff -r aca5f4f4a810 -r 99390cd1d7f7 external/bsd/dhcpcd/dist/bpf-filter.h
--- a/external/bsd/dhcpcd/dist/bpf-filter.h     Sat Jun 14 20:51:03 2014 +0000
+++ b/external/bsd/dhcpcd/dist/bpf-filter.h     Sat Jun 14 20:55:37 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf-filter.h,v 1.3 2013/06/21 19:40:20 roy Exp $ */
+/* $NetBSD: bpf-filter.h,v 1.4 2014/06/14 20:55:37 roy Exp $ */
 
 /*
  * dhcpcd - DHCP client daemon
@@ -49,8 +49,7 @@
        /* Otherwise, drop it. */
        BPF_STMT(BPF_RET + BPF_K, 0),
 };
-static const size_t arp_bpf_filter_len =
-    sizeof(arp_bpf_filter) / sizeof(arp_bpf_filter[0]);
+#define arp_bpf_filter_len sizeof(arp_bpf_filter) / sizeof(arp_bpf_filter[0])
 
 
 /* dhcp_bpf_filter taken from bpf.c in dhcp-3.1.0
@@ -99,5 +98,4 @@
        /* Otherwise, drop it. */
        BPF_STMT(BPF_RET + BPF_K, 0),
 };
-static const size_t dhcp_bpf_filter_len =
-    sizeof(dhcp_bpf_filter) / sizeof(dhcp_bpf_filter[0]);
+#define dhcp_bpf_filter_len sizeof(dhcp_bpf_filter) / sizeof(dhcp_bpf_filter[0])
diff -r aca5f4f4a810 -r 99390cd1d7f7 external/bsd/dhcpcd/dist/bpf.c
--- a/external/bsd/dhcpcd/dist/bpf.c    Sat Jun 14 20:51:03 2014 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-#include <sys/cdefs.h>
- __RCSID("$NetBSD: bpf.c,v 1.1.1.9 2014/03/14 11:27:36 roy Exp $");
-
-/*
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2014 Roy Marples <roy%marples.name@localhost>
- *
- * 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 <sys/types.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <net/bpf.h>
-#include <net/if.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "common.h"
-#include "dhcp.h"
-#include "ipv4.h"
-#include "bpf-filter.h"
-
-int
-ipv4_opensocket(struct interface *ifp, int protocol)
-{
-       struct dhcp_state *state;
-       int fd = -1;
-       struct ifreq ifr;
-       int buf_len = 0;
-       struct bpf_version pv;
-       struct bpf_program pf;
-#ifdef BIOCIMMEDIATE
-       int flags;
-#endif
-#ifdef _PATH_BPF
-       fd = open(_PATH_BPF, O_RDWR | O_CLOEXEC | O_NONBLOCK);
-#else
-       char device[32];
-       int n = 0;
-
-       do {
-               snprintf(device, sizeof(device), "/dev/bpf%d", n++);
-               fd = open(device, O_RDWR | O_CLOEXEC | O_NONBLOCK);
-       } while (fd == -1 && errno == EBUSY);
-#endif
-
-       if (fd == -1)
-               return -1;
-
-       state = D_STATE(ifp);
-
-       if (ioctl(fd, BIOCVERSION, &pv) == -1)
-               goto eexit;
-       if (pv.bv_major != BPF_MAJOR_VERSION ||
-           pv.bv_minor < BPF_MINOR_VERSION) {
-               syslog(LOG_ERR, "BPF version mismatch - recompile");
-               goto eexit;
-       }
-
-       memset(&ifr, 0, sizeof(ifr));
-       strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
-       if (ioctl(fd, BIOCSETIF, &ifr) == -1)
-               goto eexit;
-
-       /* Get the required BPF buffer length from the kernel. */
-       if (ioctl(fd, BIOCGBLEN, &buf_len) == -1)
-               goto eexit;
-       if (state->buffer_size != (size_t)buf_len) {
-               free(state->buffer);
-               state->buffer = malloc(buf_len);
-               if (state->buffer == NULL)
-                       goto eexit;
-               state->buffer_size = buf_len;
-               state->buffer_len = state->buffer_pos = 0;
-       }
-
-#ifdef BIOCIMMEDIATE
-       flags = 1;
-       if (ioctl(fd, BIOCIMMEDIATE, &flags) == -1)
-               goto eexit;
-#endif
-
-       /* Install the DHCP filter */
-       if (protocol == ETHERTYPE_ARP) {
-               pf.bf_insns = UNCONST(arp_bpf_filter);
-               pf.bf_len = arp_bpf_filter_len;
-       } else {
-               pf.bf_insns = UNCONST(dhcp_bpf_filter);
-               pf.bf_len = dhcp_bpf_filter_len;
-       }
-       if (ioctl(fd, BIOCSETF, &pf) == -1)
-               goto eexit;
-
-#ifdef __OpenBSD__
-       /* For some reason OpenBSD fails to open the fd as non blocking */
-       if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
-           fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
-               goto eexit;
-#endif
-
-       return fd;
-
-eexit:
-       free(state->buffer);
-       state->buffer = NULL;
-       close(fd);
-       return -1;
-}
-
-ssize_t
-ipv4_sendrawpacket(const struct interface *ifp, int protocol,
-    const void *data, ssize_t len)
-{
-       struct iovec iov[2];
-       struct ether_header hw;
-       int fd;
-       const struct dhcp_state *state;
-
-       memset(&hw, 0, ETHER_HDR_LEN);
-       memset(&hw.ether_dhost, 0xff, ETHER_ADDR_LEN);
-       hw.ether_type = htons(protocol);
-       iov[0].iov_base = &hw;
-       iov[0].iov_len = ETHER_HDR_LEN;
-       iov[1].iov_base = UNCONST(data);
-       iov[1].iov_len = len;
-       state = D_CSTATE(ifp);
-       if (protocol == ETHERTYPE_ARP)
-               fd = state->arp_fd;
-       else
-               fd = state->raw_fd;
-       return writev(fd, iov, 2);
-}
-
-/* BPF requires that we read the entire buffer.
- * So we pass the buffer in the API so we can loop on >1 packet. */
-ssize_t
-ipv4_getrawpacket(struct interface *ifp, int protocol,
-    void *data, ssize_t len, int *partialcsum)
-{
-       int fd = -1;
-       struct bpf_hdr packet;
-       ssize_t bytes;
-       const unsigned char *payload;
-       struct dhcp_state *state;
-
-       state = D_STATE(ifp);
-       if (protocol == ETHERTYPE_ARP)
-               fd = state->arp_fd;
-       else
-               fd = state->raw_fd;
-
-       if (partialcsum != NULL)
-               *partialcsum = 0; /* Not supported on BSD */
-
-       for (;;) {
-               if (state->buffer_len == 0) {
-                       bytes = read(fd, state->buffer, state->buffer_size);
-                       if (bytes == -1)
-                               return errno == EAGAIN ? 0 : -1;
-                       else if ((size_t)bytes < sizeof(packet))
-                               return -1;
-                       state->buffer_len = bytes;
-                       state->buffer_pos = 0;
-               }
-               bytes = -1;
-               memcpy(&packet, state->buffer + state->buffer_pos,
-                   sizeof(packet));
-               if (packet.bh_caplen != packet.bh_datalen)
-                       goto next; /* Incomplete packet, drop. */
-               if (state->buffer_pos + packet.bh_caplen + packet.bh_hdrlen >
-                   state->buffer_len)
-                       goto next; /* Packet beyond buffer, drop. */
-               payload = state->buffer + state->buffer_pos +
-                   packet.bh_hdrlen + ETHER_HDR_LEN;
-               bytes = packet.bh_caplen - ETHER_HDR_LEN;
-               if (bytes > len)
-                       bytes = len;
-               memcpy(data, payload, bytes);
-next:
-               state->buffer_pos += BPF_WORDALIGN(packet.bh_hdrlen +
-                   packet.bh_caplen);
-               if (state->buffer_pos >= state->buffer_len)
-                       state->buffer_len = state->buffer_pos = 0;
-               if (bytes != -1)
-                       return bytes;
-       }
-}
diff -r aca5f4f4a810 -r 99390cd1d7f7 external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c   Sat Jun 14 20:51:03 2014 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c   Sat Jun 14 20:55:37 2014 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp.c,v 1.12 2014/03/14 11:31:11 roy Exp $");
+ __RCSID("$NetBSD: dhcp.c,v 1.13 2014/06/14 20:55:37 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -38,8 +38,9 @@
 #endif
 
 #include <arpa/inet.h>
+#include <net/if.h>
 #include <net/route.h>
-
+#include <netinet/if_ether.h>
 #include <netinet/in_systm.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
@@ -65,6 +66,7 @@
 #include "dhcp-common.h"
 #include "duid.h"
 #include "eloop.h"
+#include "if.h"
 #include "ipv4.h"
 #include "ipv4ll.h"
 #include "script.h"
@@ -83,6 +85,10 @@
 #define RELEASE_DELAY_S                0
 #define RELEASE_DELAY_NS       10000000
 
+#ifndef IPDEFTTL
+#define IPDEFTTL 64 /* RFC1340 */
+#endif
+
 struct dhcp_op {
        uint8_t value;
        const char *name;
@@ -138,7 +144,7 @@
 #define get_option_raw(ctx, dhcp, opt) get_option(ctx, dhcp, opt, NULL)
 static const uint8_t *
 get_option(struct dhcpcd_ctx *ctx,
-    const struct dhcp_message *dhcp, uint8_t opt, int *len)
+    const struct dhcp_message *dhcp, unsigned int opt, size_t *len)
 {
        const uint8_t *p = dhcp->options;
        const uint8_t *e = p + sizeof(dhcp->options);
@@ -147,7 +153,7 @@
        uint8_t overl = 0;



Home | Main Index | Thread Index | Old Index