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/6b4dd614aa3c
branches: trunk
changeset: 327187:6b4dd614aa3c
user: roy <roy%NetBSD.org@localhost>
date: Sat Mar 01 11:04:21 2014 +0000
description:
Sync
diffstat:
external/bsd/dhcpcd/dist/dhcp.c | 40 ++++++++-----
external/bsd/dhcpcd/dist/dhcpcd.c | 18 +++--
external/bsd/dhcpcd/dist/if-options.c | 32 +++++++---
external/bsd/dhcpcd/dist/ipv6nd.c | 26 ++++++--
external/bsd/dhcpcd/dist/script.c | 102 ++++++++++++++++++++++-----------
5 files changed, 143 insertions(+), 75 deletions(-)
diffs (truncated from 597 to 300 lines):
diff -r 1335f1b2a7e3 -r 6b4dd614aa3c external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c Sat Mar 01 11:00:41 2014 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c Sat Mar 01 11:04:21 2014 +0000
@@ -1,5 +1,5 @@
#include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp.c,v 1.10 2014/02/25 13:20:23 roy Exp $");
+ __RCSID("$NetBSD: dhcp.c,v 1.11 2014/03/01 11:04:21 roy Exp $");
/*
* dhcpcd - DHCP client daemon
@@ -154,7 +154,9 @@
if (o == opt) {
if (op) {
if (!ctx->opt_buffer) {
- ctx->opt_buffer = malloc(sizeof(*dhcp));
+ ctx->opt_buffer =
+ malloc(DHCP_OPTION_LEN +
+ BOOTFILE_LEN + SERVERNAME_LEN);
if (ctx->opt_buffer == NULL)
return NULL;
}
@@ -975,9 +977,8 @@
write_lease(const struct interface *ifp, const struct dhcp_message *dhcp)
{
int fd;
- ssize_t bytes = sizeof(*dhcp);
- const uint8_t *p = dhcp->options;
- const uint8_t *e = p + sizeof(dhcp->options);
+ ssize_t bytes;
+ const uint8_t *e, *p;
uint8_t l;
uint8_t o = 0;
const struct dhcp_state *state = D_CSTATE(ifp);
@@ -996,6 +997,9 @@
return -1;
/* Only write as much as we need */
+ p = dhcp->options;
+ e = p + sizeof(dhcp->options);
+ bytes = sizeof(*dhcp);
while (p < e) {
o = *p;
if (o == DHO_END) {
@@ -1452,8 +1456,8 @@
return ~sum;
}
-static ssize_t
-dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length,
+static struct udp_dhcp_packet *
+dhcp_makeudppacket(ssize_t *sz, const uint8_t *data, size_t length,
struct in_addr source, struct in_addr dest)
{
struct udp_dhcp_packet *udpp;
@@ -1462,7 +1466,7 @@
udpp = calloc(1, sizeof(*udpp));
if (udpp == NULL)
- return -1;
+ return NULL;
ip = &udpp->ip;
udp = &udpp->udp;
@@ -1497,8 +1501,8 @@
ip->ip_len = htons(sizeof(*ip) + sizeof(*udp) + length);
ip->ip_sum = checksum(ip, sizeof(*ip));
- *p = (uint8_t *)udpp;
- return sizeof(*ip) + sizeof(*udp) + length;
+ *sz = sizeof(*ip) + sizeof(*udp) + length;
+ return udpp;
}
static void
@@ -1508,7 +1512,7 @@
struct dhcp_state *state = D_STATE(iface);
struct if_options *ifo = iface->options;
struct dhcp_message *dhcp;
- uint8_t *udp;
+ struct udp_dhcp_packet *udp;
ssize_t len, r;
struct in_addr from, to;
in_addr_t a = 0;
@@ -1567,11 +1571,15 @@
dhcp_close(iface);
}
} else {
- len = dhcp_makeudppacket(&udp, (uint8_t *)dhcp, len, from, to);
- if (len == -1)
- return;
- r = ipv4_sendrawpacket(iface, ETHERTYPE_IP, udp, len);
- free(udp);
+ r = 0;
+ udp = dhcp_makeudppacket(&r, (uint8_t *)dhcp, len, from, to);
+ if (udp == NULL) {
+ syslog(LOG_ERR, "dhcp_makeudppacket: %m");
+ } else {
+ r = ipv4_sendrawpacket(iface, ETHERTYPE_IP,
+ (uint8_t *)udp, r);
+ 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.
diff -r 1335f1b2a7e3 -r 6b4dd614aa3c external/bsd/dhcpcd/dist/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/dhcpcd.c Sat Mar 01 11:00:41 2014 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd.c Sat Mar 01 11:04:21 2014 +0000
@@ -1,5 +1,5 @@
#include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcpcd.c,v 1.2 2014/02/25 14:10:09 roy Exp $");
+ __RCSID("$NetBSD: dhcpcd.c,v 1.3 2014/03/01 11:04:21 roy Exp $");
/*
* dhcpcd - DHCP client daemon
@@ -149,7 +149,7 @@
}
if (ctx->ifdc) {
for (ctx->ifdc--; ctx->ifdc >= 0; ctx->ifdc--)
- free(ctx->ifdv[ctx->ifac]);
+ free(ctx->ifdv[ctx->ifdc]);
free(ctx->ifdv);
ctx->ifdv = NULL;
}
@@ -660,7 +660,7 @@
init_state(struct interface *ifp, int argc, char **argv)
{
struct if_options *ifo;
- const char *reason = NULL;
+ const char *reason;
configure_interface(ifp, argc, argv);
ifo = ifp->options;
@@ -674,9 +674,7 @@
ifo->options &= ~DHCPCD_IPV6RS;
}
- if (!(ifp->ctx->options & DHCPCD_TEST))
- script_runreason(ifp, "PREINIT");
-
+ reason = NULL; /* appease gcc */
if (ifo->options & DHCPCD_LINK) {
switch (carrier_status(ifp)) {
case LINK_DOWN:
@@ -691,10 +689,14 @@
ifp->carrier = LINK_UNKNOWN;
return;
}
- if (reason && !(ifp->ctx->options & DHCPCD_TEST))
- script_runreason(ifp, reason);
} else
ifp->carrier = LINK_UNKNOWN;
+
+ if (!(ifp->ctx->options & DHCPCD_TEST))
+ script_runreason(ifp, "PREINIT");
+
+ if (ifp->carrier != LINK_UNKNOWN && !(ifp->ctx->options & DHCPCD_TEST))
+ script_runreason(ifp, reason);
}
void
diff -r 1335f1b2a7e3 -r 6b4dd614aa3c external/bsd/dhcpcd/dist/if-options.c
--- a/external/bsd/dhcpcd/dist/if-options.c Sat Mar 01 11:00:41 2014 +0000
+++ b/external/bsd/dhcpcd/dist/if-options.c Sat Mar 01 11:04:21 2014 +0000
@@ -1,5 +1,5 @@
#include <sys/cdefs.h>
- __RCSID("$NetBSD: if-options.c,v 1.6 2014/02/25 13:20:23 roy Exp $");
+ __RCSID("$NetBSD: if-options.c,v 1.7 2014/03/01 11:04:21 roy Exp $");
/*
* dhcpcd - DHCP client daemon
@@ -204,8 +204,12 @@
return NULL;
}
p = strchr(match, '=');
- if (p)
- *p++ = '\0';
+ if (p == NULL) {
+ syslog(LOG_ERR, "%s: no assignment: %s", __func__, value);
+ free(match);
+ return NULL;
+ }
+ *p++ = '\0';
l = strlen(match);
while (lst && lst[i]) {
@@ -214,6 +218,7 @@
n = strdup(value);
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
+ free(match);
return NULL;
}
free(lst[i]);
@@ -225,6 +230,7 @@
n = realloc(lst[i], l + lv + 2);
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
+ free(match);
return NULL;
}
lst[i] = n;
@@ -238,6 +244,7 @@
i++;
}
+ free(match);
n = strdup(value);
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
@@ -246,12 +253,12 @@
newlist = realloc(lst, sizeof(char *) * (i + 2));
if (newlist == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
+ free(n);
return NULL;
}
newlist[i] = n;
newlist[i + 1] = NULL;
ifo->environ = newlist;
- free(match);
return newlist[i];
}
@@ -434,16 +441,18 @@
nt = strdup(t);
if (nt == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
- return NULL;
+ free(o);
+ return v;
}
- (*argc)++;
- n = realloc(v, sizeof(char *) * ((*argc)));
+ n = realloc(v, sizeof(char *) * ((*argc) + 1));
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
- return NULL;
+ free(o);
+ free(nt);
+ return v;
}
v = n;
- v[(*argc) - 1] = nt;
+ v[(*argc)++] = nt;
}
free(o);
return v;
@@ -480,7 +489,7 @@
}
if (p != NULL)
*--p = '/';
- else if (net != NULL)
+ else if (net != NULL && addr != NULL)
net->s_addr = ipv4_getnetmask(addr->s_addr);
return 0;
}
@@ -623,7 +632,9 @@
dop = NULL;
dop_len = NULL;
+#ifdef INET6
i = 0;
+#endif
switch(opt) {
case 'f': /* FALLTHROUGH */
case 'g': /* FALLTHROUGH */
@@ -1515,6 +1526,7 @@
sizeof(**dop) * ((*dop_len) + 1))) == NULL)
{
syslog(LOG_ERR, "%s: %m", __func__);
+ free(np);
return -1;
}
*dop = ndop;
diff -r 1335f1b2a7e3 -r 6b4dd614aa3c external/bsd/dhcpcd/dist/ipv6nd.c
--- a/external/bsd/dhcpcd/dist/ipv6nd.c Sat Mar 01 11:00:41 2014 +0000
+++ b/external/bsd/dhcpcd/dist/ipv6nd.c Sat Mar 01 11:04:21 2014 +0000
@@ -1,5 +1,5 @@
#include <sys/cdefs.h>
- __RCSID("$NetBSD: ipv6nd.c,v 1.5 2014/02/25 13:20:23 roy Exp $");
+ __RCSID("$NetBSD: ipv6nd.c,v 1.6 2014/03/01 11:04:21 roy Exp $");
/*
* dhcpcd - DHCP client daemon
@@ -360,6 +360,8 @@
/* Set the outbound interface */
cm = CMSG_FIRSTHDR(&ctx->sndhdr);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(pi));
@@ -369,6 +371,8 @@
/* Hop limit */
cm = CMSG_NXTHDR(&ctx->sndhdr, cm);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
Home |
Main Index |
Thread Index |
Old Index