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/b4405e98f10b
branches: trunk
changeset: 332338:b4405e98f10b
user: roy <roy%NetBSD.org@localhost>
date: Tue Sep 16 22:27:04 2014 +0000
description:
Sync
diffstat:
external/bsd/dhcpcd/dist/dhcp.c | 190 +++++++++-------------
external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in | 97 ++++++++++-
external/bsd/dhcpcd/dist/dhcpcd.8.in | 20 +-
external/bsd/dhcpcd/dist/dhcpcd.c | 206 ++++++++++++------------
external/bsd/dhcpcd/dist/dhcpcd.conf | 5 +-
external/bsd/dhcpcd/dist/dhcpcd.conf.5.in | 29 ++-
external/bsd/dhcpcd/dist/if-bsd.c | 48 +++--
external/bsd/dhcpcd/dist/if-options.c | 9 +-
external/bsd/dhcpcd/dist/ipv6nd.c | 29 ++-
external/bsd/dhcpcd/dist/script.c | 147 +++++++++++------
10 files changed, 463 insertions(+), 317 deletions(-)
diffs (truncated from 1447 to 300 lines):
diff -r 569c87ffee26 -r b4405e98f10b external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c Tue Sep 16 22:23:17 2014 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c Tue Sep 16 22:27:04 2014 +0000
@@ -1,5 +1,5 @@
#include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp.c,v 1.15 2014/07/30 15:47:32 roy Exp $");
+ __RCSID("$NetBSD: dhcp.c,v 1.16 2014/09/16 22:27:04 roy Exp $");
/*
* dhcpcd - DHCP client daemon
@@ -126,7 +126,7 @@
static const size_t udp_dhcp_len = sizeof(struct udp_dhcp_packet);
-static int dhcp_open(struct interface *);
+static int dhcp_open(struct interface *ifp);
void
dhcp_printoptions(const struct dhcpcd_ctx *ctx,
@@ -302,6 +302,10 @@
return -1;
}
ocets = (cidr + 7) / NBBY;
+ if (p + 4 + ocets > e) {
+ errno = ERANGE;
+ return -1;
+ }
if (!out) {
p += 4 + ocets;
bytes += ((4 * 4) * 2) + 4;
@@ -364,6 +368,13 @@
return NULL;
}
+ ocets = (cidr + 7) / NBBY;
+ if (p + 4 + ocets > e) {
+ ipv4_freeroutes(routes);
+ errno = ERANGE;
+ return NULL;
+ }
+
rt = calloc(1, sizeof(*rt));
if (rt == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
@@ -372,7 +383,6 @@
}
TAILQ_INSERT_TAIL(routes, rt, next);
- ocets = (cidr + 7) / NBBY;
/* If we have ocets then we have a destination and netmask */
if (ocets > 0) {
memcpy(&rt->dest.s_addr, p, ocets);
@@ -831,7 +841,6 @@
p += ifo->vendorclassid[0] + 1;
}
-
if (type != DHCP_INFORM) {
if (ifo->leasetime != 0) {
*p++ = DHO_LEASETIME;
@@ -993,7 +1002,11 @@
auth_len = (size_t)dhcp_auth_encode(&ifo->auth,
state->auth.token,
NULL, 0, 4, type, NULL, 0);
- if (auth_len > 0) {
+ if ((ssize_t)auth_len == -1) {
+ syslog(LOG_ERR, "%s: dhcp_auth_encode: %m",
+ iface->name);
+ auth_len = 0;
+ } else if (auth_len != 0) {
len = (size_t)((p + auth_len) - m);
if (auth_len > 255 || len > sizeof(*dhcp))
goto toobig;
@@ -1001,9 +1014,7 @@
*p++ = (uint8_t)auth_len;
auth = p;
p += auth_len;
- } else if ((ssize_t)auth_len == -1)
- syslog(LOG_ERR, "%s: dhcp_auth_encode: %m",
- iface->name);
+ }
}
*p++ = DHO_END;
@@ -1017,7 +1028,7 @@
#endif
len = (size_t)(p - m);
- if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len > 0)
+ if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len != 0)
dhcp_auth_encode(&ifo->auth, state->auth.token,
m, len, 4, type, auth, auth_len);
@@ -1398,26 +1409,21 @@
return;
if (state->arp_fd != -1) {
- eloop_event_delete(ifp->ctx->eloop, state->arp_fd);
+ eloop_event_delete(ifp->ctx->eloop, state->arp_fd, 0);
close(state->arp_fd);
state->arp_fd = -1;
}
if (state->raw_fd != -1) {
- eloop_event_delete(ifp->ctx->eloop, state->raw_fd);
+ eloop_event_delete(ifp->ctx->eloop, state->raw_fd, 0);
close(state->raw_fd);
state->raw_fd = -1;
}
- if (state->udp_fd != -1) {
- eloop_event_delete(ifp->ctx->eloop, state->udp_fd);
- close(state->udp_fd);
- state->udp_fd = -1;
- }
state->interval = 0;
}
static int
-dhcp_openudp(struct dhcpcd_ctx *ctx, struct interface *ifp)
+dhcp_openudp(struct interface *ifp)
{
int s;
struct sockaddr_in sin;
@@ -1469,31 +1475,13 @@
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
goto eexit;
- if (ifp)
- state->udp_fd = s;
- else
- ctx->udp_fd = s;
- return 0;
+ return s;
eexit:
close(s);
return -1;
}
-static ssize_t
-dhcp_sendpacket(const struct interface *iface, struct in_addr to,
- const uint8_t *data, size_t len)
-{
- 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(DHCP_SERVER_PORT);
- return sendto(D_CSTATE(iface)->udp_fd, data, len, 0,
- (struct sockaddr *)&sin, sizeof(sin));
-}
-
static uint16_t
checksum(const void *data, uint16_t len)
{
@@ -1578,8 +1566,9 @@
size_t len;
ssize_t r;
struct in_addr from, to;
- in_addr_t a = 0;
+ in_addr_t a = INADDR_ANY;
struct timeval tv;
+ int s;
if (!callback)
syslog(LOG_DEBUG, "%s: sending %s with xid 0x%x",
@@ -1602,23 +1591,30 @@
timeval_to_double(&tv));
}
- /* Ensure sockets are open. */
- if (dhcp_open(iface) == -1) {
- if (!(iface->ctx->options & DHCPCD_TEST))
- dhcp_drop(iface, "FAIL");
+ if (dhcp_open(iface) == -1)
return;
- }
+
+ if (state->addr.s_addr != INADDR_ANY &&
+ state->new != NULL &&
+ (state->new->cookie == htonl(MAGIC_COOKIE) ||
+ iface->options->options & DHCPCD_INFORM))
+ {
+ s = dhcp_openudp(iface);
+ if (s == -1 && errno != EADDRINUSE)
+ syslog(LOG_ERR, "%s: dhcp_openudp: %m", iface->name);
+ } else
+ s = -1;
/* If we couldn't open a UDP port for our IP address
* then we cannot renew.
* This could happen if our IP was pulled out from underneath us.
* Also, we should not unicast from a BOOTP lease. */
- if (state->udp_fd == -1 ||
+ if (s == -1 ||
(!(ifo->options & DHCPCD_INFORM) &&
is_bootp(iface, state->new)))
{
a = state->addr.s_addr;
- state->addr.s_addr = 0;
+ state->addr.s_addr = INADDR_ANY;
}
r = make_message(&dhcp, iface, type);
if (r == -1)
@@ -1630,13 +1626,18 @@
if (from.s_addr)
to.s_addr = state->lease.server.s_addr;
else
- to.s_addr = 0;
+ to.s_addr = INADDR_ANY;
if (to.s_addr && to.s_addr != INADDR_BROADCAST) {
- r = dhcp_sendpacket(iface, to, (uint8_t *)dhcp, len);
- if (r == -1) {
+ 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(DHCP_SERVER_PORT);
+ r = sendto(s, (uint8_t *)dhcp, len, 0,
+ (struct sockaddr *)&sin, sizeof(sin));
+ if (r == -1)
syslog(LOG_ERR, "%s: dhcp_sendpacket: %m", iface->name);
- dhcp_close(iface);
- }
} else {
size_t ulen;
@@ -1675,6 +1676,9 @@
free(dhcp);
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)
@@ -2144,7 +2148,7 @@
dhcp_auth_reset(&state->auth);
dhcp_close(ifp);
arp_close(ifp);
- eloop_timeouts_delete(ifp->ctx->eloop, ifp, dhcp_expire, NULL);
+ eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
if (ifp->options->options & DHCPCD_RELEASE) {
unlink(state->leasefile);
if (ifp->carrier != LINK_DOWN &&
@@ -2697,40 +2701,23 @@
}
static void
-dhcp_handleudp1(struct dhcpcd_ctx *ctx, int *fd, const char *ifname)
+dhcp_handleudp(void *arg)
{
+ struct dhcpcd_ctx *ctx;
uint8_t buffer[sizeof(struct dhcp_message)];
+ ctx = arg;
+
/* Just read what's in the UDP fd and discard it as we always read
* from the raw fd */
- if (read(*fd, buffer, sizeof(buffer)) == -1) {
- syslog(LOG_ERR, "%s: %s: %m", ifname, __func__);
- eloop_event_delete(ctx->eloop, *fd);
- close(*fd);
- *fd = -1;
+ if (read(ctx->udp_fd, buffer, sizeof(buffer)) == -1) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ eloop_event_delete(ctx->eloop, ctx->udp_fd, 0);
+ close(ctx->udp_fd);
+ ctx->udp_fd = -1;
}
}
-static void
-dhcp_handleudp(void *arg)
-{
- struct dhcpcd_ctx *ctx;
-
- ctx = arg;
- dhcp_handleudp1(arg, &ctx->udp_fd, NULL);
-}
-
-static void
-dhcp_handleifudp(void *arg)
-{
- const struct interface *ifp;
- struct dhcp_state *state;
-
- ifp = arg;
- state = D_STATE(ifp);
- dhcp_handleudp1(ifp->ctx, &state->udp_fd, ifp->name);
-}
-
static int
dhcp_open(struct interface *ifp)
{
@@ -2752,21 +2739,7 @@
return -1;
Home |
Main Index |
Thread Index |
Old Index