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/5a1a106163d4
branches: trunk
changeset: 352915:5a1a106163d4
user: roy <roy%NetBSD.org@localhost>
date: Fri Apr 14 09:56:32 2017 +0000
description:
Sync
diffstat:
external/bsd/dhcpcd/dist/src/bpf.c | 26 +-
external/bsd/dhcpcd/dist/src/dhcpcd.c | 242 +++++++++----------
external/bsd/dhcpcd/dist/src/if-options.c | 318 ++++++++++++-------------
external/bsd/dhcpcd/dist/test/GNUmakefile | 7 -
external/bsd/dhcpcd/dist/test/Makefile | 35 --
external/bsd/dhcpcd/dist/test/test.c | 38 ---
external/bsd/dhcpcd/dist/test/test.h | 32 --
external/bsd/dhcpcd/dist/test/test_hmac_md5.c | 173 --------------
8 files changed, 292 insertions(+), 579 deletions(-)
diffs (truncated from 2288 to 300 lines):
diff -r 1e405590b78f -r 5a1a106163d4 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c Fri Apr 14 09:53:06 2017 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c Fri Apr 14 09:56:32 2017 +0000
@@ -48,13 +48,13 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include "common.h"
#include "arp.h"
#include "bpf.h"
#include "dhcp.h"
#include "if.h"
+#include "logerr.h"
#define ARP_ADDRS_MAX 3
@@ -150,7 +150,7 @@
goto eexit;
if (pv.bv_major != BPF_MAJOR_VERSION ||
pv.bv_minor < BPF_MINOR_VERSION) {
- syslog(LOG_ERR, "BPF version mismatch - recompile");
+ logerrx("BPF version mismatch - recompile");
goto eexit;
}
@@ -174,7 +174,6 @@
goto eexit;
state->buffer = nb;
state->buffer_size = buf_len;
- state->buffer_len = state->buffer_pos = 0;
}
#ifdef BIOCIMMEDIATE
@@ -222,8 +221,6 @@
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. */
@@ -288,6 +285,16 @@
}
#endif
+int
+bpf_close(struct interface *ifp, int fd)
+{
+ struct ipv4_state *state = IPV4_STATE(ifp);
+
+ /* Rewind the buffer on closing. */
+ state->buffer_len = state->buffer_pos = 0;
+ return close(fd);
+}
+
static unsigned int
bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off,
bool equal, uint8_t *hwaddr, size_t hwaddr_len)
@@ -428,6 +435,7 @@
struct bpf_insn bpf[3+ bpf_arp_filter_len + bpf_arp_hw + bpf_arp_extra];
struct bpf_insn *bp;
struct iarp_state *state;
+ uint16_t arp_len;
if (fd == -1)
return 0;
@@ -438,6 +446,7 @@
case ARPHRD_ETHER:
memcpy(bp, bpf_arp_ether, sizeof(bpf_arp_ether));
bp += bpf_arp_ether_len;
+ arp_len = sizeof(struct ether_header)+sizeof(struct ether_arp);
break;
default:
errno = EINVAL;
@@ -465,13 +474,13 @@
TAILQ_FOREACH(astate, &state->arp_states, next) {
if (++naddrs > ARP_ADDRS_MAX) {
errno = ENOBUFS;
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
break;
}
BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
htonl(astate->addr.s_addr), 0, 1);
bp++;
- BPF_SET_STMT(bp, BPF_RET + BPF_K, BPF_WHOLEPACKET);
+ BPF_SET_STMT(bp, BPF_RET + BPF_K, arp_len);
bp++;
}
@@ -496,8 +505,7 @@
BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
htonl(astate->addr.s_addr), 0, 1);
bp++;
- BPF_SET_STMT(bp, BPF_RET + BPF_K,
- BPF_WHOLEPACKET);
+ BPF_SET_STMT(bp, BPF_RET + BPF_K, arp_len);
bp++;
}
diff -r 1e405590b78f -r 5a1a106163d4 external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c Fri Apr 14 09:53:06 2017 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c Fri Apr 14 09:56:32 2017 +0000
@@ -44,7 +44,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <time.h>
@@ -63,6 +62,7 @@
#include "ipv4ll.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "script.h"
#ifdef HAVE_UTIL_H
@@ -173,7 +173,7 @@
struct dhcpcd_ctx *ctx;
ctx = arg;
- syslog(LOG_ERR, "timed out");
+ logerrx("timed out");
if (!(ctx->options & DHCPCD_MASTER)) {
eloop_exit(ctx->eloop, EXIT_FAILURE);
return;
@@ -258,16 +258,14 @@
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
- syslog(LOG_DEBUG,
- "%s: waiting for an %s address",
+ logdebugx("%s: waiting for an %s address",
ifp->name, dhcpcd_af(af));
return 0;
}
}
if ((af = dhcpcd_afwaiting(ctx)) != AF_MAX) {
- syslog(LOG_DEBUG,
- "waiting for an %s address",
+ logdebugx("waiting for an %s address",
dhcpcd_af(af));
return 0;
}
@@ -296,7 +294,7 @@
}
if (ctx->options & DHCPCD_ONESHOT) {
- syslog(LOG_INFO, "exiting due to oneshot");
+ loginfox("exiting due to oneshot");
eloop_exit(ctx->eloop, EXIT_SUCCESS);
return 0;
}
@@ -305,11 +303,11 @@
if (ctx->options & DHCPCD_DAEMONISED ||
!(ctx->options & DHCPCD_DAEMONISE))
return 0;
- syslog(LOG_DEBUG, "forking to background");
+ logdebugx("forking to background");
/* Setup a signal pipe so parent knows when to exit. */
if (pipe(sidpipe) == -1) {
- syslog(LOG_ERR, "pipe: %m");
+ logerr("%s: pipe", __func__);
return 0;
}
@@ -322,22 +320,21 @@
switch (pid = fork()) {
case -1:
- syslog(LOG_ERR, "fork: %m");
+ logerr("%s: fork", __func__);
return 0;
case 0:
if ((lpid = pidfile_lock(ctx->pidfile)) != 0)
- syslog(LOG_ERR, "%s: pidfile_lock %d: %m",
- __func__, lpid);
+ logerr("%s: pidfile_lock %d", __func__, lpid);
setsid();
/* Notify parent it's safe to exit as we've detached. */
close(sidpipe[0]);
if (write(sidpipe[1], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to notify parent: %m");
+ logerr("%s: write", __func__);
close(sidpipe[1]);
/* Some polling methods don't survive after forking,
* so ensure we can requeue all our events. */
if (eloop_requeue(ctx->eloop) == -1) {
- syslog(LOG_ERR, "eloop_requeue: %m");
+ logerr("%s: eloop_requeue", __func__);
eloop_exit(ctx->eloop, EXIT_FAILURE);
}
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
@@ -352,9 +349,9 @@
/* Wait for child to detach */
close(sidpipe[1]);
if (read(sidpipe[0], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to read child: %m");
+ logerr("%s: read", __func__);
close(sidpipe[0]);
- syslog(LOG_INFO, "forked to background, child pid %d", pid);
+ loginfox("forked to background, child pid %d", pid);
ctx->options |= DHCPCD_FORKED;
eloop_exit(ctx->eloop, EXIT_SUCCESS);
return pid;
@@ -380,7 +377,7 @@
struct dhcpcd_ctx *ctx;
ctx = ifp->ctx;
- syslog(LOG_INFO, "%s: removing interface", ifp->name);
+ loginfox("%s: removing interface", ifp->name);
ifp->options->options |= DHCPCD_STOPPING;
dhcpcd_drop(ifp, 1);
@@ -518,7 +515,7 @@
{
ifo->ia = malloc(sizeof(*ifo->ia));
if (ifo->ia == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
else {
ifo->ia_len = 1;
ifo->ia->ia_type = D6_OPTION_IA_NA;
@@ -553,20 +550,19 @@
r = print_string(pssid, sizeof(pssid), OT_ESCSTRING,
ifp->ssid, ifp->ssid_len);
if (r == -1) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logerr(__func__);
pssid[0] = '\0';
}
} else
pssid[0] = '\0';
ifo = read_config(ifp->ctx, ifp->name, pssid, profile);
if (ifo == NULL) {
- syslog(LOG_DEBUG, "%s: no profile %s", ifp->name, profile);
+ logdebugx("%s: no profile %s", ifp->name, profile);
return -1;
}
if (profile != NULL) {
strlcpy(ifp->profile, profile, sizeof(ifp->profile));
- syslog(LOG_INFO, "%s: selected profile %s",
- ifp->name, profile);
+ loginfox("%s: selected profile %s", ifp->name, profile);
} else
*ifp->profile = '\0';
@@ -599,8 +595,8 @@
/* If the mtime has changed drop any old lease */
if (old != 0 && ifp->options->mtime != old) {
- syslog(LOG_WARNING,
- "%s: confile file changed, expiring leases", ifp->name);
+ logwarnx("%s: confile file changed, expiring leases",
+ ifp->name);
dhcpcd_drop(ifp, 0);
}
}
@@ -631,7 +627,7 @@
if (options) {
if ((ifo = default_config(ifp->ctx)) == NULL) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logerr(__func__);
return;
}
ifo->options |= options;
@@ -641,7 +637,7 @@
ifo = ifp->options;
if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == -1) {
- syslog(LOG_ERR, "ipv6_init: %m");
+ logerr(__func__);
ifo->options &= ~DHCPCD_IPV6;
}
}
@@ -700,11 +696,11 @@
if (carrier == LINK_UNKNOWN) {
if (errno != ENOTTY) /* For example a PPP link on BSD */
- syslog(LOG_ERR, "%s: carrier_status: %m", ifname);
+ logerr("%s: %s", ifp->name, __func__);
} else if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
if (ifp->carrier != LINK_DOWN) {
if (ifp->carrier == LINK_UP)
- syslog(LOG_INFO, "%s: carrier lost", ifp->name);
+ loginfox("%s: carrier lost", ifp->name);
ifp->carrier = LINK_DOWN;
script_runreason(ifp, "NOCARRIER");
#ifdef NOCARRIER_PRESERVE_IP
@@ -719,7 +715,7 @@
}
} else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
Home |
Main Index |
Thread Index |
Old Index