]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
dhcp: Replace DHCP Option types with defines
authorFrank Lichtenheld <frank@lichtenheld.com>
Sat, 11 Oct 2025 08:22:26 +0000 (10:22 +0200)
committerGert Doering <gert@greenie.muc.de>
Sat, 11 Oct 2025 08:37:34 +0000 (10:37 +0200)
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
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>
src/openvpn/dhcp.c
src/openvpn/dhcp.h

index 653127da88a627ef0921b16240ebe899df1ae4a5..56f03f223abd47681b43c62b401ee92ab0124640 100644 (file)
@@ -342,27 +342,27 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
     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 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
             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 */
index 8e15a3905babdf5f1c16bfa55147d9a5cf8984ae..3fcd2b6524b6252c8f0b1b01505b6f1596d419c3 100644 (file)
 #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