summaryrefslogtreecommitdiffstats
path: root/src/vnet
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/vnet
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/vnet')
-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
5 files changed, 47 insertions, 29 deletions
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;