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)
{
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);
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);
#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>
{ 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)
{
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;
}
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);
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
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);
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 */
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;
}
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
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
/* 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;
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",
.build_rewrite = ethernet_build_rewrite,
.update_adjacency = ethernet_update_adjacency,
.mac_addr_change_function = ethernet_mac_change,
+ .set_mtu = ethernet_set_mtu,
};
/* *INDENT-ON* */
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);
/* 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;
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)
{
"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);
}
(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,
/* 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;