]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: move and rename network_apply_anonymize_if_set()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Apr 2021 03:41:23 +0000 (12:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 14 Apr 2021 04:06:50 +0000 (13:06 +0900)
src/network/networkd-dhcp-common.c
src/network/networkd-dhcp4.c
src/network/networkd-dhcp4.h
src/network/networkd-network.c

index 9677dfb0c36b39e4998613f8b1153ea1c2453302..f09f0ee50e45d024189a67b52268f1a7047083f0 100644 (file)
@@ -57,6 +57,8 @@ void network_adjust_dhcp(Network *network) {
                             "Disabling DHCPv6 client.", network->filename);
                 SET_FLAG(network->dhcp, ADDRESS_FAMILY_IPV6, false);
         }
+
+        network_adjust_dhcp4(network);
 }
 
 static struct DUID fallback_duid = { .type = DUID_TYPE_EN };
index 6f06e2218d348897461b8b66984da1fc4351d998..a27bf9ba64033bb32f5916014d99af35f0348ad2 100644 (file)
 static int dhcp4_update_address(Link *link, bool announce);
 static int dhcp4_remove_all(Link *link);
 
+void network_adjust_dhcp4(Network *network) {
+        assert(network);
+
+        if (!FLAGS_SET(network->dhcp, ADDRESS_FAMILY_IPV4))
+                return;
+
+        if (network->dhcp_use_gateway < 0)
+                network->dhcp_use_gateway = network->dhcp_use_routes;
+
+        if (network->dhcp_anonymize) {
+                /* RFC7844 3.7: SHOULD NOT send the Host Name option */
+                network->dhcp_send_hostname = false;
+
+                /* RFC7844 section 3.: MAY contain the Client Identifier option
+                 * Section 3.5: clients MUST use client identifiers based solely on the link-layer address
+                 * NOTE: Using MAC, as it does not reveal extra information, and some servers might not
+                 * answer if this option is not sent */
+                network->dhcp_client_identifier = DHCP_CLIENT_ID_MAC;
+
+                /* RFC7844 3.10: SHOULD NOT use the Vendor Class Identifier option */
+                network->dhcp_vendor_class_identifier = mfree(network->dhcp_vendor_class_identifier);
+
+                /* RFC7844 section 3.6.: The client intending to protect its privacy SHOULD only
+                 * request a minimal number of options in the PRL and SHOULD also randomly shuffle the
+                 * ordering of option codes in the PRL. If this random ordering cannot be implemented,
+                 * the client MAY order the option codes in the PRL by option code number (lowest to
+                 * highest).
+                 *
+                 * TODO: Maybe there should be another variable called dhcp_request_mtu (to use the MTU
+                 * sent by the server but to do not request the option in the PRL)? */
+                network->dhcp_use_mtu = false;
+
+                /* NOTE: when Anonymize=yes, the PRL route options are sent by default, but this is
+                 * needed to use them. */
+                network->dhcp_use_routes = true;
+
+                /* RFC7844 section 3.6: same comments as previous option */
+                network->dhcp_use_timezone = false;
+        }
+}
+
 static int dhcp4_release_old_lease(Link *link) {
         Route *route;
         int k, r = 0;
index 5ec2f88b7ee4321066d93c3c5974953364315af4..cfad656c3d74a7f562af1f4102b6af2538887c4d 100644 (file)
@@ -17,6 +17,7 @@ typedef enum DHCPClientIdentifier {
         _DHCP_CLIENT_ID_INVALID = -EINVAL,
 } DHCPClientIdentifier;
 
+void network_adjust_dhcp4(Network *network);
 int dhcp4_configure(Link *link);
 int dhcp4_update_mac(Link *link);
 
index 8ae2315f1b8bb2c4e06f815b1bcd323a4206cb77..1c119bcf59da6858bb9939fe274c3463c874a6cd 100644 (file)
 /* Let's assume that anything above this number is a user misconfiguration. */
 #define MAX_NTP_SERVERS 128
 
-/* Set defaults following RFC7844 */
-void network_apply_anonymize_if_set(Network *network) {
-        if (!network->dhcp_anonymize)
-                return;
-        /* RFC7844 3.7
-         SHOULD NOT send the Host Name option */
-        network->dhcp_send_hostname = false;
-        /* RFC7844 section 3.:
-         MAY contain the Client Identifier option
-         Section 3.5:
-         clients MUST use client identifiers based solely
-         on the link-layer address */
-        /* NOTE: Using MAC, as it does not reveal extra information,
-        * and some servers might not answer if this option is not sent */
-        network->dhcp_client_identifier = DHCP_CLIENT_ID_MAC;
-        /* RFC 7844 3.10:
-         SHOULD NOT use the Vendor Class Identifier option */
-        network->dhcp_vendor_class_identifier = mfree(network->dhcp_vendor_class_identifier);
-        /* RFC7844 section 3.6.:
-         The client intending to protect its privacy SHOULD only request a
-         minimal number of options in the PRL and SHOULD also randomly shuffle
-         the ordering of option codes in the PRL. If this random ordering
-         cannot be implemented, the client MAY order the option codes in the
-         PRL by option code number (lowest to highest).
-        */
-        /* NOTE: dhcp_use_mtu is false by default,
-        * though it was not initiallized to any value in network_load_one.
-        * Maybe there should be another var called *send*?
-        * (to use the MTU sent by the server but to do not send
-        * the option in the PRL). */
-        network->dhcp_use_mtu = false;
-        /* NOTE: when Anonymize=yes, the PRL route options are sent by default,
-         * but this is needed to use them. */
-        network->dhcp_use_routes = true;
-        /* RFC7844 section 3.6.
-        * same comments as previous option */
-        network->dhcp_use_timezone = false;
-}
-
 static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret_netdev) {
         const char *kind_string;
         NetDev *netdev;
@@ -223,9 +184,6 @@ int network_verify(Network *network) {
                 network->dhcp_use_mtu = false;
         }
 
-        if (network->dhcp_use_gateway < 0)
-                network->dhcp_use_gateway = network->dhcp_use_routes;
-
         if (network->dhcp_critical >= 0) {
                 if (network->keep_configuration >= 0)
                         log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. "
@@ -353,19 +311,19 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
                 .dhcp_use_hostname = true,
                 .dhcp_use_routes = true,
                 .dhcp_use_gateway = -1,
-                /* NOTE: this var might be overwritten by network_apply_anonymize_if_set */
+                /* NOTE: this var might be overwritten by network_adjust_dhcp4() */
                 .dhcp_send_hostname = true,
                 .dhcp_send_release = true,
                 /* To enable/disable RFC7844 Anonymity Profiles */
                 .dhcp_anonymize = false,
                 .dhcp_route_metric = DHCP_ROUTE_METRIC,
-                /* NOTE: this var might be overwritten by network_apply_anonymize_if_set */
+                /* NOTE: this var might be overwritten by network_adjust_dhcp4() */
                 .dhcp_client_identifier = DHCP_CLIENT_ID_DUID,
                 .dhcp_route_table = RT_TABLE_MAIN,
                 .dhcp_route_table_set = false,
-                /* NOTE: from man: UseMTU=... Defaults to false*/
+                /* NOTE: from man: UseMTU=... Defaults to false */
                 .dhcp_use_mtu = false,
-                /* NOTE: from man: UseTimezone=... Defaults to "no".*/
+                /* NOTE: from man: UseTimezone=... Defaults to "no". */
                 .dhcp_use_timezone = false,
                 .dhcp_ip_service_type = -1,
 
@@ -505,8 +463,6 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
         if (r < 0)
                 return r;
 
-        network_apply_anonymize_if_set(network);
-
         r = network_add_ipv4ll_route(network);
         if (r < 0)
                 log_warning_errno(r, "%s: Failed to add IPv4LL route, ignoring: %m", network->filename);