changeset 2570:12b378a0f258 draft

Print user defined options via -V
author Roy Marples <roy@marples.name>
date Thu, 03 Jul 2014 23:11:00 +0000
parents 7af1b6b4b883
children 51235d228097
files dhcp.c dhcp.h dhcp6.c dhcp6.h dhcpcd.c
diffstat 5 files changed, 42 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp.c	Thu Jul 03 14:23:32 2014 +0000
+++ b/dhcp.c	Thu Jul 03 23:11:00 2014 +0000
@@ -125,16 +125,24 @@
 static int dhcp_open(struct interface *);
 
 void
-dhcp_printoptions(const struct dhcpcd_ctx *ctx)
+dhcp_printoptions(const struct dhcpcd_ctx *ctx,
+    const struct dhcp_opt *opts, size_t opts_len)
 {
 	const char * const *p;
-	size_t i;
-	const struct dhcp_opt *opt;
+	size_t i, j;
+	const struct dhcp_opt *opt, *opt2;
 
 	for (p = dhcp_params; *p; p++)
 		printf("    %s\n", *p);
 
-	for (i = 0, opt = ctx->dhcp_opts; i < ctx->dhcp_opts_len; i++, opt++)
+	for (i = 0, opt = ctx->dhcp_opts; i < ctx->dhcp_opts_len; i++, opt++) {
+		for (j = 0, opt2 = opts; j < opts_len; j++, opt2++)
+			if (opt->option == opt2->option)
+				break;
+		if (j == opts_len)
+			printf("%03d %s\n", opt->option, opt->var);
+	}
+	for (i = 0, opt = opts; i < opts_len; i++, opt++)
 		printf("%03d %s\n", opt->option, opt->var);
 }
 
--- a/dhcp.h	Thu Jul 03 14:23:32 2014 +0000
+++ b/dhcp.h	Thu Jul 03 23:11:00 2014 +0000
@@ -250,7 +250,8 @@
 ssize_t decode_rfc3442(char *, size_t, const uint8_t *p, size_t);
 ssize_t decode_rfc5969(char *, size_t, const uint8_t *p, size_t);
 
-void dhcp_printoptions(const struct dhcpcd_ctx *);
+void dhcp_printoptions(const struct dhcpcd_ctx *,
+    const struct dhcp_opt *, size_t);
 int get_option_addr(struct dhcpcd_ctx *,struct in_addr *,
     const struct dhcp_message *, uint8_t);
 #define is_bootp(i, m) ((m) &&						\
@@ -287,7 +288,6 @@
 void dhcp_free(struct interface *);
 int dhcp_dump(struct interface *);
 #else
-#define dhcp_printoptions
 #define dhcp_drop(a, b)
 #define dhcp_start(a) {}
 #define dhcp_reboot(a, b) b = b
--- a/dhcp6.c	Thu Jul 03 14:23:32 2014 +0000
+++ b/dhcp6.c	Thu Jul 03 23:11:00 2014 +0000
@@ -121,13 +121,22 @@
 };
 
 void
-dhcp6_printoptions(const struct dhcpcd_ctx *ctx)
+dhcp6_printoptions(const struct dhcpcd_ctx *ctx,
+    const struct dhcp_opt *opts, size_t opts_len)
 {
-	size_t i;
-	const struct dhcp_opt *opt;
+	size_t i, j;
+	const struct dhcp_opt *opt, *opt2;
 
 	for (i = 0, opt = ctx->dhcp6_opts;
 	    i < ctx->dhcp6_opts_len; i++, opt++)
+	{
+		for (j = 0, opt2 = opts; j < opts_len; j++, opt2++)
+			if (opt2->option == opt->option)
+				break;
+		if (j == opts_len)
+			printf("%05d %s\n", opt->option, opt->var);
+	}
+	for (i = 0, opt = opts; i < opts_len; i++, opt++)
 		printf("%05d %s\n", opt->option, opt->var);
 }
 
--- a/dhcp6.h	Thu Jul 03 14:23:32 2014 +0000
+++ b/dhcp6.h	Thu Jul 03 23:11:00 2014 +0000
@@ -225,7 +225,8 @@
     ((const uint8_t *)(o) + sizeof(struct dhcp6_option))
 
 #ifdef INET6
-void dhcp6_printoptions(const struct dhcpcd_ctx *);
+void dhcp6_printoptions(const struct dhcpcd_ctx *,
+    const struct dhcp_opt *, size_t);
 int dhcp6_addrexists(struct dhcpcd_ctx *, const struct ipv6_addr *);
 size_t dhcp6_find_delegates(struct interface *);
 int dhcp6_start(struct interface *, enum DH6S);
@@ -238,7 +239,6 @@
 void dhcp6_drop(struct interface *, const char *);
 int dhcp6_dump(struct interface *);
 #else
-#define dhcp6_printoptions()
 #define dhcp6_addrexists(a, b) (0)
 #define dhcp6_find_delegates(a)
 #define dhcp6_start(a, b) (0)
--- a/dhcpcd.c	Thu Jul 03 14:23:32 2014 +0000
+++ b/dhcpcd.c	Thu Jul 03 23:11:00 2014 +0000
@@ -1282,6 +1282,8 @@
 	ctx.ifv = argv + optind;
 
 	ifo = read_config(&ctx, NULL, NULL, NULL);
+	if (ifo == NULL)
+		goto exit_failure;
 	opt = add_options(&ctx, NULL, ifo, argc, argv);
 	if (opt != 1) {
 		if (opt == 0)
@@ -1290,17 +1292,26 @@
 	}
 	if (i == 3) {
 		printf("Interface options:\n");
+		if (optind == argc - 1) {
+			free_options(ifo);
+			ifo = read_config(&ctx, argv[optind], NULL, NULL);
+			if (ifo == NULL)
+				goto exit_failure;
+			add_options(&ctx, NULL, ifo, argc, argv);
+		}
 		if_printoptions();
 #ifdef INET
 		if (family == 0 || family == AF_INET) {
 			printf("\nDHCPv4 options:\n");
-			dhcp_printoptions(&ctx);
+			dhcp_printoptions(&ctx,
+			    ifo->dhcp_override, ifo->dhcp_override_len);
 		}
 #endif
 #ifdef INET6
 		if (family == 0 || family == AF_INET6) {
 			printf("\nDHCPv6 options:\n");
-			dhcp6_printoptions(&ctx);
+			dhcp6_printoptions(&ctx,
+			    ifo->dhcp6_override, ifo->dhcp6_override_len);
 		}
 #endif
 		goto exit_success;
@@ -1399,7 +1410,7 @@
 			ifp->ctx = &ctx;
 			TAILQ_INSERT_HEAD(ctx.ifaces, ifp, next);
 		}
-		configure_interface(ifp, 0, NULL);
+		configure_interface(ifp, ctx.argc, ctx.argv);
 		if (family == 0 || family == AF_INET) {
 			if (dhcp_dump(ifp) == -1)
 				i = 1;