[dpdk-dev] [PATCH 4/6] net/tap: add MTU management
Wiles, Keith
keith.wiles at intel.com
Fri Mar 3 16:23:28 CET 2017
> On Mar 3, 2017, at 3:46 AM, Pascal Mazon <pascal.mazon at 6wind.com> wrote:
>
> The MTU is assigned to the tap netdevice according to the argument, but
> packet transmission and reception just write/read on an fd with the
> default limit being the socket buffer size.
>
> Signed-off-by: Pascal Mazon <pascal.mazon at 6wind.com>
> ---
> doc/guides/nics/features/tap.ini | 1 +
> drivers/net/tap/rte_eth_tap.c | 37 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/doc/guides/nics/features/tap.ini b/doc/guides/nics/features/tap.ini
> index 6878a9b8fd17..6aa11874e2bc 100644
> --- a/doc/guides/nics/features/tap.ini
> +++ b/doc/guides/nics/features/tap.ini
> @@ -9,6 +9,7 @@ Jumbo frame = Y
> Promiscuous mode = Y
> Allmulticast mode = Y
> Basic stats = Y
> +MTU update = Y
> Multicast MAC filter = Y
> Speed capabilities = Y
> Unicast MAC filter = Y
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 131c09fbc1a5..64b84cd76321 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -724,6 +724,42 @@ tap_set_mc_addr_list(struct rte_eth_dev *dev __rte_unused,
> return 0;
> }
>
> +static int
> +tap_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
> +{
> + struct pmd_internals *pmd = dev->data->dev_private;
> + struct ifreq ifr;
> + int err, s;
> +
> + s = socket(AF_INET, SOCK_DGRAM, 0);
> + if (s < 0) {
> + RTE_LOG(ERR, PMD,
> + "Unable to get a socket for %s to set flags: %s\n",
> + pmd->name, strerror(errno));
> + return -1;
> + }
> + memset(&ifr, 0, sizeof(ifr));
> + strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
This needs to be converted to a snprintf() to avoid overflow.
> + err = ioctl(s, SIOCGIFMTU, &ifr);
> + if (err < 0) {
> + RTE_LOG(WARNING, PMD, "Unable to get %s device MTU: %s\n",
> + pmd->name, strerror(errno));
> + close(s);
> + return -1;
> + }
> + ifr.ifr_mtu = mtu;
> + err = ioctl(s, SIOCSIFMTU, &ifr);
> + if (err < 0) {
> + RTE_LOG(WARNING, PMD, "Unable to set %s mtu %d: %s\n",
> + pmd->name, mtu, strerror(errno));
> + close(s);
> + return -1;
> + }
> + close(s);
> + dev->data->mtu = mtu;
> + return 0;
> +}
> +
> static const struct eth_dev_ops ops = {
> .dev_start = tap_dev_start,
> .dev_stop = tap_dev_stop,
> @@ -745,6 +781,7 @@ static const struct eth_dev_ops ops = {
> .mac_addr_add = tap_mac_add,
> .mac_addr_set = tap_mac_set,
> .set_mc_addr_list = tap_set_mc_addr_list,
> + .mtu_set = tap_mtu_set,
> .stats_get = tap_stats_get,
> .stats_reset = tap_stats_reset,
> };
> --
> 2.8.0.rc0
>
Regards,
Keith
More information about the dev
mailing list