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/de3bf05d60ae
branches: trunk
changeset: 356342:de3bf05d60ae
user: roy <roy%NetBSD.org@localhost>
date: Tue Sep 19 19:19:21 2017 +0000
description:
Sync
diffstat:
external/bsd/dhcpcd/dist/.gitignore | 3 +
external/bsd/dhcpcd/dist/src/bpf.c | 16 +-
external/bsd/dhcpcd/dist/src/dhcp.c | 333 +++++++++++++++++------------
external/bsd/dhcpcd/dist/src/dhcpcd.c | 32 +-
external/bsd/dhcpcd/dist/src/if-options.c | 13 +-
5 files changed, 243 insertions(+), 154 deletions(-)
diffs (truncated from 898 to 300 lines):
diff -r 83d2dcca7179 -r de3bf05d60ae external/bsd/dhcpcd/dist/.gitignore
--- a/external/bsd/dhcpcd/dist/.gitignore Tue Sep 19 19:16:48 2017 +0000
+++ b/external/bsd/dhcpcd/dist/.gitignore Tue Sep 19 19:19:21 2017 +0000
@@ -24,5 +24,8 @@
# Ignore distribution
dhcpcd*.xz*
+# Ignore swap files
+*.swp
+
# Ignore Coverity
cov-int
diff -r 83d2dcca7179 -r de3bf05d60ae external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c Tue Sep 19 19:16:48 2017 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c Tue Sep 19 19:19:21 2017 +0000
@@ -166,7 +166,9 @@
if (ioctl(fd, BIOCGBLEN, &ibuf_len) == -1)
goto eexit;
buf_len = (size_t)ibuf_len;
- state = IPV4_STATE(ifp);
+ state = ipv4_getstate(ifp);
+ if (state == NULL)
+ goto eexit;
if (state->buffer_size != buf_len) {
void *nb;
@@ -241,7 +243,7 @@
return bytes;
}
- return bytes;
+ /* NOTREACHED */
}
int
@@ -295,6 +297,9 @@
return close(fd);
}
+/* Normally this is needed by bootp.
+ * Once that uses this again, the ARP guard here can be removed. */
+#ifdef ARP
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)
@@ -378,6 +383,7 @@
return (unsigned int)(bp - bpf);
}
+#endif
#ifdef ARP
@@ -589,6 +595,7 @@
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTREPLY, 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
};
+
#define BPF_BOOTP_FILTER_LEN __arraycount(bpf_bootp_filter)
#define BPF_BOOTP_CHADDR_LEN ((BOOTP_CHADDR_LEN / 4) * 3)
#define BPF_BOOTP_XID_LEN 4 /* BOUND check is 4 instructions */
@@ -599,7 +606,9 @@
int
bpf_bootp(struct interface *ifp, int fd)
{
+#if 0
const struct dhcp_state *state = D_CSTATE(ifp);
+#endif
struct bpf_insn bpf[BPF_BOOTP_LEN];
struct bpf_insn *bp;
@@ -622,6 +631,8 @@
memcpy(bp, bpf_bootp_filter, sizeof(bpf_bootp_filter));
bp += BPF_BOOTP_FILTER_LEN;
+ /* These checks won't work when same IP exists on other interfaces. */
+#if 0
if (ifp->hwlen <= sizeof(((struct bootp *)0)->chaddr))
bp += bpf_cmp_hwaddr(bp, BPF_BOOTP_CHADDR_LEN,
offsetof(struct bootp, chaddr),
@@ -654,6 +665,7 @@
BPF_SET_STMT(bp, BPF_RET + BPF_K, 0);
bp++;
}
+#endif
/* All passed, return the packet
* (Frame length in M0, IP length in M2). */
diff -r 83d2dcca7179 -r de3bf05d60ae external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c Tue Sep 19 19:16:48 2017 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c Tue Sep 19 19:19:21 2017 +0000
@@ -118,10 +118,13 @@
NULL
};
-static int dhcp_open(struct interface *);
+static int dhcp_openbpf(struct interface *);
#ifdef ARP
static void dhcp_arp_conflicted(struct arp_state *, const struct arp_msg *);
#endif
+static void dhcp_handledhcp(struct interface *, struct bootp *, size_t,
+ const struct in_addr *);
+static int dhcp_initstate(struct interface *);
void
dhcp_printoptions(const struct dhcpcd_ctx *ctx,
@@ -483,7 +486,7 @@
switch (enc) {
case 0:
if ((r = decode_rfc1035(NULL, 0, data, dl)) > 0) {
- l = (size_t)r;
+ l = (size_t)r + 1;
sip = malloc(l);
if (sip == NULL)
return 0;
@@ -697,7 +700,7 @@
{
const struct dhcp_state *state;
- if ((state = D_CSTATE(ifp)) == NULL || state->state != DHS_BOUND)
+ if ((state = D_CSTATE(ifp)) == NULL || !(state->added & STATE_ADDED))
return 0;
return get_option_routes(routes, ifp, state->new, state->new_len);
}
@@ -1527,11 +1530,14 @@
else
state->xid = arc4random();
+ /* We can't do this when sharing leases across interfaes */
+#if 0
/* As the XID changes, re-apply the filter. */
if (state->bpf_fd != -1) {
if (bpf_bootp(ifp, state->bpf_fd) == -1)
logerr(__func__); /* try to continue */
}
+#endif
}
void
@@ -1672,17 +1678,11 @@
struct if_options *ifo = ifp->options;
struct bootp *bootp;
struct bootp_pkt *udp;
- size_t len;
+ size_t len, ulen;
ssize_t r;
struct in_addr from, to;
- struct ipv4_addr *iap;
struct timespec tv;
- int s;
-#ifdef IN_IFF_NOTUSEABLE
- struct ipv4_addr *ia;
-#endif
-
- s = -1;
+
if (!callback) {
/* No carrier? Don't bother sending the packet. */
if (ifp->carrier == LINK_DOWN)
@@ -1714,91 +1714,51 @@
timespec_to_double(&tv));
}
- if (dhcp_open(ifp) == -1)
+ if (dhcp_openbpf(ifp) == -1)
return;
- iap = state->addr;
- if (state->added && !(state->added & STATE_FAKE) &&
- state->addr != NULL && state->new != NULL &&
-#ifdef IN_IFF_NOTUSEABLE
- ((ia = ipv4_iffindaddr(ifp, &state->addr->addr, NULL)) &&
- !(ia->addr_flags & IN_IFF_NOTUSEABLE)) &&
-#endif
- (state->lease.server.s_addr ||
- ifp->options->options & DHCPCD_INFORM) &&
- IS_DHCP(state->new))
- {
- s = dhcp_openudp(ifp);
- if (s == -1) {
- if (errno != EADDRINUSE)
- logerr("%s: dhcp_openudp", ifp->name);
- /* We cannot renew */
- state->addr = NULL;
- }
- }
-
r = make_message(&bootp, ifp, type);
- state->addr = iap;
if (r == -1)
goto fail;
len = (size_t)r;
from.s_addr = bootp->ciaddr;
- if (s != -1 && from.s_addr != INADDR_ANY)
+ if (from.s_addr != INADDR_ANY)
to.s_addr = state->lease.server.s_addr;
else
to.s_addr = INADDR_ANY;
- if (to.s_addr && to.s_addr != INADDR_BROADCAST) {
- struct sockaddr_in sin;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = to.s_addr;
- sin.sin_port = htons(BOOTPS);
- r = sendto(s, (uint8_t *)bootp, len, 0,
- (struct sockaddr *)&sin, sizeof(sin));
- if (r == -1)
- logerr("%s: dhcp_sendpacket", ifp->name);
+ udp = dhcp_makeudppacket(&ulen, (uint8_t *)bootp, len, from, to);
+ if (udp == NULL) {
+ logerr("%s: dhcp_makeudppacket", ifp->name);
+ r = 0;
} else {
- size_t ulen;
-
- udp = dhcp_makeudppacket(&ulen, (uint8_t *)bootp, len, from,to);
- if (udp == NULL) {
- logerr("%s: dhcp_makeudppacket", ifp->name);
- r = 0;
- } else {
- r = bpf_send(ifp, state->bpf_fd,
- ETHERTYPE_IP, (uint8_t *)udp, ulen);
- free(udp);
- }
- /* If we failed to send a raw packet this normally means
- * we don't have the ability to work beneath the IP layer
- * for this interface.
- * As such we remove it from consideration without actually
- * stopping the interface. */
- if (r == -1) {
- logerr("%s: if_sendraw", ifp->name);
- switch(errno) {
- case ENETDOWN:
- case ENETRESET:
- case ENETUNREACH:
- case ENOBUFS:
- break;
- default:
- if (!(ifp->ctx->options & DHCPCD_TEST))
- dhcp_drop(ifp, "FAIL");
- dhcp_free(ifp);
- eloop_timeout_delete(ifp->ctx->eloop,
- NULL, ifp);
- callback = NULL;
- }
+ r = bpf_send(ifp, state->bpf_fd,
+ ETHERTYPE_IP, (uint8_t *)udp, ulen);
+ free(udp);
+ }
+ /* If we failed to send a raw packet this normally means
+ * we don't have the ability to work beneath the IP layer
+ * for this interface.
+ * As such we remove it from consideration without actually
+ * stopping the interface. */
+ if (r == -1) {
+ logerr("%s: if_sendraw", ifp->name);
+ switch(errno) {
+ case ENETDOWN:
+ case ENETRESET:
+ case ENETUNREACH:
+ case ENOBUFS:
+ break;
+ default:
+ if (!(ifp->ctx->options & DHCPCD_TEST))
+ dhcp_drop(ifp, "FAIL");
+ eloop_timeout_delete(ifp->ctx->eloop,
+ NULL, ifp);
+ callback = NULL;
}
}
free(bootp);
fail:
- if (s != -1)
- close(s);
-
/* Even if we fail to send a packet we should continue as we are
* as our failure timeouts will change out codepath when needed. */
if (callback)
@@ -1915,9 +1875,10 @@
dhcp_drop(ifp, "EXPIRE");
unlink(state->leasefile);
state->interval = 0;
- dhcp_discover(ifp);
-
+ if (!(ifp->options->options & DHCPCD_LINK) || ifp->carrier != LINK_DOWN)
+ dhcp_discover(ifp);
}
+
static void
dhcp_expire(void *arg)
{
@@ -1932,7 +1893,7 @@
dhcp_expire1(ifp);
}
-#ifdef ARP
+#if defined(ARP) || defined(IN_IFF_DUPLICATED)
static void
Home |
Main Index |
Thread Index |
Old Index