]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd,udev: clean up MTU handling
authorLennart Poettering <lennart@poettering.net>
Fri, 20 Apr 2018 14:33:00 +0000 (16:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 26 Apr 2018 11:51:44 +0000 (13:51 +0200)
This cleans up handling of MTU values across the codebase. Previously
MTU values where stored sometimes in uint32_t, sometimes in uint16_t,
sometimes unsigned and sometimes in size_t. This now unifies this to
uint32_t across the codebase, as that's what netlink spits out, and what
the majority was already using.

Also, all MTU parameters are now parsed with config_parse_mtu() and
config_parse_ipv6_mtu() is dropped as it is now unneeded.

(Note there is one exception for the MTU typing: in the DCHPv4 code we
continue to process the MTU as uint16_t value, as it is encoded like
that in the protocol, and it's probably better stay close to the
protocol there.)

16 files changed:
src/libsystemd/sd-netlink/netlink-util.c
src/libsystemd/sd-netlink/netlink-util.h
src/libsystemd/sd-netlink/test-netlink.c
src/network/netdev/geneve.c
src/network/netdev/netdev-gperf.gperf
src/network/netdev/netdev.h
src/network/netdev/tuntap.c
src/network/networkctl.c
src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
src/udev/net/link-config-gperf.gperf
src/udev/net/link-config.c
src/udev/net/link-config.h

index b14d1d21c6d4c3a0a245a0ab7d8c7ddcd7d55698..36b11030b0e3d79c513f0ae73475b2f0ba2676ad 100644 (file)
@@ -40,7 +40,7 @@ int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
 }
 
 int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
-                             const struct ether_addr *mac, unsigned mtu) {
+                             const struct ether_addr *mac, uint32_t mtu) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
         int r;
 
@@ -72,7 +72,7 @@ int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
                         return r;
         }
 
-        if (mtu > 0) {
+        if (mtu != 0) {
                 r = sd_netlink_message_append_u32(message, IFLA_MTU, mtu);
                 if (r < 0)
                         return r;
index 70eda91b0388a6b69a6d40d4efe22c96754b34bb..c39ded342948ba0e4289ad737d666c8a46f13a1b 100644 (file)
@@ -40,7 +40,7 @@ static inline bool rtnl_message_type_is_routing_policy_rule(uint16_t type) {
 }
 
 int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name);
-int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu);
+int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, uint32_t mtu);
 
 int rtnl_log_parse_error(int r);
 int rtnl_log_create_error(int r);
index 3ef611d165a1d9fe90be818f0200cad0df794200..54149bde0fd514fb2d4301280ffa06b4d71b1725 100644 (file)
@@ -40,7 +40,7 @@ static void test_link_configure(sd_netlink *rtnl, int ifindex) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
         const char *mac = "98:fe:94:3f:c6:18", *name = "test";
         char buffer[ETHER_ADDR_TO_STRING_MAX];
-        unsigned int mtu = 1450, mtu_out;
+        uint32_t mtu = 1450, mtu_out;
         const char *name_out;
         struct ether_addr mac_out;
 
@@ -66,7 +66,7 @@ static void test_link_configure(sd_netlink *rtnl, int ifindex) {
 static void test_link_get(sd_netlink *rtnl, int ifindex) {
         sd_netlink_message *m;
         sd_netlink_message *r;
-        unsigned int mtu = 1500;
+        uint32_t mtu = 1500;
         const char *str_data;
         uint8_t u8_data;
         uint32_t u32_data;
index 175acb4cfbc63d73dce52975d4cc485c12af299d..4e865553ec01aa80105e05c373d965010e8f224b 100644 (file)
@@ -66,7 +66,7 @@ static int netdev_geneve_create(NetDev *netdev) {
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m");
         }
 
-        if (netdev->mtu) {
+        if (netdev->mtu != 0) {
                 r = sd_netlink_message_append_u32(m, IFLA_MTU, netdev->mtu);
                 if (r < 0)
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_MTU attribute: %m");
index ba6268fa66e82d26d9c870ae2c96984e6cb86419..c0d4375a99083fc5dea0810642f240ff6b18e167 100644 (file)
@@ -40,7 +40,7 @@ Match.Architecture,                config_parse_net_condition,           CONDITI
 NetDev.Description,                config_parse_string,                  0,                             offsetof(NetDev, description)
 NetDev.Name,                       config_parse_ifname,                  0,                             offsetof(NetDev, ifname)
 NetDev.Kind,                       config_parse_netdev_kind,             0,                             offsetof(NetDev, kind)
-NetDev.MTUBytes,                   config_parse_iec_size,                0,                             offsetof(NetDev, mtu)
+NetDev.MTUBytes,                   config_parse_mtu,                     AF_UNSPEC,                     offsetof(NetDev, mtu)
 NetDev.MACAddress,                 config_parse_hwaddr,                  0,                             offsetof(NetDev, mac)
 VLAN.Id,                           config_parse_vlanid,                  0,                             offsetof(VLan, id)
 VLAN.GVRP,                         config_parse_tristate,                0,                             offsetof(VLan, gvrp)
@@ -50,7 +50,7 @@ VLAN.ReorderHeader,                config_parse_tristate,                0,
 MACVLAN.Mode,                      config_parse_macvlan_mode,            0,                             offsetof(MacVlan, mode)
 MACVTAP.Mode,                      config_parse_macvlan_mode,            0,                             offsetof(MacVlan, mode)
 IPVLAN.Mode,                       config_parse_ipvlan_mode,             0,                             offsetof(IPVlan, mode)
-IPVLAN.Flags,                      config_parse_ipvlan_flags,             0,                            offsetof(IPVlan, flags)
+IPVLAN.Flags,                      config_parse_ipvlan_flags,            0,                             offsetof(IPVlan, flags)
 Tunnel.Local,                      config_parse_tunnel_address,          0,                             offsetof(Tunnel, local)
 Tunnel.Remote,                     config_parse_tunnel_address,          0,                             offsetof(Tunnel, remote)
 Tunnel.TOS,                        config_parse_unsigned,                0,                             offsetof(Tunnel, tos)
index 2b01d4190f98f2e2711bf5d4575a182f386e479a..0d0671d37bc08893c69abd5c78dc08ee25239247 100644 (file)
@@ -91,7 +91,7 @@ typedef struct NetDev {
         char *description;
         char *ifname;
         struct ether_addr *mac;
-        size_t mtu;
+        uint32_t mtu;
         int ifindex;
 
         LIST_HEAD(netdev_join_callback, callbacks);
index 1d037f2985f24605326d14b4e79ab6bddddcd8eb..3dd962440db08ba509104eda48badd8afe8b9652 100644 (file)
@@ -144,7 +144,7 @@ static void tuntap_done(NetDev *netdev) {
 static int tuntap_verify(NetDev *netdev, const char *filename) {
         assert(netdev);
 
-        if (netdev->mtu)
+        if (netdev->mtu != 0)
                 log_netdev_warning(netdev, "MTU configured for %s, ignoring", netdev_kind_to_string(netdev->kind));
 
         if (netdev->mac)
index b666913e623ad916f3ef1cb7d3551e6ab83b9bc9..29899a9ba74b9a026fef093e7d3f21454dc033c6 100644 (file)
@@ -821,7 +821,7 @@ static int link_status_one(
         }
 
         if (info->has_mtu)
-                printf("             MTU: %u\n", info->mtu);
+                printf("             MTU: %" PRIu32 "\n", info->mtu);
 
         (void) dump_addresses(rtnl, "         Address: ", info->ifindex);
         (void) dump_gateways(rtnl, hwdb, "         Gateway: ", info->ifindex);
index 6f5dcb843a3ad363df54a54109e140b23fa824ee..fae750be203d3aedb6392224642afdd58091655c 100644 (file)
@@ -1757,7 +1757,7 @@ int link_up(Link *link) {
            for this interface, or if it is a bridge slave, then disable IPv6 else enable it. */
         (void) link_enable_ipv6(link);
 
-        if (link->network->mtu) {
+        if (link->network->mtu != 0) {
                 /* IPv6 protocol requires a minimum MTU of IPV6_MTU_MIN(1280) bytes
                    on the interface. Bump up MTU bytes to IPV6_MTU_MIN. */
                 if (link_ipv6_enabled(link) && link->network->mtu < IPV6_MIN_MTU) {
@@ -2486,7 +2486,7 @@ static int link_set_ipv6_mtu(Link *link) {
 
         p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/mtu");
 
-        xsprintf(buf, "%u", link->network->ipv6_mtu);
+        xsprintf(buf, "%" PRIu32, link->network->ipv6_mtu);
 
         r = write_string_file(p, buf, 0);
         if (r < 0)
@@ -3229,7 +3229,7 @@ int link_update(Link *link, sd_netlink_message *m) {
         r = sd_netlink_message_read_u32(m, IFLA_MTU, &mtu);
         if (r >= 0 && mtu > 0) {
                 link->mtu = mtu;
-                if (!link->original_mtu) {
+                if (link->original_mtu == 0) {
                         link->original_mtu = mtu;
                         log_link_debug(link, "Saved original MTU: %" PRIu32, link->original_mtu);
                 }
index c17ac3f3ce71e4d4d4678160d96b100e73acfdf1..a3ea1f8bf827b489f52042a70edaf68a9d3ff311 100644 (file)
@@ -88,7 +88,7 @@ typedef struct Link {
         sd_dhcp_client *dhcp_client;
         sd_dhcp_lease *dhcp_lease;
         char *lease_file;
-        uint16_t original_mtu;
+        uint32_t original_mtu;
         unsigned dhcp4_messages;
         bool dhcp4_configured;
         bool dhcp6_configured;
index ba5c5db70d1897288b8346c69269c3bed8f33490..e828fe8c6c3d2770a726db07ef3a7f88cba63a45 100644 (file)
@@ -31,7 +31,7 @@ Match.KernelCommandLine,                config_parse_net_condition,
 Match.KernelVersion,                    config_parse_net_condition,                     CONDITION_KERNEL_VERSION,      offsetof(Network, match_kernel_version)
 Match.Architecture,                     config_parse_net_condition,                     CONDITION_ARCHITECTURE,        offsetof(Network, match_arch)
 Link.MACAddress,                        config_parse_hwaddr,                            0,                             offsetof(Network, mac)
-Link.MTUBytes,                          config_parse_iec_size,                          0,                             offsetof(Network, mtu)
+Link.MTUBytes,                          config_parse_mtu,                               AF_UNSPEC,                     offsetof(Network, mtu)
 Link.ARP,                               config_parse_tristate,                          0,                             offsetof(Network, arp)
 Link.Unmanaged,                         config_parse_bool,                              0,                             offsetof(Network, unmanaged)
 Link.RequiredForOnline,                 config_parse_bool,                              0,                             offsetof(Network, required_for_online)
@@ -69,7 +69,7 @@ Network.IPv6AcceptRouterAdvertisements, config_parse_tristate,
 Network.IPv6DuplicateAddressDetection,  config_parse_int,                               0,                             offsetof(Network, ipv6_dad_transmits)
 Network.IPv6HopLimit,                   config_parse_int,                               0,                             offsetof(Network, ipv6_hop_limit)
 Network.IPv6ProxyNDP,                   config_parse_tristate,                          0,                             offsetof(Network, ipv6_proxy_ndp)
-Network.IPv6MTUBytes,                   config_parse_ipv6_mtu,                          0,                             0
+Network.IPv6MTUBytes,                   config_parse_mtu,                               AF_INET6,                      0
 Network.ActiveSlave,                    config_parse_bool,                              0,                             offsetof(Network, active_slave)
 Network.PrimarySlave,                   config_parse_bool,                              0,                             offsetof(Network, primary_slave)
 Network.IPv4ProxyARP,                   config_parse_tristate,                          0,                             offsetof(Network, proxy_arp)
index 03dfd4e510b1e0bfab3d9db4bff19b3bc1f237bb..e25909374f810d78b109349784e60219db43d2ab 100644 (file)
@@ -1417,42 +1417,6 @@ int config_parse_dhcp_route_table(const char *unit,
         return 0;
 }
 
-int config_parse_ipv6_mtu(
-                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) {
-
-        Network *network = data;
-        uint32_t mtu;
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        r = safe_atou32(rvalue, &mtu);
-        if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse IPv6 MTU, ignoring assignment: %s", rvalue);
-                return 0;
-        }
-
-        if (mtu < IPV6_MIN_MTU) {
-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse IPv6 MTU for interface. Allowed minimum MTU is 1280 bytes, ignoring: %s", rvalue);
-                return 0;
-        }
-
-        network->ipv6_mtu = mtu;
-
-        return 0;
-}
-
 DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_use_domains, dhcp_use_domains, DHCPUseDomains, "Failed to parse DHCP use domains setting");
 
 static const char* const dhcp_use_domains_table[_DHCP_USE_DOMAINS_MAX] = {
index 13938d4ad7840f5165ebeb82abca5859ee7ce591..fc3dd65a4a3730d4645970f2db8a21bdc5cde240 100644 (file)
@@ -198,7 +198,7 @@ struct Network {
         int ipv6_hop_limit;
         int ipv6_proxy_ndp;
         int proxy_arp;
-        unsigned ipv6_mtu;
+        uint32_t ipv6_mtu;
 
         bool ipv6_accept_ra_use_dns;
         bool active_slave;
@@ -210,7 +210,7 @@ struct Network {
         IPv6PrivacyExtensions ipv6_privacy_extensions;
 
         struct ether_addr *mac;
-        size_t mtu;
+        uint32_t mtu;
         int arp;
         bool unmanaged;
         bool configure_without_carrier;
@@ -290,7 +290,6 @@ int config_parse_dhcp_use_domains(const char *unit, const char *filename, unsign
 int config_parse_lldp_mode(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);
 int config_parse_dhcp_route_table(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);
 int config_parse_ntp(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);
-int config_parse_ipv6_mtu(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);
 /* Legacy IPv4LL support */
 int config_parse_ipv4ll(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);
 
index b4c3a45cf3037b9076e3a6e9022820d3551361f7..8bfa998dacf6a70d0c0b08074886f7242b3aac9a 100644 (file)
@@ -35,7 +35,7 @@ Link.MACAddress,                 config_parse_hwaddr,        0,
 Link.NamePolicy,                 config_parse_name_policy,   0,                             offsetof(link_config, name_policy)
 Link.Name,                       config_parse_ifname,        0,                             offsetof(link_config, name)
 Link.Alias,                      config_parse_ifalias,       0,                             offsetof(link_config, alias)
-Link.MTUBytes,                   config_parse_iec_size,      0,                             offsetof(link_config, mtu)
+Link.MTUBytes,                   config_parse_mtu,           AF_UNSPEC,                     offsetof(link_config, mtu)
 Link.BitsPerSecond,              config_parse_si_size,       0,                             offsetof(link_config, speed)
 Link.Duplex,                     config_parse_duplex,        0,                             offsetof(link_config, duplex)
 Link.AutoNegotiation,            config_parse_tristate,      0,                             offsetof(link_config, autonegotiation)
index 48f6c5775862b36c9432993a2108c0f246a1e0bc..71d68f60d4196d6b38e407b1584ee7daed0d0621 100644 (file)
@@ -169,7 +169,7 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
         else
                 log_debug("Parsed configuration file %s", filename);
 
-        if (link->mtu > UINT_MAX || link->speed > UINT_MAX)
+        if (link->speed > UINT_MAX)
                 return -ERANGE;
 
         link->filename = strdup(filename);
index 699e54c83734d7e4ce93fbf6ed1917e06ccd3849..9f411328105573a851426e654642ef8d05c866a9 100644 (file)
@@ -55,7 +55,7 @@ struct link_config {
         NamePolicy *name_policy;
         char *name;
         char *alias;
-        size_t mtu;
+        uint32_t mtu;
         size_t speed;
         Duplex duplex;
         int autonegotiation;