From ee8a3b3428999c2e01fb1dac4caefb42d0b32c9b Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 3 Jul 2014 23:11:00 +0000 Subject: [PATCH] Print user defined options via -V --- dhcp.c | 16 ++++++++++++---- dhcp.h | 4 ++-- dhcp6.c | 15 ++++++++++++--- dhcp6.h | 4 ++-- dhcpcd.c | 17 ++++++++++++++--- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/dhcp.c b/dhcp.c index 0b108a30..3cea1cca 100644 --- a/dhcp.c +++ b/dhcp.c @@ -125,16 +125,24 @@ static const size_t udp_dhcp_len = sizeof(struct udp_dhcp_packet); 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); } diff --git a/dhcp.h b/dhcp.h index 6eabc4c6..bca918b8 100644 --- a/dhcp.h +++ b/dhcp.h @@ -250,7 +250,8 @@ char *decode_rfc3361(const uint8_t *, size_t); 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_close(struct interface *); 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 diff --git a/dhcp6.c b/dhcp6.c index 921ea00c..9cd9e734 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -121,13 +121,22 @@ static const char * const dhcp6_statuses[] = { }; 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); } diff --git a/dhcp6.h b/dhcp6.h index 27a6932e..f8602dbe 100644 --- a/dhcp6.h +++ b/dhcp6.h @@ -225,7 +225,8 @@ struct dhcp6_state { ((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_handleifa(struct dhcpcd_ctx *, int, const char *, 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) diff --git a/dhcpcd.c b/dhcpcd.c index 294364cf..3ed932b1 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1282,6 +1282,8 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) } 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 @@ main(int argc, char **argv) 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; -- 2.47.3