1.基础环境
dpdk-stable-17.02.1
2.问题情况
由于临时接手同事代码,其代码运行dpdk相关程序后会建立2个虚拟网卡veth0_0,veth0_1。想修改其中的mtu值,可采用
ifconfig veth0_0 mtu 1300时程序闪退,后来学习dpdk相关网站内容后发现同事写的kni_change_mtu回调函数为,该代码是dpdk16.11中的样例程序
static struct rte_kni_ops kni_ops = {
.change_mtu = kni_change_mtu,
.config_network_if = kni_config_network_interface,
};
/* Callback for request of changing MTU */
static int
kni_change_mtu(uint8_t port_id, unsigned new_mtu)
{
int ret;
struct rte_eth_conf conf;
if (port_id >= rte_eth_dev_count()) {
RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id);
return -EINVAL;
}
RTE_LOG(INFO, APP, "Change MTU of port %d to %u\n", port_id, new_mtu);
/* Stop specific port */
rte_eth_dev_stop(port_id);
memcpy(&conf, &port_conf, sizeof(conf));
/* Set new MTU */
if (new_mtu > ETHER_MAX_LEN)
conf.rxmode.jumbo_frame = 1;
else
conf.rxmode.jumbo_frame = 0;
/* mtu + length of header + length of FCS = max pkt length */
conf.rxmode.max_rx_pkt_len = new_mtu + KNI_ENET_HEADER_SIZE + KNI_ENET_FCS_SIZE;
ret = rte_eth_dev_configure(port_id, 1, 1, &conf);
if (ret < 0) {
RTE_LOG(ERR, APP, "Fail to reconfigure port %d\n", port_id);
return ret;
}
/* Restart specific port */
ret = rte_eth_dev_start(port_id);
if (ret < 0) {
RTE_LOG(ERR, APP, "Fail to restart port %d\n", port_id);
return ret;
}
return 0;
}
而我们采用的dpdk版本为17,该部分代码已被官方修改为
static int
kni_change_mtu(uint16_t port_id, unsigned int new_mtu)
{
int ret;
if (!rte_eth_dev_is_valid_port(port_id))
return -EINVAL;
if (new_mtu > ETHER_MAX_LEN)
return -EINVAL;
/* Set new MTU */
ret = rte_eth_dev_set_mtu(port_id, new_mtu);
if (ret < 0)
return ret;
return 0;
}
将代码替换为17的代码后重新编译后采用
ifconfig veth0_0 mtu 1300生效