From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0058.outbound.protection.outlook.com [104.47.2.58]) by dpdk.org (Postfix) with ESMTP id 40A7E2C4F for ; Tue, 22 May 2018 17:04:35 +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=kvRSUlzfMtMhHyn4s4v8isTxFvVx1bxwvaUNNja31E8=; b=L/rP5hOw79J/7Qz13zsSefkVM9UFYpAZFDjUduA3EKov+O5PIHiVPyC2wscNLmxCFMFrRv1GmhySpjS47RB0/4niXMsWljtYD2ClFh4pDTEuofk3Y5TDqwSY1Dfh1jSwi8QjtmwO2g0enzJKrWEGqJD3mToAtZ7M7YdtwtFXiV4= Received: from HE1PR0501MB2314.eurprd05.prod.outlook.com (10.168.34.19) by HE1PR0501MB2219.eurprd05.prod.outlook.com (10.168.33.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Tue, 22 May 2018 15:04:33 +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.0776.015; Tue, 22 May 2018 15:04:33 +0000 From: Ophir Munk To: Vipin Varghese , "dev@dpdk.org" , "ferruh.yigit@intel.com" , "keith.wiles@intel.com" CC: Thomas Monjalon , Olga Shern Thread-Topic: [PATCH v3] net/tap: perform proto field update for tun only Thread-Index: AQHT8bpB+uuf0DuILkKvsFFB1cK/AqQ704mA Date: Tue, 22 May 2018 15:04:32 +0000 Message-ID: References: <1526395780-105792-1-git-send-email-vipin.varghese@intel.com> <1526986034-2862-1-git-send-email-vipin.varghese@intel.com> In-Reply-To: <1526986034-2862-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: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR0501MB2219; 7:vi+TJrI8yMGBtF8n+DKVOWwsVLIh9/YzphasdkPrrOzDx13RSyOIuIYPhIIiefkciKbktNXfs+tz3qLqVLoDEawehG18uRc7eHFMX0AtDXOWRR2nYXHfpxbXbQGSTjOGX3eZbjTrePu4NVGNBHTs9RCYyk9lOO3/FQ6O4jN88vOCcKJ/DaVlyy+qHByM+7DFsz+5E6e1vGIWlvir/LBB1fbNRuCVYykFzoQT/bgUNG5Bh2Cg3gR7e5SyQUnzXvxk 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)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:HE1PR0501MB2219; x-ms-traffictypediagnostic: HE1PR0501MB2219: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(788757137089)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(6055026)(149027)(150027)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:HE1PR0501MB2219; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2219; x-forefront-prvs: 0680FADD48 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(366004)(39380400002)(396003)(376002)(346002)(13464003)(199004)(189003)(3280700002)(6246003)(81156014)(229853002)(15650500001)(6436002)(2201001)(106356001)(105586002)(86362001)(4326008)(53936002)(97736004)(7736002)(2906002)(33656002)(575784001)(68736007)(9686003)(55016002)(110136005)(54906003)(305945005)(6116002)(316002)(3846002)(3660700001)(107886003)(81166006)(8676002)(11346002)(476003)(2900100001)(446003)(74316002)(486006)(5660300001)(25786009)(186003)(8936002)(6506007)(2501003)(53546011)(102836004)(14454004)(66066001)(7696005)(478600001)(5250100002)(76176011)(59450400001)(99286004)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2219; H:HE1PR0501MB2314.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Fca8YIOCdk+1SPVI5ZIOTFx2kmLthekaU0pET6w+FIehngvQHwAj8YjAwIRhCLHnZv61Zpqafp8dJhiE5XXfNe2Wkq9TaWmPlLj7We6kZWgDt65J4KFQzhPLrnPQG+S9O6le9H/fPwkQmRv/HhR3NqVbDIk+hYti3Yj9D4MxpK3QGlU+F7cYEQI3Zt47l5is 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: e52bd836-3f7f-4956-71be-08d5bff55373 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: e52bd836-3f7f-4956-71be-08d5bff55373 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2018 15:04:32.9979 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2219 Subject: Re: [dpdk-dev] [PATCH v3] 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, 22 May 2018 15:04:35 -0000 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 > Cc: Thomas Monjalon ; Olga Shern > ; Vipin Varghese > Subject: [PATCH v3] 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 > --- Shouldn't it be a fix commit? If so - please update the commit title, add Fixes: ... , Cc: stable@dpdk.or= g... > 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 >=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 | 61 +++++++++++++++++++++++++------------= - > ----- > drivers/net/tap/rte_eth_tap.h | 9 +++++++ > 2 files changed, 45 insertions(+), 25 deletions(-) >=20 > 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[] =3D { static int > tap_unit; static unsigned int tun_unit; >=20 > -static int tap_type; > static char tuntap_name[8]; >=20 > 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 =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); @@ -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; >=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 : > + 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); > @@ -928,6 +930,9 @@ tap_mac_set(struct rte_eth_dev *dev, struct > ether_addr *mac_addr) > struct ifreq ifr; > int ret; >=20 > + if (pmd->type =3D=3D ETH_TUNTAP_TYPE_TUN) > + return -ENOTSUP; Can you please add a TAP_LOG(ERR, ...) to log this error similar to other e= rror 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 =3D &dev->data->mtu; > rx->rxmode =3D &dev->data->dev_conf.rxmode; >=20 > + tx->type =3D pmd->type; > + > return *fd; > } >=20 > @@ -1342,7 +1349,8 @@ static const struct eth_dev_ops ops =3D { >=20 > 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 =3D 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 =3D dev->data->dev_private; > pmd->dev =3D dev; > snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name); > + pmd->type =3D type; >=20 > pmd->ioctl_sock =3D socket(AF_INET, SOCK_DGRAM, 0); > if (pmd->ioctl_sock =3D=3D -1) { > @@ -1400,7 +1409,7 @@ eth_dev_tap_create(struct rte_vdev_device > *vdev, char *tap_name, > pmd->txq[i].fd =3D -1; > } >=20 > - if (tap_type) { > + 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 > @@ -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; >=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, @@ - > 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]; >=20 > - tap_type =3D 0; > strcpy(tuntap_name, "TUN"); >=20 > name =3D 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); >=20 > - ret =3D eth_dev_tap_create(dev, tun_name, remote_iface, 0); > + ret =3D eth_dev_tap_create(dev, tun_name, remote_iface, 0, > + ETH_TUNTAP_TYPE_TUN); >=20 > leave: > if (ret =3D=3D -1) { > @@ -1700,7 +1709,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > struct ether_addr user_mac =3D { .addr_bytes =3D {0} }; > struct rte_eth_dev *eth_dev; >=20 > - tap_type =3D 1; > strcpy(tuntap_name, "TAP"); >=20 > name =3D 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); >=20 > - ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, > &user_mac); > + ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac, > + ETH_TUNTAP_TYPE_TAP); >=20 > leave: > if (ret =3D=3D -1) { > @@ -1784,15 +1793,17 @@ 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", > - rte_socket_id()); > - > /* find the ethdev entry */ > eth_dev =3D rte_eth_dev_allocated(rte_vdev_device_name(dev)); > if (!eth_dev) > return 0; >=20 > 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()); > + > 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 >=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 */ > @@ -48,6 +55,7 @@ struct rx_queue { >=20 > 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