From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0075.outbound.protection.outlook.com [104.47.1.75]) by dpdk.org (Postfix) with ESMTP id 9EE887CA3 for ; Fri, 20 Apr 2018 23:49:27 +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=EgCfq8g4eko5h5+zjX0KCEj4Z2lHQXmhmNqMxsR+9g8=; b=W6fFDWTofmMnBXFApThBo03r6o8Rdr6iIMJLV1Ig0R4lrHrQMX0b2bEORD3ZLJ3v+5ZQ6jjlpfLA6w5eQASoixOV9RZyRXYpKD2zVzo9WewxY/reMGLbt9cDorUv6HF8kgKV82PIVXTyeGzyvTutVBE7cf4LBjJNq72xZX1vbPA= 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:49:25 +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:49:25 +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/AgAEKDICADCbbIA== Date: Fri, 20 Apr 2018 21:49:25 +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: <4C9E0AB70F954A408CC4ADDBF0F8FA7D4D1C8BAB@BGSMSX101.gar.corp.intel.com> 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:lY+H6fKAU+W4DG2h4tq4zZvKP/uONgHAzH0pYIPqr+nFVlJ7YVlQYoyh1Bpe/R+MERRXNw/iusVAEeQ9xJYUFi3/xOcJU0XGn86kgGFCwLT41d0DU3r0cexjZO1HJoTnhhB+BtTf6rMEb3e5veR7GzlsFLNtOtsDzAhbtEkTIs9dDl/ziijwIlPPEHZqy6M1eXHaa/vuqdaOEgG0iMVzcaeqOPQcmYKsJyoJeChh5dtZbc8Su0BzZ2vpdgSE4Z7a 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)(366004)(396003)(39380400002)(39860400002)(376002)(346002)(13464003)(74316002)(53936002)(110136005)(6436002)(3846002)(66066001)(8676002)(2201001)(6246003)(6306002)(102836004)(8936002)(9686003)(25786009)(316002)(55016002)(53546011)(6116002)(6636002)(81166006)(5250100002)(6506007)(26005)(2906002)(86362001)(7736002)(476003)(76176011)(11346002)(966005)(478600001)(305945005)(186003)(93886005)(2501003)(2900100001)(7696005)(5660300001)(33656002)(59450400001)(3660700001)(3280700002)(446003)(229853002); 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: NY2kAYNmpnwhezGsKeAEhg88PJ4rfbBpo8wNLUHKUuFazo0lRebeO/iQ0cF9wrssBYBTo9385XpKbTtuqv56ZhiLrFsqBtrpjEBdZlR89wyYIQiYB6y5M/1iiOE+pOm3cv26gp22lGX/1rB9kBMyrSzN/Mu+KJ6jSID7j56BOQQ0ZZQGwkMQulNGpxyVV1gs 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: 4e0e050a-2529-499b-0c5d-08d5a70895b7 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e0e050a-2529-499b-0c5d-08d5a70895b7 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2018 21:49:25.3359 (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 21:49:30 -0000 Hi Vipin, Please find comments inline. > -----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 >=20 > Hi Ophir, >=20 > Please find my answers inline to the queries. >=20 > > -----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 uniqu= e > 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. >=20 > Based on linux code base '/driver/net/tap.c' and '/driver/net/tun.c' from > 3.13. to 4.16, >=20 > 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->flags= 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. > 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 abov= e. 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. >=20 > 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.=20 I am injecting a TCP packet, which is forwarded back (mac addresses swapped= ) to the sender.=20 Using gdb I set a breakpoint at pmd_tx_burst() in file rte_eth_tap.c Looking at the following code inside pmd_tx_burst(): 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; I am printing the first 20 bytes of buff_data in line 527: (gdb) p/x *(unsigned char *)buff_data@20 $3 =3D {0x0, 0x25, 0x88, 0x10, 0x66, 0x2, 0xf4, 0x52, 0x14, 0x7a, 0x59, 0x8= 1, 0x8, 0x0, 0x45, 0x0, 0x4, 0xdf, 0x0, 0x1} 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 In the case of TAP - buff_data starts with the destination MAC address of t= he sender (0x0, ...).=20 The code in line 528 expects that buff_data would start with an IP header p= rotocol (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 setting= pi.proto=3D0x00, which is correct for TAP). However, if the sender had an Intel NIC - the destination MAC address could= have started with: $3 =3D {0x40, 0x25, 0xC2, ... Or- $3 =3D {0x64, 0xD4, 0xDA, ... as 4025C2 and 64D4DA are reserved prefixes for Intel Ethernet MAC addresses= , see: http://www.coffer.com/mac_find/?string=3Dintel In this case pi.proto could end up with 0x0008 or 0xdd86 instead of 0x0 as = expected for TAP. 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 >=20 > I see your point. You are correct about this. Thanks for pointing out, ma= y I > send correction for this as >=20 > """ > - 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; > """