From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30051.outbound.protection.outlook.com [40.107.3.51]) by dpdk.org (Postfix) with ESMTP id C373C5F45 for ; Fri, 20 Apr 2018 23:58:28 +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; bh=yyxZuLtw8m6qSoYe3oFl0XvSqbkgKb1S7n1sEySVgME=; b=HIe3rJP+MRdj891XuiM9r2Oy/EINCj4Mg9pNIuOMFkRO1GmFDqClZGqfyQmgq7OKO5f8YRUDnufdBbnBQqS6w4rP3lOTu9IqWn94GCXyh8T8mMQsOXhUYyMJ13u07DYGPqucCMPFHgg38KVWyAQ/eBOHCAeGuoQs8XQ68E5IbFo= Received: from HE1PR0501MB2314.eurprd05.prod.outlook.com (10.168.34.19) by HE1PR0501MB2491.eurprd05.prod.outlook.com (10.168.126.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.12; Fri, 20 Apr 2018 21:58:15 +0000 Received: from HE1PR0501MB2314.eurprd05.prod.outlook.com ([fe80::d405:aec8:cd2f:85cc]) by HE1PR0501MB2314.eurprd05.prod.outlook.com ([fe80::d405:aec8:cd2f:85cc%18]) with mapi id 15.20.0675.015; Fri, 20 Apr 2018 21:58:15 +0000 From: Ophir Munk To: "Varghese, Vipin" , "dev@dpdk.org" , "pascal.mazon@6wind.com" , "Yigit, Ferruh" , Thomas Monjalon , "Olga Shern" , Shahaf Shuler Thread-Topic: [dpdk-dev] [PATCH 1/2] net/tap: add tun support Thread-Index: AQHTypscfcCG5aLvi02SSrXdyDUkCaP9DN/AgAEKDICADCbbIIAAEQog Date: Fri, 20 Apr 2018 21:58:15 +0000 Message-ID: References: <1519625719-10443-1-git-send-email-vipin.varghese@intel.com> <1522705068-18198-1-git-send-email-vipin.varghese@intel.com> <4C9E0AB70F954A408CC4ADDBF0F8FA7D4D1C8BAB@BGSMSX101.gar.corp.intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=mellanox.com; x-originating-ip: [93.173.51.187] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR0501MB2491; 7:3XGo2mHZKoyC+9f1KFnfdaIJCXGHC3APJecgmtI1LRyyJKAPzxDeo8dyy85ZKp0zppVMwpOI8OevMx0SHZxJ3CH407X4gWIqnpwS6g1vnN0vZcl4npefUuXzDSySVRFOjTXhcwC8MxZsSR/z5S1u4bag9M7wAOAeWXgD8TAZ6ntaW6G/foDBMoiO5RNxZ0kyMtdMwQjUcqwxiExBsRryj9/bSUJeLJPe2KppUj42tclJ8ii6YBuWrIc1oaNcWKzT 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:HE1PR0501MB2491; x-ms-traffictypediagnostic: HE1PR0501MB2491: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(224247188773048)(228905959029699)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231232)(944501398)(52105095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:HE1PR0501MB2491; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2491; x-forefront-prvs: 0648FCFFA8 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(346002)(39380400002)(396003)(39860400002)(366004)(13464003)(186003)(93886005)(478600001)(305945005)(2501003)(2900100001)(476003)(7736002)(966005)(11346002)(76176011)(7696005)(3280700002)(446003)(3660700001)(2940100002)(229853002)(33656002)(5660300001)(59450400001)(86362001)(6246003)(6306002)(2201001)(102836004)(8936002)(110136005)(6436002)(74316002)(53936002)(3846002)(8676002)(66066001)(53546011)(6116002)(26005)(2906002)(6506007)(6636002)(5250100002)(81166006)(9686003)(316002)(55016002)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2491; H:HE1PR0501MB2314.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; MLV:sfv; x-microsoft-antispam-message-info: ezlezofX/w3h5TMciBLw8TSmKwRXe/HeGzWKegc19DhS+GJxRah4ItY+VOcSq7Si3GXjGe/yLZNT9/1LVe3dEJBg8YaTwXZGy6uCIhTgfVp7pX2ITQ3R/K5DSFVi5QvIxxsx/9Aud9nG64vg/aUCu957a8Z85tJ03CpMAdBMhYX5qLa6YAHDE2zoNaY5AwEm 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: 52055c4d-9b5d-4685-11d0-08d5a709d1ab X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52055c4d-9b5d-4685-11d0-08d5a709d1ab X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2018 21:58:15.5111 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2491 Subject: Re: [dpdk-dev] [PATCH 1/2] net/tap: add tun support 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: Fri, 20 Apr 2018 22:01:18 -0000 Hi Vipin, I missed your point: You claim that TAP should work regardless of any pi.proto values. Can you confirm that for ALL kernels versions (past and future)? > -----Original Message----- > From: Ophir Munk > Sent: Saturday, April 21, 2018 12:49 AM > To: Varghese, Vipin ; dev@dpdk.org; > pascal.mazon@6wind.com; Yigit, Ferruh ; Thomas > Monjalon ; Olga Shern ; > Shahaf Shuler > Subject: RE: [dpdk-dev] [PATCH 1/2] net/tap: add tun support >=20 > Hi Vipin, >=20 > Please find comments inline. >=20 > > -----Original Message----- > > From: Varghese, Vipin [mailto:vipin.varghese@intel.com] > > Sent: Friday, April 13, 2018 6:18 AM > > To: Ophir Munk ; dev@dpdk.org; > > pascal.mazon@6wind.com; Yigit, Ferruh ; Thomas > > Monjalon ; Olga Shern ; > > Shahaf Shuler > > Subject: RE: [dpdk-dev] [PATCH 1/2] net/tap: add tun support > > > > Hi Ophir, > > > > Please find my answers inline to the queries. > > > > > -----Original Message----- > > > From: Ophir Munk [mailto:ophirmu@mellanox.com] > > > Sent: Thursday, April 12, 2018 5:19 PM > > > To: Varghese, Vipin ; dev@dpdk.org; > > > pascal.mazon@6wind.com; Yigit, Ferruh ; > > > Thomas Monjalon ; Olga Shern > > > ; Shahaf Shuler > > > Subject: RE: [dpdk-dev] [PATCH 1/2] net/tap: add tun support > > > > > > Hi Vipin, > > > This patch (adding TUN to TAP) has been Acked and accepted in > > > next-net branch. > > > I have some questions regarding the implementation (please find below= ). > > > > > > > -----Original Message----- > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Vipin > > > > Varghese > > > > Sent: Tuesday, April 03, 2018 12:38 AM > > > > To: dev@dpdk.org; pascal.mazon@6wind.com; ferruh.yigit@intel.com > > > > Cc: Vipin Varghese > > > > Subject: [dpdk-dev] [PATCH 1/2] net/tap: add tun support > > > > > > > > The change adds functional TUN PMD logic to the existing TAP PMD. > > > > TUN PMD can be initialized with 'net_tunX' where 'X' represents > > > > unique > > id. > > > > PMD supports argument interface, while MAC address and remote are > > > > not supported. > > > > > > > > > > [...] > > > > > > > > > > > + /* > > > > + * 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); > > > > + if (j & (0x40 | 0x60)) > > > > + pi.proto =3D (j =3D=3D 0x40) ? 0x0008 : 0xdd86; > > > > + > > > > > > 1. Accessing the first byte here assumes it is the first IP header > > > byte (layer 3) which is correct for TUN. > > > For TAP however the first byte belongs to Ethernet destination > > > address (layer 2). > > > Please explain how this logic will work for TAP. > > > > Based on linux code base '/driver/net/tap.c' and '/driver/net/tun.c' > > from 3.13. to 4.16, > > > > Please find my observation below > > 1. File: tun.c, function: tun_get_user, check for 'tun->flags & > > TUN_TYPE_MASK' is done and if non ip is taken counter 'rx_dropped' is > > updated. > > 2. File: tap.c, there are no checks for 'tap->flags' for IFF_NO_PI in > > rx data path. Counter 'rx_dropped' is updated in 'tap_handle_frame'. > > >=20 > I understand that in kernel implementation there is no check for tap->fla= gs in > file tap.c, however I think there is a bug in dpdk rte_eth_tap.c file. > Please find below an example which demonstrates this claim. >=20 > > Please find my reasoning below > > 1. First approach was to have separate function for tap and tun TX and = RX. > > But this will introduce code duplication, hence reworked the code as > above. >=20 > I agree. Avoiding code duplication is a good approach. >=20 > > 2. During my internal testing assigning dummy value for protocol field > > in TAP packets, did not show a difference in behaviour. May be there > > are some specific cases this failing. > > > > If there difference in behaviour, can please share the same? > > >=20 > Please consider the following example: > I am running testpmd with a TAP device, --forward-mode=3Dcsum. > I am injecting a TCP packet, which is forwarded back (mac addresses > swapped) to the sender. > Using gdb I set a breakpoint at pmd_tx_burst() in file rte_eth_tap.c >=20 > Looking at the following code inside pmd_tx_burst(): >=20 > 527 char *buff_data =3D rte_pktmbuf_mtod(seg, void *); > 528 j =3D (*buff_data & 0xf0); > 529 pi.proto =3D (j =3D=3D 0x40) ? 0x0008 : > 530 (j =3D=3D 0x60) ? 0xdd86 : 0x00; >=20 > I am printing the first 20 bytes of buff_data in line 527: >=20 > (gdb) p/x *(unsigned char *)buff_data@20 > $3 =3D {0x0, 0x25, 0x88, 0x10, 0x66, 0x2, 0xf4, 0x52, 0x14, 0x7a, 0x59, 0= x81, > 0x8, 0x0, 0x45, 0x0, 0x4, 0xdf, 0x0, 0x1} >=20 > The gdb printout refers to: > 6 bytes of destination MAC address: 0x0, 0x25, 0x88, 0x10, 0x66, 0x2 > 6 bytes of source MAC address: 0xf4, 0x52, 0x14, 0x7a, 0x59, 0x81 > 2 bytes of Ethernet type: 0x8, 0x0 - (IPv4) IP header starting with 0x45,= ... > which is the byte (0x45) that "j" should have looked at >=20 > In the case of TAP - buff_data starts with the destination MAC address of= the > sender (0x0, ...). > The code in line 528 expects that buff_data would start with an IP header > protocol (e.g. 0x45), but it is not the case for TAP. > In my case j=3D0x0 (line 528) which is harmless (as it ends up with setti= ng > pi.proto=3D0x00, which is correct for TAP). > However, if the sender had an Intel NIC - the destination MAC address cou= ld > have started with: > $3 =3D {0x40, 0x25, 0xC2, ... > Or- > $3 =3D {0x64, 0xD4, 0xDA, ... >=20 > as 4025C2 and 64D4DA are reserved prefixes for Intel Ethernet MAC > addresses, see: http://www.coffer.com/mac_find/?string=3Dintel >=20 > In this case pi.proto could end up with 0x0008 or 0xdd86 instead of 0x0 a= s > expected for TAP. >=20 > I hope that this example clarifies the bug I am referring to. >=20 > > > > > > 2. If the first TUN byte contains 0x2X (which is neither IPv4 nor > > > IPv6) it will end up by setting ip.proto as 0xdd86. > > > Please explain how this logic will work for non-IP packets in TUN > > > > I see your point. You are correct about this. Thanks for pointing out, > > may I send correction for this as > > > > """ > > - if (j & (0x40 | 0x60)) > > - pi.proto =3D (j =3D=3D 0x40) ? 0x0008 : 0xdd86; > > + pi.proto =3D (j =3D=3D 0x40) ? 0x0008 : > > + (j =3D=3D 0x60) ? 0xdd86 : > > + 0x00; > > """