From e39376e4d5aa66a5f8973f4f5470c736afeab4ed Mon Sep 17 00:00:00 2001 From: Aloys Augustin Date: Mon, 29 Mar 2021 22:08:09 +0200 Subject: devices: af_packet - use netlink to get/set mtu The /sys filesystem is not always accurate when switching network namespaces. Using netlink should work in more situations. Type: improvement Change-Id: I71611f14319820469ea7794eec5b7c6c70e2be6d Signed-off-by: Aloys Augustin --- src/vnet/devices/af_packet/af_packet.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/vnet/devices/af_packet') diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c index 60a3ccc081f..76677a43092 100644 --- a/src/vnet/devices/af_packet/af_packet.c +++ b/src/vnet/devices/af_packet/af_packet.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -63,22 +64,18 @@ af_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags) { clib_error_t *error; - u8 *s; af_packet_main_t *apm = &af_packet_main; af_packet_if_t *apif = pool_elt_at_index (apm->interfaces, hi->dev_instance); if (flags == ETHERNET_INTERFACE_FLAG_MTU) { - s = format (0, "/sys/class/net/%s/mtu%c", apif->host_if_name, 0); - - error = clib_sysfs_write ((char *) s, "%d", hi->max_packet_bytes); - vec_free (s); + error = + vnet_netlink_set_link_mtu (apif->host_if_index, hi->max_packet_bytes); if (error) { - vlib_log_err (apm->log_class, - "sysfs write failed to change MTU: %U", + vlib_log_err (apm->log_class, "netlink failed to change MTU: %U", format_clib_error, error); clib_error_free (error); return VNET_API_ERROR_SYSCALL_ERROR_1; @@ -95,13 +92,10 @@ af_packet_read_mtu (af_packet_if_t *apif) { af_packet_main_t *apm = &af_packet_main; clib_error_t *error; - u8 *s; - s = format (0, "/sys/class/net/%s/mtu%c", apif->host_if_name, 0); - error = clib_sysfs_read ((char *) s, "%d", &apif->host_mtu); - vec_free (s); + error = vnet_netlink_get_link_mtu (apif->host_if_index, &apif->host_mtu); if (error) { - vlib_log_err (apm->log_class, "sysfs read failed to get MTU: %U", + vlib_log_err (apm->log_class, "netlink failed to get MTU: %U", format_clib_error, error); clib_error_free (error); return VNET_API_ERROR_SYSCALL_ERROR_1; -- cgit 1.2.3-korg