From 230d0f47484e9299077de5649ad81567e5ff4b16 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Wed, 16 Jul 2008 19:06:01 -1000 Subject: Set interface MTU if user specified mtu= param (#435874) If the user passed mtu=X as a boot parameter, set the interface MTU to that value before configuring the network. --- isys/iface.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ isys/iface.h | 1 + 2 files changed, 50 insertions(+) (limited to 'isys') diff --git a/isys/iface.c b/isys/iface.c index 51f923c06..6f274bc76 100644 --- a/isys/iface.c +++ b/isys/iface.c @@ -231,3 +231,52 @@ mac2str_error2: return buf; } + +/* + * Set the MTU on the specified device. + */ +int iface_set_interface_mtu(char *ifname, int mtu) { + int ret = 0; + struct nl_handle *handle = NULL; + struct nl_cache *cache = NULL; + struct rtnl_link *link = NULL; + struct rtnl_link *request = NULL; + + if (ifname == NULL) { + perror("Missing ifname in iface_set_interface_mtu()"); + return -1; + } + + if (mtu <= 0) { + perror("MTU cannot be <= 0 in iface_set_interface_mtu()"); + return -2; + } + + if ((cache = iface_get_link_cache(&handle)) == NULL) { + perror("iface_get_link_cache() failure in iface_set_interface_mtu()"); + return -3; + } + + if ((link = rtnl_link_get_by_name(cache, ifname)) == NULL) { + perror("rtnl_link_get_by_name() failure in iface_set_interface_mtu()"); + ret = -4; + goto ifacemtu_error1; + } + + request = rtnl_link_alloc(); + rtnl_link_set_mtu(request, mtu); + + if (rtnl_link_change(handle, link, request, 0)) { + perror("rtnl_link_change() failure in iface_set_interface_mtu()"); + ret = -5; + goto ifacemtu_error2; + } + +ifacemtu_error2: + rtnl_link_put(link); +ifacemtu_error1: + nl_close(handle); + nl_handle_destroy(handle); + + return ret; +} diff --git a/isys/iface.h b/isys/iface.h index cc1f81330..4b0e50f2d 100644 --- a/isys/iface.h +++ b/isys/iface.h @@ -26,3 +26,4 @@ struct nl_cache *iface_get_link_cache(struct nl_handle **handle); char *iface_mac2str(char *ifname); char *iface_ip2str(char *ifname); +int iface_set_interface_mtu(char *ifname, int mtu); -- cgit