// 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) {
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.
if (r)
return r;
+ // Update the MTU
+ r = nw_link_update_mtu(link, message);
+ if (r)
+ return r;
+
return 0;
}