dpdk kni建立虚拟网卡设置mtu问题

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生效

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值