DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v2] pcap: support MTU set
@ 2022-05-23 14:27 Ido Goshen
  2022-05-23 14:52 ` Ido Goshen
  0 siblings, 1 reply; 6+ messages in thread
From: Ido Goshen @ 2022-05-23 14:27 UTC (permalink / raw)
  To: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko; +Cc: dev, Ido Goshen

Support rte_eth_dev_set_mtu by pcap vdevs
Enforce mtu on rx/tx

Bugzilla ID: 961
Signed-off-by: Ido Goshen <ido@cgstowernetworks.com>

---
v2:
preserve pcap behavior to support max size packets by default
---
 drivers/net/pcap/pcap_ethdev.c | 35 +++++++++++++++++++++++++++++++---
 lib/ethdev/rte_ethdev.c        |  3 ++-
 lib/ethdev/rte_ethdev.h        |  1 +
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index ec29fd6bc5..7c5fd6dd98 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -278,11 +278,12 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	const u_char *packet;
 	struct rte_mbuf *mbuf;
 	struct pcap_rx_queue *pcap_q = queue;
+	struct rte_eth_dev *dev = &rte_eth_devices[pcap_q->port_id];
 	uint16_t num_rx = 0;
 	uint32_t rx_bytes = 0;
 	pcap_t *pcap;
 
-	pp = rte_eth_devices[pcap_q->port_id].process_private;
+	pp = dev->process_private;
 	pcap = pp->rx_pcap[pcap_q->queue_id];
 
 	if (unlikely(pcap == NULL || nb_pkts == 0))
@@ -303,6 +304,12 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			break;
 		}
 
+		if (unlikely(header.caplen > dev->data->mtu)) {
+			pcap_q->rx_stat.err_pkts++;
+			rte_pktmbuf_free(mbuf);
+			break;
+		}
+
 		if (header.caplen <= rte_pktmbuf_tailroom(mbuf)) {
 			/* pcap packet will fit in the mbuf, can copy it */
 			rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet,
@@ -378,6 +385,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
+	struct rte_eth_dev *dev = &rte_eth_devices[dumper_q->port_id];
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
@@ -385,7 +393,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
 	size_t len, caplen;
 
-	pp = rte_eth_devices[dumper_q->port_id].process_private;
+	pp = dev->process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
 
 	if (dumper == NULL || nb_pkts == 0)
@@ -396,6 +404,12 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	for (i = 0; i < nb_pkts; i++) {
 		mbuf = bufs[i];
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
+
+		if (unlikely(len > dev->data->mtu)) {
+			rte_pktmbuf_free(mbuf);
+			continue;
+		}
+
 		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
 				len > sizeof(temp_data))) {
 			caplen = sizeof(temp_data);
@@ -464,13 +478,14 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
+	struct rte_eth_dev *dev = &rte_eth_devices[tx_queue->port_id];
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
 	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
 	size_t len;
 
-	pp = rte_eth_devices[tx_queue->port_id].process_private;
+	pp = dev->process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
@@ -479,6 +494,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	for (i = 0; i < nb_pkts; i++) {
 		mbuf = bufs[i];
 		len = rte_pktmbuf_pkt_len(mbuf);
+
+		if (unlikely(len > dev->data->mtu)) {
+			rte_pktmbuf_free(mbuf);
+			continue;
+		}
+
 		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
 				len > sizeof(temp_data))) {
 			PMD_LOG(ERR,
@@ -737,6 +758,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->default_mtu = dev_info->max_mtu;
 
 	return 0;
 }
@@ -807,6 +829,12 @@ eth_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static int eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+	PMD_LOG(INFO, "mtu set %s %u\n", dev->device->name, mtu);
+	return 0;
+}
+
 static inline void
 infinite_rx_ring_free(struct rte_ring *pkts)
 {
@@ -1004,6 +1032,7 @@ static const struct eth_dev_ops ops = {
 	.link_update = eth_link_update,
 	.stats_get = eth_stats_get,
 	.stats_reset = eth_stats_reset,
+	.mtu_set = eth_mtu_set,
 };
 
 static int
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 29a3d80466..75cb38a4b2 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -1186,7 +1186,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	}
 
 	if (dev_conf->rxmode.mtu == 0)
-		dev->data->dev_conf.rxmode.mtu = RTE_ETHER_MTU;
+		dev->data->dev_conf.rxmode.mtu = dev_info.default_mtu;
 
 	ret = eth_dev_validate_mtu(port_id, &dev_info,
 			dev->data->dev_conf.rxmode.mtu);
@@ -3126,6 +3126,7 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
 	dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN -
 		RTE_ETHER_CRC_LEN;
 	dev_info->max_mtu = UINT16_MAX;
+	dev_info->default_mtu = RTE_ETHER_MTU;
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
 	diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info);
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 04cff8ee10..8a2fd2f4ff 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -1861,6 +1861,7 @@ struct rte_eth_dev_info {
 		Use if_indextoname() to translate into an interface name. */
 	uint16_t min_mtu;	/**< Minimum MTU allowed */
 	uint16_t max_mtu;	/**< Maximum MTU allowed */
+	uint16_t default_mtu;
 	const uint32_t *dev_flags; /**< Device flags */
 	uint32_t min_rx_bufsize; /**< Minimum size of Rx buffer. */
 	uint32_t max_rx_pktlen; /**< Maximum configurable length of Rx pkt. */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] pcap: support MTU set
  2022-05-23 14:27 [PATCH v2] pcap: support MTU set Ido Goshen
@ 2022-05-23 14:52 ` Ido Goshen
  0 siblings, 0 replies; 6+ messages in thread
From: Ido Goshen @ 2022-05-23 14:52 UTC (permalink / raw)
  To: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko; +Cc: dev

> -----Original Message-----
> From: Ido Goshen <Ido@cgstowernetworks.com>
> Sent: Monday, 23 May 2022 17:27
> To: Thomas Monjalon <thomas@monjalon.net>; Ferruh Yigit
> <ferruh.yigit@xilinx.com>; Andrew Rybchenko
> <andrew.rybchenko@oktetlabs.ru>
> Cc: dev@dpdk.org; Ido Goshen <Ido@cgstowernetworks.com>
> Subject: [PATCH v2] pcap: support MTU set

> v2:
> preserve pcap behavior to support max size packets by default
> ---

[idog] on top enforcing mtu and giving an option to set it
the v2 of the patch also preserves the default behavior of pcap pmd to rx jumbo packets

By default it will receive jumbo packets (jumbo_9000.pcap as a single 9000 bytes long packet)
    cgs@idog-ubuntu:~/dpdk-next-net$ build/app/dpdk-testpmd --no-huge -m1024 -l 0-1  --vdev='net_pcap0,rx_pcap=rx_pcap=pcap/jumbo_9000.pcap,tx_pcap=pcap/file_tx.pcap' 
    -- --no-flush-rx  -i --auto-start
     ...
    testpmd> stop
    Telling cores to stop...
    Waiting for lcores to finish...
     ---------------------- Forward statistics for port 0  ----------------------
      RX-packets: 1              RX-dropped: 0             RX-total: 1
      TX-packets: 1              TX-dropped: 0             TX-total: 1
      ----------------------------------------------------------------------------
But now it will also nicely reflect it by rte_eth_dev_get_mtu
    testpmd> show port info 0
    ********************* Infos for port 0  *********************
    MAC address: 02:70:63:61:70:00
    Device name: net_pcap0
    Driver name: net_pcap
    ...
    MTU: 65535

In addition it gives option to control the mtu for anyone who wants  to reduce it 
In testpmd either 'port config mtu' or --max-pkt-len can be used (as for other pmd's)

e.g.
    cgs@idog-ubuntu:~/dpdk-next-net$ build/app/dpdk-testpmd --no-huge -m1024 -l 0-1  --vdev='net_pcap0,rx_pcap=rx_pcap=pcap/jumbo_9000.pcap,tx_pcap=pcap/file_tx.pcap'
    -- --no-flush-rx  -i 
    ...
    testpmd> port config mtu 0 1500
    testpmd> show port info 0

    ********************* Infos for port 0  *********************
    MAC address: 02:70:63:61:70:00
    Device name: net_pcap0 
    Driver name: net_pcap
    ...
    MTU: 1500
    ...
    testpmd> start
    ....
    testpmd> stop
      ---------------------- Forward statistics for port 0  ----------------------
      RX-packets: 0              RX-dropped: 0             RX-total: 0
      RX-error: 1
      RX-nombufs: 0             
      TX-packets: 0              TX-dropped: 0             TX-total: 0
     ----------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] pcap: support MTU set
  2023-07-05 15:18     ` Stephen Hemminger
@ 2023-07-06 10:45       ` Ido Goshen
  0 siblings, 0 replies; 6+ messages in thread
From: Ido Goshen @ 2023-07-06 10:45 UTC (permalink / raw)
  To: Stephen Hemminger, Ferruh Yigit; +Cc: dev

I've suggested 2 ways to do it
1. Data path enforcement by pcap pmd [PATCH v4] 
http://patches.dpdk.org/project/dpdk/patch/20220606162147.57218-1-ido@cgstowernetworks.com/
2. Control path only sets the underlying OS network interface MTU [PATCH v8]
http://patches.dpdk.org/project/dpdk/cover/20220620083944.51517-1-ido@cgstowernetworks.com/

It was pretty long ago - not sure which is in favor

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Wednesday, 5 July 2023 18:19
> To: Ferruh Yigit <ferruh.yigit@amd.com>
> Cc: dev@dpdk.org; Ido Goshen <Ido@cgstowernetworks.com>
> Subject: Re: [PATCH v2] pcap: support MTU set
> 
> On Wed, 5 Jul 2023 12:37:41 +0100
> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> 
> > On 7/4/2023 10:02 PM, Stephen Hemminger wrote:
> > > Support rte_eth_dev_set_mtu for pcap driver when the pcap device is
> > > convigured to point to a network interface.
> > >
> > > This is rebased an consolidated from earlier version.
> > > Added support for FreeBSD.
> > >
> >
> > As far as I understand motivation is to make pcap PMD behave close the
> > physical NIC and able to test the application MTU feature.
> > If so, Ido's v4 was simpler, which doesn't distinguish if pcap backed
> > by physical interface or .pcap file.
> > What was wrong with that approach?
> 
> I started with Ido's patch, then:
>   - combined the two patches into one.
>   - fixed the error handling (propogate errno correctly)
>   - add missing freebsd support
> 
> Normally would just give feedback but patch was so old not sure if it was
> stuck and unlikely to get merged.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] pcap: support MTU set
  2023-07-05 11:37   ` Ferruh Yigit
@ 2023-07-05 15:18     ` Stephen Hemminger
  2023-07-06 10:45       ` Ido Goshen
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2023-07-05 15:18 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Ido Goshen

On Wed, 5 Jul 2023 12:37:41 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> On 7/4/2023 10:02 PM, Stephen Hemminger wrote:
> > Support rte_eth_dev_set_mtu for pcap driver when the
> > pcap device is convigured to point to a network interface.
> > 
> > This is rebased an consolidated from earlier version.
> > Added support for FreeBSD.
> >   
> 
> As far as I understand motivation is to make pcap PMD behave close the
> physical NIC and able to test the application MTU feature.
> If so, Ido's v4 was simpler, which doesn't distinguish if pcap backed by
> physical interface or .pcap file.
> What was wrong with that approach?

I started with Ido's patch, then:
  - combined the two patches into one.
  - fixed the error handling (propogate errno correctly)
  - add missing freebsd support

Normally would just give feedback but patch was so old not sure if it was
stuck and unlikely to get merged.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] pcap: support MTU set
  2023-07-04 21:02 ` [PATCH v2] pcap: " Stephen Hemminger
@ 2023-07-05 11:37   ` Ferruh Yigit
  2023-07-05 15:18     ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Ferruh Yigit @ 2023-07-05 11:37 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Ido Goshen

On 7/4/2023 10:02 PM, Stephen Hemminger wrote:
> Support rte_eth_dev_set_mtu for pcap driver when the
> pcap device is convigured to point to a network interface.
> 
> This is rebased an consolidated from earlier version.
> Added support for FreeBSD.
> 

As far as I understand motivation is to make pcap PMD behave close the
physical NIC and able to test the application MTU feature.
If so, Ido's v4 was simpler, which doesn't distinguish if pcap backed by
physical interface or .pcap file.
What was wrong with that approach?

> Signed-off-by: Ido Goshen <ido@cgstowernetworks.com>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> v2 - fix FreeBSD part
> 
>  drivers/net/pcap/pcap_ethdev.c        | 49 ++++++++++++++++++++++++++-
>  drivers/net/pcap/pcap_osdep.h         |  1 +
>  drivers/net/pcap/pcap_osdep_freebsd.c | 23 +++++++++++++
>  drivers/net/pcap/pcap_osdep_linux.c   | 21 ++++++++++++
>  drivers/net/pcap/pcap_osdep_windows.c |  7 ++++
>  5 files changed, 100 insertions(+), 1 deletion(-)
> 

Better to update driver documentation and release notes too.

> diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
> index bfec0850456f..672f42d30d8e 100644
> --- a/drivers/net/pcap/pcap_ethdev.c
> +++ b/drivers/net/pcap/pcap_ethdev.c
> @@ -5,6 +5,7 @@
>   */
>  
>  #include <stdlib.h>
> +#include <stdbool.h>
>  #include <time.h>
>  
>  #include <pcap.h>
> @@ -495,8 +496,13 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
>  		 */
>  		ret = pcap_sendpacket(pcap,
>  			rte_pktmbuf_read(mbuf, 0, len, temp_data), len);
> -		if (unlikely(ret != 0))
> +		if (unlikely(ret != 0)) {
> +			/* Oversize packet dropped due to MTU */
> +			if (errno == EMSGSIZE)
> +				continue;

This will leak mbuf, since loop continues application will assume driver
sent the packet and freed mbuf. Ido's version does it right.

>  			break;
> +		}
> +
>  		num_tx++;
>  		tx_bytes += len;
>  		rte_pktmbuf_free(mbuf);
> @@ -808,6 +814,46 @@ eth_stats_reset(struct rte_eth_dev *dev)
>  	return 0;
>  }
>  
> +static int
> +eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
> +{
> +	struct pmd_internals *internals = dev->data->dev_private;
> +	unsigned int i;
> +	bool is_supported = false;
> +	int ret;
> +
> +	for (i = 0; i < dev->data->nb_rx_queues; i++) {
> +		struct pcap_rx_queue *queue = &internals->rx_queue[i];
> +
> +		if ((strcmp(queue->type, ETH_PCAP_IFACE_ARG) == 0) ||
> +		    (strcmp(queue->type, ETH_PCAP_RX_IFACE_ARG) == 0) ||
> +		    (strcmp(queue->type, ETH_PCAP_RX_IFACE_IN_ARG) == 0)) {
> +			ret = osdep_iface_mtu_set(queue->name, mtu);
> +			if (ret < 0)
> +				return ret;
> +			is_supported = true;
> +		}

If there are multiple devices (each pcap queue represents a device), and
one in the middle one fails to set MTU, there will be mixed MTU values
in devices.

> +	}
> +
> +	for (i = 0; i < dev->data->nb_tx_queues; i++) {
> +		struct pcap_tx_queue *queue = &internals->tx_queue[i];
> +
> +		if ((strcmp(queue->type, ETH_PCAP_IFACE_ARG) == 0) ||

Rx devices and Tx devices can be same device, causing duplicated MTU set
for same device, but it is hard to detect if they are same devices.
At least it is easier to detect when queue type is 'ETH_PCAP_IFACE_ARG',
what about set MTU once for this queue type?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] pcap: support MTU set
  2022-03-17 17:43 [PATCH] net/pcap: " ido g
@ 2023-07-04 21:02 ` Stephen Hemminger
  2023-07-05 11:37   ` Ferruh Yigit
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2023-07-04 21:02 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Ido Goshen

Support rte_eth_dev_set_mtu for pcap driver when the
pcap device is convigured to point to a network interface.

This is rebased an consolidated from earlier version.
Added support for FreeBSD.

Signed-off-by: Ido Goshen <ido@cgstowernetworks.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2 - fix FreeBSD part

 drivers/net/pcap/pcap_ethdev.c        | 49 ++++++++++++++++++++++++++-
 drivers/net/pcap/pcap_osdep.h         |  1 +
 drivers/net/pcap/pcap_osdep_freebsd.c | 23 +++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c   | 21 ++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c |  7 ++++
 5 files changed, 100 insertions(+), 1 deletion(-)

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index bfec0850456f..672f42d30d8e 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -5,6 +5,7 @@
  */
 
 #include <stdlib.h>
+#include <stdbool.h>
 #include <time.h>
 
 #include <pcap.h>
@@ -495,8 +496,13 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		 */
 		ret = pcap_sendpacket(pcap,
 			rte_pktmbuf_read(mbuf, 0, len, temp_data), len);
-		if (unlikely(ret != 0))
+		if (unlikely(ret != 0)) {
+			/* Oversize packet dropped due to MTU */
+			if (errno == EMSGSIZE)
+				continue;
 			break;
+		}
+
 		num_tx++;
 		tx_bytes += len;
 		rte_pktmbuf_free(mbuf);
@@ -808,6 +814,46 @@ eth_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static int
+eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	unsigned int i;
+	bool is_supported = false;
+	int ret;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		struct pcap_rx_queue *queue = &internals->rx_queue[i];
+
+		if ((strcmp(queue->type, ETH_PCAP_IFACE_ARG) == 0) ||
+		    (strcmp(queue->type, ETH_PCAP_RX_IFACE_ARG) == 0) ||
+		    (strcmp(queue->type, ETH_PCAP_RX_IFACE_IN_ARG) == 0)) {
+			ret = osdep_iface_mtu_set(queue->name, mtu);
+			if (ret < 0)
+				return ret;
+			is_supported = true;
+		}
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		struct pcap_tx_queue *queue = &internals->tx_queue[i];
+
+		if ((strcmp(queue->type, ETH_PCAP_IFACE_ARG) == 0) ||
+		    (strcmp(queue->type, ETH_PCAP_TX_IFACE_ARG) == 0)) {
+			ret = osdep_iface_mtu_set(queue->name, mtu);
+			if (ret < 0)
+				return ret;
+			is_supported = true;
+		}
+	}
+
+	if (!is_supported)
+		return -ENOTSUP;
+
+	PMD_LOG(INFO, "MTU set %s %u\n", dev->device->name, mtu);
+	return 0;
+}
+
 static inline void
 infinite_rx_ring_free(struct rte_ring *pkts)
 {
@@ -1005,6 +1051,7 @@ static const struct eth_dev_ops ops = {
 	.link_update = eth_link_update,
 	.stats_get = eth_stats_get,
 	.stats_reset = eth_stats_reset,
+	.mtu_set = eth_mtu_set,
 };
 
 static int
diff --git a/drivers/net/pcap/pcap_osdep.h b/drivers/net/pcap/pcap_osdep.h
index bf41cba982ec..043677ec777d 100644
--- a/drivers/net/pcap/pcap_osdep.h
+++ b/drivers/net/pcap/pcap_osdep.h
@@ -14,5 +14,6 @@ extern int eth_pcap_logtype;
 
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
+int osdep_iface_mtu_set(const char *name, uint16_t mtu);
 
 #endif
diff --git a/drivers/net/pcap/pcap_osdep_freebsd.c b/drivers/net/pcap/pcap_osdep_freebsd.c
index 20556b3e9215..de6358197391 100644
--- a/drivers/net/pcap/pcap_osdep_freebsd.c
+++ b/drivers/net/pcap/pcap_osdep_freebsd.c
@@ -6,7 +6,9 @@
 
 #include <net/if.h>
 #include <net/if_dl.h>
+#include <sys/ioctl.h>
 #include <sys/sysctl.h>
+#include <unistd.h>
 
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
@@ -57,3 +59,24 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	rte_free(buf);
 	return 0;
 }
+
+int
+osdep_iface_mtu_set(const char *if_name, uint16_t mtu)
+{
+	struct ifreq ifr = { };
+	int if_fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+	if (if_fd == -1)
+		return -errno;
+
+	strlcpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
+	ifr.ifr_mtu = mtu;
+	if (ioctl(if_fd, SIOCSIFMTU, &ifr)) {
+		PMD_LOG(ERR, "%s mtu set to %d failed\n", if_name, mtu);
+		close(if_fd);
+		return -errno;
+	}
+
+	close(if_fd);
+	return 0;
+}
diff --git a/drivers/net/pcap/pcap_osdep_linux.c b/drivers/net/pcap/pcap_osdep_linux.c
index 97033f57c5d9..845296595f86 100644
--- a/drivers/net/pcap/pcap_osdep_linux.c
+++ b/drivers/net/pcap/pcap_osdep_linux.c
@@ -40,3 +40,24 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	close(if_fd);
 	return 0;
 }
+
+int
+osdep_iface_mtu_set(const char *if_name, uint16_t mtu)
+{
+	struct ifreq ifr;
+	int if_fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+	if (if_fd == -1)
+		return -errno;
+
+	rte_strscpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
+	ifr.ifr_mtu = mtu;
+	if (ioctl(if_fd, SIOCSIFMTU, &ifr)) {
+		PMD_LOG(ERR, "%s mtu set to %d failed\n", if_name, mtu);
+		close(if_fd);
+		return -errno;
+	}
+
+	close(if_fd);
+	return 0;
+}
diff --git a/drivers/net/pcap/pcap_osdep_windows.c b/drivers/net/pcap/pcap_osdep_windows.c
index 1d398dc7ed9f..db34fc49e22e 100644
--- a/drivers/net/pcap/pcap_osdep_windows.c
+++ b/drivers/net/pcap/pcap_osdep_windows.c
@@ -116,3 +116,10 @@ osdep_iface_mac_get(const char *device_name, struct rte_ether_addr *mac)
 	free(info);
 	return ret;
 }
+
+int
+osdep_iface_mtu_set(__rte_unused const char *device_name, __rte_unused uint16_t mtu)
+{
+	PMD_LOG(ERR, "mtu set not supported on Windows\n");
+	return -ENOTSUP;
+}
-- 
2.39.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-06 10:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 14:27 [PATCH v2] pcap: support MTU set Ido Goshen
2022-05-23 14:52 ` Ido Goshen
  -- strict thread matches above, loose matches on Subject: below --
2022-03-17 17:43 [PATCH] net/pcap: " ido g
2023-07-04 21:02 ` [PATCH v2] pcap: " Stephen Hemminger
2023-07-05 11:37   ` Ferruh Yigit
2023-07-05 15:18     ` Stephen Hemminger
2023-07-06 10:45       ` Ido Goshen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).