DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/tap: perform proto field update for tun only
@ 2018-05-14  4:53 Vipin Varghese
  2018-05-14 22:27 ` Wiles, Keith
  2018-05-15 14:49 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
  0 siblings, 2 replies; 23+ messages in thread
From: Vipin Varghese @ 2018-05-14  4:53 UTC (permalink / raw)
  To: dev, ophirmu, ferruh.yigit; +Cc: Vipin Varghese

The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
type field will ensure the TAP PMD will always have protocol field as 0.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
---
 drivers/net/tap/rte_eth_tap.c | 50 +++++++++++++++++++++++++++----------------
 drivers/net/tap/rte_eth_tap.h | 10 +++++++++
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index ea6d899..98ac3b5 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
 	 * Do not set IFF_NO_PI as packet information header will be needed
 	 * to check if a received packet has been truncated.
 	 */
-	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
+	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
+			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
 
 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
@@ -502,20 +503,24 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
 			break;
 
-		/*
-		 * TUN and TAP are created with IFF_NO_PI disabled.
-		 * For TUN PMD this mandatory as fields are used by
-		 * Kernel tun.c to determine whether its IP or non IP
-		 * packets.
-		 *
-		 * The logic fetches the first byte of data from mbuf.
-		 * compares whether its v4 or v6. If none matches default
-		 * value 0x00 is taken for protocol field.
-		 */
-		char *buff_data = rte_pktmbuf_mtod(seg, void *);
-		j = (*buff_data & 0xf0);
-		pi.proto = (j == 0x40) ? 0x0008 :
-				(j == 0x60) ? 0xdd86 : 0x00;
+		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
+			/*
+			 * TUN and TAP are created with IFF_NO_PI disabled.
+			 * For TUN PMD this mandatory as fields are used by
+			 * Kernel tun.c to determine whether its IP or non IP
+			 * packets.
+			 *
+			 * The logic fetches the first byte of data from mbuf.
+			 * compares whether its v4 or v6. If none match default
+			 * value 0x00 is taken for protocol field.
+			 */
+			char *buff_data = rte_pktmbuf_mtod(seg, void *);
+			j = (*buff_data & 0xf0);
+			pi.proto = (j == 0x40) ? 0x0008 :
+					(j == 0x60) ? 0xdd86 : 0x00;
+			printf("j %x pi proto %x\n", j, pi.proto);
+			rte_pktmbuf_dump(stdout, seg, 64);
+		}
 
 		iovecs[0].iov_base = &pi;
 		iovecs[0].iov_len = sizeof(pi);
@@ -1052,6 +1057,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
 	tx->mtu = &dev->data->mtu;
 	rx->rxmode = &dev->data->dev_conf.rxmode;
 
+	tx->type = pmd->type;
+	rx->type = pmd->type;
+
 	return *fd;
 }
 
@@ -1386,6 +1394,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	pmd = dev->data->dev_private;
 	pmd->dev = dev;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (pmd->ioctl_sock == -1) {
@@ -1421,7 +1430,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		pmd->txq[i].fd = -1;
 	}
 
-	if (tap_type) {
+	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP : ETH_TUNTAP_TYPE_TUN;
+
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (is_zero_ether_addr(mac_addr))
 			eth_random_addr((uint8_t *)&pmd->eth_addr);
 		else
@@ -1440,7 +1451,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
 		goto error_exit;
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		memset(&ifr, 0, sizeof(struct ifreq));
 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
@@ -1812,7 +1823,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	struct pmd_internals *internals;
 	int i;
 
-	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
+	internals = eth_dev->data->dev_private;
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
 		rte_socket_id());
 
 	/* find the ethdev entry */
@@ -1820,7 +1833,6 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	if (!eth_dev)
 		return 0;
 
-	internals = eth_dev->data->dev_private;
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index 67c9d4b..8b0da5a 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -23,6 +23,13 @@
 #define RTE_PMD_TAP_MAX_QUEUES	1
 #endif
 
+enum rte_tuntap_type {
+	ETH_TUNTAP_TYPE_UNKNOWN,
+	ETH_TUNTAP_TYPE_TUN,
+	ETH_TUNTAP_TYPE_TAP,
+	ETH_TUNTAP_TYPE_MAX,
+};
+
 struct pkt_stats {
 	uint64_t opackets;              /* Number of output packets */
 	uint64_t ipackets;              /* Number of input packets */
@@ -38,6 +45,7 @@ struct rx_queue {
 	uint32_t trigger_seen;          /* Last seen Rx trigger value */
 	uint16_t in_port;               /* Port ID */
 	int fd;
+	int type;			  /* Type field - TUN|TAP */
 	struct pkt_stats stats;         /* Stats for this RX queue */
 	uint16_t nb_rx_desc;            /* max number of mbufs available */
 	struct rte_eth_rxmode *rxmode;  /* RX features */
@@ -48,6 +56,7 @@ struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	int type;			  /* Type field - TUN|TAP */
 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	uint16_t csum:1;                /* Enable checksum offloading */
 	struct pkt_stats stats;         /* Stats for this TX queue */
@@ -57,6 +66,7 @@ struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	int type;			  /* Type field - TUN|TAP */
 	struct ether_addr eth_addr;       /* Mac address of the device port */
 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH] net/tap: perform proto field update for tun only
  2018-05-14  4:53 [dpdk-dev] [PATCH] net/tap: perform proto field update for tun only Vipin Varghese
@ 2018-05-14 22:27 ` Wiles, Keith
  2018-05-15  9:08   ` Varghese, Vipin
  2018-05-15 14:49 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
  1 sibling, 1 reply; 23+ messages in thread
From: Wiles, Keith @ 2018-05-14 22:27 UTC (permalink / raw)
  To: Varghese, Vipin; +Cc: dev, ophirmu, Yigit, Ferruh



> On May 13, 2018, at 11:53 PM, Vipin Varghese <vipin.varghese@intel.com> wrote:
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> ---
> drivers/net/tap/rte_eth_tap.c | 50 +++++++++++++++++++++++++++----------------
> drivers/net/tap/rte_eth_tap.h | 10 +++++++++
> 2 files changed, 41 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index ea6d899..98ac3b5 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
> 	 * Do not set IFF_NO_PI as packet information header will be needed
> 	 * to check if a received packet has been truncated.
> 	 */
> -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> +			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
> 
> 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
> @@ -502,20 +503,24 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
> 			break;
> 
> -		/*
> -		 * TUN and TAP are created with IFF_NO_PI disabled.
> -		 * For TUN PMD this mandatory as fields are used by
> -		 * Kernel tun.c to determine whether its IP or non IP
> -		 * packets.
> -		 *
> -		 * The logic fetches the first byte of data from mbuf.
> -		 * compares whether its v4 or v6. If none matches default
> -		 * value 0x00 is taken for protocol field.
> -		 */
> -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
> -		j = (*buff_data & 0xf0);
> -		pi.proto = (j == 0x40) ? 0x0008 :
> -				(j == 0x60) ? 0xdd86 : 0x00;
> +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
> +			/*
> +			 * TUN and TAP are created with IFF_NO_PI disabled.
> +			 * For TUN PMD this mandatory as fields are used by
> +			 * Kernel tun.c to determine whether its IP or non IP
> +			 * packets.
> +			 *
> +			 * The logic fetches the first byte of data from mbuf.
> +			 * compares whether its v4 or v6. If none match default
> +			 * value 0x00 is taken for protocol field.

Little reword and remove the ‘.’ at end of first line.

The logic fetches the first byte of data from mbuf then compares whether it is v4 or v6. If not equal to zero then it must be a protocol field.



> +			 */
> +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> +			j = (*buff_data & 0xf0);
> +			pi.proto = (j == 0x40) ? 0x0008 :
> +					(j == 0x60) ? 0xdd86 : 0x00;
> +			printf("j %x pi proto %x\n", j, pi.proto);

Should this not be a LOG message or is this debug that was not removed? If log message then add move text to explain the output better.

> +			rte_pktmbuf_dump(stdout, seg, 64);
> +		}
> 
> 		iovecs[0].iov_base = &pi;
> 		iovecs[0].iov_len = sizeof(pi);
> @@ -1052,6 +1057,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
> 	tx->mtu = &dev->data->mtu;
> 	rx->rxmode = &dev->data->dev_conf.rxmode;
> 
> +	tx->type = pmd->type;
> +	rx->type = pmd->type;
> +
> 	return *fd;
> }
> 
> @@ -1386,6 +1394,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> 	pmd = dev->data->dev_private;
> 	pmd->dev = dev;
> 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
> +	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
> 
> 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
> 	if (pmd->ioctl_sock == -1) {
> @@ -1421,7 +1430,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> 		pmd->txq[i].fd = -1;
> 	}
> 
> -	if (tap_type) {
> +	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP : ETH_TUNTAP_TYPE_TUN;
> +
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> 		if (is_zero_ether_addr(mac_addr))
> 			eth_random_addr((uint8_t *)&pmd->eth_addr);
> 		else
> @@ -1440,7 +1451,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
> 		goto error_exit;
> 
> -	if (tap_type) {
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> 		memset(&ifr, 0, sizeof(struct ifreq));
> 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
> 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
> @@ -1812,7 +1823,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
> 	struct pmd_internals *internals;
> 	int i;
> 
> -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
> +	internals = eth_dev->data->dev_private;
> +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
> +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
> 		rte_socket_id());
> 
> 	/* find the ethdev entry */
> @@ -1820,7 +1833,6 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
> 	if (!eth_dev)
> 		return 0;
> 
> -	internals = eth_dev->data->dev_private;
> 	if (internals->nlsk_fd) {
> 		tap_flow_flush(eth_dev, NULL);
> 		tap_flow_implicit_flush(internals, NULL);
> diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
> index 67c9d4b..8b0da5a 100644
> --- a/drivers/net/tap/rte_eth_tap.h
> +++ b/drivers/net/tap/rte_eth_tap.h
> @@ -23,6 +23,13 @@
> #define RTE_PMD_TAP_MAX_QUEUES	1
> #endif
> 
> +enum rte_tuntap_type {
> +	ETH_TUNTAP_TYPE_UNKNOWN,
> +	ETH_TUNTAP_TYPE_TUN,
> +	ETH_TUNTAP_TYPE_TAP,
> +	ETH_TUNTAP_TYPE_MAX,
> +};
> +
> struct pkt_stats {
> 	uint64_t opackets;              /* Number of output packets */
> 	uint64_t ipackets;              /* Number of input packets */
> @@ -38,6 +45,7 @@ struct rx_queue {
> 	uint32_t trigger_seen;          /* Last seen Rx trigger value */
> 	uint16_t in_port;               /* Port ID */
> 	int fd;
> +	int type;			  /* Type field - TUN|TAP */
> 	struct pkt_stats stats;         /* Stats for this RX queue */
> 	uint16_t nb_rx_desc;            /* max number of mbufs available */
> 	struct rte_eth_rxmode *rxmode;  /* RX features */
> @@ -48,6 +56,7 @@ struct rx_queue {
> 
> struct tx_queue {
> 	int fd;
> +	int type;			  /* Type field - TUN|TAP */
> 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
> 	uint16_t csum:1;                /* Enable checksum offloading */
> 	struct pkt_stats stats;         /* Stats for this TX queue */
> @@ -57,6 +66,7 @@ struct pmd_internals {
> 	struct rte_eth_dev *dev;          /* Ethernet device. */
> 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
> 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
> +	int type;			  /* Type field - TUN|TAP */
> 	struct ether_addr eth_addr;       /* Mac address of the device port */
> 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
> 	int remote_if_index;              /* remote netdevice IF_INDEX */
> -- 
> 2.7.4
> 

Regards,
Keith


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

* Re: [dpdk-dev] [PATCH] net/tap: perform proto field update for tun only
  2018-05-14 22:27 ` Wiles, Keith
@ 2018-05-15  9:08   ` Varghese, Vipin
  0 siblings, 0 replies; 23+ messages in thread
From: Varghese, Vipin @ 2018-05-15  9:08 UTC (permalink / raw)
  To: Wiles, Keith; +Cc: dev, ophirmu, Yigit, Ferruh

Thanks Keith,

I have made changes and shared v2 patch for both the suggestions.

Thanks
Vipin Varghese

<snipped>

> > +			/*
> > +			 * TUN and TAP are created with IFF_NO_PI disabled.
> > +			 * For TUN PMD this mandatory as fields are used by
> > +			 * Kernel tun.c to determine whether its IP or non IP
> > +			 * packets.
> > +			 *
> > +			 * The logic fetches the first byte of data from mbuf.
> > +			 * compares whether its v4 or v6. If none match default
> > +			 * value 0x00 is taken for protocol field.
> 
> Little reword and remove the ‘.’ at end of first line.
> 
> The logic fetches the first byte of data from mbuf then compares whether it is v4
> or v6. If not equal to zero then it must be a protocol field.
> 
> 
> 
> > +			 */
> > +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> > +			j = (*buff_data & 0xf0);
> > +			pi.proto = (j == 0x40) ? 0x0008 :
> > +					(j == 0x60) ? 0xdd86 : 0x00;
> > +			printf("j %x pi proto %x\n", j, pi.proto);
> 
> Should this not be a LOG message or is this debug that was not removed? If log
> message then add move text to explain the output better.
> 

<snipped>


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

* Re: [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only
  2018-05-15 14:49 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
@ 2018-05-15 12:31   ` Wiles, Keith
  2018-05-15 22:28   ` Ophir Munk
  2018-05-22 10:47   ` [dpdk-dev] [PATCH v3] " Vipin Varghese
  2 siblings, 0 replies; 23+ messages in thread
From: Wiles, Keith @ 2018-05-15 12:31 UTC (permalink / raw)
  To: Varghese, Vipin; +Cc: dev, Yigit, Ferruh, ophirmu



> On May 15, 2018, at 9:49 AM, Varghese, Vipin <vipin.varghese@intel.com> wrote:
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field
> as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> 
> Changes in V2:
> updated in comment wording - Keith Wiles
> remove debug print from tx code - Keith Wiles


Acked by: Keith Wiles<keith.wiles@intel.com>

Regards,
Keith

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

* [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only
  2018-05-14  4:53 [dpdk-dev] [PATCH] net/tap: perform proto field update for tun only Vipin Varghese
  2018-05-14 22:27 ` Wiles, Keith
@ 2018-05-15 14:49 ` Vipin Varghese
  2018-05-15 12:31   ` Wiles, Keith
                     ` (2 more replies)
  1 sibling, 3 replies; 23+ messages in thread
From: Vipin Varghese @ 2018-05-15 14:49 UTC (permalink / raw)
  To: dev, keith.wiles, ferruh.yigit, ophirmu; +Cc: Vipin Varghese

The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
type field will ensure the TAP PMD will always have protocol field
as 0.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---

Changes in V2:
updated in comment wording - Keith Wiles
remove debug print from tx code - Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 48 ++++++++++++++++++++++++++-----------------
 drivers/net/tap/rte_eth_tap.h | 10 +++++++++
 2 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index ea6d899..fafd557 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
 	 * Do not set IFF_NO_PI as packet information header will be needed
 	 * to check if a received packet has been truncated.
 	 */
-	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
+	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
+			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
 
 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
@@ -502,20 +503,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
 			break;
 
-		/*
-		 * TUN and TAP are created with IFF_NO_PI disabled.
-		 * For TUN PMD this mandatory as fields are used by
-		 * Kernel tun.c to determine whether its IP or non IP
-		 * packets.
-		 *
-		 * The logic fetches the first byte of data from mbuf.
-		 * compares whether its v4 or v6. If none matches default
-		 * value 0x00 is taken for protocol field.
-		 */
-		char *buff_data = rte_pktmbuf_mtod(seg, void *);
-		j = (*buff_data & 0xf0);
-		pi.proto = (j == 0x40) ? 0x0008 :
-				(j == 0x60) ? 0xdd86 : 0x00;
+		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
+			/*
+			 * TUN and TAP are created with IFF_NO_PI disabled.
+			 * For TUN PMD this mandatory as fields are used by
+			 * Kernel tun.c to determine whether its IP or non IP
+			 * packets.
+			 *
+			 * The logic fetches the first byte of data from mbuf
+			 * then compares whether its v4 or v6. If first byte
+			 * is 4 or 6, then protocol field is updated.
+			 */
+			char *buff_data = rte_pktmbuf_mtod(seg, void *);
+			j = (*buff_data & 0xf0);
+			pi.proto = (j == 0x40) ? 0x0008 :
+					(j == 0x60) ? 0xdd86 : 0x00;
+		}
 
 		iovecs[0].iov_base = &pi;
 		iovecs[0].iov_len = sizeof(pi);
@@ -1052,6 +1055,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
 	tx->mtu = &dev->data->mtu;
 	rx->rxmode = &dev->data->dev_conf.rxmode;
 
+	tx->type = pmd->type;
+	rx->type = pmd->type;
+
 	return *fd;
 }
 
@@ -1386,6 +1392,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	pmd = dev->data->dev_private;
 	pmd->dev = dev;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (pmd->ioctl_sock == -1) {
@@ -1421,7 +1428,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		pmd->txq[i].fd = -1;
 	}
 
-	if (tap_type) {
+	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP : ETH_TUNTAP_TYPE_TUN;
+
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (is_zero_ether_addr(mac_addr))
 			eth_random_addr((uint8_t *)&pmd->eth_addr);
 		else
@@ -1440,7 +1449,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
 		goto error_exit;
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		memset(&ifr, 0, sizeof(struct ifreq));
 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
@@ -1812,7 +1821,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	struct pmd_internals *internals;
 	int i;
 
-	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
+	internals = eth_dev->data->dev_private;
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
 		rte_socket_id());
 
 	/* find the ethdev entry */
@@ -1820,7 +1831,6 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	if (!eth_dev)
 		return 0;
 
-	internals = eth_dev->data->dev_private;
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index 67c9d4b..8b0da5a 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -23,6 +23,13 @@
 #define RTE_PMD_TAP_MAX_QUEUES	1
 #endif
 
+enum rte_tuntap_type {
+	ETH_TUNTAP_TYPE_UNKNOWN,
+	ETH_TUNTAP_TYPE_TUN,
+	ETH_TUNTAP_TYPE_TAP,
+	ETH_TUNTAP_TYPE_MAX,
+};
+
 struct pkt_stats {
 	uint64_t opackets;              /* Number of output packets */
 	uint64_t ipackets;              /* Number of input packets */
@@ -38,6 +45,7 @@ struct rx_queue {
 	uint32_t trigger_seen;          /* Last seen Rx trigger value */
 	uint16_t in_port;               /* Port ID */
 	int fd;
+	int type;			  /* Type field - TUN|TAP */
 	struct pkt_stats stats;         /* Stats for this RX queue */
 	uint16_t nb_rx_desc;            /* max number of mbufs available */
 	struct rte_eth_rxmode *rxmode;  /* RX features */
@@ -48,6 +56,7 @@ struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	int type;			  /* Type field - TUN|TAP */
 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	uint16_t csum:1;                /* Enable checksum offloading */
 	struct pkt_stats stats;         /* Stats for this TX queue */
@@ -57,6 +66,7 @@ struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	int type;			  /* Type field - TUN|TAP */
 	struct ether_addr eth_addr;       /* Mac address of the device port */
 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only
  2018-05-15 14:49 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
  2018-05-15 12:31   ` Wiles, Keith
@ 2018-05-15 22:28   ` Ophir Munk
  2018-05-22  6:33     ` Varghese, Vipin
  2018-05-22 10:47   ` [dpdk-dev] [PATCH v3] " Vipin Varghese
  2 siblings, 1 reply; 23+ messages in thread
From: Ophir Munk @ 2018-05-15 22:28 UTC (permalink / raw)
  To: Vipin Varghese, dev, keith.wiles, ferruh.yigit
  Cc: Thomas Monjalon, Olga Shern

Hi,
I am adding my review although this patch has already been acked.
Please find some comments inline. Otherwise it looks OK.

Regards,
Ophir

> -----Original Message-----
> From: Vipin Varghese [mailto:vipin.varghese@intel.com]
> Sent: Tuesday, May 15, 2018 5:50 PM
> To: dev@dpdk.org; keith.wiles@intel.com; ferruh.yigit@intel.com; Ophir
> Munk <ophirmu@mellanox.com>
> Cc: Vipin Varghese <vipin.varghese@intel.com>
> Subject: [PATCH v2] net/tap: perform proto field update for tun only
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> 
> Changes in V2:
> updated in comment wording - Keith Wiles remove debug print from tx code
> - Keith Wiles
> ---
>  drivers/net/tap/rte_eth_tap.c | 48 ++++++++++++++++++++++++++-----------
> ------
>  drivers/net/tap/rte_eth_tap.h | 10 +++++++++
>  2 files changed, 39 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index ea6d899..fafd557 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
>  	 * Do not set IFF_NO_PI as packet information header will be needed
>  	 * to check if a received packet has been truncated.
>  	 */
> -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> +			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
>  	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
> 
>  	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); @@ -502,20
> +503,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t
> nb_pkts)
>  		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
>  			break;
> 
> -		/*
> -		 * TUN and TAP are created with IFF_NO_PI disabled.
> -		 * For TUN PMD this mandatory as fields are used by
> -		 * Kernel tun.c to determine whether its IP or non IP
> -		 * packets.
> -		 *
> -		 * The logic fetches the first byte of data from mbuf.
> -		 * compares whether its v4 or v6. If none matches default
> -		 * value 0x00 is taken for protocol field.
> -		 */
> -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
> -		j = (*buff_data & 0xf0);
> -		pi.proto = (j == 0x40) ? 0x0008 :
> -				(j == 0x60) ? 0xdd86 : 0x00;
> +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
> +			/*
> +			 * TUN and TAP are created with IFF_NO_PI disabled.
> +			 * For TUN PMD this mandatory as fields are used by
> +			 * Kernel tun.c to determine whether its IP or non IP
> +			 * packets.
> +			 *
> +			 * The logic fetches the first byte of data from mbuf
> +			 * then compares whether its v4 or v6. If first byte
> +			 * is 4 or 6, then protocol field is updated.
> +			 */
> +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> +			j = (*buff_data & 0xf0);
> +			pi.proto = (j == 0x40) ? 0x0008 :
> +					(j == 0x60) ? 0xdd86 : 0x00;
> +		}
> 
>  		iovecs[0].iov_base = &pi;
>  		iovecs[0].iov_len = sizeof(pi);
> @@ -1052,6 +1055,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
>  	tx->mtu = &dev->data->mtu;
>  	rx->rxmode = &dev->data->dev_conf.rxmode;
> 
> +	tx->type = pmd->type;
> +	rx->type = pmd->type;

It seems there is no usage for rx->type in TAP code. Therefore - can you please remove rx->type assignment?
> +
>  	return *fd;
>  }
> 
> @@ -1386,6 +1392,7 @@ eth_dev_tap_create(struct rte_vdev_device
> *vdev, char *tap_name,
>  	pmd = dev->data->dev_private;
>  	pmd->dev = dev;
>  	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
> +	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
> 
>  	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
>  	if (pmd->ioctl_sock == -1) {
> @@ -1421,7 +1428,9 @@ eth_dev_tap_create(struct rte_vdev_device
> *vdev, char *tap_name,
>  		pmd->txq[i].fd = -1;
>  	}
> 
> -	if (tap_type) {
> +	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP :
> ETH_TUNTAP_TYPE_TUN;

1. It seem you are using 'tap_type' as a global static variable to pass a value to eth_dev_tap_create().
Can you please pass this value by adding a parameter to eth_dev_tap_create() call and remove the global static variable?
2. You are using tap_type with values 0 and 1 which are converted to enums ETH_TUNTAP_TYPE_TUN and ETH_TUNTAP_TYPE_TAP respectively. Can you please always just use the enums (avoiding the conversion)?

> +
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
>  		if (is_zero_ether_addr(mac_addr))
>  			eth_random_addr((uint8_t *)&pmd->eth_addr);
>  		else
> @@ -1440,7 +1449,7 @@ eth_dev_tap_create(struct rte_vdev_device
> *vdev, char *tap_name,
>  	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
>  		goto error_exit;
> 
> -	if (tap_type) {
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
>  		memset(&ifr, 0, sizeof(struct ifreq));
>  		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
>  		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, @@ -
> 1812,7 +1821,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
>  	struct pmd_internals *internals;
>  	int i;
> 
> -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
> +	internals = eth_dev->data->dev_private;
> +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
> +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" :
> "TUN",
>  		rte_socket_id());
> 
>  	/* find the ethdev entry */
> @@ -1820,7 +1831,6 @@ rte_pmd_tap_remove(struct rte_vdev_device
> *dev)
>  	if (!eth_dev)
>  		return 0;
> 
> -	internals = eth_dev->data->dev_private;
>  	if (internals->nlsk_fd) {
>  		tap_flow_flush(eth_dev, NULL);
>  		tap_flow_implicit_flush(internals, NULL); diff --git
> a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index
> 67c9d4b..8b0da5a 100644
> --- a/drivers/net/tap/rte_eth_tap.h
> +++ b/drivers/net/tap/rte_eth_tap.h
> @@ -23,6 +23,13 @@
>  #define RTE_PMD_TAP_MAX_QUEUES	1
>  #endif
> 
> +enum rte_tuntap_type {
> +	ETH_TUNTAP_TYPE_UNKNOWN,
> +	ETH_TUNTAP_TYPE_TUN,
> +	ETH_TUNTAP_TYPE_TAP,
> +	ETH_TUNTAP_TYPE_MAX,
> +};
> +
>  struct pkt_stats {
>  	uint64_t opackets;              /* Number of output packets */
>  	uint64_t ipackets;              /* Number of input packets */
> @@ -38,6 +45,7 @@ struct rx_queue {
>  	uint32_t trigger_seen;          /* Last seen Rx trigger value */
>  	uint16_t in_port;               /* Port ID */
>  	int fd;
> +	int type;			  /* Type field - TUN|TAP */

In seems there is no usage for 'type' field from rx_queue struct in the code. If so - can you please remove it?

>  	struct pkt_stats stats;         /* Stats for this RX queue */
>  	uint16_t nb_rx_desc;            /* max number of mbufs available */
>  	struct rte_eth_rxmode *rxmode;  /* RX features */ @@ -48,6 +56,7
> @@ struct rx_queue {
> 
>  struct tx_queue {
>  	int fd;
> +	int type;			  /* Type field - TUN|TAP */

Please use spaces (like all other fields in this struct) instead of tabs, so all fields look aligned.

>  	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
>  	uint16_t csum:1;                /* Enable checksum offloading */
>  	struct pkt_stats stats;         /* Stats for this TX queue */
> @@ -57,6 +66,7 @@ struct pmd_internals {
>  	struct rte_eth_dev *dev;          /* Ethernet device. */
>  	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote
> netdevice name */
>  	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device
> name */
> +	int type;			  /* Type field - TUN|TAP */

Same comment here about replacing tabs with spaces

>  	struct ether_addr eth_addr;       /* Mac address of the device port */
>  	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init
> */
>  	int remote_if_index;              /* remote netdevice IF_INDEX */
> --
> 2.7.4

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

* Re: [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only
  2018-05-15 22:28   ` Ophir Munk
@ 2018-05-22  6:33     ` Varghese, Vipin
  2018-05-22 11:05       ` Varghese, Vipin
  0 siblings, 1 reply; 23+ messages in thread
From: Varghese, Vipin @ 2018-05-22  6:33 UTC (permalink / raw)
  To: Ophir Munk, dev, Wiles,  Keith, Yigit, Ferruh; +Cc: Thomas Monjalon, Olga Shern

Hi Ophir,

Thanks for the suggestion, once these are merged to dpdk or dpdk-net mainline, I can start the modifications.

Thanks
Vipin Varghese

> -----Original Message-----
> From: Ophir Munk [mailto:ophirmu@mellanox.com]
> Sent: Wednesday, May 16, 2018 3:59 AM
> To: Varghese, Vipin <vipin.varghese@intel.com>; dev@dpdk.org; Wiles, Keith
> <keith.wiles@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
> <olgas@mellanox.com>
> Subject: RE: [PATCH v2] net/tap: perform proto field update for tun only
> 
> Hi,
> I am adding my review although this patch has already been acked.
> Please find some comments inline. Otherwise it looks OK.
> 
> Regards,
> Ophir
> 
> > -----Original Message-----
> > From: Vipin Varghese [mailto:vipin.varghese@intel.com]
> > Sent: Tuesday, May 15, 2018 5:50 PM
> > To: dev@dpdk.org; keith.wiles@intel.com; ferruh.yigit@intel.com; Ophir
> > Munk <ophirmu@mellanox.com>
> > Cc: Vipin Varghese <vipin.varghese@intel.com>
> > Subject: [PATCH v2] net/tap: perform proto field update for tun only
> >
> > The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> > type field will ensure the TAP PMD will always have protocol field as 0.
> >
> > Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> > Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > ---
> >
> > Changes in V2:
> > updated in comment wording - Keith Wiles remove debug print from tx
> > code
> > - Keith Wiles
> > ---
> >  drivers/net/tap/rte_eth_tap.c | 48
> > ++++++++++++++++++++++++++-----------
> > ------
> >  drivers/net/tap/rte_eth_tap.h | 10 +++++++++
> >  2 files changed, 39 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/net/tap/rte_eth_tap.c
> > b/drivers/net/tap/rte_eth_tap.c index ea6d899..fafd557 100644
> > --- a/drivers/net/tap/rte_eth_tap.c
> > +++ b/drivers/net/tap/rte_eth_tap.c
> > @@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
> >  	 * Do not set IFF_NO_PI as packet information header will be needed
> >  	 * to check if a received packet has been truncated.
> >  	 */
> > -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> > +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> > +			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> >  	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
> >
> >  	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); @@ -502,20
> > +503,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t
> > nb_pkts)
> >  		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
> >  			break;
> >
> > -		/*
> > -		 * TUN and TAP are created with IFF_NO_PI disabled.
> > -		 * For TUN PMD this mandatory as fields are used by
> > -		 * Kernel tun.c to determine whether its IP or non IP
> > -		 * packets.
> > -		 *
> > -		 * The logic fetches the first byte of data from mbuf.
> > -		 * compares whether its v4 or v6. If none matches default
> > -		 * value 0x00 is taken for protocol field.
> > -		 */
> > -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
> > -		j = (*buff_data & 0xf0);
> > -		pi.proto = (j == 0x40) ? 0x0008 :
> > -				(j == 0x60) ? 0xdd86 : 0x00;
> > +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
> > +			/*
> > +			 * TUN and TAP are created with IFF_NO_PI disabled.
> > +			 * For TUN PMD this mandatory as fields are used by
> > +			 * Kernel tun.c to determine whether its IP or non IP
> > +			 * packets.
> > +			 *
> > +			 * The logic fetches the first byte of data from mbuf
> > +			 * then compares whether its v4 or v6. If first byte
> > +			 * is 4 or 6, then protocol field is updated.
> > +			 */
> > +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> > +			j = (*buff_data & 0xf0);
> > +			pi.proto = (j == 0x40) ? 0x0008 :
> > +					(j == 0x60) ? 0xdd86 : 0x00;
> > +		}
> >
> >  		iovecs[0].iov_base = &pi;
> >  		iovecs[0].iov_len = sizeof(pi);
> > @@ -1052,6 +1055,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
> >  	tx->mtu = &dev->data->mtu;
> >  	rx->rxmode = &dev->data->dev_conf.rxmode;
> >
> > +	tx->type = pmd->type;
> > +	rx->type = pmd->type;
> 
> It seems there is no usage for rx->type in TAP code. Therefore - can you please
> remove rx->type assignment?
> > +
> >  	return *fd;
> >  }
> >
> > @@ -1386,6 +1392,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev,
> > char *tap_name,
> >  	pmd = dev->data->dev_private;
> >  	pmd->dev = dev;
> >  	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
> > +	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
> >
> >  	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
> >  	if (pmd->ioctl_sock == -1) {
> > @@ -1421,7 +1428,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev,
> > char *tap_name,
> >  		pmd->txq[i].fd = -1;
> >  	}
> >
> > -	if (tap_type) {
> > +	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP :
> > ETH_TUNTAP_TYPE_TUN;
> 
> 1. It seem you are using 'tap_type' as a global static variable to pass a value to
> eth_dev_tap_create().
> Can you please pass this value by adding a parameter to eth_dev_tap_create()
> call and remove the global static variable?
> 2. You are using tap_type with values 0 and 1 which are converted to enums
> ETH_TUNTAP_TYPE_TUN and ETH_TUNTAP_TYPE_TAP respectively. Can you
> please always just use the enums (avoiding the conversion)?
> 
> > +
> > +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> >  		if (is_zero_ether_addr(mac_addr))
> >  			eth_random_addr((uint8_t *)&pmd->eth_addr);
> >  		else
> > @@ -1440,7 +1449,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev,
> > char *tap_name,
> >  	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
> >  		goto error_exit;
> >
> > -	if (tap_type) {
> > +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> >  		memset(&ifr, 0, sizeof(struct ifreq));
> >  		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
> >  		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, @@ -
> > 1812,7 +1821,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
> >  	struct pmd_internals *internals;
> >  	int i;
> >
> > -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
> > +	internals = eth_dev->data->dev_private;
> > +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
> > +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" :
> > "TUN",
> >  		rte_socket_id());
> >
> >  	/* find the ethdev entry */
> > @@ -1820,7 +1831,6 @@ rte_pmd_tap_remove(struct rte_vdev_device
> > *dev)
> >  	if (!eth_dev)
> >  		return 0;
> >
> > -	internals = eth_dev->data->dev_private;
> >  	if (internals->nlsk_fd) {
> >  		tap_flow_flush(eth_dev, NULL);
> >  		tap_flow_implicit_flush(internals, NULL); diff --git
> > a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index
> > 67c9d4b..8b0da5a 100644
> > --- a/drivers/net/tap/rte_eth_tap.h
> > +++ b/drivers/net/tap/rte_eth_tap.h
> > @@ -23,6 +23,13 @@
> >  #define RTE_PMD_TAP_MAX_QUEUES	1
> >  #endif
> >
> > +enum rte_tuntap_type {
> > +	ETH_TUNTAP_TYPE_UNKNOWN,
> > +	ETH_TUNTAP_TYPE_TUN,
> > +	ETH_TUNTAP_TYPE_TAP,
> > +	ETH_TUNTAP_TYPE_MAX,
> > +};
> > +
> >  struct pkt_stats {
> >  	uint64_t opackets;              /* Number of output packets */
> >  	uint64_t ipackets;              /* Number of input packets */
> > @@ -38,6 +45,7 @@ struct rx_queue {
> >  	uint32_t trigger_seen;          /* Last seen Rx trigger value */
> >  	uint16_t in_port;               /* Port ID */
> >  	int fd;
> > +	int type;			  /* Type field - TUN|TAP */
> 
> In seems there is no usage for 'type' field from rx_queue struct in the code. If so
> - can you please remove it?
> 
> >  	struct pkt_stats stats;         /* Stats for this RX queue */
> >  	uint16_t nb_rx_desc;            /* max number of mbufs available */
> >  	struct rte_eth_rxmode *rxmode;  /* RX features */ @@ -48,6 +56,7
> @@
> > struct rx_queue {
> >
> >  struct tx_queue {
> >  	int fd;
> > +	int type;			  /* Type field - TUN|TAP */
> 
> Please use spaces (like all other fields in this struct) instead of tabs, so all fields
> look aligned.
> 
> >  	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
> >  	uint16_t csum:1;                /* Enable checksum offloading */
> >  	struct pkt_stats stats;         /* Stats for this TX queue */
> > @@ -57,6 +66,7 @@ struct pmd_internals {
> >  	struct rte_eth_dev *dev;          /* Ethernet device. */
> >  	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice
> name */
> >  	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
> > +	int type;			  /* Type field - TUN|TAP */
> 
> Same comment here about replacing tabs with spaces
> 
> >  	struct ether_addr eth_addr;       /* Mac address of the device port */
> >  	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init
> > */
> >  	int remote_if_index;              /* remote netdevice IF_INDEX */
> > --
> > 2.7.4

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

* [dpdk-dev] [PATCH v3] net/tap: perform proto field update for tun only
  2018-05-15 14:49 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
  2018-05-15 12:31   ` Wiles, Keith
  2018-05-15 22:28   ` Ophir Munk
@ 2018-05-22 10:47   ` Vipin Varghese
  2018-05-22 13:53     ` Wiles, Keith
                       ` (2 more replies)
  2 siblings, 3 replies; 23+ messages in thread
From: Vipin Varghese @ 2018-05-22 10:47 UTC (permalink / raw)
  To: dev, ferruh.yigit, keith.wiles, ophirmu; +Cc: thomas, olgas, Vipin Varghese

The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
type field will ensure the TAP PMD will always have protocol field
as 0.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Changes in V3:
- remove type field from rx struct - Ophir Munk
- add space for comment in struct - Ophir Munk
- pass type field into eth_dev_tap_create - Ophir Munk
- replace with enum value for type - Ophir Munk
- return as 'not supported' for mac_set - Vipin Varghese

Changes in V2:
- updated in comment wording - Keith Wiles
- remove debug print from tx code - Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 61 +++++++++++++++++++++++++------------------
 drivers/net/tap/rte_eth_tap.h |  9 +++++++
 2 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 01552fa..8d8f67b 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -68,7 +68,6 @@ static const char *valid_arguments[] = {
 static int tap_unit;
 static unsigned int tun_unit;
 
-static int tap_type;
 static char tuntap_name[8];
 
 static volatile uint32_t tap_trigger;	/* Rx trigger */
@@ -116,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
 	 * Do not set IFF_NO_PI as packet information header will be needed
 	 * to check if a received packet has been truncated.
 	 */
-	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
+	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
+		IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
 
 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
@@ -472,20 +472,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
 			break;
 
-		/*
-		 * TUN and TAP are created with IFF_NO_PI disabled.
-		 * For TUN PMD this mandatory as fields are used by
-		 * Kernel tun.c to determine whether its IP or non IP
-		 * packets.
-		 *
-		 * The logic fetches the first byte of data from mbuf.
-		 * compares whether its v4 or v6. If none matches default
-		 * value 0x00 is taken for protocol field.
-		 */
-		char *buff_data = rte_pktmbuf_mtod(seg, void *);
-		j = (*buff_data & 0xf0);
-		pi.proto = (j == 0x40) ? 0x0008 :
+		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
+			/*
+			 * TUN and TAP are created with IFF_NO_PI disabled.
+			 * For TUN PMD this mandatory as fields are used by
+			 * Kernel tun.c to determine whether its IP or non IP
+			 * packets.
+			 *
+			 * The logic fetches the first byte of data from mbuf
+			 * then compares whether its v4 or v6. If first byte
+			 * is 4 or 6, then protocol field is updated.
+			 */
+			char *buff_data = rte_pktmbuf_mtod(seg, void *);
+			j = (*buff_data & 0xf0);
+			pi.proto = (j == 0x40) ? 0x0008 :
 				(j == 0x60) ? 0xdd86 : 0x00;
+		}
 
 		iovecs[0].iov_base = &pi;
 		iovecs[0].iov_len = sizeof(pi);
@@ -928,6 +930,9 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 	struct ifreq ifr;
 	int ret;
 
+	if (pmd->type == ETH_TUNTAP_TYPE_TUN)
+		return -ENOTSUP;
+
 	if (is_zero_ether_addr(mac_addr)) {
 		TAP_LOG(ERR, "%s: can't set an empty MAC address",
 			dev->device->name);
@@ -1025,6 +1030,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
 	tx->mtu = &dev->data->mtu;
 	rx->rxmode = &dev->data->dev_conf.rxmode;
 
+	tx->type = pmd->type;
+
 	return *fd;
 }
 
@@ -1342,7 +1349,8 @@ static const struct eth_dev_ops ops = {
 
 static int
 eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
-		   char *remote_iface, struct ether_addr *mac_addr)
+		   char *remote_iface, struct ether_addr *mac_addr,
+		   enum rte_tuntap_type type)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev;
@@ -1364,6 +1372,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	pmd = dev->data->dev_private;
 	pmd->dev = dev;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+	pmd->type = type;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (pmd->ioctl_sock == -1) {
@@ -1400,7 +1409,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		pmd->txq[i].fd = -1;
 	}
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (is_zero_ether_addr(mac_addr))
 			eth_random_addr((uint8_t *)&pmd->eth_addr);
 		else
@@ -1423,7 +1432,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
 		goto error_exit;
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		memset(&ifr, 0, sizeof(struct ifreq));
 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
@@ -1642,7 +1651,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	char tun_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
 
-	tap_type = 0;
 	strcpy(tuntap_name, "TUN");
 
 	name = rte_vdev_device_name(dev);
@@ -1673,7 +1681,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s",
 		name, tun_name);
 
-	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0);
+	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
+		ETH_TUNTAP_TYPE_TUN);
 
 leave:
 	if (ret == -1) {
@@ -1700,7 +1709,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	struct ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 
-	tap_type = 1;
 	strcpy(tuntap_name, "TAP");
 
 	name = rte_vdev_device_name(dev);
@@ -1762,7 +1770,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac);
+	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,
+		ETH_TUNTAP_TYPE_TAP);
 
 leave:
 	if (ret == -1) {
@@ -1784,15 +1793,17 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	struct pmd_internals *internals;
 	int i;
 
-	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
-		rte_socket_id());
-
 	/* find the ethdev entry */
 	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
 	internals = eth_dev->data->dev_private;
+
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
+		rte_socket_id());
+
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index c87a0b8..7b21d0d 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -23,6 +23,13 @@
 #define RTE_PMD_TAP_MAX_QUEUES	1
 #endif
 
+enum rte_tuntap_type {
+	ETH_TUNTAP_TYPE_UNKNOWN,
+	ETH_TUNTAP_TYPE_TUN,
+	ETH_TUNTAP_TYPE_TAP,
+	ETH_TUNTAP_TYPE_MAX,
+};
+
 struct pkt_stats {
 	uint64_t opackets;              /* Number of output packets */
 	uint64_t ipackets;              /* Number of input packets */
@@ -48,6 +55,7 @@ struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	int type;                       /* Type field - TUN|TAP */
 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	uint16_t csum:1;                /* Enable checksum offloading */
 	struct pkt_stats stats;         /* Stats for this TX queue */
@@ -57,6 +65,7 @@ struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	int type;                         /* Type field - TUN|TAP */
 	struct ether_addr eth_addr;       /* Mac address of the device port */
 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only
  2018-05-22  6:33     ` Varghese, Vipin
@ 2018-05-22 11:05       ` Varghese, Vipin
  2018-05-22 13:55         ` Wiles, Keith
  0 siblings, 1 reply; 23+ messages in thread
From: Varghese, Vipin @ 2018-05-22 11:05 UTC (permalink / raw)
  To: 'Ophir Munk', 'dev@dpdk.org',
	Wiles, Keith, Yigit, Ferruh
  Cc: 'Thomas Monjalon', 'Olga Shern'

Hi Ophir, Keith and Ferruh,

I have shared v3 with all the suggested changes. 

Thanks
Vipin Varghese

> -----Original Message-----
> From: Varghese, Vipin
> Sent: Tuesday, May 22, 2018 12:04 PM
> To: Ophir Munk <ophirmu@mellanox.com>; dev@dpdk.org; Wiles, Keith
> <keith.wiles@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
> <olgas@mellanox.com>
> Subject: RE: [PATCH v2] net/tap: perform proto field update for tun only
> 
> Hi Ophir,
> 
> Thanks for the suggestion, once these are merged to dpdk or dpdk-net mainline,
> I can start the modifications.
> 
> Thanks
> Vipin Varghese
> 
> > -----Original Message-----
> > From: Ophir Munk [mailto:ophirmu@mellanox.com]
> > Sent: Wednesday, May 16, 2018 3:59 AM
> > To: Varghese, Vipin <vipin.varghese@intel.com>; dev@dpdk.org; Wiles,
> > Keith <keith.wiles@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
> > Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
> > <olgas@mellanox.com>
> > Subject: RE: [PATCH v2] net/tap: perform proto field update for tun
> > only
> >
> > Hi,
> > I am adding my review although this patch has already been acked.
> > Please find some comments inline. Otherwise it looks OK.
> >
> > Regards,
> > Ophir
> >
> > > -----Original Message-----
> > > From: Vipin Varghese [mailto:vipin.varghese@intel.com]
> > > Sent: Tuesday, May 15, 2018 5:50 PM
> > > To: dev@dpdk.org; keith.wiles@intel.com; ferruh.yigit@intel.com;
> > > Ophir Munk <ophirmu@mellanox.com>
> > > Cc: Vipin Varghese <vipin.varghese@intel.com>
> > > Subject: [PATCH v2] net/tap: perform proto field update for tun only
> > >
> > > The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> > > type field will ensure the TAP PMD will always have protocol field as 0.
> > >
> > > Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> > > Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > > ---
> > >
> > > Changes in V2:
> > > updated in comment wording - Keith Wiles remove debug print from tx
> > > code
> > > - Keith Wiles
> > > ---
> > >  drivers/net/tap/rte_eth_tap.c | 48
> > > ++++++++++++++++++++++++++-----------
> > > ------
> > >  drivers/net/tap/rte_eth_tap.h | 10 +++++++++
> > >  2 files changed, 39 insertions(+), 19 deletions(-)
> > >
> > > diff --git a/drivers/net/tap/rte_eth_tap.c
> > > b/drivers/net/tap/rte_eth_tap.c index ea6d899..fafd557 100644
> > > --- a/drivers/net/tap/rte_eth_tap.c
> > > +++ b/drivers/net/tap/rte_eth_tap.c
> > > @@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
> > >  	 * Do not set IFF_NO_PI as packet information header will be needed
> > >  	 * to check if a received packet has been truncated.
> > >  	 */
> > > -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> > > +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> > > +			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> > >  	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
> > >
> > >  	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); @@ -502,20
> > > +503,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs,
> > > +uint16_t
> > > nb_pkts)
> > >  		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
> > >  			break;
> > >
> > > -		/*
> > > -		 * TUN and TAP are created with IFF_NO_PI disabled.
> > > -		 * For TUN PMD this mandatory as fields are used by
> > > -		 * Kernel tun.c to determine whether its IP or non IP
> > > -		 * packets.
> > > -		 *
> > > -		 * The logic fetches the first byte of data from mbuf.
> > > -		 * compares whether its v4 or v6. If none matches default
> > > -		 * value 0x00 is taken for protocol field.
> > > -		 */
> > > -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
> > > -		j = (*buff_data & 0xf0);
> > > -		pi.proto = (j == 0x40) ? 0x0008 :
> > > -				(j == 0x60) ? 0xdd86 : 0x00;
> > > +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
> > > +			/*
> > > +			 * TUN and TAP are created with IFF_NO_PI disabled.
> > > +			 * For TUN PMD this mandatory as fields are used by
> > > +			 * Kernel tun.c to determine whether its IP or non IP
> > > +			 * packets.
> > > +			 *
> > > +			 * The logic fetches the first byte of data from mbuf
> > > +			 * then compares whether its v4 or v6. If first byte
> > > +			 * is 4 or 6, then protocol field is updated.
> > > +			 */
> > > +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> > > +			j = (*buff_data & 0xf0);
> > > +			pi.proto = (j == 0x40) ? 0x0008 :
> > > +					(j == 0x60) ? 0xdd86 : 0x00;
> > > +		}
> > >
> > >  		iovecs[0].iov_base = &pi;
> > >  		iovecs[0].iov_len = sizeof(pi);
> > > @@ -1052,6 +1055,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
> > >  	tx->mtu = &dev->data->mtu;
> > >  	rx->rxmode = &dev->data->dev_conf.rxmode;
> > >
> > > +	tx->type = pmd->type;
> > > +	rx->type = pmd->type;
> >
> > It seems there is no usage for rx->type in TAP code. Therefore - can
> > you please remove rx->type assignment?
> > > +
> > >  	return *fd;
> > >  }
> > >
> > > @@ -1386,6 +1392,7 @@ eth_dev_tap_create(struct rte_vdev_device
> > > *vdev, char *tap_name,
> > >  	pmd = dev->data->dev_private;
> > >  	pmd->dev = dev;
> > >  	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
> > > +	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
> > >
> > >  	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
> > >  	if (pmd->ioctl_sock == -1) {
> > > @@ -1421,7 +1428,9 @@ eth_dev_tap_create(struct rte_vdev_device
> > > *vdev, char *tap_name,
> > >  		pmd->txq[i].fd = -1;
> > >  	}
> > >
> > > -	if (tap_type) {
> > > +	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP :
> > > ETH_TUNTAP_TYPE_TUN;
> >
> > 1. It seem you are using 'tap_type' as a global static variable to
> > pass a value to eth_dev_tap_create().
> > Can you please pass this value by adding a parameter to
> > eth_dev_tap_create() call and remove the global static variable?
> > 2. You are using tap_type with values 0 and 1 which are converted to
> > enums ETH_TUNTAP_TYPE_TUN and ETH_TUNTAP_TYPE_TAP respectively.
> Can
> > you please always just use the enums (avoiding the conversion)?
> >
> > > +
> > > +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> > >  		if (is_zero_ether_addr(mac_addr))
> > >  			eth_random_addr((uint8_t *)&pmd->eth_addr);
> > >  		else
> > > @@ -1440,7 +1449,7 @@ eth_dev_tap_create(struct rte_vdev_device
> > > *vdev, char *tap_name,
> > >  	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
> > >  		goto error_exit;
> > >
> > > -	if (tap_type) {
> > > +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> > >  		memset(&ifr, 0, sizeof(struct ifreq));
> > >  		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
> > >  		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, @@ -
> > > 1812,7 +1821,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
> > >  	struct pmd_internals *internals;
> > >  	int i;
> > >
> > > -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
> > > +	internals = eth_dev->data->dev_private;
> > > +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
> > > +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" :
> > > "TUN",
> > >  		rte_socket_id());
> > >
> > >  	/* find the ethdev entry */
> > > @@ -1820,7 +1831,6 @@ rte_pmd_tap_remove(struct rte_vdev_device
> > > *dev)
> > >  	if (!eth_dev)
> > >  		return 0;
> > >
> > > -	internals = eth_dev->data->dev_private;
> > >  	if (internals->nlsk_fd) {
> > >  		tap_flow_flush(eth_dev, NULL);
> > >  		tap_flow_implicit_flush(internals, NULL); diff --git
> > > a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
> > > index 67c9d4b..8b0da5a 100644
> > > --- a/drivers/net/tap/rte_eth_tap.h
> > > +++ b/drivers/net/tap/rte_eth_tap.h
> > > @@ -23,6 +23,13 @@
> > >  #define RTE_PMD_TAP_MAX_QUEUES	1
> > >  #endif
> > >
> > > +enum rte_tuntap_type {
> > > +	ETH_TUNTAP_TYPE_UNKNOWN,
> > > +	ETH_TUNTAP_TYPE_TUN,
> > > +	ETH_TUNTAP_TYPE_TAP,
> > > +	ETH_TUNTAP_TYPE_MAX,
> > > +};
> > > +
> > >  struct pkt_stats {
> > >  	uint64_t opackets;              /* Number of output packets */
> > >  	uint64_t ipackets;              /* Number of input packets */
> > > @@ -38,6 +45,7 @@ struct rx_queue {
> > >  	uint32_t trigger_seen;          /* Last seen Rx trigger value */
> > >  	uint16_t in_port;               /* Port ID */
> > >  	int fd;
> > > +	int type;			  /* Type field - TUN|TAP */
> >
> > In seems there is no usage for 'type' field from rx_queue struct in
> > the code. If so
> > - can you please remove it?
> >
> > >  	struct pkt_stats stats;         /* Stats for this RX queue */
> > >  	uint16_t nb_rx_desc;            /* max number of mbufs available */
> > >  	struct rte_eth_rxmode *rxmode;  /* RX features */ @@ -48,6 +56,7
> > @@
> > > struct rx_queue {
> > >
> > >  struct tx_queue {
> > >  	int fd;
> > > +	int type;			  /* Type field - TUN|TAP */
> >
> > Please use spaces (like all other fields in this struct) instead of
> > tabs, so all fields look aligned.
> >
> > >  	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
> > >  	uint16_t csum:1;                /* Enable checksum offloading */
> > >  	struct pkt_stats stats;         /* Stats for this TX queue */
> > > @@ -57,6 +66,7 @@ struct pmd_internals {
> > >  	struct rte_eth_dev *dev;          /* Ethernet device. */
> > >  	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice
> > name */
> > >  	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
> > > +	int type;			  /* Type field - TUN|TAP */
> >
> > Same comment here about replacing tabs with spaces
> >
> > >  	struct ether_addr eth_addr;       /* Mac address of the device port */
> > >  	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init
> > > */
> > >  	int remote_if_index;              /* remote netdevice IF_INDEX */
> > > --
> > > 2.7.4

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

* Re: [dpdk-dev] [PATCH v3] net/tap: perform proto field update for tun only
  2018-05-22 10:47   ` [dpdk-dev] [PATCH v3] " Vipin Varghese
@ 2018-05-22 13:53     ` Wiles, Keith
  2018-05-23  4:33       ` Varghese, Vipin
  2018-05-22 15:04     ` Ophir Munk
  2018-05-22 22:04     ` [dpdk-dev] [PATCH v4] " Ferruh Yigit
  2 siblings, 1 reply; 23+ messages in thread
From: Wiles, Keith @ 2018-05-22 13:53 UTC (permalink / raw)
  To: Varghese, Vipin; +Cc: dev, Yigit, Ferruh, ophirmu, thomas, olgas



> On May 22, 2018, at 5:47 AM, Varghese, Vipin <vipin.varghese@intel.com> wrote:
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field
> as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> Changes in V3:
> - remove type field from rx struct - Ophir Munk
> - add space for comment in struct - Ophir Munk
> - pass type field into eth_dev_tap_create - Ophir Munk
> - replace with enum value for type - Ophir Munk
> - return as 'not supported' for mac_set - Vipin Varghese
> 
> Changes in V2:
> - updated in comment wording - Keith Wiles
> - remove debug print from tx code - Keith Wiles
> —

Sorry, I did not catch the problem below before :-(

> drivers/net/tap/rte_eth_tap.c | 61 +++++++++++++++++++++++++------------------
> drivers/net/tap/rte_eth_tap.h |  9 +++++++
> 2 files changed, 45 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 01552fa..8d8f67b 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -68,7 +68,6 @@ static const char *valid_arguments[] = {
> static int tap_unit;
> static unsigned int tun_unit;
> 
> -static int tap_type;
> static char tuntap_name[8];
> 
> static volatile uint32_t tap_trigger;	/* Rx trigger */
> @@ -116,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
> 	 * Do not set IFF_NO_PI as packet information header will be needed
> 	 * to check if a received packet has been truncated.
> 	 */
> -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> +		IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
> 
> 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
> @@ -472,20 +472,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
> 			break;
> 
> -		/*
> -		 * TUN and TAP are created with IFF_NO_PI disabled.
> -		 * For TUN PMD this mandatory as fields are used by
> -		 * Kernel tun.c to determine whether its IP or non IP
> -		 * packets.
> -		 *
> -		 * The logic fetches the first byte of data from mbuf.
> -		 * compares whether its v4 or v6. If none matches default
> -		 * value 0x00 is taken for protocol field.
> -		 */
> -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
> -		j = (*buff_data & 0xf0);
> -		pi.proto = (j == 0x40) ? 0x0008 :
> +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
> +			/*
> +			 * TUN and TAP are created with IFF_NO_PI disabled.
> +			 * For TUN PMD this mandatory as fields are used by
> +			 * Kernel tun.c to determine whether its IP or non IP
> +			 * packets.
> +			 *
> +			 * The logic fetches the first byte of data from mbuf
> +			 * then compares whether its v4 or v6. If first byte
> +			 * is 4 or 6, then protocol field is updated.
> +			 */
> +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> +			j = (*buff_data & 0xf0);
> +			pi.proto = (j == 0x40) ? 0x0008 :
> 				(j == 0x60) ? 0xdd86 : 0x00;

Warning Will Robinson: Magic numbers :-)

Can we use the correct values here ETHERTYPE_IPV6 and ETHERTYPE_IP and then use htons() on the values please.

> +		}
> 
> 		iovecs[0].iov_base = &pi;
> 		iovecs[0].iov_len = sizeof(pi);
> @@ -928,6 +930,9 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
> 	struct ifreq ifr;
> 	int ret;
> 
> +	if (pmd->type == ETH_TUNTAP_TYPE_TUN)
> +		return -ENOTSUP;
> +
> 	if (is_zero_ether_addr(mac_addr)) {
> 		TAP_LOG(ERR, "%s: can't set an empty MAC address",
> 			dev->device->name);
> @@ -1025,6 +1030,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
> 	tx->mtu = &dev->data->mtu;
> 	rx->rxmode = &dev->data->dev_conf.rxmode;
> 
> +	tx->type = pmd->type;
> +
> 	return *fd;
> }
> 
> @@ -1342,7 +1349,8 @@ static const struct eth_dev_ops ops = {
> 
> static int
> eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> -		   char *remote_iface, struct ether_addr *mac_addr)
> +		   char *remote_iface, struct ether_addr *mac_addr,
> +		   enum rte_tuntap_type type)
> {
> 	int numa_node = rte_socket_id();
> 	struct rte_eth_dev *dev;
> @@ -1364,6 +1372,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> 	pmd = dev->data->dev_private;
> 	pmd->dev = dev;
> 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
> +	pmd->type = type;
> 
> 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
> 	if (pmd->ioctl_sock == -1) {
> @@ -1400,7 +1409,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> 		pmd->txq[i].fd = -1;
> 	}
> 
> -	if (tap_type) {
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> 		if (is_zero_ether_addr(mac_addr))
> 			eth_random_addr((uint8_t *)&pmd->eth_addr);
> 		else
> @@ -1423,7 +1432,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
> 		goto error_exit;
> 
> -	if (tap_type) {
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
> 		memset(&ifr, 0, sizeof(struct ifreq));
> 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
> 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
> @@ -1642,7 +1651,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
> 	char tun_name[RTE_ETH_NAME_MAX_LEN];
> 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
> 
> -	tap_type = 0;
> 	strcpy(tuntap_name, "TUN");
> 
> 	name = rte_vdev_device_name(dev);
> @@ -1673,7 +1681,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
> 	TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s",
> 		name, tun_name);
> 
> -	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0);
> +	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
> +		ETH_TUNTAP_TYPE_TUN);
> 
> leave:
> 	if (ret == -1) {
> @@ -1700,7 +1709,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
> 	struct ether_addr user_mac = { .addr_bytes = {0} };
> 	struct rte_eth_dev *eth_dev;
> 
> -	tap_type = 1;
> 	strcpy(tuntap_name, "TAP");
> 
> 	name = rte_vdev_device_name(dev);
> @@ -1762,7 +1770,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
> 	TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s",
> 		name, tap_name);
> 
> -	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac);
> +	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,
> +		ETH_TUNTAP_TYPE_TAP);
> 
> leave:
> 	if (ret == -1) {
> @@ -1784,15 +1793,17 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
> 	struct pmd_internals *internals;
> 	int i;
> 
> -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
> -		rte_socket_id());
> -
> 	/* find the ethdev entry */
> 	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
> 	if (!eth_dev)
> 		return 0;
> 
> 	internals = eth_dev->data->dev_private;
> +
> +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
> +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
> +		rte_socket_id());
> +
> 	if (internals->nlsk_fd) {
> 		tap_flow_flush(eth_dev, NULL);
> 		tap_flow_implicit_flush(internals, NULL);
> diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
> index c87a0b8..7b21d0d 100644
> --- a/drivers/net/tap/rte_eth_tap.h
> +++ b/drivers/net/tap/rte_eth_tap.h
> @@ -23,6 +23,13 @@
> #define RTE_PMD_TAP_MAX_QUEUES	1
> #endif
> 
> +enum rte_tuntap_type {
> +	ETH_TUNTAP_TYPE_UNKNOWN,
> +	ETH_TUNTAP_TYPE_TUN,
> +	ETH_TUNTAP_TYPE_TAP,
> +	ETH_TUNTAP_TYPE_MAX,
> +};
> +
> struct pkt_stats {
> 	uint64_t opackets;              /* Number of output packets */
> 	uint64_t ipackets;              /* Number of input packets */
> @@ -48,6 +55,7 @@ struct rx_queue {
> 
> struct tx_queue {
> 	int fd;
> +	int type;                       /* Type field - TUN|TAP */
> 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
> 	uint16_t csum:1;                /* Enable checksum offloading */
> 	struct pkt_stats stats;         /* Stats for this TX queue */
> @@ -57,6 +65,7 @@ struct pmd_internals {
> 	struct rte_eth_dev *dev;          /* Ethernet device. */
> 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
> 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
> +	int type;                         /* Type field - TUN|TAP */
> 	struct ether_addr eth_addr;       /* Mac address of the device port */
> 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
> 	int remote_if_index;              /* remote netdevice IF_INDEX */
> -- 
> 2.7.4
> 

Regards,
Keith


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

* Re: [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only
  2018-05-22 11:05       ` Varghese, Vipin
@ 2018-05-22 13:55         ` Wiles, Keith
  0 siblings, 0 replies; 23+ messages in thread
From: Wiles, Keith @ 2018-05-22 13:55 UTC (permalink / raw)
  To: Varghese, Vipin
  Cc: Ophir Munk, dev, Yigit,  Ferruh, Thomas Monjalon, Olga Shern



> On May 22, 2018, at 6:05 AM, Varghese, Vipin <vipin.varghese@intel.com> wrote:
> 
> Hi Ophir, Keith and Ferruh,
> 
> I have shared v3 with all the suggested changes. 

I just sent another change, sorry I did not catch if before, which I obviously was not paying attention.

> 
> Thanks
> Vipin Varghese
> 
>> -----Original Message-----
>> From: Varghese, Vipin
>> Sent: Tuesday, May 22, 2018 12:04 PM
>> To: Ophir Munk <ophirmu@mellanox.com>; dev@dpdk.org; Wiles, Keith
>> <keith.wiles@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
>> Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
>> <olgas@mellanox.com>
>> Subject: RE: [PATCH v2] net/tap: perform proto field update for tun only
>> 
>> Hi Ophir,
>> 
>> Thanks for the suggestion, once these are merged to dpdk or dpdk-net mainline,
>> I can start the modifications.
>> 
>> Thanks
>> Vipin Varghese
>> 
>>> -----Original Message-----
>>> From: Ophir Munk [mailto:ophirmu@mellanox.com]
>>> Sent: Wednesday, May 16, 2018 3:59 AM
>>> To: Varghese, Vipin <vipin.varghese@intel.com>; dev@dpdk.org; Wiles,
>>> Keith <keith.wiles@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
>>> Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
>>> <olgas@mellanox.com>
>>> Subject: RE: [PATCH v2] net/tap: perform proto field update for tun
>>> only
>>> 
>>> Hi,
>>> I am adding my review although this patch has already been acked.
>>> Please find some comments inline. Otherwise it looks OK.
>>> 
>>> Regards,
>>> Ophir
>>> 
>>>> -----Original Message-----
>>>> From: Vipin Varghese [mailto:vipin.varghese@intel.com]
>>>> Sent: Tuesday, May 15, 2018 5:50 PM
>>>> To: dev@dpdk.org; keith.wiles@intel.com; ferruh.yigit@intel.com;
>>>> Ophir Munk <ophirmu@mellanox.com>
>>>> Cc: Vipin Varghese <vipin.varghese@intel.com>
>>>> Subject: [PATCH v2] net/tap: perform proto field update for tun only
>>>> 
>>>> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
>>>> type field will ensure the TAP PMD will always have protocol field as 0.
>>>> 
>>>> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
>>>> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>>> ---
>>>> 
>>>> Changes in V2:
>>>> updated in comment wording - Keith Wiles remove debug print from tx
>>>> code
>>>> - Keith Wiles
>>>> ---
>>>> drivers/net/tap/rte_eth_tap.c | 48
>>>> ++++++++++++++++++++++++++-----------
>>>> ------
>>>> drivers/net/tap/rte_eth_tap.h | 10 +++++++++
>>>> 2 files changed, 39 insertions(+), 19 deletions(-)
>>>> 
>>>> diff --git a/drivers/net/tap/rte_eth_tap.c
>>>> b/drivers/net/tap/rte_eth_tap.c index ea6d899..fafd557 100644
>>>> --- a/drivers/net/tap/rte_eth_tap.c
>>>> +++ b/drivers/net/tap/rte_eth_tap.c
>>>> @@ -115,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
>>>> 	 * Do not set IFF_NO_PI as packet information header will be needed
>>>> 	 * to check if a received packet has been truncated.
>>>> 	 */
>>>> -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
>>>> +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
>>>> +			IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
>>>> 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
>>>> 
>>>> 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); @@ -502,20
>>>> +503,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs,
>>>> +uint16_t
>>>> nb_pkts)
>>>> 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
>>>> 			break;
>>>> 
>>>> -		/*
>>>> -		 * TUN and TAP are created with IFF_NO_PI disabled.
>>>> -		 * For TUN PMD this mandatory as fields are used by
>>>> -		 * Kernel tun.c to determine whether its IP or non IP
>>>> -		 * packets.
>>>> -		 *
>>>> -		 * The logic fetches the first byte of data from mbuf.
>>>> -		 * compares whether its v4 or v6. If none matches default
>>>> -		 * value 0x00 is taken for protocol field.
>>>> -		 */
>>>> -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
>>>> -		j = (*buff_data & 0xf0);
>>>> -		pi.proto = (j == 0x40) ? 0x0008 :
>>>> -				(j == 0x60) ? 0xdd86 : 0x00;
>>>> +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
>>>> +			/*
>>>> +			 * TUN and TAP are created with IFF_NO_PI disabled.
>>>> +			 * For TUN PMD this mandatory as fields are used by
>>>> +			 * Kernel tun.c to determine whether its IP or non IP
>>>> +			 * packets.
>>>> +			 *
>>>> +			 * The logic fetches the first byte of data from mbuf
>>>> +			 * then compares whether its v4 or v6. If first byte
>>>> +			 * is 4 or 6, then protocol field is updated.
>>>> +			 */
>>>> +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
>>>> +			j = (*buff_data & 0xf0);
>>>> +			pi.proto = (j == 0x40) ? 0x0008 :
>>>> +					(j == 0x60) ? 0xdd86 : 0x00;
>>>> +		}
>>>> 
>>>> 		iovecs[0].iov_base = &pi;
>>>> 		iovecs[0].iov_len = sizeof(pi);
>>>> @@ -1052,6 +1055,9 @@ tap_setup_queue(struct rte_eth_dev *dev,
>>>> 	tx->mtu = &dev->data->mtu;
>>>> 	rx->rxmode = &dev->data->dev_conf.rxmode;
>>>> 
>>>> +	tx->type = pmd->type;
>>>> +	rx->type = pmd->type;
>>> 
>>> It seems there is no usage for rx->type in TAP code. Therefore - can
>>> you please remove rx->type assignment?
>>>> +
>>>> 	return *fd;
>>>> }
>>>> 
>>>> @@ -1386,6 +1392,7 @@ eth_dev_tap_create(struct rte_vdev_device
>>>> *vdev, char *tap_name,
>>>> 	pmd = dev->data->dev_private;
>>>> 	pmd->dev = dev;
>>>> 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
>>>> +	pmd->type = ETH_TUNTAP_TYPE_UNKNOWN;
>>>> 
>>>> 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
>>>> 	if (pmd->ioctl_sock == -1) {
>>>> @@ -1421,7 +1428,9 @@ eth_dev_tap_create(struct rte_vdev_device
>>>> *vdev, char *tap_name,
>>>> 		pmd->txq[i].fd = -1;
>>>> 	}
>>>> 
>>>> -	if (tap_type) {
>>>> +	pmd->type = (tap_type) ? ETH_TUNTAP_TYPE_TAP :
>>>> ETH_TUNTAP_TYPE_TUN;
>>> 
>>> 1. It seem you are using 'tap_type' as a global static variable to
>>> pass a value to eth_dev_tap_create().
>>> Can you please pass this value by adding a parameter to
>>> eth_dev_tap_create() call and remove the global static variable?
>>> 2. You are using tap_type with values 0 and 1 which are converted to
>>> enums ETH_TUNTAP_TYPE_TUN and ETH_TUNTAP_TYPE_TAP respectively.
>> Can
>>> you please always just use the enums (avoiding the conversion)?
>>> 
>>>> +
>>>> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
>>>> 		if (is_zero_ether_addr(mac_addr))
>>>> 			eth_random_addr((uint8_t *)&pmd->eth_addr);
>>>> 		else
>>>> @@ -1440,7 +1449,7 @@ eth_dev_tap_create(struct rte_vdev_device
>>>> *vdev, char *tap_name,
>>>> 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
>>>> 		goto error_exit;
>>>> 
>>>> -	if (tap_type) {
>>>> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
>>>> 		memset(&ifr, 0, sizeof(struct ifreq));
>>>> 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
>>>> 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, @@ -
>>>> 1812,7 +1821,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
>>>> 	struct pmd_internals *internals;
>>>> 	int i;
>>>> 
>>>> -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
>>>> +	internals = eth_dev->data->dev_private;
>>>> +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
>>>> +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" :
>>>> "TUN",
>>>> 		rte_socket_id());
>>>> 
>>>> 	/* find the ethdev entry */
>>>> @@ -1820,7 +1831,6 @@ rte_pmd_tap_remove(struct rte_vdev_device
>>>> *dev)
>>>> 	if (!eth_dev)
>>>> 		return 0;
>>>> 
>>>> -	internals = eth_dev->data->dev_private;
>>>> 	if (internals->nlsk_fd) {
>>>> 		tap_flow_flush(eth_dev, NULL);
>>>> 		tap_flow_implicit_flush(internals, NULL); diff --git
>>>> a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
>>>> index 67c9d4b..8b0da5a 100644
>>>> --- a/drivers/net/tap/rte_eth_tap.h
>>>> +++ b/drivers/net/tap/rte_eth_tap.h
>>>> @@ -23,6 +23,13 @@
>>>> #define RTE_PMD_TAP_MAX_QUEUES	1
>>>> #endif
>>>> 
>>>> +enum rte_tuntap_type {
>>>> +	ETH_TUNTAP_TYPE_UNKNOWN,
>>>> +	ETH_TUNTAP_TYPE_TUN,
>>>> +	ETH_TUNTAP_TYPE_TAP,
>>>> +	ETH_TUNTAP_TYPE_MAX,
>>>> +};
>>>> +
>>>> struct pkt_stats {
>>>> 	uint64_t opackets;              /* Number of output packets */
>>>> 	uint64_t ipackets;              /* Number of input packets */
>>>> @@ -38,6 +45,7 @@ struct rx_queue {
>>>> 	uint32_t trigger_seen;          /* Last seen Rx trigger value */
>>>> 	uint16_t in_port;               /* Port ID */
>>>> 	int fd;
>>>> +	int type;			  /* Type field - TUN|TAP */
>>> 
>>> In seems there is no usage for 'type' field from rx_queue struct in
>>> the code. If so
>>> - can you please remove it?
>>> 
>>>> 	struct pkt_stats stats;         /* Stats for this RX queue */
>>>> 	uint16_t nb_rx_desc;            /* max number of mbufs available */
>>>> 	struct rte_eth_rxmode *rxmode;  /* RX features */ @@ -48,6 +56,7
>>> @@
>>>> struct rx_queue {
>>>> 
>>>> struct tx_queue {
>>>> 	int fd;
>>>> +	int type;			  /* Type field - TUN|TAP */
>>> 
>>> Please use spaces (like all other fields in this struct) instead of
>>> tabs, so all fields look aligned.
>>> 
>>>> 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
>>>> 	uint16_t csum:1;                /* Enable checksum offloading */
>>>> 	struct pkt_stats stats;         /* Stats for this TX queue */
>>>> @@ -57,6 +66,7 @@ struct pmd_internals {
>>>> 	struct rte_eth_dev *dev;          /* Ethernet device. */
>>>> 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice
>>> name */
>>>> 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
>>>> +	int type;			  /* Type field - TUN|TAP */
>>> 
>>> Same comment here about replacing tabs with spaces
>>> 
>>>> 	struct ether_addr eth_addr;       /* Mac address of the device port */
>>>> 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init
>>>> */
>>>> 	int remote_if_index;              /* remote netdevice IF_INDEX */
>>>> --
>>>> 2.7.4
> 

Regards,
Keith

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

* Re: [dpdk-dev] [PATCH v3] net/tap: perform proto field update for tun only
  2018-05-22 10:47   ` [dpdk-dev] [PATCH v3] " Vipin Varghese
  2018-05-22 13:53     ` Wiles, Keith
@ 2018-05-22 15:04     ` Ophir Munk
  2018-05-23  4:37       ` Varghese, Vipin
  2018-05-22 22:04     ` [dpdk-dev] [PATCH v4] " Ferruh Yigit
  2 siblings, 1 reply; 23+ messages in thread
From: Ophir Munk @ 2018-05-22 15:04 UTC (permalink / raw)
  To: Vipin Varghese, dev, ferruh.yigit, keith.wiles
  Cc: Thomas Monjalon, Olga Shern

Hi,
Overall it looks good.
Please note a few more comments below.

> -----Original Message-----
> From: Vipin Varghese [mailto:vipin.varghese@intel.com]
> Sent: Tuesday, May 22, 2018 1:47 PM
> To: dev@dpdk.org; ferruh.yigit@intel.com; keith.wiles@intel.com; Ophir
> Munk <ophirmu@mellanox.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
> <olgas@mellanox.com>; Vipin Varghese <vipin.varghese@intel.com>
> Subject: [PATCH v3] net/tap: perform proto field update for tun only
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---

Shouldn't it be a fix commit?
If so - please update the commit title, add Fixes: ... , Cc: stable@dpdk.org...

> Changes in V3:
> - remove type field from rx struct - Ophir Munk
> - add space for comment in struct - Ophir Munk
> - pass type field into eth_dev_tap_create - Ophir Munk
> - replace with enum value for type - Ophir Munk
> - return as 'not supported' for mac_set - Vipin Varghese
> 
> Changes in V2:
> - updated in comment wording - Keith Wiles
> - remove debug print from tx code - Keith Wiles
> ---
>  drivers/net/tap/rte_eth_tap.c | 61 +++++++++++++++++++++++++-------------
> -----
>  drivers/net/tap/rte_eth_tap.h |  9 +++++++
>  2 files changed, 45 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 01552fa..8d8f67b 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -68,7 +68,6 @@ static const char *valid_arguments[] = {  static int
> tap_unit;  static unsigned int tun_unit;
> 
> -static int tap_type;
>  static char tuntap_name[8];
> 
>  static volatile uint32_t tap_trigger;	/* Rx trigger */
> @@ -116,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
>  	 * Do not set IFF_NO_PI as packet information header will be needed
>  	 * to check if a received packet has been truncated.
>  	 */
> -	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> +	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> +		IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
>  	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
> 
>  	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); @@ -472,20
> +472,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t
> nb_pkts)
>  		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
>  			break;
> 
> -		/*
> -		 * TUN and TAP are created with IFF_NO_PI disabled.
> -		 * For TUN PMD this mandatory as fields are used by
> -		 * Kernel tun.c to determine whether its IP or non IP
> -		 * packets.
> -		 *
> -		 * The logic fetches the first byte of data from mbuf.
> -		 * compares whether its v4 or v6. If none matches default
> -		 * value 0x00 is taken for protocol field.
> -		 */
> -		char *buff_data = rte_pktmbuf_mtod(seg, void *);
> -		j = (*buff_data & 0xf0);
> -		pi.proto = (j == 0x40) ? 0x0008 :
> +		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
> +			/*
> +			 * TUN and TAP are created with IFF_NO_PI disabled.
> +			 * For TUN PMD this mandatory as fields are used by
> +			 * Kernel tun.c to determine whether its IP or non IP
> +			 * packets.
> +			 *
> +			 * The logic fetches the first byte of data from mbuf
> +			 * then compares whether its v4 or v6. If first byte
> +			 * is 4 or 6, then protocol field is updated.
> +			 */
> +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> +			j = (*buff_data & 0xf0);
> +			pi.proto = (j == 0x40) ? 0x0008 :
>  				(j == 0x60) ? 0xdd86 : 0x00;
> +		}
> 
>  		iovecs[0].iov_base = &pi;
>  		iovecs[0].iov_len = sizeof(pi);
> @@ -928,6 +930,9 @@ tap_mac_set(struct rte_eth_dev *dev, struct
> ether_addr *mac_addr)
>  	struct ifreq ifr;
>  	int ret;
> 
> +	if (pmd->type == ETH_TUNTAP_TYPE_TUN)
> +		return -ENOTSUP;


Can you please add a TAP_LOG(ERR, ...) to log this error similar to other error cases in this function?

> +
>  	if (is_zero_ether_addr(mac_addr)) {
>  		TAP_LOG(ERR, "%s: can't set an empty MAC address",
>  			dev->device->name);
> @@ -1025,6 +1030,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
>  	tx->mtu = &dev->data->mtu;
>  	rx->rxmode = &dev->data->dev_conf.rxmode;
> 
> +	tx->type = pmd->type;
> +
>  	return *fd;
>  }
> 
> @@ -1342,7 +1349,8 @@ static const struct eth_dev_ops ops = {
> 
>  static int
>  eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> -		   char *remote_iface, struct ether_addr *mac_addr)
> +		   char *remote_iface, struct ether_addr *mac_addr,
> +		   enum rte_tuntap_type type)
>  {
>  	int numa_node = rte_socket_id();
>  	struct rte_eth_dev *dev;
> @@ -1364,6 +1372,7 @@ eth_dev_tap_create(struct rte_vdev_device
> *vdev, char *tap_name,
>  	pmd = dev->data->dev_private;
>  	pmd->dev = dev;
>  	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
> +	pmd->type = type;
> 
>  	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
>  	if (pmd->ioctl_sock == -1) {
> @@ -1400,7 +1409,7 @@ eth_dev_tap_create(struct rte_vdev_device
> *vdev, char *tap_name,
>  		pmd->txq[i].fd = -1;
>  	}
> 
> -	if (tap_type) {
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
>  		if (is_zero_ether_addr(mac_addr))
>  			eth_random_addr((uint8_t *)&pmd->eth_addr);
>  		else
> @@ -1423,7 +1432,7 @@ eth_dev_tap_create(struct rte_vdev_device
> *vdev, char *tap_name,
>  	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
>  		goto error_exit;
> 
> -	if (tap_type) {
> +	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
>  		memset(&ifr, 0, sizeof(struct ifreq));
>  		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
>  		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, @@ -
> 1642,7 +1651,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
>  	char tun_name[RTE_ETH_NAME_MAX_LEN];
>  	char remote_iface[RTE_ETH_NAME_MAX_LEN];
> 
> -	tap_type = 0;
>  	strcpy(tuntap_name, "TUN");
> 
>  	name = rte_vdev_device_name(dev);
> @@ -1673,7 +1681,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
>  	TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s",
>  		name, tun_name);
> 
> -	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0);
> +	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
> +		ETH_TUNTAP_TYPE_TUN);
> 
>  leave:
>  	if (ret == -1) {
> @@ -1700,7 +1709,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
>  	struct ether_addr user_mac = { .addr_bytes = {0} };
>  	struct rte_eth_dev *eth_dev;
> 
> -	tap_type = 1;
>  	strcpy(tuntap_name, "TAP");
> 
>  	name = rte_vdev_device_name(dev);
> @@ -1762,7 +1770,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
>  	TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s",
>  		name, tap_name);
> 
> -	ret = eth_dev_tap_create(dev, tap_name, remote_iface,
> &user_mac);
> +	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,
> +		ETH_TUNTAP_TYPE_TAP);
> 
>  leave:
>  	if (ret == -1) {
> @@ -1784,15 +1793,17 @@ rte_pmd_tap_remove(struct rte_vdev_device
> *dev)
>  	struct pmd_internals *internals;
>  	int i;
> 
> -	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
> -		rte_socket_id());
> -
>  	/* find the ethdev entry */
>  	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
>  	if (!eth_dev)
>  		return 0;
> 
>  	internals = eth_dev->data->dev_private;
> +
> +	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
> +		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" :
> "TUN",
> +		rte_socket_id());
> +
>  	if (internals->nlsk_fd) {
>  		tap_flow_flush(eth_dev, NULL);
>  		tap_flow_implicit_flush(internals, NULL); diff --git
> a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index
> c87a0b8..7b21d0d 100644
> --- a/drivers/net/tap/rte_eth_tap.h
> +++ b/drivers/net/tap/rte_eth_tap.h
> @@ -23,6 +23,13 @@
>  #define RTE_PMD_TAP_MAX_QUEUES	1
>  #endif
> 
> +enum rte_tuntap_type {
> +	ETH_TUNTAP_TYPE_UNKNOWN,
> +	ETH_TUNTAP_TYPE_TUN,
> +	ETH_TUNTAP_TYPE_TAP,
> +	ETH_TUNTAP_TYPE_MAX,
> +};
> +
>  struct pkt_stats {
>  	uint64_t opackets;              /* Number of output packets */
>  	uint64_t ipackets;              /* Number of input packets */
> @@ -48,6 +55,7 @@ struct rx_queue {
> 
>  struct tx_queue {
>  	int fd;
> +	int type;                       /* Type field - TUN|TAP */
>  	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
>  	uint16_t csum:1;                /* Enable checksum offloading */
>  	struct pkt_stats stats;         /* Stats for this TX queue */
> @@ -57,6 +65,7 @@ struct pmd_internals {
>  	struct rte_eth_dev *dev;          /* Ethernet device. */
>  	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote
> netdevice name */
>  	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device
> name */
> +	int type;                         /* Type field - TUN|TAP */
>  	struct ether_addr eth_addr;       /* Mac address of the device port */
>  	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init
> */
>  	int remote_if_index;              /* remote netdevice IF_INDEX */
> --
> 2.7.4

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

* [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only
  2018-05-22 10:47   ` [dpdk-dev] [PATCH v3] " Vipin Varghese
  2018-05-22 13:53     ` Wiles, Keith
  2018-05-22 15:04     ` Ophir Munk
@ 2018-05-22 22:04     ` Ferruh Yigit
  2018-05-22 22:06       ` Ferruh Yigit
  2018-05-22 22:09       ` [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun Ferruh Yigit
  2 siblings, 2 replies; 23+ messages in thread
From: Ferruh Yigit @ 2018-05-22 22:04 UTC (permalink / raw)
  To: Keith Wiles; +Cc: dev, Ferruh Yigit, Vipin Varghese, Ophir Munk

From: Vipin Varghese <vipin.varghese@intel.com>

The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
type field will ensure the TAP PMD will always have protocol field
as 0.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Ophir Munk <ophirmu@mellanox.com>
---
 drivers/net/tap/rte_eth_tap.c | 66 ++++++++++++++++++++++++++-----------------
 drivers/net/tap/rte_eth_tap.h |  9 ++++++
 2 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 01552fa4f..6bb7962bb 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -68,7 +68,6 @@ static const char *valid_arguments[] = {
 static int tap_unit;
 static unsigned int tun_unit;
 
-static int tap_type;
 static char tuntap_name[8];
 
 static volatile uint32_t tap_trigger;	/* Rx trigger */
@@ -116,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
 	 * Do not set IFF_NO_PI as packet information header will be needed
 	 * to check if a received packet has been truncated.
 	 */
-	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
+	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
+		IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
 
 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
@@ -472,20 +472,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
 			break;
 
-		/*
-		 * TUN and TAP are created with IFF_NO_PI disabled.
-		 * For TUN PMD this mandatory as fields are used by
-		 * Kernel tun.c to determine whether its IP or non IP
-		 * packets.
-		 *
-		 * The logic fetches the first byte of data from mbuf.
-		 * compares whether its v4 or v6. If none matches default
-		 * value 0x00 is taken for protocol field.
-		 */
-		char *buff_data = rte_pktmbuf_mtod(seg, void *);
-		j = (*buff_data & 0xf0);
-		pi.proto = (j == 0x40) ? 0x0008 :
-				(j == 0x60) ? 0xdd86 : 0x00;
+		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
+			/*
+			 * TUN and TAP are created with IFF_NO_PI disabled.
+			 * For TUN PMD this mandatory as fields are used by
+			 * Kernel tun.c to determine whether its IP or non IP
+			 * packets.
+			 *
+			 * The logic fetches the first byte of data from mbuf
+			 * then compares whether its v4 or v6. If first byte
+			 * is 4 or 6, then protocol field is updated.
+			 */
+			char *buff_data = rte_pktmbuf_mtod(seg, void *);
+			j = (*buff_data & 0xf0);
+			pi.proto = (j == 0x40) ? rte_cpu_to_be_16(ETHER_TYPE_IPv4) :
+				(j == 0x60) ? rte_cpu_to_be_16(ETHER_TYPE_IPv6) : 0x00;
+		}
 
 		iovecs[0].iov_base = &pi;
 		iovecs[0].iov_len = sizeof(pi);
@@ -928,6 +930,12 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 	struct ifreq ifr;
 	int ret;
 
+	if (pmd->type == ETH_TUNTAP_TYPE_TUN) {
+		TAP_LOG(ERR, "%s: can't MAC address for TUN",
+			dev->device->name);
+		return -ENOTSUP;
+	}
+
 	if (is_zero_ether_addr(mac_addr)) {
 		TAP_LOG(ERR, "%s: can't set an empty MAC address",
 			dev->device->name);
@@ -1025,6 +1033,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
 	tx->mtu = &dev->data->mtu;
 	rx->rxmode = &dev->data->dev_conf.rxmode;
 
+	tx->type = pmd->type;
+
 	return *fd;
 }
 
@@ -1342,7 +1352,8 @@ static const struct eth_dev_ops ops = {
 
 static int
 eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
-		   char *remote_iface, struct ether_addr *mac_addr)
+		   char *remote_iface, struct ether_addr *mac_addr,
+		   enum rte_tuntap_type type)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev;
@@ -1364,6 +1375,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	pmd = dev->data->dev_private;
 	pmd->dev = dev;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+	pmd->type = type;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (pmd->ioctl_sock == -1) {
@@ -1400,7 +1412,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		pmd->txq[i].fd = -1;
 	}
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (is_zero_ether_addr(mac_addr))
 			eth_random_addr((uint8_t *)&pmd->eth_addr);
 		else
@@ -1423,7 +1435,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
 		goto error_exit;
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		memset(&ifr, 0, sizeof(struct ifreq));
 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
@@ -1642,7 +1654,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	char tun_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
 
-	tap_type = 0;
 	strcpy(tuntap_name, "TUN");
 
 	name = rte_vdev_device_name(dev);
@@ -1673,7 +1684,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s",
 		name, tun_name);
 
-	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0);
+	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
+		ETH_TUNTAP_TYPE_TUN);
 
 leave:
 	if (ret == -1) {
@@ -1700,7 +1712,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	struct ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 
-	tap_type = 1;
 	strcpy(tuntap_name, "TAP");
 
 	name = rte_vdev_device_name(dev);
@@ -1762,7 +1773,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac);
+	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,
+		ETH_TUNTAP_TYPE_TAP);
 
 leave:
 	if (ret == -1) {
@@ -1784,15 +1796,17 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	struct pmd_internals *internals;
 	int i;
 
-	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
-		rte_socket_id());
-
 	/* find the ethdev entry */
 	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
 	internals = eth_dev->data->dev_private;
+
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
+		rte_socket_id());
+
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index c87a0b815..7b21d0d8b 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -23,6 +23,13 @@
 #define RTE_PMD_TAP_MAX_QUEUES	1
 #endif
 
+enum rte_tuntap_type {
+	ETH_TUNTAP_TYPE_UNKNOWN,
+	ETH_TUNTAP_TYPE_TUN,
+	ETH_TUNTAP_TYPE_TAP,
+	ETH_TUNTAP_TYPE_MAX,
+};
+
 struct pkt_stats {
 	uint64_t opackets;              /* Number of output packets */
 	uint64_t ipackets;              /* Number of input packets */
@@ -48,6 +55,7 @@ struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	int type;                       /* Type field - TUN|TAP */
 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	uint16_t csum:1;                /* Enable checksum offloading */
 	struct pkt_stats stats;         /* Stats for this TX queue */
@@ -57,6 +65,7 @@ struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	int type;                         /* Type field - TUN|TAP */
 	struct ether_addr eth_addr;       /* Mac address of the device port */
 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
-- 
2.14.3

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

* Re: [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only
  2018-05-22 22:04     ` [dpdk-dev] [PATCH v4] " Ferruh Yigit
@ 2018-05-22 22:06       ` Ferruh Yigit
  2018-05-22 22:09       ` [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun Ferruh Yigit
  1 sibling, 0 replies; 23+ messages in thread
From: Ferruh Yigit @ 2018-05-22 22:06 UTC (permalink / raw)
  To: Keith Wiles; +Cc: dev, Vipin Varghese, Ophir Munk

On 5/22/2018 11:04 PM, Ferruh Yigit wrote:
> From: Vipin Varghese <vipin.varghese@intel.com>
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field
> as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> Cc: Ophir Munk <ophirmu@mellanox.com>

Self Nack. Forget to rename patch title, will send a new version soon.

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

* [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun
  2018-05-22 22:04     ` [dpdk-dev] [PATCH v4] " Ferruh Yigit
  2018-05-22 22:06       ` Ferruh Yigit
@ 2018-05-22 22:09       ` Ferruh Yigit
  2018-05-22 22:19         ` Ferruh Yigit
  1 sibling, 1 reply; 23+ messages in thread
From: Ferruh Yigit @ 2018-05-22 22:09 UTC (permalink / raw)
  To: Keith Wiles; +Cc: dev, Ferruh Yigit, Vipin Varghese, Ophir Munk

From: Vipin Varghese <vipin.varghese@intel.com>

The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
type field will ensure the TAP PMD will always have protocol field
as 0.

Fixes: 204d026a3922 ("net/tap: support tun")
Cc: vipin.varghese@intel.com

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Ophir Munk <ophirmu@mellanox.com>
---
 drivers/net/tap/rte_eth_tap.c | 66 ++++++++++++++++++++++++++-----------------
 drivers/net/tap/rte_eth_tap.h |  9 ++++++
 2 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 01552fa4f..6bb7962bb 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -68,7 +68,6 @@ static const char *valid_arguments[] = {
 static int tap_unit;
 static unsigned int tun_unit;
 
-static int tap_type;
 static char tuntap_name[8];
 
 static volatile uint32_t tap_trigger;	/* Rx trigger */
@@ -116,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
 	 * Do not set IFF_NO_PI as packet information header will be needed
 	 * to check if a received packet has been truncated.
 	 */
-	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
+	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
+		IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
 
 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
@@ -472,20 +472,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
 			break;
 
-		/*
-		 * TUN and TAP are created with IFF_NO_PI disabled.
-		 * For TUN PMD this mandatory as fields are used by
-		 * Kernel tun.c to determine whether its IP or non IP
-		 * packets.
-		 *
-		 * The logic fetches the first byte of data from mbuf.
-		 * compares whether its v4 or v6. If none matches default
-		 * value 0x00 is taken for protocol field.
-		 */
-		char *buff_data = rte_pktmbuf_mtod(seg, void *);
-		j = (*buff_data & 0xf0);
-		pi.proto = (j == 0x40) ? 0x0008 :
-				(j == 0x60) ? 0xdd86 : 0x00;
+		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
+			/*
+			 * TUN and TAP are created with IFF_NO_PI disabled.
+			 * For TUN PMD this mandatory as fields are used by
+			 * Kernel tun.c to determine whether its IP or non IP
+			 * packets.
+			 *
+			 * The logic fetches the first byte of data from mbuf
+			 * then compares whether its v4 or v6. If first byte
+			 * is 4 or 6, then protocol field is updated.
+			 */
+			char *buff_data = rte_pktmbuf_mtod(seg, void *);
+			j = (*buff_data & 0xf0);
+			pi.proto = (j == 0x40) ? rte_cpu_to_be_16(ETHER_TYPE_IPv4) :
+				(j == 0x60) ? rte_cpu_to_be_16(ETHER_TYPE_IPv6) : 0x00;
+		}
 
 		iovecs[0].iov_base = &pi;
 		iovecs[0].iov_len = sizeof(pi);
@@ -928,6 +930,12 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 	struct ifreq ifr;
 	int ret;
 
+	if (pmd->type == ETH_TUNTAP_TYPE_TUN) {
+		TAP_LOG(ERR, "%s: can't MAC address for TUN",
+			dev->device->name);
+		return -ENOTSUP;
+	}
+
 	if (is_zero_ether_addr(mac_addr)) {
 		TAP_LOG(ERR, "%s: can't set an empty MAC address",
 			dev->device->name);
@@ -1025,6 +1033,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
 	tx->mtu = &dev->data->mtu;
 	rx->rxmode = &dev->data->dev_conf.rxmode;
 
+	tx->type = pmd->type;
+
 	return *fd;
 }
 
@@ -1342,7 +1352,8 @@ static const struct eth_dev_ops ops = {
 
 static int
 eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
-		   char *remote_iface, struct ether_addr *mac_addr)
+		   char *remote_iface, struct ether_addr *mac_addr,
+		   enum rte_tuntap_type type)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev;
@@ -1364,6 +1375,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	pmd = dev->data->dev_private;
 	pmd->dev = dev;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+	pmd->type = type;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (pmd->ioctl_sock == -1) {
@@ -1400,7 +1412,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		pmd->txq[i].fd = -1;
 	}
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (is_zero_ether_addr(mac_addr))
 			eth_random_addr((uint8_t *)&pmd->eth_addr);
 		else
@@ -1423,7 +1435,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
 		goto error_exit;
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		memset(&ifr, 0, sizeof(struct ifreq));
 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
@@ -1642,7 +1654,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	char tun_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
 
-	tap_type = 0;
 	strcpy(tuntap_name, "TUN");
 
 	name = rte_vdev_device_name(dev);
@@ -1673,7 +1684,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s",
 		name, tun_name);
 
-	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0);
+	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
+		ETH_TUNTAP_TYPE_TUN);
 
 leave:
 	if (ret == -1) {
@@ -1700,7 +1712,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	struct ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 
-	tap_type = 1;
 	strcpy(tuntap_name, "TAP");
 
 	name = rte_vdev_device_name(dev);
@@ -1762,7 +1773,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac);
+	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,
+		ETH_TUNTAP_TYPE_TAP);
 
 leave:
 	if (ret == -1) {
@@ -1784,15 +1796,17 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	struct pmd_internals *internals;
 	int i;
 
-	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
-		rte_socket_id());
-
 	/* find the ethdev entry */
 	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
 	internals = eth_dev->data->dev_private;
+
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
+		rte_socket_id());
+
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index c87a0b815..7b21d0d8b 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -23,6 +23,13 @@
 #define RTE_PMD_TAP_MAX_QUEUES	1
 #endif
 
+enum rte_tuntap_type {
+	ETH_TUNTAP_TYPE_UNKNOWN,
+	ETH_TUNTAP_TYPE_TUN,
+	ETH_TUNTAP_TYPE_TAP,
+	ETH_TUNTAP_TYPE_MAX,
+};
+
 struct pkt_stats {
 	uint64_t opackets;              /* Number of output packets */
 	uint64_t ipackets;              /* Number of input packets */
@@ -48,6 +55,7 @@ struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	int type;                       /* Type field - TUN|TAP */
 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	uint16_t csum:1;                /* Enable checksum offloading */
 	struct pkt_stats stats;         /* Stats for this TX queue */
@@ -57,6 +65,7 @@ struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	int type;                         /* Type field - TUN|TAP */
 	struct ether_addr eth_addr;       /* Mac address of the device port */
 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
-- 
2.14.3

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

* Re: [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun
  2018-05-22 22:09       ` [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun Ferruh Yigit
@ 2018-05-22 22:19         ` Ferruh Yigit
  2018-05-22 22:25           ` Ferruh Yigit
  0 siblings, 1 reply; 23+ messages in thread
From: Ferruh Yigit @ 2018-05-22 22:19 UTC (permalink / raw)
  To: Keith Wiles; +Cc: dev, Vipin Varghese, Ophir Munk

On 5/22/2018 11:09 PM, Ferruh Yigit wrote:
> From: Vipin Varghese <vipin.varghese@intel.com>
> 

Proto filed is fixed for tap, so title should be:
net/tap: fix proto field for tap

Will fix while merging.

> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field
> as 0.
> 
> Fixes: 204d026a3922 ("net/tap: support tun")
> Cc: vipin.varghese@intel.com
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> Cc: Ophir Munk <ophirmu@mellanox.com>

<...>

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

* Re: [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun
  2018-05-22 22:19         ` Ferruh Yigit
@ 2018-05-22 22:25           ` Ferruh Yigit
  0 siblings, 0 replies; 23+ messages in thread
From: Ferruh Yigit @ 2018-05-22 22:25 UTC (permalink / raw)
  To: Keith Wiles; +Cc: dev, Vipin Varghese, Ophir Munk

On 5/22/2018 11:19 PM, Ferruh Yigit wrote:
> On 5/22/2018 11:09 PM, Ferruh Yigit wrote:
>> From: Vipin Varghese <vipin.varghese@intel.com>
>>
> 
> Proto filed is fixed for tap, so title should be:
> net/tap: fix proto field for tap
> 
> Will fix while merging.
> 
>> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
>> type field will ensure the TAP PMD will always have protocol field
>> as 0.
>>
>> Fixes: 204d026a3922 ("net/tap: support tun")
>> Cc: vipin.varghese@intel.com
>>
>> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/master, thanks.

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

* Re: [dpdk-dev] [PATCH v3] net/tap: perform proto field update for tun only
  2018-05-22 13:53     ` Wiles, Keith
@ 2018-05-23  4:33       ` Varghese, Vipin
  0 siblings, 0 replies; 23+ messages in thread
From: Varghese, Vipin @ 2018-05-23  4:33 UTC (permalink / raw)
  To: Wiles, Keith; +Cc: dev, Yigit, Ferruh, ophirmu, thomas, olgas

HI Keith,

Thanks for pointing out, please find my answer and update below

<Snipped> 

> > +			/*
> > +			 * TUN and TAP are created with IFF_NO_PI disabled.
> > +			 * For TUN PMD this mandatory as fields are used by
> > +			 * Kernel tun.c to determine whether its IP or non IP
> > +			 * packets.
> > +			 *
> > +			 * The logic fetches the first byte of data from mbuf
> > +			 * then compares whether its v4 or v6. If first byte
> > +			 * is 4 or 6, then protocol field is updated.
> > +			 */
> > +			char *buff_data = rte_pktmbuf_mtod(seg, void *);
> > +			j = (*buff_data & 0xf0);
> > +			pi.proto = (j == 0x40) ? 0x0008 :
> > 				(j == 0x60) ? 0xdd86 : 0x00;
> 
> Warning Will Robinson: Magic numbers :-)
> 
> Can we use the correct values here ETHERTYPE_IPV6 and ETHERTYPE_IP and
> then use htons() on the values please.

Earlier I refrained from doing this assuming htnos comparison is done for each packet leading to extra cycles. So updated the comments with explanation for logic explanation and readability. 

But I am ok to in co-operate the idea of using MACRO with htnos. I have used ETHER_TYPE_IPv4 and ETHER_TYPE_IPv6 which does not require extra include. The changes are available in v4 version.

> 
> > +		}


<Snipped>


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

* Re: [dpdk-dev] [PATCH v3] net/tap: perform proto field update for tun only
  2018-05-22 15:04     ` Ophir Munk
@ 2018-05-23  4:37       ` Varghese, Vipin
  0 siblings, 0 replies; 23+ messages in thread
From: Varghese, Vipin @ 2018-05-23  4:37 UTC (permalink / raw)
  To: Ophir Munk, dev, Yigit,  Ferruh, Wiles, Keith; +Cc: Thomas Monjalon, Olga Shern

Hi Ophir,

Thanks for inputs, please find my answers inline to the mail

> -----Original Message-----
> From: Ophir Munk [mailto:ophirmu@mellanox.com]
> Sent: Tuesday, May 22, 2018 8:35 PM
> To: Varghese, Vipin <vipin.varghese@intel.com>; dev@dpdk.org; Yigit, Ferruh
> <ferruh.yigit@intel.com>; Wiles, Keith <keith.wiles@intel.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
> <olgas@mellanox.com>
> Subject: RE: [PATCH v3] net/tap: perform proto field update for tun only
> 
> Hi,
> Overall it looks good.
> Please note a few more comments below.
> 
> > -----Original Message-----
> > From: Vipin Varghese [mailto:vipin.varghese@intel.com]
> > Sent: Tuesday, May 22, 2018 1:47 PM
> > To: dev@dpdk.org; ferruh.yigit@intel.com; keith.wiles@intel.com; Ophir
> > Munk <ophirmu@mellanox.com>
> > Cc: Thomas Monjalon <thomas@monjalon.net>; Olga Shern
> > <olgas@mellanox.com>; Vipin Varghese <vipin.varghese@intel.com>
> > Subject: [PATCH v3] net/tap: perform proto field update for tun only
> >
> > The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> > type field will ensure the TAP PMD will always have protocol field as 0.
> >
> > Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> > Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > ---
> 
> Shouldn't it be a fix commit?

The following code base is not merged with stable, dev or next-net branch. Hence do we 'fix commit' this?

> If so - please update the commit title, add Fixes: ... , Cc: stable@dpdk.org...
> 
> > Changes in V3:
> > - remove type field from rx struct - Ophir Munk
> > - add space for comment in struct - Ophir Munk
> > - pass type field into eth_dev_tap_create - Ophir Munk
> > - replace with enum value for type - Ophir Munk
> > - return as 'not supported' for mac_set - Vipin Varghese
> >
> > Changes in V2:
> > - updated in comment wording - Keith Wiles
> > - remove debug print from tx code - Keith Wiles
> > ---
> >  drivers/net/tap/rte_eth_tap.c | 61
> > +++++++++++++++++++++++++-------------
> > -----
> >  drivers/net/tap/rte_eth_tap.h |  9 +++++++
> >  2 files changed, 45 insertions(+), 25 deletions(-)
> >

<Snipped>

> >
> > +	if (pmd->type == ETH_TUNTAP_TYPE_TUN)
> > +		return -ENOTSUP;
> 
> 
> Can you please add a TAP_LOG(ERR, ...) to log this error similar to other error
> cases in this function?

Yes, I will add the change in v4 and share the same.

> 
> > +

<Snipped>

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

* Re: [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only
  2018-05-23  8:11   ` Ferruh Yigit
@ 2018-05-23  8:26     ` Varghese, Vipin
  0 siblings, 0 replies; 23+ messages in thread
From: Varghese, Vipin @ 2018-05-23  8:26 UTC (permalink / raw)
  To: Yigit, Ferruh, Wiles, Keith; +Cc: DPDK, ophirmu, thomas, olgas

Hi Ferruh,

I have checked the patch done. I am ok with the same.

Thanks
Vipin Varghese

> -----Original Message-----
> From: Yigit, Ferruh
> Sent: Wednesday, May 23, 2018 1:41 PM
> To: Wiles, Keith <keith.wiles@intel.com>; Varghese, Vipin
> <vipin.varghese@intel.com>
> Cc: DPDK <dev@dpdk.org>; ophirmu@mellanox.com; thomas@monjalon.net;
> olgas@mellanox.com
> Subject: Re: [PATCH v4] net/tap: perform proto field update for tun only
> 
> On 5/23/2018 5:48 AM, Wiles, Keith wrote:
> >
> >
> >> On May 22, 2018, at 11:44 PM, Varghese, Vipin <vipin.varghese@intel.com>
> wrote:
> >>
> >> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> >> type field will ensure the TAP PMD will always have protocol field as
> >> 0.
> >>
> >> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> >> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> >> ---
> >> Changes in V4:
> >> - convert comparision with MACRO - Keith Wiles
> >> - add LOG err for tun using set MAC - Ophir Munk
> >>
> >> Changes in V3:
> >> - remove type field from rx struct - Ophir Munk
> >> - add space for comment in struct - Ophir Munk
> >> - pass type field into eth_dev_tap_create - Ophir Munk
> >> - replace with enum value for type - Ophir Munk
> >> - return as 'not supported' for mac_set - Vipin Varghese
> >>
> >> Changes in V2:
> >> - updated in comment wording - Keith Wiles
> >> - remove debug print from tx code - Keith Wiles —
> >
> > Looks good to me.
> >
> > Acked-by: Keith Wiles<keith.wiles@intel.com>
> 
> I re-did a v5 for this patch yesterday and it has already been merged into rc5.
> https://dpdk.org/dev/patchwork/patch/40352/
> 
> @vipin, can you please check if the merged patch is good, and if is there any diff
> with what you have sent here?
> 
> Thanks,
> ferruh
> 
> >
> > Regards,
> > Keith
> >


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

* Re: [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only
  2018-05-23  4:48 ` Wiles, Keith
@ 2018-05-23  8:11   ` Ferruh Yigit
  2018-05-23  8:26     ` Varghese, Vipin
  0 siblings, 1 reply; 23+ messages in thread
From: Ferruh Yigit @ 2018-05-23  8:11 UTC (permalink / raw)
  To: Wiles, Keith, Varghese, Vipin; +Cc: DPDK, ophirmu, thomas, olgas

On 5/23/2018 5:48 AM, Wiles, Keith wrote:
> 
> 
>> On May 22, 2018, at 11:44 PM, Varghese, Vipin <vipin.varghese@intel.com> wrote:
>>
>> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
>> type field will ensure the TAP PMD will always have protocol field
>> as 0.
>>
>> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
>> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> ---
>> Changes in V4:
>> - convert comparision with MACRO - Keith Wiles
>> - add LOG err for tun using set MAC - Ophir Munk
>>
>> Changes in V3:
>> - remove type field from rx struct - Ophir Munk
>> - add space for comment in struct - Ophir Munk
>> - pass type field into eth_dev_tap_create - Ophir Munk
>> - replace with enum value for type - Ophir Munk
>> - return as 'not supported' for mac_set - Vipin Varghese
>>
>> Changes in V2:
>> - updated in comment wording - Keith Wiles
>> - remove debug print from tx code - Keith Wiles
>> —
> 
> Looks good to me.
> 
> Acked-by: Keith Wiles<keith.wiles@intel.com>

I re-did a v5 for this patch yesterday and it has already been merged into rc5.
https://dpdk.org/dev/patchwork/patch/40352/

@vipin, can you please check if the merged patch is good, and if is there any
diff with what you have sent here?

Thanks,
ferruh

> 
> Regards,
> Keith
> 

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

* Re: [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only
  2018-05-23  4:44 [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only Vipin Varghese
@ 2018-05-23  4:48 ` Wiles, Keith
  2018-05-23  8:11   ` Ferruh Yigit
  0 siblings, 1 reply; 23+ messages in thread
From: Wiles, Keith @ 2018-05-23  4:48 UTC (permalink / raw)
  To: Varghese, Vipin; +Cc: DPDK, Yigit, Ferruh, ophirmu, thomas, olgas



> On May 22, 2018, at 11:44 PM, Varghese, Vipin <vipin.varghese@intel.com> wrote:
> 
> The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
> type field will ensure the TAP PMD will always have protocol field
> as 0.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> Changes in V4:
> - convert comparision with MACRO - Keith Wiles
> - add LOG err for tun using set MAC - Ophir Munk
> 
> Changes in V3:
> - remove type field from rx struct - Ophir Munk
> - add space for comment in struct - Ophir Munk
> - pass type field into eth_dev_tap_create - Ophir Munk
> - replace with enum value for type - Ophir Munk
> - return as 'not supported' for mac_set - Vipin Varghese
> 
> Changes in V2:
> - updated in comment wording - Keith Wiles
> - remove debug print from tx code - Keith Wiles
> —

Looks good to me.

Acked-by: Keith Wiles<keith.wiles@intel.com>

Regards,
Keith


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

* [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only
@ 2018-05-23  4:44 Vipin Varghese
  2018-05-23  4:48 ` Wiles, Keith
  0 siblings, 1 reply; 23+ messages in thread
From: Vipin Varghese @ 2018-05-23  4:44 UTC (permalink / raw)
  To: dev, keith.wiles, ferruh.yigit, ophirmu; +Cc: thomas, olgas, Vipin Varghese

The TX function is shared between TAP and TUN PMD. Checking TUN-TAP
type field will ensure the TAP PMD will always have protocol field
as 0.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Changes in V4:
- convert comparision with MACRO - Keith Wiles
- add LOG err for tun using set MAC - Ophir Munk

Changes in V3:
- remove type field from rx struct - Ophir Munk
- add space for comment in struct - Ophir Munk
- pass type field into eth_dev_tap_create - Ophir Munk
- replace with enum value for type - Ophir Munk
- return as 'not supported' for mac_set - Vipin Varghese

Changes in V2:
- updated in comment wording - Keith Wiles
- remove debug print from tx code - Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 65 ++++++++++++++++++++++++++-----------------
 drivers/net/tap/rte_eth_tap.h |  9 ++++++
 2 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 01552fa..d016133 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -68,7 +68,6 @@ static const char *valid_arguments[] = {
 static int tap_unit;
 static unsigned int tun_unit;
 
-static int tap_type;
 static char tuntap_name[8];
 
 static volatile uint32_t tap_trigger;	/* Rx trigger */
@@ -116,7 +115,8 @@ tun_alloc(struct pmd_internals *pmd)
 	 * Do not set IFF_NO_PI as packet information header will be needed
 	 * to check if a received packet has been truncated.
 	 */
-	ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
+	ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
+		IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
 
 	TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
@@ -472,20 +472,22 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
 			break;
 
-		/*
-		 * TUN and TAP are created with IFF_NO_PI disabled.
-		 * For TUN PMD this mandatory as fields are used by
-		 * Kernel tun.c to determine whether its IP or non IP
-		 * packets.
-		 *
-		 * The logic fetches the first byte of data from mbuf.
-		 * compares whether its v4 or v6. If none matches default
-		 * value 0x00 is taken for protocol field.
-		 */
-		char *buff_data = rte_pktmbuf_mtod(seg, void *);
-		j = (*buff_data & 0xf0);
-		pi.proto = (j == 0x40) ? 0x0008 :
-				(j == 0x60) ? 0xdd86 : 0x00;
+		if (txq->type == ETH_TUNTAP_TYPE_TUN) {
+			/*
+			 * TUN and TAP are created with IFF_NO_PI disabled.
+			 * For TUN PMD this mandatory as fields are used by
+			 * Kernel tun.c to determine whether its IP or non IP
+			 * packets.
+			 *
+			 * The logic fetches the first byte of data from mbuf
+			 * then compares whether its v4 or v6. If first byte
+			 * is 4 or 6, then protocol field is updated.
+			 */
+			char *buff_data = rte_pktmbuf_mtod(seg, void *);
+			j = (*buff_data & 0xf0);
+			pi.proto = (j == 0x40) ? htons(ETHER_TYPE_IPv4) :
+				(j == 0x60) ? htons(ETHER_TYPE_IPv6) : 0x00;
+		}
 
 		iovecs[0].iov_base = &pi;
 		iovecs[0].iov_len = sizeof(pi);
@@ -928,6 +930,11 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 	struct ifreq ifr;
 	int ret;
 
+	if (pmd->type == ETH_TUNTAP_TYPE_TUN) {
+		TAP_LOG(ERR, "%s: can't set MAC address", dev->device->name);
+		return -ENOTSUP;
+	}
+
 	if (is_zero_ether_addr(mac_addr)) {
 		TAP_LOG(ERR, "%s: can't set an empty MAC address",
 			dev->device->name);
@@ -1025,6 +1032,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
 	tx->mtu = &dev->data->mtu;
 	rx->rxmode = &dev->data->dev_conf.rxmode;
 
+	tx->type = pmd->type;
+
 	return *fd;
 }
 
@@ -1342,7 +1351,8 @@ static const struct eth_dev_ops ops = {
 
 static int
 eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
-		   char *remote_iface, struct ether_addr *mac_addr)
+		   char *remote_iface, struct ether_addr *mac_addr,
+		   enum rte_tuntap_type type)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev;
@@ -1364,6 +1374,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	pmd = dev->data->dev_private;
 	pmd->dev = dev;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+	pmd->type = type;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (pmd->ioctl_sock == -1) {
@@ -1400,7 +1411,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		pmd->txq[i].fd = -1;
 	}
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (is_zero_ether_addr(mac_addr))
 			eth_random_addr((uint8_t *)&pmd->eth_addr);
 		else
@@ -1423,7 +1434,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
 		goto error_exit;
 
-	if (tap_type) {
+	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		memset(&ifr, 0, sizeof(struct ifreq));
 		ifr.ifr_hwaddr.sa_family = AF_LOCAL;
 		rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr,
@@ -1642,7 +1653,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	char tun_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
 
-	tap_type = 0;
 	strcpy(tuntap_name, "TUN");
 
 	name = rte_vdev_device_name(dev);
@@ -1673,7 +1683,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s",
 		name, tun_name);
 
-	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0);
+	ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
+		ETH_TUNTAP_TYPE_TUN);
 
 leave:
 	if (ret == -1) {
@@ -1700,7 +1711,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	struct ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 
-	tap_type = 1;
 	strcpy(tuntap_name, "TAP");
 
 	name = rte_vdev_device_name(dev);
@@ -1762,7 +1772,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac);
+	ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,
+		ETH_TUNTAP_TYPE_TAP);
 
 leave:
 	if (ret == -1) {
@@ -1784,15 +1795,17 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	struct pmd_internals *internals;
 	int i;
 
-	TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u",
-		rte_socket_id());
-
 	/* find the ethdev entry */
 	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
 	internals = eth_dev->data->dev_private;
+
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		(internals->type == ETH_TUNTAP_TYPE_TAP) ? "TAP" : "TUN",
+		rte_socket_id());
+
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index c87a0b8..7b21d0d 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -23,6 +23,13 @@
 #define RTE_PMD_TAP_MAX_QUEUES	1
 #endif
 
+enum rte_tuntap_type {
+	ETH_TUNTAP_TYPE_UNKNOWN,
+	ETH_TUNTAP_TYPE_TUN,
+	ETH_TUNTAP_TYPE_TAP,
+	ETH_TUNTAP_TYPE_MAX,
+};
+
 struct pkt_stats {
 	uint64_t opackets;              /* Number of output packets */
 	uint64_t ipackets;              /* Number of input packets */
@@ -48,6 +55,7 @@ struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	int type;                       /* Type field - TUN|TAP */
 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	uint16_t csum:1;                /* Enable checksum offloading */
 	struct pkt_stats stats;         /* Stats for this TX queue */
@@ -57,6 +65,7 @@ struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	int type;                         /* Type field - TUN|TAP */
 	struct ether_addr eth_addr;       /* Mac address of the device port */
 	struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
-- 
2.7.4

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

end of thread, other threads:[~2018-05-23  8:26 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-14  4:53 [dpdk-dev] [PATCH] net/tap: perform proto field update for tun only Vipin Varghese
2018-05-14 22:27 ` Wiles, Keith
2018-05-15  9:08   ` Varghese, Vipin
2018-05-15 14:49 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
2018-05-15 12:31   ` Wiles, Keith
2018-05-15 22:28   ` Ophir Munk
2018-05-22  6:33     ` Varghese, Vipin
2018-05-22 11:05       ` Varghese, Vipin
2018-05-22 13:55         ` Wiles, Keith
2018-05-22 10:47   ` [dpdk-dev] [PATCH v3] " Vipin Varghese
2018-05-22 13:53     ` Wiles, Keith
2018-05-23  4:33       ` Varghese, Vipin
2018-05-22 15:04     ` Ophir Munk
2018-05-23  4:37       ` Varghese, Vipin
2018-05-22 22:04     ` [dpdk-dev] [PATCH v4] " Ferruh Yigit
2018-05-22 22:06       ` Ferruh Yigit
2018-05-22 22:09       ` [dpdk-dev] [PATCH v5] net/tap: fix proto field for tun Ferruh Yigit
2018-05-22 22:19         ` Ferruh Yigit
2018-05-22 22:25           ` Ferruh Yigit
2018-05-23  4:44 [dpdk-dev] [PATCH v4] net/tap: perform proto field update for tun only Vipin Varghese
2018-05-23  4:48 ` Wiles, Keith
2018-05-23  8:11   ` Ferruh Yigit
2018-05-23  8:26     ` Varghese, Vipin

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).