changeset 2187:9c8b8f4c11f4 draft

Fix a few memory leaks, DHCPv6 prefix definition and the -V option.
author Roy Marples <roy@marples.name>
date Tue, 03 Dec 2013 23:10:21 +0000
parents b4d8f5bb2fe4
children 20c4c537a339
files dhcp6.c dhcpcd-definitions.conf dhcpcd.c if-options.c
diffstat 4 files changed, 35 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp6.c	Tue Dec 03 17:55:40 2013 +0000
+++ b/dhcp6.c	Tue Dec 03 23:10:21 2013 +0000
@@ -134,11 +134,11 @@
 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 @@
 	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 @@
 			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 @@
 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 @@
 	}
 
 	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)
 		{
--- a/dhcpcd-definitions.conf	Tue Dec 03 17:55:40 2013 +0000
+++ b/dhcpcd-definitions.conf	Tue Dec 03 23:10:21 2013 +0000
@@ -192,7 +192,7 @@
 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
--- a/dhcpcd.c	Tue Dec 03 17:55:40 2013 +0000
+++ b/dhcpcd.c	Tue Dec 03 23:10:21 2013 +0000
@@ -1155,21 +1155,8 @@
 			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 @@
 			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)
--- a/if-options.c	Tue Dec 03 17:55:40 2013 +0000
+++ b/if-options.c	Tue Dec 03 23:10:21 2013 +0000
@@ -557,7 +557,8 @@
 	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;