Add ACTION_IGNORE and nuke ignored_options, ignored_option_count fields
authorkrw <krw@openbsd.org>
Sat, 9 Dec 2017 15:48:04 +0000 (15:48 +0000)
committerkrw <krw@openbsd.org>
Sat, 9 Dec 2017 15:48:04 +0000 (15:48 +0000)
in struct client_config.

sbin/dhclient/clparse.c
sbin/dhclient/dhclient.c
sbin/dhclient/dhcpd.h

index ee00f74..d40694c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: clparse.c,v 1.153 2017/12/08 20:17:28 krw Exp $       */
+/*     $OpenBSD: clparse.c,v 1.154 2017/12/09 15:48:04 krw Exp $       */
 
 /* Parser for dhclient config and lease files. */
 
@@ -256,8 +256,9 @@ read_client_leases(char *name, struct client_lease_tq *tq)
 void
 parse_client_statement(FILE *cfile, char *name, int nested)
 {
+       uint8_t                  list[DHO_COUNT];
        char                    *val;
-       int                      i, token;
+       int                      i, count, token;
 
        token = next_token(NULL, cfile);
 
@@ -290,9 +291,11 @@ parse_client_statement(FILE *cfile, char *name, int nested)
                        parse_semi(cfile);
                break;
        case TOK_IGNORE:
-               if (parse_option_list(cfile, &config->ignored_option_count,
-                   config->ignored_options) == 1)
+               if (parse_option_list(cfile, &count, list) == 1) {
+                       for (i = 0; i < count; i++)
+                               config->default_actions[list[i]] = ACTION_IGNORE;
                        parse_semi(cfile);
+               }
                break;
        case TOK_INITIAL_INTERVAL:
                if (parse_lease_time(cfile, &config->initial_interval) == 1)
index 264eaeb..24d4404 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhclient.c,v 1.539 2017/12/08 20:17:28 krw Exp $      */
+/*     $OpenBSD: dhclient.c,v 1.540 2017/12/09 15:48:04 krw Exp $      */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -2187,7 +2187,7 @@ struct client_lease *
 apply_defaults(struct client_lease *lease)
 {
        struct client_lease     *newlease;
-       int                      i, j;
+       int                      i;
 
        newlease = clone_lease(lease);
        if (newlease == NULL)
@@ -2207,18 +2207,13 @@ apply_defaults(struct client_lease *lease)
                newlease->next_server.s_addr = config->next_server.s_addr;
 
        for (i = 0; i < DHO_COUNT; i++) {
-               for (j = 0; j < config->ignored_option_count; j++) {
-                       if (config->ignored_options[j] == i) {
-                               free(newlease->options[i].data);
-                               newlease->options[i].data = NULL;
-                               newlease->options[i].len = 0;
-                               break;
-                       }
-               }
-               if (j < config->ignored_option_count)
-                       continue;
-
                switch (config->default_actions[i]) {
+               case ACTION_IGNORE:
+                       free(newlease->options[i].data);
+                       newlease->options[i].data = NULL;
+                       newlease->options[i].len = 0;
+                       break;
+
                case ACTION_SUPERSEDE:
                        free(newlease->options[i].data);
                        newlease->options[i].len = config->defaults[i].len;
@@ -2392,8 +2387,8 @@ apply_ignore_list(char *ignore_list)
                        list[ix++] = i;
        }
 
-       config->ignored_option_count = ix;
-       memcpy(config->ignored_options, list, sizeof(config->ignored_options));
+       for (i = 0; i < ix; i++)
+               config->default_actions[list[i]] = ACTION_IGNORE;
 }
 
 void
index 6b46965..8e33725 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhcpd.h,v 1.240 2017/12/07 19:03:15 krw Exp $ */
+/*     $OpenBSD: dhcpd.h,v 1.241 2017/12/09 15:48:04 krw Exp $ */
 
 /*
  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -88,7 +88,8 @@ struct client_config {
                ACTION_DEFAULT,
                ACTION_SUPERSEDE,
                ACTION_PREPEND,
-               ACTION_APPEND
+               ACTION_APPEND,
+               ACTION_IGNORE
        } default_actions[DHO_COUNT];
 
        struct in_addr           address;
@@ -96,10 +97,8 @@ struct client_config {
        struct option_data       send_options[DHO_COUNT];
        uint8_t                  required_options[DHO_COUNT];
        uint8_t                  requested_options[DHO_COUNT];
-       uint8_t                  ignored_options[DHO_COUNT];
        int                      requested_option_count;
        int                      required_option_count;
-       int                      ignored_option_count;
        time_t                   timeout;
        time_t                   initial_interval;
        time_t                   link_timeout;