From: Michael Tremer Date: Fri, 10 Feb 2023 10:13:37 +0000 (+0000) Subject: networkd: Read link MTU X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f37df5ea0920add075e294db28a3ec5ed83b0fe5;p=network.git networkd: Read link MTU Signed-off-by: Michael Tremer --- diff --git a/src/networkd/link.c b/src/networkd/link.c index 40f809f5..62be8937 100644 --- a/src/networkd/link.c +++ b/src/networkd/link.c @@ -40,6 +40,11 @@ struct nw_link { // Interface Name char ifname[IF_NAMESIZE]; + + // MTU + uint32_t mtu; + uint32_t min_mtu; + uint32_t max_mtu; }; int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex) { @@ -115,6 +120,54 @@ static int nw_link_update_ifname(struct nw_link* link, sd_netlink_message* messa return 0; } +static int nw_link_update_mtu(struct nw_link* link, sd_netlink_message* message) { + uint32_t mtu = 0; + uint32_t min_mtu = 0; + uint32_t max_mtu = 0; + int r; + + // Read the MTU + r = sd_netlink_message_read_u32(message, IFLA_MTU, &mtu); + if (r < 0) { + ERROR("Could not read MTU for link %d: %m\n", link->ifindex); + return r; + } + + // Read the minimum MTU + r = sd_netlink_message_read_u32(message, IFLA_MIN_MTU, &min_mtu); + if (r < 0) { + ERROR("Could not read the minimum MTU for link %d: %m\n", link->ifindex); + return r; + } + + // Read the maximum MTU + r = sd_netlink_message_read_u32(message, IFLA_MAX_MTU, &max_mtu); + if (r < 0) { + ERROR("Could not read the maximum MTU for link %d: %m\n", link->ifindex); + return r; + } + + // Set the maximum MTU to infinity + if (!max_mtu) + max_mtu = UINT32_MAX; + + // Store min/max MTU + link->min_mtu = min_mtu; + link->max_mtu = max_mtu; + + // End here, if the MTU has not been changed + if (link->mtu == mtu) + return 0; + + DEBUG("Link %d: MTU has changed to %" PRIu32 " (min: %" PRIu32 ", max: %" PRIu32 ")\n", + link->ifindex, link->mtu, link->min_mtu, link->max_mtu); + + // Store MTU + link->mtu = mtu; + + return 0; +} + /* This function is called whenever anything changes, so that we can update our internal link object. @@ -127,6 +180,11 @@ static int nw_link_update(struct nw_link* link, sd_netlink_message* message) { if (r) return r; + // Update the MTU + r = nw_link_update_mtu(link, message); + if (r) + return r; + return 0; }