chiark / gitweb /
networkd: monopolize in_addr utility functions in shared/in-addr-util.h
[elogind.git] / src / network / networkd-link.c
index d633399890d29f3b576c09a18b64ff7cf32bc7ec..d13a47bb2ebc705dc9fd0009b1bd015309c2ea93 100644 (file)
@@ -311,7 +311,7 @@ static int link_enter_configured(Link *link) {
 
                 log_debug_link(link, "offering DHCPv4 leases");
 
-                r = sd_dhcp_server_set_address(link->dhcp_server, &address->in_addr.in);
+                r = sd_dhcp_server_set_address(link->dhcp_server, &address->in_addr.in, address->prefixlen);
                 if (r < 0)
                         return r;
 
@@ -750,7 +750,7 @@ static int link_enter_set_addresses(Link *link) {
                         return r;
                 }
 
-                prefixlen = net_netmask_to_prefixlen(&netmask);
+                prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
                 r = address_new_dynamic(&address);
                 if (r < 0) {
@@ -983,7 +983,7 @@ static int dhcp_lease_lost(Link *link) {
 
                 sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
                 sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
-                prefixlen = net_netmask_to_prefixlen(&netmask);
+                prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
                 address->family = AF_INET;
                 address->in_addr.in = addr;
@@ -1073,7 +1073,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
                 return r;
         }
 
-        prefixlen = net_netmask_to_prefixlen(&netmask);
+        prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
         r = sd_dhcp_lease_get_router(lease, &gateway);
         if (r < 0 && r != -ENOENT) {
@@ -1835,6 +1835,12 @@ static int link_configure(Link *link) {
                 if (r < 0)
                         return r;
 
+                if (link->mtu) {
+                        r = sd_dhcp_client_set_mtu(link->dhcp_client, link->mtu);
+                        if (r < 0)
+                                return r;
+                }
+
                 if (link->network->dhcp_mtu) {
                         r = sd_dhcp_client_set_request_option(link->dhcp_client, DHCP_OPTION_INTERFACE_MTU);
                         if (r < 0)
@@ -2146,7 +2152,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
                 sprintf(ifindex_str, "n%d", link->ifindex);
                 device = udev_device_new_from_device_id(m->udev, ifindex_str);
                 if (!device) {
-                        log_warning_link(link, "could not find udev device");
+                        log_warning_link(link, "could not find udev device: %m");
                         return -errno;
                 }
 
@@ -2174,6 +2180,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
 int link_update(Link *link, sd_rtnl_message *m) {
         struct ether_addr mac;
         const char *ifname;
+        uint32_t mtu;
         int r;
 
         assert(link);
@@ -2196,11 +2203,23 @@ int link_update(Link *link, sd_rtnl_message *m) {
                         return -ENOMEM;
         }
 
-        if (!link->original_mtu) {
-                r = sd_rtnl_message_read_u16(m, IFLA_MTU, &link->original_mtu);
-                if (r >= 0)
+        r = sd_rtnl_message_read_u32(m, IFLA_MTU, &mtu);
+        if (r >= 0 && mtu > 0) {
+                link->mtu = mtu;
+                if (!link->original_mtu) {
+                        link->original_mtu = mtu;
                         log_debug_link(link, "saved original MTU: %"
-                                       PRIu16, link->original_mtu);
+                                       PRIu32, link->original_mtu);
+                }
+
+                if (link->dhcp_client) {
+                        r = sd_dhcp_client_set_mtu(link->dhcp_client, link->mtu);
+                        if (r < 0) {
+                                log_warning_link(link, "Could not update MTU in DHCP client: %s",
+                                                 strerror(-r));
+                                return r;
+                        }
+                }
         }
 
         /* The kernel may broadcast NEWLINK messages without the MAC address
@@ -2366,6 +2385,8 @@ int link_save(Link *link) {
                                 (address + 1 ? " " : ""));
 
                 fputs("\n", f);
+
+                fprintf(f, "LLMNR=%s\n", llmnr_support_to_string(link->network->llmnr));
         }
 
         if (link->dhcp_lease) {
@@ -2418,55 +2439,3 @@ static const char* const link_operstate_table[_LINK_OPERSTATE_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(link_operstate, LinkOperationalState);
-
-static const char* const dhcp_support_table[_DHCP_SUPPORT_MAX] = {
-        [DHCP_SUPPORT_NONE] = "none",
-        [DHCP_SUPPORT_BOTH] = "both",
-        [DHCP_SUPPORT_V4] = "v4",
-        [DHCP_SUPPORT_V6] = "v6",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(dhcp_support, DHCPSupport);
-
-int config_parse_dhcp(
-                const char* unit,
-                const char *filename,
-                unsigned line,
-                const char *section,
-                unsigned section_line,
-                const char *lvalue,
-                int ltype,
-                const char *rvalue,
-                void *data,
-                void *userdata) {
-
-        DHCPSupport *dhcp = data;
-        int k;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-        assert(data);
-
-        /* Our enum shall be a superset of booleans, hence first try
-         * to parse as boolean, and then as enum */
-
-        k = parse_boolean(rvalue);
-        if (k > 0)
-                *dhcp = DHCP_SUPPORT_BOTH;
-        else if (k == 0)
-                *dhcp = DHCP_SUPPORT_NONE;
-        else {
-                DHCPSupport s;
-
-                s = dhcp_support_from_string(rvalue);
-                if (s < 0){
-                        log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse DHCP option, ignoring: %s", rvalue);
-                        return 0;
-                }
-
-                *dhcp = s;
-        }
-
-        return 0;
-}