]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-dhcp-common.c
tree-wide: use ASSERT_PTR more
[thirdparty/systemd.git] / src / network / networkd-dhcp-common.c
index 0c0a76d362df45aa456eca5fc0cfaccec7a7df89..6526d3378fae25f65c945049a87fa3bd743b2bc5 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/if_arp.h>
 
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "dhcp-identifier.h"
 #include "dhcp-internal.h"
 #include "dhcp6-internal.h"
@@ -39,15 +40,6 @@ uint32_t link_get_dhcp4_route_table(Link *link) {
         return link_get_vrf_table(link);
 }
 
-uint32_t link_get_dhcp6_route_table(Link *link) {
-        assert(link);
-        assert(link->network);
-
-        if (link->network->dhcp6_route_table_set)
-                return link->network->dhcp6_route_table;
-        return link_get_vrf_table(link);
-}
-
 uint32_t link_get_ipv6_accept_ra_route_table(Link *link) {
         assert(link);
         assert(link->network);
@@ -61,6 +53,10 @@ bool link_dhcp_enabled(Link *link, int family) {
         assert(link);
         assert(IN_SET(family, AF_INET, AF_INET6));
 
+        /* Currently, sd-dhcp-client supports only ethernet and infiniband. */
+        if (family == AF_INET && !IN_SET(link->iftype, ARPHRD_ETHER, ARPHRD_INFINIBAND))
+                return false;
+
         if (family == AF_INET6 && !socket_ipv6_is_supported())
                 return false;
 
@@ -93,7 +89,7 @@ void network_adjust_dhcp(Network *network) {
 
         if (!FLAGS_SET(network->link_local, ADDRESS_FAMILY_IPV6) &&
             FLAGS_SET(network->dhcp, ADDRESS_FAMILY_IPV6)) {
-                log_warning("%s: DHCPv6 client is enabled but IPv6 link local addressing is disabled. "
+                log_warning("%s: DHCPv6 client is enabled but IPv6 link-local addressing is disabled. "
                             "Disabling DHCPv6 client.", network->filename);
                 SET_FLAG(network->dhcp, ADDRESS_FAMILY_IPV6, false);
         }
@@ -135,14 +131,13 @@ const DUID *link_get_duid(Link *link, int family) {
 }
 
 static int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
-        Manager *manager = userdata;
+        Manager *manager = ASSERT_PTR(userdata);
         const sd_bus_error *e;
         const void *a;
         size_t sz;
         int r;
 
         assert(m);
-        assert(manager);
 
         /* To avoid calling GetProductUUID() bus method so frequently, set the flag below
          * even if the method fails. */
@@ -192,12 +187,10 @@ int manager_request_product_uuid(Manager *m) {
 
         m->product_uuid_requested = false;
 
-        r = sd_bus_call_method_async(
+        r = bus_call_method_async(
                         m->bus,
                         NULL,
-                        "org.freedesktop.hostname1",
-                        "/org/freedesktop/hostname1",
-                        "org.freedesktop.hostname1",
+                        bus_hostname,
                         "GetProductUUID",
                         get_product_uuid_handler,
                         m,
@@ -339,7 +332,7 @@ int config_parse_dhcp_or_ra_route_metric(
                 return 0;
         }
 
-        switch(ltype) {
+        switch (ltype) {
         case AF_INET:
                 network->dhcp_route_metric = metric;
                 network->dhcp_route_metric_set = true;
@@ -390,7 +383,7 @@ int config_parse_dhcp_use_dns(
                 return 0;
         }
 
-        switch(ltype) {
+        switch (ltype) {
         case AF_INET:
                 network->dhcp_use_dns = r;
                 network->dhcp_use_dns_set = true;
@@ -441,7 +434,7 @@ int config_parse_dhcp_use_domains(
                 return 0;
         }
 
-        switch(ltype) {
+        switch (ltype) {
         case AF_INET:
                 network->dhcp_use_domains = d;
                 network->dhcp_use_domains_set = true;
@@ -492,7 +485,7 @@ int config_parse_dhcp_use_ntp(
                 return 0;
         }
 
-        switch(ltype) {
+        switch (ltype) {
         case AF_INET:
                 network->dhcp_use_ntp = r;
                 network->dhcp_use_ntp_set = true;
@@ -527,19 +520,14 @@ int config_parse_dhcp_or_ra_route_table(
                 void *data,
                 void *userdata) {
 
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         uint32_t rt;
         int r;
 
         assert(filename);
         assert(lvalue);
-        assert(IN_SET(ltype,
-                      (RTPROT_DHCP<<16) | AF_UNSPEC,
-                      (RTPROT_DHCP<<16) | AF_INET,
-                      (RTPROT_DHCP<<16) | AF_INET6,
-                      (RTPROT_RA<<16) | AF_INET6));
+        assert(IN_SET(ltype, AF_INET, AF_INET6));
         assert(rvalue);
-        assert(data);
 
         r = safe_atou32(rvalue, &rt);
         if (r < 0) {
@@ -548,29 +536,12 @@ int config_parse_dhcp_or_ra_route_table(
                 return 0;
         }
 
-        switch(ltype) {
-        case (RTPROT_DHCP<<16) | AF_INET:
+        switch (ltype) {
+        case AF_INET:
                 network->dhcp_route_table = rt;
                 network->dhcp_route_table_set = true;
-                network->dhcp_route_table_set_explicitly = true;
-                break;
-        case (RTPROT_DHCP<<16) | AF_INET6:
-                network->dhcp6_route_table = rt;
-                network->dhcp6_route_table_set = true;
-                network->dhcp6_route_table_set_explicitly = true;
-                break;
-        case (RTPROT_DHCP<<16) | AF_UNSPEC:
-                /* For backward compatibility. */
-                if (!network->dhcp_route_table_set_explicitly) {
-                        network->dhcp_route_table = rt;
-                        network->dhcp_route_table_set = true;
-                }
-                if (!network->dhcp6_route_table_set_explicitly) {
-                        network->dhcp6_route_table = rt;
-                        network->dhcp6_route_table_set = true;
-                }
                 break;
-        case (RTPROT_RA<<16) | AF_INET6:
+        case AF_INET6:
                 network->ipv6_accept_ra_route_table = rt;
                 network->ipv6_accept_ra_route_table_set = true;
                 break;
@@ -593,14 +564,13 @@ int config_parse_iaid(
                 void *data,
                 void *userdata) {
 
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         uint32_t iaid;
         int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
-        assert(network);
         assert(IN_SET(ltype, AF_INET, AF_INET6));
 
         r = safe_atou32(rvalue, &iaid);
@@ -641,10 +611,9 @@ int config_parse_dhcp_user_or_vendor_class(
                 void *data,
                 void *userdata) {
 
-        char ***l = data;
+        char ***l = ASSERT_PTR(data);
         int r;
 
-        assert(l);
         assert(lvalue);
         assert(rvalue);
         assert(IN_SET(ltype, AF_INET, AF_INET6));
@@ -708,7 +677,7 @@ int config_parse_dhcp_send_option(
         _unused_ _cleanup_(sd_dhcp6_option_unrefp) sd_dhcp6_option *old6 = NULL;
         uint32_t uint32_data, enterprise_identifier = 0;
         _cleanup_free_ char *word = NULL, *q = NULL;
-        OrderedHashmap **options = data;
+        OrderedHashmap **options = ASSERT_PTR(data);
         uint16_t u16, uint16_data;
         union in_addr_union addr;
         DHCPOptionDataType type;
@@ -721,7 +690,6 @@ int config_parse_dhcp_send_option(
         assert(filename);
         assert(lvalue);
         assert(rvalue);
-        assert(data);
 
         if (isempty(rvalue)) {
                 *options = ordered_hashmap_free(*options);
@@ -800,7 +768,7 @@ int config_parse_dhcp_send_option(
                 return 0;
         }
 
-        switch(type) {
+        switch (type) {
         case DHCP_OPTION_DATA_UINT8:{
                 r = safe_atou8(p, &uint8_data);
                 if (r < 0) {
@@ -1032,16 +1000,14 @@ int config_parse_duid_type(
                 void *userdata) {
 
         _cleanup_free_ char *type_string = NULL;
-        const char *p = rvalue;
+        const char *p = ASSERT_PTR(rvalue);
         bool force = ltype;
-        DUID *duid = data;
+        DUID *duid = ASSERT_PTR(data);
         DUIDType type;
         int r;
 
         assert(filename);
         assert(lvalue);
-        assert(rvalue);
-        assert(duid);
 
         if (!force && duid->set)
                 return 0;
@@ -1104,11 +1070,9 @@ int config_parse_manager_duid_type(
                 void *data,
                 void *userdata) {
 
-        Manager *manager = userdata;
+        Manager *manager = ASSERT_PTR(userdata);
         int r;
 
-        assert(manager);
-
         /* For backward compatibility. Setting both DHCPv4 and DHCPv6 DUID if they are not specified explicitly. */
 
         r = config_parse_duid_type(unit, filename, line, section, section_line, lvalue, false, rvalue, &manager->dhcp_duid, manager);
@@ -1130,11 +1094,9 @@ int config_parse_network_duid_type(
                 void *data,
                 void *userdata) {
 
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         int r;
 
-        assert(network);
-
         r = config_parse_duid_type(unit, filename, line, section, section_line, lvalue, true, rvalue, &network->dhcp_duid, network);
         if (r < 0)
                 return r;
@@ -1158,12 +1120,11 @@ int config_parse_duid_rawdata(
         uint8_t raw_data[MAX_DUID_LEN];
         unsigned count = 0;
         bool force = ltype;
-        DUID *duid = data;
+        DUID *duid = ASSERT_PTR(data);
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
-        assert(duid);
 
         if (!force && duid->set)
                 return 0;
@@ -1229,11 +1190,9 @@ int config_parse_manager_duid_rawdata(
                 void *data,
                 void *userdata) {
 
-        Manager *manager = userdata;
+        Manager *manager = ASSERT_PTR(userdata);
         int r;
 
-        assert(manager);
-
         /* For backward compatibility. Setting both DHCPv4 and DHCPv6 DUID if they are not specified explicitly. */
 
         r = config_parse_duid_rawdata(unit, filename, line, section, section_line, lvalue, false, rvalue, &manager->dhcp_duid, manager);
@@ -1255,11 +1214,9 @@ int config_parse_network_duid_rawdata(
                 void *data,
                 void *userdata) {
 
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         int r;
 
-        assert(network);
-
         r = config_parse_duid_rawdata(unit, filename, line, section, section_line, lvalue, true, rvalue, &network->dhcp_duid, network);
         if (r < 0)
                 return r;
@@ -1280,7 +1237,7 @@ int config_parse_uplink(
                 void *data,
                 void *userdata) {
 
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         bool accept_none = true;
         int *index, r;
         char **name;
@@ -1289,7 +1246,6 @@ int config_parse_uplink(
         assert(section);
         assert(lvalue);
         assert(rvalue);
-        assert(userdata);
 
         if (streq(section, "DHCPServer")) {
                 index = &network->dhcp_server_uplink_index;
@@ -1297,9 +1253,9 @@ int config_parse_uplink(
         } else if (streq(section, "IPv6SendRA")) {
                 index = &network->router_uplink_index;
                 name = &network->router_uplink_name;
-        } else if (streq(section, "DHCPv6PrefixDelegation")) {
-                index = &network->dhcp6_pd_uplink_index;
-                name = &network->dhcp_server_uplink_name;
+        } else if (STR_IN_SET(section, "DHCPv6PrefixDelegation", "DHCPPrefixDelegation")) {
+                index = &network->dhcp_pd_uplink_index;
+                name = &network->dhcp_pd_uplink_name;
                 accept_none = false;
         } else
                 assert_not_reached();