diff options
| author | roy <roy@NetBSD.org> | 2014-03-01 11:04:21 +0000 |
|---|---|---|
| committer | roy <roy@NetBSD.org> | 2014-03-01 11:04:21 +0000 |
| commit | 8dfdca58de0b80df1efcfbf81e29a4b14a7029ae (patch) | |
| tree | 9667a601e0f6b81df139af920082a09784f60c89 /external | |
| parent | 27ad3e0fceaf77f7274de012b94124261f05bf25 (diff) | |
Sync
Diffstat (limited to 'external')
| -rw-r--r-- | external/bsd/dhcpcd/dist/dhcp.c | 40 | ||||
| -rw-r--r-- | external/bsd/dhcpcd/dist/dhcpcd.c | 18 | ||||
| -rw-r--r-- | external/bsd/dhcpcd/dist/if-options.c | 32 | ||||
| -rw-r--r-- | external/bsd/dhcpcd/dist/ipv6nd.c | 26 | ||||
| -rw-r--r-- | external/bsd/dhcpcd/dist/script.c | 102 |
5 files changed, 143 insertions, 75 deletions
diff --git a/external/bsd/dhcpcd/dist/dhcp.c b/external/bsd/dhcpcd/dist/dhcp.c index ad12e6412df..2bc7e020c9f 100644 --- a/external/bsd/dhcpcd/dist/dhcp.c +++ b/external/bsd/dhcpcd/dist/dhcp.c @@ -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 @@ get_option(struct dhcpcd_ctx *ctx, 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 @@ ssize_t 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 @@ write_lease(const struct interface *ifp, const struct dhcp_message *dhcp) 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 @@ checksum(const void *data, uint16_t len) 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 @@ dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length, udpp = calloc(1, sizeof(*udpp)); if (udpp == NULL) - return -1; + return NULL; ip = &udpp->ip; udp = &udpp->udp; @@ -1497,8 +1501,8 @@ dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length, 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 @@ send_message(struct interface *iface, int type, 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 @@ send_message(struct interface *iface, int type, 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 --git a/external/bsd/dhcpcd/dist/dhcpcd.c b/external/bsd/dhcpcd/dist/dhcpcd.c index 6a79a0af3cd..0054e9c69f2 100644 --- a/external/bsd/dhcpcd/dist/dhcpcd.c +++ b/external/bsd/dhcpcd/dist/dhcpcd.c @@ -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 @@ free_globals(struct dhcpcd_ctx *ctx) } 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 @@ static void 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 @@ init_state(struct interface *ifp, int argc, char **argv) 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 @@ init_state(struct interface *ifp, int argc, char **argv) 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 --git a/external/bsd/dhcpcd/dist/if-options.c b/external/bsd/dhcpcd/dist/if-options.c index 06a43fd5280..ac76be521fb 100644 --- a/external/bsd/dhcpcd/dist/if-options.c +++ b/external/bsd/dhcpcd/dist/if-options.c @@ -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 @@ add_environ(struct if_options *ifo, const char *value, int uniq) 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 @@ add_environ(struct if_options *ifo, const char *value, int uniq) n = strdup(value); if (n == NULL) { syslog(LOG_ERR, "%s: %m", __func__); + free(match); return NULL; } free(lst[i]); @@ -225,6 +230,7 @@ add_environ(struct if_options *ifo, const char *value, int uniq) 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 @@ add_environ(struct if_options *ifo, const char *value, int uniq) i++; } + free(match); n = strdup(value); if (n == NULL) { syslog(LOG_ERR, "%s: %m", __func__); @@ -246,12 +253,12 @@ add_environ(struct if_options *ifo, const char *value, int uniq) 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 @@ splitv(int *argc, char **argv, const char *arg) 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 @@ parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg) } 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 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, dop = NULL; dop_len = NULL; +#ifdef INET6 i = 0; +#endif switch(opt) { case 'f': /* FALLTHROUGH */ case 'g': /* FALLTHROUGH */ @@ -1515,6 +1526,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, sizeof(**dop) * ((*dop_len) + 1))) == NULL) { syslog(LOG_ERR, "%s: %m", __func__); + free(np); return -1; } *dop = ndop; diff --git a/external/bsd/dhcpcd/dist/ipv6nd.c b/external/bsd/dhcpcd/dist/ipv6nd.c index cbe0c452062..e958a4e2262 100644 --- a/external/bsd/dhcpcd/dist/ipv6nd.c +++ b/external/bsd/dhcpcd/dist/ipv6nd.c @@ -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 @@ ipv6nd_sendrsprobe(void *arg) /* 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 @@ ipv6nd_sendrsprobe(void *arg) /* Hop limit */ cm = CMSG_NXTHDR(&ctx->sndhdr, cm); + if (cm == NULL) /* unlikely */ + return; cm->cmsg_level = IPPROTO_IPV6; cm->cmsg_type = IPV6_HOPLIMIT; cm->cmsg_len = CMSG_LEN(sizeof(hoplimit)); @@ -753,9 +757,8 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp, len -= sizeof(struct nd_router_advert); p = ((uint8_t *)icp) + sizeof(struct nd_router_advert); - olen = 0; lifetime = ~0U; - for (olen = 0; len > 0; p += olen, len -= olen) { + for (; len > 0; p += olen, len -= olen) { if ((size_t)len < sizeof(struct nd_opt_hdr)) { syslog(LOG_ERR, "%s: short option", ifp->name); break; @@ -1415,12 +1418,15 @@ ipv6nd_probeaddr(void *arg) //memcpy(&dst.sin6_addr, &ap->addr, sizeof(dst.sin6_addr)); dst.sin6_scope_id = ap->iface->index; - sndhdr.msg_name = (caddr_t)&dst; - sndhdr.msg_iov[0].iov_base = ap->ns; - sndhdr.msg_iov[0].iov_len = ap->nslen; + ctx = ap->iface->ctx->ipv6; + ctx->sndhdr.msg_name = (caddr_t)&dst; + ctx->sndhdr.msg_iov[0].iov_base = ap->ns; + ctx->sndhdr.msg_iov[0].iov_len = ap->nslen; /* Set the outbound interface */ - cm = CMSG_FIRSTHDR(&sndhdr); + 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)); @@ -1430,6 +1436,8 @@ ipv6nd_probeaddr(void *arg) /* Hop limit */ cm = CMSG_NXTHDR(&sndhdr, cm); + if (cm == NULL) /* unlikely */ + return; cm->cmsg_level = IPPROTO_IPV6; cm->cmsg_type = IPV6_HOPLIMIT; cm->cmsg_len = CMSG_LEN(sizeof(hoplimit)); @@ -1571,6 +1579,8 @@ ipv6nd_proberouter(void *arg) /* 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)); @@ -1580,6 +1590,8 @@ ipv6nd_proberouter(void *arg) /* Hop limit */ cm = CMSG_NXTHDR(&ctx->sndhdr, cm); + if (cm == NULL) /* unlikely */ + return; cm->cmsg_level = IPPROTO_IPV6; cm->cmsg_type = IPV6_HOPLIMIT; cm->cmsg_len = CMSG_LEN(sizeof(hoplimit)); diff --git a/external/bsd/dhcpcd/dist/script.c b/external/bsd/dhcpcd/dist/script.c index 6845c00bae9..408c3eaddff 100644 --- a/external/bsd/dhcpcd/dist/script.c +++ b/external/bsd/dhcpcd/dist/script.c @@ -1,5 +1,5 @@ #include <sys/cdefs.h> - __RCSID("$NetBSD: script.c,v 1.4 2014/02/25 13:20:23 roy Exp $"); + __RCSID("$NetBSD: script.c,v 1.5 2014/03/01 11:04:21 roy Exp $"); /* * dhcpcd - DHCP client daemon @@ -61,6 +61,7 @@ static const char * const if_params[] = { "interface", "reason", "pid", + "ifcarrier", "ifmetric", "ifwireless", "ifflags", @@ -142,11 +143,13 @@ append_config(char ***env, ssize_t *len, { ssize_t i, j, e1; char **ne, *eq, **nep, *p; + int ret; if (config == NULL) return 0; ne = *env; + ret = 0; for (i = 0; config[i] != NULL; i++) { eq = strchr(config[i], '='); e1 = eq - config[i] + 1; @@ -154,22 +157,29 @@ append_config(char ***env, ssize_t *len, if (strncmp(ne[j] + strlen(prefix) + 1, config[i], e1) == 0) { + p = make_var(prefix, config[i]); + if (p == NULL) { + ret = -1; + break; + } free(ne[j]); - ne[j] = make_var(prefix, config[i]); - if (ne[j] == NULL) - return -1; + ne[j] = p; break; } } if (j == *len) { j++; p = make_var(prefix, config[i]); - if (p == NULL) - return -1; + if (p == NULL) { + ret = -1; + break; + } nep = realloc(ne, sizeof(char *) * (j + 1)); if (nep == NULL) { syslog(LOG_ERR, "%s: %m", __func__); - return -1; + free(p); + ret = -1; + break; } ne = nep; ne[j - 1] = p; @@ -177,7 +187,7 @@ append_config(char ***env, ssize_t *len, } } *env = ne; - return 0; + return ret; } #endif @@ -188,6 +198,8 @@ arraytostr(const char *const *argv, char **s) char *p; size_t len, l; + if (*argv == NULL) + return 0; len = 0; ap = argv; while (*ap) @@ -212,39 +224,53 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) ssize_t e, elen, l; const struct if_options *ifo = ifp->options; const struct interface *ifp2; - int dhcp, dhcp6, ra; +#ifdef INET + int dhcp; const struct dhcp_state *state; +#endif #ifdef INET6 const struct dhcp6_state *d6_state; + int dhcp6, ra; #endif - dhcp = dhcp6 = ra = 0; +#ifdef INET + dhcp = 0; state = D_STATE(ifp); +#endif #ifdef INET6 + dhcp6 = ra = 0; d6_state = D6_CSTATE(ifp); #endif if (strcmp(reason, "TEST") == 0) { + if (1 == 2) {} #ifdef INET6 - if (d6_state && d6_state->new) + else if (d6_state && d6_state->new) dhcp6 = 1; else if (ipv6nd_has_ra(ifp)) ra = 1; - else #endif +#ifdef INET + else dhcp = 1; - } else if (reason[strlen(reason) - 1] == '6') +#endif + } +#ifdef INET6 + else if (reason[strlen(reason) - 1] == '6') dhcp6 = 1; else if (strcmp(reason, "ROUTERADVERT") == 0) ra = 1; +#endif +#ifdef INET else dhcp = 1; +#endif /* When dumping the lease, we only want to report interface and reason - the other interface variables are meaningless */ if (ifp->ctx->options & DHCPCD_DUMPLEASE) elen = 2; else - elen = 10; + elen = 11; #define EMALLOC(i, l) if ((env[(i)] = malloc(l)) == NULL) goto eexit; /* Make our env */ @@ -263,19 +289,23 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) EMALLOC(2, e); snprintf(env[2], e, "pid=%d", getpid()); EMALLOC(3, e); - snprintf(env[3], e, "ifmetric=%d", ifp->metric); + snprintf(env[3], e, "ifcarrier=%s", + ifp->carrier == LINK_UNKNOWN ? "unknown" : + ifp->carrier == LINK_UP ? "up" : "down"); EMALLOC(4, e); - snprintf(env[4], e, "ifwireless=%d", ifp->wireless); + snprintf(env[4], e, "ifmetric=%d", ifp->metric); EMALLOC(5, e); - snprintf(env[5], e, "ifflags=%u", ifp->flags); + snprintf(env[5], e, "ifwireless=%d", ifp->wireless); EMALLOC(6, e); - snprintf(env[6], e, "ifmtu=%d", get_mtu(ifp->name)); + snprintf(env[6], e, "ifflags=%u", ifp->flags); + EMALLOC(7, e); + snprintf(env[7], e, "ifmtu=%d", get_mtu(ifp->name)); l = e = strlen("interface_order="); TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) { e += strlen(ifp2->name) + 1; } - EMALLOC(7, e); - p = env[7]; + EMALLOC(8, e); + p = env[8]; strlcpy(p, "interface_order=", e); e -= l; p += l; @@ -288,22 +318,25 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) } *--p = '\0'; if (strcmp(reason, "TEST") == 0) { - env[8] = strdup("if_up=false"); - env[9] = strdup("if_down=false"); - } else if ((dhcp && state && state->new) + env[9] = strdup("if_up=false"); + env[10] = strdup("if_down=false"); + } else if (1 == 2 /* appease ifdefs */ +#ifdef INET + || (dhcp && state && state->new) +#endif #ifdef INET6 || (dhcp6 && d6_state && d6_state->new) || (ra && ipv6nd_has_ra(ifp)) #endif ) { - env[8] = strdup("if_up=true"); - env[9] = strdup("if_down=false"); + env[9] = strdup("if_up=true"); + env[10] = strdup("if_down=false"); } else { - env[8] = strdup("if_up=false"); - env[9] = strdup("if_down=true"); + env[9] = strdup("if_up=false"); + env[10] = strdup("if_down=true"); } - if (env[8] == NULL || env[9] == NULL) + if (env[9] == NULL || env[10] == NULL) goto eexit; if (*ifp->profile) { e = strlen("profile=") + strlen(ifp->profile) + 2; @@ -319,8 +352,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) env = nenv; EMALLOC(elen, e); snprintf(env[elen++], e, "new_ssid=%s", ifp->ssid); - } - else if (strcmp(reason, "NOCARRIER") == 0) { + } else if (strcmp(reason, "NOCARRIER") == 0) { nenv = realloc(env, sizeof(char *) * (elen + 2)); if (nenv == NULL) goto eexit; @@ -441,10 +473,12 @@ dumplease: eexit: syslog(LOG_ERR, "%s: %m", __func__); - nenv = env; - while (*nenv) - free(*nenv++); - free(env); + if (env) { + nenv = env; + while (*nenv) + free(*nenv++); + free(env); + } return -1; } |
