Hi.

I've got a bunch of things that have static reservations by MAC address in
dhcpd.conf.  I also have the MAC addresses in /etc/ethers for tcpdumping.
This duplication and potential inconsistency annoys me.

Is there any reason we can't have dhcpd look up names in /etc/ethers?

Index: usr.sbin/dhcpd/parse.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/parse.c,v
retrieving revision 1.26
diff -u -p -r1.26 parse.c
--- usr.sbin/dhcpd/parse.c      16 Feb 2017 00:24:43 -0000      1.26
+++ usr.sbin/dhcpd/parse.c      18 Feb 2020 09:36:02 -0000
@@ -46,6 +46,7 @@
 #include <net/if.h>
 
 #include <netinet/in.h>
+#include <netinet/if_ether.h>
 
 #include <ctype.h>
 #include <errno.h>
@@ -218,8 +219,8 @@ void
 parse_hardware_param(FILE *cfile, struct hardware *hardware)
 {
        char *val;
-       int token, hlen;
-       unsigned char *t;
+       int token, hlen = 0;
+       unsigned char *e, *t = NULL;
 
        token = next_token(&val, cfile);
        switch (token) {
@@ -235,6 +236,19 @@ parse_hardware_param(FILE *cfile, struct
                return;
        }
 
+       /* Try looking up in /etc/ethers first. */
+       if (hardware->htype == HTYPE_ETHER) {
+               token = peek_token(&val, cfile);
+               hlen = sizeof(struct ether_addr);
+               if ((e = malloc(hlen)) == NULL)
+                       fatalx("can't allocate space for ethernet address.");
+               if (ether_hostton(val, (struct ether_addr *)e) == 0) {
+                       (void)next_token(&val, cfile); /* consume token */
+                       t = e;
+               } else
+                       free(e);
+       }
+
        /*
         * Parse the hardware address information.   Technically, it
         * would make a lot of sense to restrict the length of the data
@@ -244,8 +258,9 @@ parse_hardware_param(FILE *cfile, struct
         * accept that data in the lease file rather than simply failing
         * on such clients.   Yuck.
         */
-       hlen = 0;
-       t = parse_numeric_aggregate(cfile, NULL, &hlen, ':', 16, 8);
+       if (!t)
+               t = parse_numeric_aggregate(cfile, NULL, &hlen, ':', 16, 8);
+
        if (!t)
                return;
        if (hlen > sizeof(hardware->haddr)) {

-- 
Darren Tucker (dtucker at dtucker.net)
GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860  37F4 9357 ECEF 11EA A6FA (new)
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.

Reply via email to