]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Print user defined options via -V
authorRoy Marples <roy@marples.name>
Thu, 3 Jul 2014 23:11:00 +0000 (23:11 +0000)
committerRoy Marples <roy@marples.name>
Thu, 3 Jul 2014 23:11:00 +0000 (23:11 +0000)
dhcp.c
dhcp.h
dhcp6.c
dhcp6.h
dhcpcd.c

diff --git a/dhcp.c b/dhcp.c
index 0b108a305eb4a71f7455572cec45a554930e0bc2..3cea1ccacb882dc8cc3958c14d837c7e3783384e 100644 (file)
--- 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 6eabc4c667b208d05cef32ffaaf3d1f9661369d3..bca918b856ec235e5eb67179c6fc746622f906c7 100644 (file)
--- 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 921ea00cc27be35f139062c8b8cdf6e4308d4c31..9cd9e734322a8439703a9dfc96f7397a5bb5f3eb 100644 (file)
--- 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 27a6932eff14199956e6a2d5535354d36aa421ac..f8602dbe3924d583fb402a85f16bb7c2f78cfe28 100644 (file)
--- 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)
index 294364cf272722e70c6980d38829df84535c8884..3ed932b133192d2eaa78291d2321ae02db09dff2 100644 (file)
--- 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;