aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-01-06 21:14:08 +0100
committerDamjan Marion <damarion@cisco.com>2022-01-17 12:41:24 +0100
commit88a9c0e02ab919cadd4e035133995a6afb4d1c32 (patch)
tree15741e8bbe6c9d7077fa2a62b6ac369a17836cfb /src
parent81bb6fc611d321a92ad2218e1b852db67980768a (diff)
interface: improve MTU handling
- per hw-interface-class handlers - ethernet set_mtu callback - driver can now refuse MTU change Type: improvement Change-Id: I3d37c9129930ebec7bb70caf4263025413873048 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/af_xdp/device.c13
-rw-r--r--src/plugins/dpdk/device/init.c46
-rw-r--r--src/plugins/rdma/device.c10
-rw-r--r--src/vnet/devices/af_packet/af_packet.c37
-rw-r--r--src/vnet/ethernet/ethernet.h7
-rw-r--r--src/vnet/ethernet/interface.c19
-rw-r--r--src/vnet/interface.c7
-rw-r--r--src/vnet/interface.h6
8 files changed, 98 insertions, 47 deletions
diff --git a/src/plugins/af_xdp/device.c b/src/plugins/af_xdp/device.c
index 4aa36d95dd5..a5e0b739300 100644
--- a/src/plugins/af_xdp/device.c
+++ b/src/plugins/af_xdp/device.c
@@ -67,6 +67,15 @@ af_xdp_mac_change (vnet_hw_interface_t * hw, const u8 * old, const u8 * new)
return 0;
}
+static clib_error_t *
+af_xdp_set_mtu (vnet_main_t *vnm, vnet_hw_interface_t *hw, u32 mtu)
+{
+ af_xdp_main_t *am = &af_xdp_main;
+ af_xdp_device_t *ad = vec_elt_at_index (am->devices, hw->dev_instance);
+ af_xdp_log (VLIB_LOG_LEVEL_ERR, ad, "set mtu not supported yet");
+ return vnet_error (VNET_ERR_UNSUPPORTED, 0);
+}
+
static u32
af_xdp_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
{
@@ -82,9 +91,6 @@ af_xdp_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
af_xdp_log (VLIB_LOG_LEVEL_ERR, ad,
"set promiscuous not supported yet");
return ~0;
- case ETHERNET_INTERFACE_FLAG_MTU:
- af_xdp_log (VLIB_LOG_LEVEL_ERR, ad, "set mtu not supported yet");
- return ~0;
}
af_xdp_log (VLIB_LOG_LEVEL_ERR, ad, "unknown flag %x requested", flags);
@@ -651,6 +657,7 @@ af_xdp_create_if (vlib_main_t * vm, af_xdp_create_if_args_t * args)
eir.dev_instance = ad->dev_instance;
eir.address = ad->hwaddr;
eir.cb.flag_change = af_xdp_flag_change;
+ eir.cb.set_mtu = af_xdp_set_mtu;
ad->hw_if_index = vnet_eth_register_interface (vnm, &eir);
sw = vnet_get_hw_sw_interface (vnm, ad->hw_if_index);
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index 5e06e48d37e..4faf6290dba 100644
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -21,6 +21,7 @@
#include <vlib/unix/unix.h>
#include <vlib/log.h>
+#include <vnet/vnet.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/interface/rx_queue_funcs.h>
#include <dpdk/buffer.h>
@@ -68,6 +69,41 @@ const struct
{ ETH_LINK_SPEED_1G, "GigabitEthernet" },
};
+static clib_error_t *
+dpdk_set_mtu (vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 mtu)
+{
+ dpdk_main_t *dm = &dpdk_main;
+ dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
+ int rv;
+
+ rv = rte_eth_dev_set_mtu (xd->port_id, mtu);
+
+ if (rv < 0)
+ {
+ dpdk_log_err ("[%u] rte_eth_dev_set_mtu failed (mtu %u, rv %d)",
+ xd->port_id, mtu, rv);
+ switch (rv)
+ {
+ case -ENOTSUP:
+ return vnet_error (VNET_ERR_UNSUPPORTED,
+ "dpdk driver doesn't support MTU change");
+ case -EBUSY:
+ return vnet_error (VNET_ERR_BUSY, "port is running");
+ case -EINVAL:
+ return vnet_error (VNET_ERR_INVALID_VALUE, "invalid MTU");
+ default:
+ return vnet_error (VNET_ERR_BUG,
+ "unexpected return value %d returned from "
+ "rte_eth_dev_set_mtu(...)",
+ rv);
+ }
+ }
+ else
+ dpdk_log_debug ("[%u] mtu set to %u", xd->port_id, mtu);
+
+ return 0;
+}
+
static u32
dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
{
@@ -84,15 +120,6 @@ dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
dpdk_device_flag_set (xd, DPDK_DEVICE_FLAG_PROMISC, 1);
break;
- case ETHERNET_INTERFACE_FLAG_MTU:
- if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
- rte_eth_dev_stop (xd->port_id);
- rte_eth_dev_set_mtu (xd->port_id, hi->max_packet_bytes);
- if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
- rte_eth_dev_start (xd->port_id);
- dpdk_log_debug ("[%u] mtu changed to %u", xd->port_id,
- hi->max_packet_bytes);
- return 0;
default:
return ~0;
}
@@ -370,6 +397,7 @@ dpdk_lib_init (dpdk_main_t * dm)
eir.dev_instance = xd->device_index;
eir.address = addr;
eir.cb.flag_change = dpdk_flag_change;
+ eir.cb.set_mtu = dpdk_set_mtu;
xd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
hi = vnet_get_hw_interface (vnm, xd->hw_if_index);
hi->numa_node = xd->cpu_socket = (i8) rte_eth_dev_socket_id (port_id);
diff --git a/src/plugins/rdma/device.c b/src/plugins/rdma/device.c
index cad5fdb541f..167a23213cc 100644
--- a/src/plugins/rdma/device.c
+++ b/src/plugins/rdma/device.c
@@ -183,11 +183,10 @@ rdma_mac_change (vnet_hw_interface_t * hw, const u8 * old, const u8 * new)
return 0;
}
-static u32
-rdma_dev_change_mtu (rdma_device_t * rd)
+static clib_error_t *
+rdma_set_mtu (vnet_main_t *vnm, vnet_hw_interface_t *hw, u32 mtu)
{
- rdma_log__ (VLIB_LOG_LEVEL_ERR, rd, "MTU change not supported");
- return ~0;
+ return vnet_error (VNET_ERR_UNSUPPORTED, 0);
}
static u32
@@ -202,8 +201,6 @@ rdma_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
return rdma_dev_set_ucast (rd);
case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
return rdma_dev_set_promisc (rd);
- case ETHERNET_INTERFACE_FLAG_MTU:
- return rdma_dev_change_mtu (rd);
}
rdma_log__ (VLIB_LOG_LEVEL_ERR, rd, "unknown flag %x requested", flags);
@@ -361,6 +358,7 @@ rdma_register_interface (vnet_main_t * vnm, rdma_device_t * rd)
eir.dev_instance = rd->dev_instance;
eir.address = rd->hwaddr.bytes;
eir.cb.flag_change = rdma_flag_change;
+ eir.cb.set_mtu = rdma_set_mtu;
rd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
/* Indicate ability to support L3 DMAC filtering and
* initialize interface to L3 non-promisc mode */
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index cf32e92c94c..cf4f91e2fcd 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -56,31 +56,26 @@ unsigned int if_nametoindex (const char *ifname);
typedef struct tpacket_req tpacket_req_t;
-static u32
-af_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
- u32 flags)
+static clib_error_t *
+af_packet_eth_set_mtu (vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 mtu)
{
- clib_error_t *error;
+ clib_error_t *error, *rv;
af_packet_main_t *apm = &af_packet_main;
- af_packet_if_t *apif =
- pool_elt_at_index (apm->interfaces, hi->dev_instance);
+ af_packet_if_t *apif = pool_elt_at_index (apm->interfaces, hi->dev_instance);
- if (flags == ETHERNET_INTERFACE_FLAG_MTU)
- {
- error =
- vnet_netlink_set_link_mtu (apif->host_if_index, hi->max_packet_bytes);
+ error = vnet_netlink_set_link_mtu (apif->host_if_index, mtu);
- if (error)
- {
- 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;
- }
- else
- apif->host_mtu = hi->max_packet_bytes;
+ if (error)
+ {
+ vlib_log_err (apm->log_class, "netlink failed to change MTU: %U",
+ format_clib_error, error);
+ rv = vnet_error (VNET_ERR_SYSCALL_ERROR_1, "netlink error: %U",
+ format_clib_error, error);
+ clib_error_free (error);
+ return rv;
}
-
+ else
+ apif->host_mtu = mtu;
return 0;
}
@@ -403,7 +398,7 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
eir.dev_class_index = af_packet_device_class.index;
eir.dev_instance = if_index;
eir.address = hw_addr;
- eir.cb.flag_change = af_packet_eth_flag_change;
+ eir.cb.set_mtu = af_packet_eth_set_mtu;
apif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
else
diff --git a/src/vnet/ethernet/ethernet.h b/src/vnet/ethernet/ethernet.h
index 9621429e4ee..b6adeb6f44d 100644
--- a/src/vnet/ethernet/ethernet.h
+++ b/src/vnet/ethernet/ethernet.h
@@ -130,7 +130,11 @@ typedef u32 (ethernet_flag_change_function_t)
typedef struct
{
+ /* ethernet interface flags change */
ethernet_flag_change_function_t *flag_change;
+
+ /* set MTU callback */
+ vnet_interface_set_mtu_function_t *set_mtu;
} vnet_eth_if_callbacks_t;
#define ETHERNET_MIN_PACKET_BYTES 64
@@ -166,9 +170,6 @@ typedef struct ethernet_interface
/* Set interface to accept all packets (promiscuous mode). */
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL 1
- /* Change MTU on interface from hw interface structure */
-#define ETHERNET_INTERFACE_FLAG_MTU 2
-
/* Callback, e.g. to turn on/off promiscuous mode */
vnet_eth_if_callbacks_t cb;
diff --git a/src/vnet/ethernet/interface.c b/src/vnet/ethernet/interface.c
index b1513a79774..bac882228cb 100644
--- a/src/vnet/ethernet/interface.c
+++ b/src/vnet/ethernet/interface.c
@@ -310,6 +310,18 @@ ethernet_mac_change (vnet_hw_interface_t * hi,
return (NULL);
}
+static clib_error_t *
+ethernet_set_mtu (vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 mtu)
+{
+ ethernet_interface_t *ei =
+ pool_elt_at_index (ethernet_main.interfaces, hi->hw_instance);
+
+ if (ei->cb.set_mtu)
+ return ei->cb.set_mtu (vnm, hi, mtu);
+
+ return 0;
+}
+
/* *INDENT-OFF* */
VNET_HW_INTERFACE_CLASS (ethernet_hw_interface_class) = {
.name = "Ethernet",
@@ -321,6 +333,7 @@ VNET_HW_INTERFACE_CLASS (ethernet_hw_interface_class) = {
.build_rewrite = ethernet_build_rewrite,
.update_adjacency = ethernet_update_adjacency,
.mac_addr_change_function = ethernet_mac_change,
+ .set_mtu = ethernet_set_mtu,
};
/* *INDENT-ON* */
@@ -367,8 +380,8 @@ vnet_eth_register_interface (vnet_main_t *vnm,
hi->min_packet_bytes = hi->min_supported_packet_bytes =
ETHERNET_MIN_PACKET_BYTES;
- hi->max_packet_bytes = hi->max_supported_packet_bytes =
- ETHERNET_MAX_PACKET_BYTES;
+ hi->max_supported_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
+ hi->max_packet_bytes = em->default_mtu;
/* Default ethernet MTU, 9000 unless set by ethernet_config see below */
vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, em->default_mtu);
@@ -460,8 +473,6 @@ ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
/* fall through */
case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
ei->flags &= ~ETHERNET_INTERFACE_FLAG_STATUS_L3;
- /* fall through */
- case ETHERNET_INTERFACE_FLAG_MTU:
return ei->cb.flag_change (vnm, hi, opn_flags);
default:
return ~0;
diff --git a/src/vnet/interface.c b/src/vnet/interface.c
index 05a1c7c34a9..a1493c66c23 100644
--- a/src/vnet/interface.c
+++ b/src/vnet/interface.c
@@ -772,6 +772,9 @@ clib_error_t *
vnet_hw_interface_set_mtu (vnet_main_t *vnm, u32 hw_if_index, u32 mtu)
{
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
+ vnet_hw_interface_class_t *hw_if_class =
+ vnet_get_hw_interface_class (vnm, hi->hw_class_index);
+ clib_error_t *err = 0;
if (hi->max_packet_bytes != mtu)
{
@@ -781,8 +784,10 @@ vnet_hw_interface_set_mtu (vnet_main_t *vnm, u32 hw_if_index, u32 mtu)
"requested mtu must be in the %u to %u range",
hi->min_supported_packet_bytes,
hi->max_supported_packet_bytes);
+ if (hw_if_class->set_mtu)
+ if ((err = hw_if_class->set_mtu (vnm, hi, mtu)))
+ return err;
hi->max_packet_bytes = mtu;
- ethernet_set_flags (vnm, hw_if_index, ETHERNET_INTERFACE_FLAG_MTU);
vnet_hw_interface_walk_sw (vnm, hw_if_index, sw_interface_walk_callback,
&mtu);
}
diff --git a/src/vnet/interface.h b/src/vnet/interface.h
index 801298a0f05..2eb50aed5e8 100644
--- a/src/vnet/interface.h
+++ b/src/vnet/interface.h
@@ -70,6 +70,10 @@ typedef clib_error_t *(vnet_subif_add_del_function_t)
(struct vnet_main_t * vnm, u32 if_index,
struct vnet_sw_interface_t * template, int is_add);
+/* Interface set mtu callback. */
+typedef clib_error_t *(vnet_interface_set_mtu_function_t) (
+ struct vnet_main_t *vnm, struct vnet_hw_interface_t *hi, u32 mtu);
+
/* Interface set mac address callback. */
typedef clib_error_t *(vnet_interface_set_mac_address_function_t)
(struct vnet_hw_interface_t * hi,
@@ -428,6 +432,8 @@ typedef struct _vnet_hw_interface_class
/* Function to add/delete additional MAC addresses */
vnet_interface_add_del_mac_address_function_t *mac_addr_add_del_function;
+ /* Function to set mtu. */
+ vnet_interface_set_mtu_function_t *set_mtu;
/* Format function to display interface name. */
format_function_t *format_interface_name;