From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0056.outbound.protection.outlook.com [104.47.1.56]) by dpdk.org (Postfix) with ESMTP id 260011B637 for ; Wed, 16 May 2018 00:28:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S8zPqhdlJW2UYXqSgbd//fvgoCzB1esPLYK/pZGiUQ4=; b=N7NIPfai9an4yUYF3VKgCTz+WjDraPmjds5DFtHI9+wPXoWPVGYpJ/IHPRbhimvyanX4lk8oClUnbE75XmZ4kI2bBcEo6Gumj8IWHf8Ha/YstlNdvUWbmw37ZB0LK3SXYcfxM2g6zyjlgDD0fozb0COl4EIJRDVVZxGIwP8VpUM= Received: from HE1PR0501MB2314.eurprd05.prod.outlook.com (10.168.34.19) by HE1PR0501MB2524.eurprd05.prod.outlook.com (10.168.126.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Tue, 15 May 2018 22:28:35 +0000 Received: from HE1PR0501MB2314.eurprd05.prod.outlook.com ([fe80::1071:70d0:eac1:5d97]) by HE1PR0501MB2314.eurprd05.prod.outlook.com ([fe80::1071:70d0:eac1:5d97%18]) with mapi id 15.20.0755.018; Tue, 15 May 2018 22:28:35 +0000 From: Ophir Munk To: Vipin Varghese , "dev@dpdk.org" , "keith.wiles@intel.com" , "ferruh.yigit@intel.com" CC: Thomas Monjalon , Olga Shern Thread-Topic: [PATCH v2] net/tap: perform proto field update for tun only Thread-Index: AQHT7CwsuUe30XWYm0WTo+dVIvu646QxV3PA Date: Tue, 15 May 2018 22:28:35 +0000 Message-ID: References: <1526273615-154067-1-git-send-email-vipin.varghese@intel.com> <1526395780-105792-1-git-send-email-vipin.varghese@intel.com> In-Reply-To: <1526395780-105792-1-git-send-email-vipin.varghese@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; x-originating-ip: [85.250.111.138] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR0501MB2524; 7:A9g7Wln8/XKU0LBBvi1000n+bSiDSYTImBMMTJg2fY4G/0qAadivbYWoDzv+ZC0bJbr3OaC1zzk8UXwqaZJ7IM+DY0fNBdLZwmOTz54ZskGGrnz5z/xWzcLZ6OR409wB9QOqdpMd2hUtdMGhMlejn6ffZLxrLitHp6YDn1wTomwusYdfqpoDf31gyZQSDXnN9z+0fl4jQ5aJV5kOmWCrr+GQ+M9uLMRPAdSi/R7nqXkbvvBrhPF4rTV58hCNBaen x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:HE1PR0501MB2524; x-ms-traffictypediagnostic: HE1PR0501MB2524: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:HE1PR0501MB2524; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2524; x-forefront-prvs: 0673F5BE31 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(376002)(366004)(396003)(346002)(189003)(199004)(13464003)(106356001)(8676002)(15650500001)(55016002)(74316002)(3660700001)(9686003)(68736007)(81166006)(81156014)(8936002)(186003)(3280700002)(5250100002)(26005)(2501003)(2900100001)(14454004)(2201001)(2906002)(6246003)(86362001)(575784001)(7736002)(305945005)(102836004)(4326008)(33656002)(3846002)(476003)(6116002)(76176011)(486006)(7696005)(11346002)(446003)(99286004)(316002)(97736004)(53546011)(5660300001)(478600001)(229853002)(110136005)(59450400001)(105586002)(6436002)(53936002)(107886003)(66066001)(25786009)(54906003)(6506007); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2524; H:HE1PR0501MB2314.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: yqnl7qblh0GLLLuD1QrzI2ECAFxZqQpOYmjWNNtMXWQCnW9Iuq0YIlMCGbEs3NnxngCCnPzdrkLLsgfLkpEPCtd9HlXDAjc8t5s4NETyxb1ijT7l3iC4ovlIa1T7UTjHgp2S2lleAwPnJbd3m/k6dX/bCyWLR0ElmxTQRFQA6qSpwzTxqYcaB4H6gAANwZiA spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 565c313f-1af2-4036-6632-08d5bab332e6 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 565c313f-1af2-4036-6632-08d5bab332e6 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 May 2018 22:28:35.7259 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2524 Subject: Re: [dpdk-dev] [PATCH v2] net/tap: perform proto field update for tun only X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 May 2018 22:28:39 -0000 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 > Cc: Vipin Varghese > Subject: [PATCH v2] net/tap: perform proto field update for tun only >=20 > 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. >=20 > Signed-off-by: Vipin Varghese > Suggested-by: Ferruh Yigit > --- >=20 > 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(-) >=20 > 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 =3D (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT; > + ifr.ifr_flags =3D (pmd->type =3D=3D ETH_TUNTAP_TYPE_TAP) ? > + IFF_TAP : IFF_TUN | IFF_POINTOPOINT; > snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name); >=20 > 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; >=20 > - /* > - * 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 =3D rte_pktmbuf_mtod(seg, void *); > - j =3D (*buff_data & 0xf0); > - pi.proto =3D (j =3D=3D 0x40) ? 0x0008 : > - (j =3D=3D 0x60) ? 0xdd86 : 0x00; > + if (txq->type =3D=3D 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 =3D rte_pktmbuf_mtod(seg, void *); > + j =3D (*buff_data & 0xf0); > + pi.proto =3D (j =3D=3D 0x40) ? 0x0008 : > + (j =3D=3D 0x60) ? 0xdd86 : 0x00; > + } >=20 > iovecs[0].iov_base =3D π > iovecs[0].iov_len =3D sizeof(pi); > @@ -1052,6 +1055,9 @@ tap_setup_queue(struct rte_eth_dev *dev, > tx->mtu =3D &dev->data->mtu; > rx->rxmode =3D &dev->data->dev_conf.rxmode; >=20 > + tx->type =3D pmd->type; > + rx->type =3D pmd->type; It seems there is no usage for rx->type in TAP code. Therefore - can you pl= ease remove rx->type assignment? > + > return *fd; > } >=20 > @@ -1386,6 +1392,7 @@ eth_dev_tap_create(struct rte_vdev_device > *vdev, char *tap_name, > pmd =3D dev->data->dev_private; > pmd->dev =3D dev; > snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name); > + pmd->type =3D ETH_TUNTAP_TYPE_UNKNOWN; >=20 > pmd->ioctl_sock =3D socket(AF_INET, SOCK_DGRAM, 0); > if (pmd->ioctl_sock =3D=3D -1) { > @@ -1421,7 +1428,9 @@ eth_dev_tap_create(struct rte_vdev_device > *vdev, char *tap_name, > pmd->txq[i].fd =3D -1; > } >=20 > - if (tap_type) { > + pmd->type =3D (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 v= alue 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 al= ways just use the enums (avoiding the conversion)? > + > + if (pmd->type =3D=3D 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; >=20 > - if (tap_type) { > + if (pmd->type =3D=3D ETH_TUNTAP_TYPE_TAP) { > memset(&ifr, 0, sizeof(struct ifreq)); > ifr.ifr_hwaddr.sa_family =3D 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; >=20 > - TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u", > + internals =3D eth_dev->data->dev_private; > + TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u", > + (internals->type =3D=3D ETH_TUNTAP_TYPE_TAP) ? "TAP" : > "TUN", > rte_socket_id()); >=20 > /* find the ethdev entry */ > @@ -1820,7 +1831,6 @@ rte_pmd_tap_remove(struct rte_vdev_device > *dev) > if (!eth_dev) > return 0; >=20 > - internals =3D 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 >=20 > +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 cod= e. 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 { >=20 > struct tx_queue { > int fd; > + int type; /* Type field - TUN|TAP */ Please use spaces (like all other fields in this struct) instead of tabs, s= o 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