diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-gperf.gperf | 1 | ||||
-rw-r--r-- | src/network/networkd-link.c | 93 | ||||
-rw-r--r-- | src/network/networkd-network.c | 1 | ||||
-rw-r--r-- | src/network/networkd.h | 2 |
4 files changed, 96 insertions, 1 deletions
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf index 3e20681c30..d4c7a26c88 100644 --- a/src/network/networkd-gperf.gperf +++ b/src/network/networkd-gperf.gperf @@ -31,5 +31,6 @@ Address.Label, config_parse_label, 0, 0 Route.Gateway, config_parse_gateway, 0, 0 Route.Destination, config_parse_destination, 0, 0 DHCPv4.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_dns) +DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_mtu) Bridge.Description, config_parse_string, 0, offsetof(Bridge, description) Bridge.Name, config_parse_ifname, 0, offsetof(Bridge, name) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 6186f7f892..993931d1cd 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -310,6 +310,56 @@ static int address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdat return 1; } +static int set_mtu_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { + Link *link = userdata; + int r; + + assert(m); + assert(link); + assert(link->ifname); + + if (link->state == LINK_STATE_FAILED) + return 1; + + r = sd_rtnl_message_get_errno(m); + if (r < 0 && r != -EEXIST) + log_warning_link(link, "Could not set MTU: %s", strerror(-r)); + + return 1; +} + +static int link_set_mtu(Link *link, uint32_t mtu) { + _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL; + int r; + + assert(link); + assert(link->manager); + assert(link->manager->rtnl); + + log_debug_link(link, "setting MTU: %" PRIu32, mtu); + + r = sd_rtnl_message_link_new(RTM_SETLINK, link->ifindex, &req); + if (r < 0) { + log_error_link(link, "Could not allocate RTM_SETLINK message"); + return r; + } + + r = sd_rtnl_message_append_u32(req, IFLA_MTU, mtu); + if (r < 0) { + log_error_link(link, "Could not append MTU: %s", strerror(-r)); + return r; + } + + r = sd_rtnl_call_async(link->manager->rtnl, req, set_mtu_handler, link, 0, NULL); + if (r < 0) { + log_error_link(link, + "Could not send rtnetlink message: %s", strerror(-r)); + return r; + } + + return 0; +} + static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) { Link *link = userdata; struct in_addr address; @@ -346,6 +396,20 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) { route_free(link->dhcp_route); link->dhcp_route = NULL; } + + if (link->network->dhcp_mtu) { + uint16_t mtu; + + r = sd_dhcp_client_get_mtu(client, &mtu); + if (r >= 0 && link->original_mtu != mtu) { + r = link_set_mtu(link, link->original_mtu); + if (r < 0) { + log_warning_link(link, "DHCP error: could not reset MTU"); + link_enter_failed(link); + return; + } + } + } } r = sd_dhcp_client_get_address(client, &address); @@ -431,6 +495,18 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) { } } + if (link->network->dhcp_mtu) { + uint16_t mtu; + + r = sd_dhcp_client_get_mtu(client, &mtu); + if (r >= 0) { + r = link_set_mtu(link, mtu); + if (r < 0) + log_error_link(link, "Failed to set MTU " + "to %" PRIu16, mtu); + } + } + link_enter_set_addresses(link); } @@ -466,6 +542,12 @@ static int link_acquire_conf(Link *link) { log_debug_link(link, "acquiring DHCPv4 lease"); + if (link->network->dhcp_mtu) { + r = sd_dhcp_client_set_request_option(link->dhcp, 26); + if (r < 0) + return r; + } + r = sd_dhcp_client_start(link->dhcp); if (r < 0) return r; @@ -727,6 +809,8 @@ int link_configure(Link *link) { int link_update(Link *link, sd_rtnl_message *m) { unsigned flags; + void *data; + uint16_t type; int r; assert(link); @@ -737,9 +821,16 @@ int link_update(Link *link, sd_rtnl_message *m) { r = sd_rtnl_message_link_get_flags(m, &flags); if (r < 0) { - log_warning_link(link, "could not get link flags"); + log_warning_link(link, "Could not get link flags"); return r; } + while (sd_rtnl_message_read(m, &type, &data) > 0) { + if (type == IFLA_MTU && link->network->dhcp_mtu && !link->original_mtu) { + link->original_mtu = *(uint16_t *) data; + log_debug_link(link, "saved original MTU: %" PRIu16, link->original_mtu); + } + } + return link_update_flags(link, flags); } diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 498dea65fe..02ffdb1a72 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -66,6 +66,7 @@ static int network_load_one(Manager *manager, const char *filename) { return log_oom(); network->dhcp_dns = true; + network->dhcp_mtu = true; r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0DHCPv4\0", config_item_perf_lookup, (void*) network_gperf_lookup, false, false, network); diff --git a/src/network/networkd.h b/src/network/networkd.h index 26d7f6baa6..5bd7e750ea 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -86,6 +86,7 @@ struct Network { Bridge *bridge; bool dhcp; bool dhcp_dns; + bool dhcp_mtu; LIST_HEAD(Address, static_addresses); LIST_HEAD(Route, static_routes); @@ -160,6 +161,7 @@ struct Link { Route *dhcp_route; Address *dhcp_address; Address *dns; + uint16_t original_mtu; LinkState state; |