According to RFC 2132 (9.14. Client identifier) a hardware type of 0
authorflorian <florian@openbsd.org>
Mon, 20 Sep 2021 11:46:22 +0000 (11:46 +0000)
committerflorian <florian@openbsd.org>
Mon, 20 Sep 2021 11:46:22 +0000 (11:46 +0000)
should be used when the client identifier is not a hardware address,
for example if it's just a string. It turns out that the majority of
dhcp clients (and possibly servers?) does not do this but rather
transmits the client identifier verbatim if a string is
configured. The first character becomes the hardware type.
Make dhcpleased(8) behave the same.
Difference in behavior with dhclient(8) and interoperability issues
with dhcp(8) first pointed out by Olivier Cherrier on misc@
OK sthen
fine to get it in for 7.0 deraadt

sbin/dhcpleased/dhcpleased.conf.5
sbin/dhcpleased/parse.y
sbin/dhcpleased/printconf.c

index a54ea98..fcc7f66 100644 (file)
@@ -1,4 +1,4 @@
-.\"    $OpenBSD: dhcpleased.conf.5,v 1.5 2021/08/12 12:41:08 florian Exp $
+.\"    $OpenBSD: dhcpleased.conf.5,v 1.6 2021/09/20 11:46:22 florian Exp $
 .\"
 .\" Copyright (c) 2018, 2021 Florian Obser <florian@openbsd.org>
 .\" Copyright (c) 2005 Esben Norby <norby@openbsd.org>
@@ -18,7 +18,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: August 12 2021 $
+.Dd $Mdocdate: September 20 2021 $
 .Dt DHCPLEASED.CONF 5
 .Os
 .Sh NAME
@@ -82,7 +82,7 @@ send client id "01:00:53:FF:AA:BB:CC"
 .Pp
 Otherwise the string
 .Ar client-id
-is sent verbatim with type zero.
+is sent verbatim.
 The default is to send the interface's MAC address as client identifier.
 .It Ic send vendor class id Ar vendor-class-id
 Send the dhcp vendor class identifier option with a value of
index 3df654e..12e332f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.y,v 1.3 2021/08/12 12:41:08 florian Exp $       */
+/*     $OpenBSD: parse.y,v 1.4 2021/09/20 11:46:22 florian Exp $       */
 
 /*
  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -252,15 +252,14 @@ ifaceoptsl        : SEND VENDOR CLASS ID STRING {
                                        yyerror("client-id too long");
                                        YYERROR;
                                }
-                               iface_conf->c_id_len = 3 + strlen(buf);
+                               iface_conf->c_id_len = 2 + len;
                                iface_conf->c_id = malloc(iface_conf->c_id_len);
                                if (iface_conf->c_id == NULL) {
                                        yyerror("malloc");
                                        YYERROR;
                                }
-                               iface_conf->c_id[2] = HTYPE_NONE;
-                               memcpy(&iface_conf->c_id[3], buf,
-                                   iface_conf->c_id_len - 3);
+                               memcpy(&iface_conf->c_id[2], buf,
+                                   iface_conf->c_id_len - 2);
                        } else {
                                free($4);
                                iface_conf->c_id_len = 2 + i;
index 593733f..5de7869 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: printconf.c,v 1.2 2021/08/12 12:41:08 florian Exp $   */
+/*     $OpenBSD: printconf.c,v 1.3 2021/09/20 11:46:22 florian Exp $   */
 
 /*
  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -45,7 +45,7 @@ print_dhcp_options(char *indent, uint8_t *p, int len)
 {
        static char      buf[4 * 1500 + 1];
        int              rem, i;
-       uint8_t          dho, dho_len, type;
+       uint8_t          dho, dho_len;
 
        rem = len;
 
@@ -72,28 +72,22 @@ print_dhcp_options(char *indent, uint8_t *p, int len)
                case DHO_DHCP_CLIENT_IDENTIFIER:
                        if (dho_len < 1)
                                fatal("dhcp option too short");
-                       type = *p;
-                       p += 1;
-                       rem -= 1;
-                       switch (type) {
-                       case HTYPE_NONE:
-                               strvisx(buf, p, dho_len - 1, VIS_DQ |
-                                   VIS_CSTYLE);
-                               printf("%ssend client id \"%s\"\n",
-                                   indent, buf);
+                       switch (*p) {
+                       case HTYPE_ETHER:
+                               printf("%ssend client id \"", indent);
+                               for (i = 0; i < dho_len; i++)
+                                       printf("%s%02x", i != 0? ":" : "",
+                                           *(p + i));
+                               printf("\"\n");
                                break;
                        default:
-                               printf("%ssend client id \"%02x",
-                                   indent, type);
-
-                               for (i = 0; i < dho_len - 1; i++) {
-                                       printf(":%02x", *(p + i));
-                               }
-                               printf("\"\n");
+                               strvisx(buf, p, dho_len, VIS_DQ | VIS_CSTYLE);
+                               printf("%ssend client id \"%s\"\n",
+                                   indent, buf);
                                break;
                        }
-                       p += dho_len - 1;
-                       rem -= dho_len - 1;
+                       p += dho_len;
+                       rem -= dho_len;
                        break;
                default:
                        fatal("unknown dhcp option: %d [%d]", *p, rem);