dhcpv4: use search domain instead of domain option
authorSteven Barth <steven@midlink.org>
Thu, 12 Jun 2014 08:01:06 +0000 (10:01 +0200)
committerSteven Barth <steven@midlink.org>
Thu, 12 Jun 2014 08:01:06 +0000 (10:01 +0200)
src/dhcpv4.c
src/dhcpv4.h

index 4b694672455b25c8c3489f9099fbb8436cc40bdd..53e46824b2a430e6ecee6e8d5465792df88cddbc 100644 (file)
@@ -362,14 +362,16 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
                dhcpv4_put(&reply, &cookie, DHCPV4_OPT_MTU, 2, &mtu);
        }
 
-       if (iface->search) {
-               char b[256];
-               if (dn_expand(iface->search, iface->search + iface->search_len,
-                               iface->search, b, sizeof(b)) > 0)
-                       dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DOMAIN, strlen(b), b);
+       if (iface->search && iface->search_len <= 255) {
+               dhcpv4_put(&reply, &cookie, DHCPV4_OPT_SEARCH_DOMAIN,
+                               iface->search_len, iface->search);
        } else if (!res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
-               dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DOMAIN,
-                               strlen(_res.dnsrch[0]), _res.dnsrch[0]);
+               uint8_t search_buf[256];
+               int len = dn_comp(_res.dnsrch[0], search_buf,
+                                               sizeof(search_buf), NULL, NULL);
+               if (len > 0)
+                       dhcpv4_put(&reply, &cookie, DHCPV4_OPT_SEARCH_DOMAIN,
+                                       len, search_buf);
        }
 
        dhcpv4_put(&reply, &cookie, DHCPV4_OPT_ROUTER, 4, &ifaddr.sin_addr);
index a31d8fe4b4b4811e636422de32e697e3619d7bad..57d52dcb1b8059db77357cfedcf5c2815ca3d662 100644 (file)
@@ -51,6 +51,7 @@ enum dhcpv4_opt {
        DHCPV4_OPT_HOSTNAME = 10,
        DHCPV4_OPT_REQUEST = 17,
        DHCPV4_OPT_USER_CLASS = 77,
+       DHCPV4_OPT_SEARCH_DOMAIN = 119,
        DHCPV4_OPT_END = 255,
 };