]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-server: also send DNS servers or friends on DHCPOFFER
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 May 2023 07:42:27 +0000 (16:42 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 13 May 2023 11:37:17 +0000 (12:37 +0100)
From RFC 2131 section 4.3.1 (https://www.rfc-editor.org/rfc/rfc2131#section-4.3.1):
----
The server MUST return to the client:
- Parameters requested by the client, according to the following rules:
  -- IF the server has been explicitly configured with a default
     value for the parameter, the server MUST include that value
     in an appropriate option in the 'option' field,
----
The sentence is not only for ACK, but for all (positive) responses, that
is DHCPOFFER and DHCPACK.

Fixes #27471.

src/libsystemd-network/sd-dhcp-server.c

index 55290ee0f114d83b7268b6b8c6a5e4d54edb8141..196867360f1f54ce50bdf0bea50fd28b2de59f21 100644 (file)
@@ -564,6 +564,15 @@ static int server_send_offer_or_ack(
                 be32_t address,
                 uint8_t type) {
 
+        static const uint8_t option_map[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = {
+                [SD_DHCP_LEASE_DNS]  = SD_DHCP_OPTION_DOMAIN_NAME_SERVER,
+                [SD_DHCP_LEASE_NTP]  = SD_DHCP_OPTION_NTP_SERVER,
+                [SD_DHCP_LEASE_SIP]  = SD_DHCP_OPTION_SIP_SERVER,
+                [SD_DHCP_LEASE_POP3] = SD_DHCP_OPTION_POP3_SERVER,
+                [SD_DHCP_LEASE_SMTP] = SD_DHCP_OPTION_SMTP_SERVER,
+                [SD_DHCP_LEASE_LPR]  = SD_DHCP_OPTION_LPR_SERVER,
+        };
+
         _cleanup_free_ DHCPPacket *packet = NULL;
         sd_dhcp_option *j;
         be32_t lease_time;
@@ -619,38 +628,26 @@ static int server_send_offer_or_ack(
                         return r;
         }
 
-        if (type == DHCP_ACK) {
-                static const uint8_t option_map[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = {
-                        [SD_DHCP_LEASE_DNS] = SD_DHCP_OPTION_DOMAIN_NAME_SERVER,
-                        [SD_DHCP_LEASE_NTP] = SD_DHCP_OPTION_NTP_SERVER,
-                        [SD_DHCP_LEASE_SIP] = SD_DHCP_OPTION_SIP_SERVER,
-                        [SD_DHCP_LEASE_POP3] = SD_DHCP_OPTION_POP3_SERVER,
-                        [SD_DHCP_LEASE_SMTP] = SD_DHCP_OPTION_SMTP_SERVER,
-                        [SD_DHCP_LEASE_LPR] = SD_DHCP_OPTION_LPR_SERVER,
-                };
-
-                for (sd_dhcp_lease_server_type_t k = 0; k < _SD_DHCP_LEASE_SERVER_TYPE_MAX; k++) {
-                        if (server->servers[k].size <= 0)
-                                continue;
-
-                        r = dhcp_option_append(
-                                        &packet->dhcp, req->max_optlen, &offset, 0,
-                                        option_map[k],
-                                        sizeof(struct in_addr) * server->servers[k].size,
-                                        server->servers[k].addr);
-                        if (r < 0)
-                                return r;
-                }
+        for (sd_dhcp_lease_server_type_t k = 0; k < _SD_DHCP_LEASE_SERVER_TYPE_MAX; k++) {
+                if (server->servers[k].size <= 0)
+                        continue;
 
+                r = dhcp_option_append(
+                                &packet->dhcp, req->max_optlen, &offset, 0,
+                                option_map[k],
+                                sizeof(struct in_addr) * server->servers[k].size,
+                                server->servers[k].addr);
+                if (r < 0)
+                        return r;
+        }
 
-                if (server->timezone) {
-                        r = dhcp_option_append(
-                                        &packet->dhcp, req->max_optlen, &offset, 0,
-                                        SD_DHCP_OPTION_TZDB_TIMEZONE,
-                                        strlen(server->timezone), server->timezone);
-                        if (r < 0)
-                                return r;
-                }
+        if (server->timezone) {
+                r = dhcp_option_append(
+                                &packet->dhcp, req->max_optlen, &offset, 0,
+                                SD_DHCP_OPTION_TZDB_TIMEZONE,
+                                strlen(server->timezone), server->timezone);
+                if (r < 0)
+                        return r;
         }
 
         ORDERED_SET_FOREACH(j, server->extra_options) {