Replace yet another hand-rolled list with a TAILQ. reject_list this
authorkrw <krw@openbsd.org>
Mon, 30 Dec 2013 03:36:17 +0000 (03:36 +0000)
committerkrw <krw@openbsd.org>
Mon, 30 Dec 2013 03:36:17 +0000 (03:36 +0000)
time.

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

index eba4972..ca88396 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: clparse.c,v 1.64 2013/12/28 21:48:04 krw Exp $        */
+/*     $OpenBSD: clparse.c,v 1.65 2013/12/30 03:36:17 krw Exp $        */
 
 /* Parser for dhclient config and lease files. */
 
@@ -748,7 +748,7 @@ bad_flag:
 void
 parse_reject_statement(FILE *cfile)
 {
-       struct reject_elem *list;
+       struct reject_elem *elem;
        struct in_addr addr;
        int token;
 
@@ -759,13 +759,12 @@ parse_reject_statement(FILE *cfile)
                        return;
                }
 
-               list = malloc(sizeof(struct reject_elem));
-               if (!list)
-                       error("no memory for reject list!");
+               elem = malloc(sizeof(struct reject_elem));
+               if (!elem)
+                       error("no memory for reject address!");
 
-               list->addr = addr;
-               list->next = config->reject_list;
-               config->reject_list = list;
+               elem->addr = addr;
+               TAILQ_INSERT_TAIL(&config->reject_list, elem, next);
 
                token = next_token(NULL, cfile);
        } while (token == ',');
index 9bc527c..0b5768d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhclient.c,v 1.280 2013/12/21 18:23:10 krw Exp $      */
+/*     $OpenBSD: dhclient.c,v 1.281 2013/12/30 03:36:17 krw Exp $      */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -456,6 +456,7 @@ main(int argc, char *argv[])
        config = calloc(1, sizeof(*config));
        if (config == NULL)
                error("config calloc");
+       TAILQ_INIT(&config->reject_list);
 
        get_ifname(argv[0]);
        if (path_dhclient_db == NULL && asprintf(&path_dhclient_db, "%s.%s",
index 8d6c382..ef7d992 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhcpd.h,v 1.127 2013/12/21 18:23:10 krw Exp $ */
+/*     $OpenBSD: dhcpd.h,v 1.128 2013/12/30 03:36:17 krw Exp $ */
 
 /*
  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -89,7 +89,7 @@ struct option_data {
 };
 
 struct reject_elem {
-       struct reject_elem      *next;
+       TAILQ_ENTRY(reject_elem) next;
        struct in_addr           addr;
 };
 
@@ -142,7 +142,7 @@ struct client_config {
        time_t                   backoff_cutoff;
        enum { IGNORE, ACCEPT, PREFER }
                                 bootp_policy;
-       struct reject_elem      *reject_list;
+       TAILQ_HEAD(, reject_elem) reject_list;
        char                    *resolv_tail;
 };
 
index be8659c..cb10ee3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: options.c,v 1.64 2013/12/22 04:47:57 krw Exp $        */
+/*     $OpenBSD: options.c,v 1.65 2013/12/30 03:36:17 krw Exp $        */
 
 /* DHCP options parsing and reassembly. */
 
@@ -488,7 +488,7 @@ do_packet(unsigned int from_port, struct in_addr from,
                return;
        }
 
-       for (ap = config->reject_list; ap; ap = ap->next)
+       TAILQ_FOREACH(ap, &config->reject_list, next)
                if (from.s_addr == ap->addr.s_addr) {
 #ifdef DEBUG
                        debug("Discarding packet from address on reject list "