[Openvpn-devel,v1] dhcp: Replace DHCP Option types with defines

Message ID 20251011082232.27602-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v1] dhcp: Replace DHCP Option types with defines | expand

Commit Message

Gert Doering Oct. 11, 2025, 8:22 a.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

Just nicer. Verified against
https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml

Change-Id: Ie41101bd00d038fa6fb906f3d30d44bf65788b96
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1266
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1266
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <gert@greenie.muc.de>

Comments

Gert Doering Oct. 11, 2025, 8:40 a.m. UTC | #1
"Because it makes sense".  Magic numbers are never good.

Verified that the new constants match the old magic number (not checked
the RFC, but "the old numbers" are what we had, so those should be fine).

Your patch has been applied to the master branch.

commit e03d53842b5494d8caf19fc47ea788a32a3544c7
Author: Frank Lichtenheld
Date:   Sat Oct 11 10:22:26 2025 +0200

     dhcp: Replace DHCP Option types with defines

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1266
     Message-Id: <20251011082232.27602-1-gert@greenie.muc.de>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59245241/
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dhcp.c b/src/openvpn/dhcp.c
index 653127d..56f03f2 100644
--- a/src/openvpn/dhcp.c
+++ b/src/openvpn/dhcp.c
@@ -342,27 +342,27 @@ 
     bool error = false;
     if (o->domain)
     {
-        write_dhcp_str(buf, 15, o->domain, &error);
+        write_dhcp_str(buf, DHCP_DOMAIN_NAME, o->domain, &error);
     }
 
     if (o->netbios_scope)
     {
-        write_dhcp_str(buf, 47, o->netbios_scope, &error);
+        write_dhcp_str(buf, DHCP_NETBIOS_SCOPE, o->netbios_scope, &error);
     }
 
     if (o->netbios_node_type)
     {
-        write_dhcp_u8(buf, 46, o->netbios_node_type, &error);
+        write_dhcp_u8(buf, DHCP_NETBIOS_NODE_TYPE, o->netbios_node_type, &error);
     }
 
-    write_dhcp_u32_array(buf, 6, (uint32_t *)o->dns, o->dns_len, &error);
-    write_dhcp_u32_array(buf, 44, (uint32_t *)o->wins, o->wins_len, &error);
-    write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
-    write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
+    write_dhcp_u32_array(buf, DHCP_DOMAIN_SERVER, (uint32_t *)o->dns, o->dns_len, &error);
+    write_dhcp_u32_array(buf, DHCP_NETBIOS_DOMAIN_SERVER, (uint32_t *)o->wins, o->wins_len, &error);
+    write_dhcp_u32_array(buf, DHCP_NTP_SERVER, (uint32_t *)o->ntp, o->ntp_len, &error);
+    write_dhcp_u32_array(buf, DHCP_NETBIOS_DIST_SERVER, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
     if (o->domain_search_list_len > 0)
     {
-        write_dhcp_search_str(buf, 119, o->domain_search_list, o->domain_search_list_len, &error);
+        write_dhcp_search_str(buf, DHCP_DOMAIN_SEARCH, o->domain_search_list, o->domain_search_list_len, &error);
     }
 
     /* the MS DHCP server option 'Disable Netbios-over-TCP/IP
@@ -375,7 +375,7 @@ 
             msg(M_WARN, "build_dhcp_options_string: buffer overflow building DHCP options");
             return false;
         }
-        buf_write_u8(buf, 43);
+        buf_write_u8(buf, DHCP_VENDOR);
         buf_write_u8(buf, 6); /* total length field */
         buf_write_u8(buf, 0x001);
         buf_write_u8(buf, 4); /* length of the vendor specified field */
diff --git a/src/openvpn/dhcp.h b/src/openvpn/dhcp.h
index 8e15a39..3fcd2b6 100644
--- a/src/openvpn/dhcp.h
+++ b/src/openvpn/dhcp.h
@@ -30,10 +30,19 @@ 
 #pragma pack(1)
 
 /* DHCP Option types */
-#define DHCP_PAD      0
-#define DHCP_ROUTER   3
-#define DHCP_MSG_TYPE 53 /* message type (u8) */
-#define DHCP_END      255
+#define DHCP_PAD                   0
+#define DHCP_ROUTER                3
+#define DHCP_DOMAIN_SERVER         6
+#define DHCP_DOMAIN_NAME           15
+#define DHCP_NTP_SERVER            42
+#define DHCP_VENDOR                43
+#define DHCP_NETBIOS_DOMAIN_SERVER 44
+#define DHCP_NETBIOS_DIST_SERVER   45
+#define DHCP_NETBIOS_NODE_TYPE     46
+#define DHCP_NETBIOS_SCOPE         47
+#define DHCP_MSG_TYPE              53
+#define DHCP_DOMAIN_SEARCH         119
+#define DHCP_END                   255
 
 /* DHCP Messages types */
 #define DHCPDISCOVER 1