From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 46C7BA0540; Tue, 14 Jul 2020 19:08:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B27E81C2BB; Tue, 14 Jul 2020 19:08:46 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id CC77C1C2B7 for ; Tue, 14 Jul 2020 19:08:45 +0200 (CEST) IronPort-SDR: CNCCsDDxVrvta6tIZrbwUI1UCBSdfHyPF/oe6t4wwKbVIUrsKKoo/zh/rWnu9dHZ5oHOVV0fZJ iQ5cfCULpY8Q== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="146983110" X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="146983110" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 10:08:44 -0700 IronPort-SDR: v9ZwGnWsSSNNnG9m9fzkKHQlZ1n3zHP4aRE4pRgWDLj4S2M3qu/+YSetIJnPSk9t7NjRp53ahR UCkV4zoVkLXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="317787966" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga002.fm.intel.com with ESMTP; 14 Jul 2020 10:08:44 -0700 Received: from fmsmsx606.amr.corp.intel.com (10.18.126.86) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 14 Jul 2020 10:08:44 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 14 Jul 2020 10:08:44 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.108) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 14 Jul 2020 10:08:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ejqJUl0jhxFuBD43CdGjo6MDyZEG5MBgNi/BxqjZ/RwmVyruEEKXSStDAsWvKDbRsRMqhPLpo60HoJdb+upDQ6yk1MIkFT8aNmC1V5RyymQ5RK77cmM8+Ba/tEAm8SQVxttPcBsVNyMXx11Eex8cS7HMxE54FZs5WAuPMX4n0JbcXjtTP8v3T1RvuXjg3uwhSUjlZ6qU52QyW91PrRVkR82Gk7bQvqJzNQz3drJwzGjxyG0guTyp6WpIn9PQGjXSr/O3SSeRqzggE/nloyyxaPme/oGGjXuI7+uZy39fz+0KTby2p4pv9g2Xkmwzo0pArXwqQmjNTkEWPtqiVFEA2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8khznNLw0MCKQwaq8AqGkBGe3Rs0eB4nssjANMX/0tA=; b=SiKchK+d39PpMxrtVdx+DQqj71BEax/VoACY2dtFwC8S2YOSS9XTluZwEySjdZYxgT9/nbkByJMBWgV4f7JgYRziHVW/0gt3BCPWF6Kz2qGGjG+6HHQloANqU1X/bU1tkESicvQbqjAdx7YNK11aPqBJmQ6LIDHVOEL5lYJIHZXTlH2PhJtp/jztEgkxiBqWGnRbL4F9BkbiKptBzQMmBBrrAan6WOeVz/cBJSY1X/4EqpXAJfoHNDFwtINXIvzwczqlEpHyYnfYeCbCVLl1xcdcb2AAthQH4XfbvGO8uaIUxScJHBx7MUc4zcHqaYEOmee+QlSLftPlxOD0Ukh/Xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8khznNLw0MCKQwaq8AqGkBGe3Rs0eB4nssjANMX/0tA=; b=li037maSNn+axJbh16YH6P90u3vnObRICnbZn++5V8ybmLsu3E79fqcQQWz92cpvgcTVzOeWf+0yyMECMemiJ8XSHzQVit5yLo8nvm54/YGaPaRXCnqwq7hLxdMP2uRf4J4CSXdMfidizFVtAcxjfbjhjCaXhk4CJ5qXqC4kMDg= Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26) by BYAPR11MB2534.namprd11.prod.outlook.com (2603:10b6:a02:c2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.23; Tue, 14 Jul 2020 17:08:41 +0000 Received: from BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f160:29ab:b8f9:4189]) by BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f160:29ab:b8f9:4189%6]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 17:08:41 +0000 From: "Ananyev, Konstantin" To: Ibtisam Tariq , "Dumitrescu, Cristian" , "Nicolau, Radu" , "akhil.goyal@nxp.com" , "Singh, Jasvinder" CC: "dev@dpdk.org" , "Zhang, Roy Fan" Thread-Topic: [dpdk-dev] [PATCH v4 3/3] examples/ipsec-secgw: Remove the re-implementation of inet_pton Thread-Index: AQHWWPxVH7yGMEQmLUqibrTkcV00P6kHUJjA Date: Tue, 14 Jul 2020 17:08:41 +0000 Message-ID: References: <20200608075836.3609-3-ibtisam.tariq@emumba.com> <20200713095730.10331-1-ibtisam.tariq@emumba.com> <20200713095730.10331-3-ibtisam.tariq@emumba.com> In-Reply-To: <20200713095730.10331-3-ibtisam.tariq@emumba.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZmJmOTIyZGEtZTZkZS00OThjLTllYjctNjVlNDBmNDYyMjZiIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiYXROVTdDVkZ5RWE3WGhRd0lpaFdhUlV2ekRTMFwvSkxmSW94MmNSNUQrM0R5TGUzZ1NCZ2xCM0Y4WmpuQzBPc2EifQ== dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 x-ctpclassification: CTP_NT authentication-results: emumba.com; dkim=none (message not signed) header.d=none;emumba.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [46.7.38.224] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 815b82bb-21db-4421-db9d-08d828188f0e x-ms-traffictypediagnostic: BYAPR11MB2534: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:632; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 72Usrc3FTtKkYrc/I7x05I4zsyfYyvyW9nc7pfKCLc/b45fdzKMVG62GMNTTSqJDOMIIieHxs9tFWQE178/idWfOMFnh9OXcf2gIOW2XvITi6sBI5pc5+ThqhrngYkqibsWwCPlul/VIMuRsxaUS9NrgFqz3SkF5JTd3vHy1sLByfF3TZzv7HN9d/SP5cf35e5MOHP7JvD7Ba0MRkLh5UFyapHL/qn7hgBPMk6iFseYVmKrI+sDDtvmKTwKMxGp/K/XXcBNgcwv1Kr7QNjYXFMUp8GFzeaGi/NisD0jywZ8hZjGQdGqAFBKB+AhHjKB0bXMAsZNRmcadV8mLNQxvIA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3301.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(54906003)(498600001)(110136005)(33656002)(66946007)(66556008)(64756008)(66446008)(6636002)(66476007)(76116006)(71200400001)(7696005)(2906002)(6506007)(107886003)(4326008)(186003)(9686003)(26005)(55016002)(83380400001)(8936002)(5660300002)(52536014)(86362001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: RdBRBK0ClY7kSk6hQVkXEfI0jhHY1/HkeM8WlBmwgWHn8t3uaihwUpv4RhzGDkLereCAT89rqCSfbGRwGRj8WyLCIQqPYiMERvI1u3bokzUm4d5cR6uXhqoKHIb6CKmgT9OGSHFvJRiaA76cLwd96e4XT4/F55M1GXLiIhNC/LKa9uFwT56c5omQnoRfvx7a5bFMjX3ATIb36/W7pWS1kogOu9/VeIpApNBiOOAwF1B+EIkDk34p3KcBY3AI51AW3sr8H2G1yzEB8Bt/Q1//xO+nCr+3enivaltUyxZ7hbwKn6JX/J7ZQdbyh1YMfkJtDpFVkeQFm/IfDopZlFQ67SPo30peMhQOrLwE8ak5l4M8jO+pYOqzuxkpklKDfJ6S1+ycIJzFNV8UAvoaSuDQlE4U8Q8z6hwAJUslOVNWKYtm9+9XBjnF28aaBIBSimyjEHZFVWJMU5SHRlAdcalmwvN4JMBYJkjcqwfPJTI0Tsg= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3301.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 815b82bb-21db-4421-db9d-08d828188f0e X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jul 2020 17:08:41.5957 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VdET+Y9I1LvRtjhxot+auJCOt83WnSNSamSdZdHPvTlS/cdfUwY4/mc+Gu1vd+0KzIS5GaXwDFVPHf4EnCYLA5Ce19gkxx3QZfKmgxdJgtg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB2534 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v4 3/3] examples/ipsec-secgw: Remove the re-implementation of inet_pton 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > inet_pton4 and inet_pton6 was reimplemented. Replace implementation of > inet_pton4 and inet_pton6 with libc inet_pton function >=20 > Bugzilla ID: 365 > Fixes: 0d547ed03717 ("examples/ipsec-secgw: support configuration file") > Cc: roy.fan.zhang@intel.com >=20 > Reported-by: David Marchand > Signed-off-by: Ibtisam Tariq > --- > v4: > * Added header file for FreeBSD. >=20 > v3: > * None >=20 > v2: > * Fixed the name of variable, passed as input to inet_pton function. > * Added fixed id in commit body > --- > examples/ipsec-secgw/parser.c | 172 +--------------------------------- > 1 file changed, 4 insertions(+), 168 deletions(-) >=20 > diff --git a/examples/ipsec-secgw/parser.c b/examples/ipsec-secgw/parser.= c > index 65eb7e9e2..99c3d3879 100644 > --- a/examples/ipsec-secgw/parser.c > +++ b/examples/ipsec-secgw/parser.c > @@ -10,6 +10,8 @@ > #include > #include > #include > +#include > +#include >=20 > #include "ipsec.h" > #include "parser.h" > @@ -39,172 +41,6 @@ parse_tokenize_string(char *string, char *tokens[], u= int32_t *n_tokens) > return 0; > } >=20 > -#define INADDRSZ 4 > -#define IN6ADDRSZ 16 > - > -/* int > - * inet_pton4(src, dst) > - * like inet_aton() but without all the hexadecimal and shorthand. > - * return: > - * 1 if `src' is a valid dotted quad, else 0. > - * notice: > - * does not touch `dst' unless it's returning 1. > - * author: > - * Paul Vixie, 1996. > - */ > -static int > -inet_pton4(const char *src, unsigned char *dst) > -{ > - static const char digits[] =3D "0123456789"; > - int saw_digit, octets, ch; > - unsigned char tmp[INADDRSZ], *tp; > - > - saw_digit =3D 0; > - octets =3D 0; > - *(tp =3D tmp) =3D 0; > - while ((ch =3D *src++) !=3D '\0') { > - const char *pch; > - > - pch =3D strchr(digits, ch); > - if (pch !=3D NULL) { > - unsigned int new =3D *tp * 10 + (pch - digits); > - > - if (new > 255) > - return 0; > - if (!saw_digit) { > - if (++octets > 4) > - return 0; > - saw_digit =3D 1; > - } > - *tp =3D (unsigned char)new; > - } else if (ch =3D=3D '.' && saw_digit) { > - if (octets =3D=3D 4) > - return 0; > - *++tp =3D 0; > - saw_digit =3D 0; > - } else > - return 0; > - } > - if (octets < 4) > - return 0; > - > - memcpy(dst, tmp, INADDRSZ); > - return 1; > -} > - > -/* int > - * inet_pton6(src, dst) > - * convert presentation level address to network order binary form. > - * return: > - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. > - * notice: > - * (1) does not touch `dst' unless it's returning 1. > - * (2) :: in a full address is silently ignored. > - * credit: > - * inspired by Mark Andrews. > - * author: > - * Paul Vixie, 1996. > - */ > -static int > -inet_pton6(const char *src, unsigned char *dst) > -{ > - static const char xdigits_l[] =3D "0123456789abcdef", > - xdigits_u[] =3D "0123456789ABCDEF"; > - unsigned char tmp[IN6ADDRSZ], *tp =3D 0, *endp =3D 0, *colonp =3D 0; > - const char *xdigits =3D 0, *curtok =3D 0; > - int ch =3D 0, saw_xdigit =3D 0, count_xdigit =3D 0; > - unsigned int val =3D 0; > - unsigned dbloct_count =3D 0; > - > - memset((tp =3D tmp), '\0', IN6ADDRSZ); > - endp =3D tp + IN6ADDRSZ; > - colonp =3D NULL; > - /* Leading :: requires some special handling. */ > - if (*src =3D=3D ':') > - if (*++src !=3D ':') > - return 0; > - curtok =3D src; > - saw_xdigit =3D count_xdigit =3D 0; > - val =3D 0; > - > - while ((ch =3D *src++) !=3D '\0') { > - const char *pch; > - > - pch =3D strchr((xdigits =3D xdigits_l), ch); > - if (pch =3D=3D NULL) > - pch =3D strchr((xdigits =3D xdigits_u), ch); > - if (pch !=3D NULL) { > - if (count_xdigit >=3D 4) > - return 0; > - val <<=3D 4; > - val |=3D (pch - xdigits); > - if (val > 0xffff) > - return 0; > - saw_xdigit =3D 1; > - count_xdigit++; > - continue; > - } > - if (ch =3D=3D ':') { > - curtok =3D src; > - if (!saw_xdigit) { > - if (colonp) > - return 0; > - colonp =3D tp; > - continue; > - } else if (*src =3D=3D '\0') { > - return 0; > - } > - if (tp + sizeof(int16_t) > endp) > - return 0; > - *tp++ =3D (unsigned char) ((val >> 8) & 0xff); > - *tp++ =3D (unsigned char) (val & 0xff); > - saw_xdigit =3D 0; > - count_xdigit =3D 0; > - val =3D 0; > - dbloct_count++; > - continue; > - } > - if (ch =3D=3D '.' && ((tp + INADDRSZ) <=3D endp) && > - inet_pton4(curtok, tp) > 0) { > - tp +=3D INADDRSZ; > - saw_xdigit =3D 0; > - dbloct_count +=3D 2; > - break; /* '\0' was seen by inet_pton4(). */ > - } > - return 0; > - } > - if (saw_xdigit) { > - if (tp + sizeof(int16_t) > endp) > - return 0; > - *tp++ =3D (unsigned char) ((val >> 8) & 0xff); > - *tp++ =3D (unsigned char) (val & 0xff); > - dbloct_count++; > - } > - if (colonp !=3D NULL) { > - /* if we already have 8 double octets, having a colon > - * means error */ > - if (dbloct_count =3D=3D 8) > - return 0; > - > - /* > - * Since some memmove()'s erroneously fail to handle > - * overlapping regions, we'll do the shift by hand. > - */ > - const int n =3D tp - colonp; > - int i; > - > - for (i =3D 1; i <=3D n; i++) { > - endp[-i] =3D colonp[n - i]; > - colonp[n - i] =3D 0; > - } > - tp =3D endp; > - } > - if (tp !=3D endp) > - return 0; > - memcpy(dst, tmp, IN6ADDRSZ); > - return 1; > -} > - > int > parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask) > { > @@ -229,7 +65,7 @@ parse_ipv4_addr(const char *token, struct in_addr *ipv= 4, uint32_t *mask) > if (strlen(ip_str) >=3D INET_ADDRSTRLEN) > return -EINVAL; >=20 > - if (inet_pton4(ip_str, (unsigned char *)ipv4) !=3D 1) > + if (inet_pton(AF_INET, ip_str, ipv4) !=3D 1) > return -EINVAL; >=20 > return 0; > @@ -260,7 +96,7 @@ parse_ipv6_addr(const char *token, struct in6_addr *ip= v6, uint32_t *mask) > if (strlen(ip_str) >=3D INET6_ADDRSTRLEN) > return -EINVAL; >=20 > - if (inet_pton6(ip_str, (unsigned char *)ipv6) !=3D 1) > + if (inet_pton(AF_INET6, ip_str, ipv6) !=3D 1) > return -EINVAL; >=20 > return 0; > -- Acked-by: Konstantin Ananyev > 2.17.1