From: Roy Marples Date: Tue, 3 Dec 2013 23:10:21 +0000 (+0000) Subject: Fix a few memory leaks, DHCPv6 prefix definition and the -V option. X-Git-Tag: v6.2.0~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b7f5d1db5ba84809c9fb1d905ea428fc8f56ba0c;p=thirdparty%2Fdhcpcd.git Fix a few memory leaks, DHCPv6 prefix definition and the -V option. --- diff --git a/dhcp6.c b/dhcp6.c index 061d3d82..09a0ed69 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -134,11 +134,11 @@ dhcp6_cleanup(void) void dhcp6_printoptions(void) { + size_t i; const struct dhcp_opt *opt; - for (opt = dhcp6_opts; opt->option; opt++) - if (opt->v.var) - printf("%05d %s\n", opt->option, opt->v.var); + for (i = 0, opt = dhcp6_opts; i < dhcp6_opts_len; i++, opt++) + printf("%05d %s\n", opt->option, opt->v.var); } static int @@ -417,7 +417,7 @@ dhcp6_makemessage(struct interface *ifp) len = 0; si = NULL; if (state->state != DH6S_RELEASE) { - for (opt = dhcp6_opts; opt->option; opt++) { + for (l = 0, opt = dhcp6_opts; l < dhcp6_opts_len ; l++, opt++) { if (!(opt->type & NOREQ) && (opt->type & REQUEST || has_option_mask(ifo->requestmask6, opt->option))) @@ -662,7 +662,10 @@ dhcp6_makemessage(struct interface *ifp) o->code = htons(D6_OPTION_ORO); o->len = 0; u16 = (uint16_t *)(void *)D6_OPTION_DATA(o); - for (opt = dhcp6_opts; opt->option; opt++) { + for (l = 0, opt = dhcp6_opts; + l < dhcp6_opts_len; + l++, opt++) + { if (!(opt->type & NOREQ) && (opt->type & REQUEST || has_option_mask(ifo->requestmask6, @@ -1974,6 +1977,7 @@ static void dhcp6_handledata(__unused void *arg) { ssize_t len; + size_t i; struct cmsghdr *cm; struct in6_pktinfo pkt; struct interface *ifp; @@ -2075,7 +2079,7 @@ dhcp6_handledata(__unused void *arg) } ifo = ifp->options; - for (opt = dhcp6_opts; opt->option; opt++) { + for (i = 0, opt = dhcp6_opts; i < dhcp6_opts_len; i++, opt++) { if (has_option_mask(ifo->requiremask6, opt->option) && dhcp6_getmoption(opt->option, r, len) == NULL) { diff --git a/dhcpcd-definitions.conf b/dhcpcd-definitions.conf index 96984493..9df58903 100644 --- a/dhcpcd-definitions.conf +++ b/dhcpcd-definitions.conf @@ -192,7 +192,7 @@ embed uint32 t1 embed uint32 t2 encap 26 option -define 26 index embed prefix +define6 26 index embed prefix embed uint32 pltime embed uint32 vltime embed ip6address prefix diff --git a/dhcpcd.c b/dhcpcd.c index 5288ed7c..193c9a1a 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1155,21 +1155,8 @@ main(int argc, char **argv) i = 2; break; case 'V': - printf("Interface options:\n"); - if_printoptions(); -#ifdef INET - if (family == 0 || family == AF_INET) { - printf("\nDHCPv4 options:\n"); - dhcp_printoptions(); - } -#endif -#ifdef INET6 - if (family == 0 || family == AF_INET6) { - printf("\nDHCPv6 options:\n"); - dhcp6_printoptions(); - } -#endif - exit(EXIT_SUCCESS); + i = 3; + break; case '?': usage(); exit(EXIT_FAILURE); @@ -1185,6 +1172,26 @@ main(int argc, char **argv) usage(); exit(EXIT_FAILURE); } + if (i == 3) { + printf("Interface options:\n"); + if_printoptions(); +#ifdef INET + if (family == 0 || family == AF_INET) { + printf("\nDHCPv4 options:\n"); + dhcp_printoptions(); + } +#endif +#ifdef INET6 + if (family == 0 || family == AF_INET6) { + printf("\nDHCPv6 options:\n"); + dhcp6_printoptions(); + } +#endif +#ifdef DEBUG_MEMORY + cleanup(); +#endif + exit(EXIT_SUCCESS); + } options = if_options->options; if (i != 0) { if (i == 1) diff --git a/if-options.c b/if-options.c index c84ef337..e0839048 100644 --- a/if-options.c +++ b/if-options.c @@ -557,7 +557,8 @@ parse_option(struct if_options *ifo, int opt, const char *arg) case 'n': /* FALLTHROUGH */ case 'x': /* FALLTHROUGH */ case 'T': /* FALLTHROUGH */ - case 'U': /* We need to handle non interface options */ + case 'U': /* FALLTHROUGH */ + case 'V': /* We need to handle non interface options */ break; case 'b': ifo->options |= DHCPCD_BACKGROUND;