From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3F988A0C41; Wed, 15 Sep 2021 13:34:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A75714003F; Wed, 15 Sep 2021 13:34:48 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id E2E8A4003C for ; Wed, 15 Sep 2021 13:34:46 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10107"; a="221956516" X-IronPort-AV: E=Sophos;i="5.85,295,1624345200"; d="scan'208";a="221956516" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 04:34:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,295,1624345200"; d="scan'208";a="470720120" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by fmsmga007.fm.intel.com with ESMTP; 15 Sep 2021 04:34:45 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Wed, 15 Sep 2021 04:34:45 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Wed, 15 Sep 2021 04:34:45 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12 via Frontend Transport; Wed, 15 Sep 2021 04:34:45 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.46) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.12; Wed, 15 Sep 2021 04:34:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jcjl+VZBT/WniVcWPViarWlpk8WEKizYRyHWlOWx6unRbWfTEg8tMlbzs8UZVbZBYUJcTjvrFsAPAKbpIJ7ZZLZEJBtKnykR0OxgMTz1RwkT7DbN8OPqq2v0PMWfVxlqs94tRa5z8oFH7BDlInKMJZgS090qNCEdkzTMX/txNbg8l+on3T5XRXIlRpDd8sNPPw/8se0KGcAo7dUpIdnujt5CH0tTTe9WbX22/67gNVSq59LSWYhiyDQIKOOhc4QUu6RN8HapIClxhfu6nOFBSLrPuda5zo3ESAcg98NZUW+vGa4cFBkVT7q/pHjWZKvXiA1jO3LNEg1O34XfVb8vHg== 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; bh=Rx4weD9diiRFoE2Kh+LOziOgBBJVuLQdDGBDR0t0MkU=; b=oNegcYtzLYS7RpjPTacg8DFBeo4h8ipnuGHhkVAI1Un3aUSBoC0+xgJQrIlRvSXb3VbYActnomM/mKtXtWSNJZRdev9eSLcGAvnpIsmInSpzU4xMtZMVLpirH2ef4OedZgbgmTxjMVZt1aFmbZMhvrFkt9NFPOeRsbvvn3KVOTgU7jv41K5+X4SGBmS8gP5UC9QzudftHyA8PjlliUtfjKdEBbiO4SSHTZIqYK+S+WJBIDQBBbt67TKtfmV6cU1EBWcYANCdTsJDda/u5je3PXdrxbH7+095FTxkjDLJ09G3SuvbuuNi8vScUGobTXQznzYyT3w/a2kQY3LIYe6RHw== 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=Rx4weD9diiRFoE2Kh+LOziOgBBJVuLQdDGBDR0t0MkU=; b=hpDLuvlOBmsV5qoJRPyzM8DFNGec6SlaRGI794Gc5N8pwJft27OPLqjKq+GnNUJwhQrhNNfUYxmxjVPYVWE/n4XBj0JAqW45Xx9uqEQyyYLXNJBY2c5Zc7L4bcrQMaslbUip0gspbznfwUbM6Ehqc6qIrBAJJEGAykEagSCHoLw= Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by DM5PR11MB1292.namprd11.prod.outlook.com (2603:10b6:3:7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Wed, 15 Sep 2021 11:34:43 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::740e:126e:c785:c8fd]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::740e:126e:c785:c8fd%4]) with mapi id 15.20.4523.014; Wed, 15 Sep 2021 11:34:43 +0000 From: "Ananyev, Konstantin" To: Stephen Hemminger , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v8 08/12] test: add test for bpf_convert Thread-Index: AQHXqMt55dz29O80cUi7i114jAVHL6uk9/7A Date: Wed, 15 Sep 2021 11:34:43 +0000 Message-ID: References: <20210903004732.109023-1-stephen@networkplumber.org> <20210913181510.46058-1-stephen@networkplumber.org> <20210913181510.46058-9-stephen@networkplumber.org> In-Reply-To: <20210913181510.46058-9-stephen@networkplumber.org> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 authentication-results: networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8648cd5f-ca0c-4b7b-7d66-08d9783cd01d x-ms-traffictypediagnostic: DM5PR11MB1292: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:137; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /7vjh0YXvs5eXefSXB7La3+1EqP5rafk7zUwoJBe0FkhTJjI2NV49PeNwqizhKn9Yce5gyIathzrs/r0gTHMc/Qcv6OFTIvofD1NR+b8ZbrF4lfFtmHDabusFdV9N1dtL+J+CO+U++f6e+8Wo1Sq++dTlsttDNcjcbP+cO0kOR525WgroTdlj2cXUcyJQY5l9fNOsnm1Rsv+6t8v6wh9aDIZZB3SvgI91yIcBpxKi3k37c1EQSN9U+1+chg9iR3lHtQ9pMMgxG6maUtu7xg+Q7UN1fwONknILjgQJwslFWDLzX/Sx+abH74m7AXLr9y7RFiNAAqI7DHcnCOvEhAdiqDsNKWyC5G3c5OoDUel6IYCDl84v59ztlumdtaxss8cKSGtorx344/VKspEKq3IDwqdZuGFUbgZ8Zo7TyooIS4sMwyHEkabXlf2tpq3md7qzGrLFgHM7ZcuZmcUiYwlSUObTvuTsay5zYJhKM028YUhkRnSb9yfgFzXoeInpMeULctW9UquDgCapON2q1EbByiO23K7KwWfdoRV75zTuVGtw/UFovfkjJrakLIONJ3cmP6eb8s0k7vHwSpNGbRXotrzrpa16BfcUouqcoCdo8JVQ7uQruCL5EKW7WgVFkFsZaBtIUjY+7FJohZDBaKYLKgZXV+Vc/JamRheSWB94Yd4wgQmt+vsbbnUMCLTyjA2qJOZ8sZNEOGSoMlA3W9Xkkw+7TQ5IQ15RRpQnxXBQ9jb4IEliivV0dkMjo3kdZSk5eiJLsiBosc2FLnGU1k4QIwPxsNPL19P9q4S1fmkamA= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(39860400002)(376002)(366004)(346002)(110136005)(71200400001)(6506007)(33656002)(478600001)(5660300002)(2906002)(83380400001)(7696005)(8936002)(9686003)(38070700005)(55016002)(86362001)(122000001)(52536014)(66946007)(186003)(26005)(8676002)(66446008)(64756008)(66556008)(316002)(66476007)(55236004)(76116006)(38100700002)(966005)(15974865002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?sJa3yV4o1Bh5mc7UeZ+j895U6fJDq+Rk6riyr9z0zK60uFBgL+CQpZTMYMvx?= =?us-ascii?Q?jUjAn6DIExbqWZ0uNNXVOTenGNcjE/Wq1ud/Iybl942A/tYYJvCdo4J0X58T?= =?us-ascii?Q?j6wgjcRxaq8TD7AuOAmSmG8hYuhWqFQzUqFyR4xi0aSgNeClDqlqlDEVE7Tj?= =?us-ascii?Q?jsnbgiYsM7DMw5OYDsA4O/hqwRofOgvlZylgiL0KM4wIHaYnmLMSkFyRozyv?= =?us-ascii?Q?yjzDcSemAX/sZUt3h51GW8/UDOjMQQuQG7YSGaYJQ9ovDmW2omgc05elpqum?= =?us-ascii?Q?ewgoZrOHrvctaEcOMH7mSUuwgt/g6sKD02LbTV+kKaU/gDS/1EBlm+GXeARm?= =?us-ascii?Q?Z0Z7rMsK5DZFy5JCad44s5qn2sgiV+UdwUqKmTEdecjh7PqXdkCGv61dptI5?= =?us-ascii?Q?/bbOmWLfhxw/l+tKrM2gTy7MMS2pme/BEN1s6gGYv8UNG7hpA8Nf0LJ3ebO9?= =?us-ascii?Q?oehioYtp/+4rluJmQqn0RaIY2aUuIOtIDsVPQ2sDBBgnOfGgWd4gNzax/XBx?= =?us-ascii?Q?HI25zvs+KfB0x+pT9Pd3TjlygfMKQOjFUpKsJjJ2n2wb461Ds9BRLaQS+ZeM?= =?us-ascii?Q?PccWvXjRrlgj0OSKhsPOwZei/xt8CXg1j7G7TlpbFAK7o9lnWkPQOjypolAB?= =?us-ascii?Q?KT0m/uvkZOrwea1rK1OYoPKA4NoFRmVA/AaKElg+RpAEqXdzFwymunc39m8Z?= =?us-ascii?Q?mFOI95mNKo4LvK3qVeoRiNxGDGqqDHSL+fS/xe/Q0YSGjqH/6nGD41UgS8Df?= =?us-ascii?Q?hMFZ4J4GjAd6qgs8zSrbhYH3gZNtL6+PbYJZwLoQNxjDDkZ9HVzLestjOHUa?= =?us-ascii?Q?6wMfvdtPjI3i6ILhVYirVD71wKvx7NacbmLMIPCEw/9SKAWBy7cuIDcjb/Nk?= =?us-ascii?Q?My5JooSP2Rn6HFvyavo9hu68VJsaPPXramf4rCcpRotgl30uDQp4VBorDcfe?= =?us-ascii?Q?Gzz4jCDfCIJ1Mu518ZKZ6a8ZTu7WSi8UrUjdnOJoXt141+M8QPpvpjVpaYWn?= =?us-ascii?Q?3ULdqNRunROeVYYC5bD9rGlIZuOB2YKHXLlyoM9qWg4qm2Fx6lYYZJ6Nt7/O?= =?us-ascii?Q?lKO+N/ys4+f6/ZA9DqJwGf04t+Pg+KkmVv2FdAMJSAYTiufk1yWXe+JbZVTX?= =?us-ascii?Q?NGyl8VmP+7+ubKJEsvgj7UgNRDQNAGiY2ZvIT4raXwQUC/4H3vcPd1T8Z1ms?= =?us-ascii?Q?MStc1x5cWDKj7BDBtORQQz8LsiwlJkS3LMi4XkqcAtrAoPIxZbU5VW0uDk2j?= =?us-ascii?Q?qn5iX8eKzwRMuY+qgZy6CHVADLVFxK6Jsy1For11tuvNy3Oa8XeVt65lik5w?= =?us-ascii?Q?ytO0VmNwlUJRw11BJEIEKvrA?= x-ms-exchange-transport-forked: True 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: DM6PR11MB4491.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8648cd5f-ca0c-4b7b-7d66-08d9783cd01d X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Sep 2021 11:34:43.3530 (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: 14d2nVjCAfn/AeuKtAa33FY8BJJLhqI+OvQyk5ivZ7I7QyrpOhE5RLoZdLs6ZnO2+vcVx+yKQjPcoxsVyDA4Tn15bBky2VLadhMVu0fWUX0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1292 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v8 08/12] test: add test for bpf_convert X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" >=20 > Add some functional tests for the Classic BPF to DPDK BPF converter. >=20 > Signed-off-by: Stephen Hemminger > --- > app/test/test_bpf.c | 173 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 173 insertions(+) >=20 > diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c > index 527c06b80708..1b5a178241d8 100644 > --- a/app/test/test_bpf.c > +++ b/app/test/test_bpf.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -3233,3 +3234,175 @@ test_bpf(void) > } >=20 > REGISTER_TEST_COMMAND(bpf_autotest, test_bpf); > + > +#ifdef RTE_PORT_PCAP > +#include > + > +static void > +test_bpf_dump(struct bpf_program *cbf, const struct rte_bpf_prm *prm) > +{ > + printf("cBPF program (%u insns)\n", cbf->bf_len); > + bpf_dump(cbf, 1); > + > + printf("\neBPF program (%u insns)\n", prm->nb_ins); > + rte_bpf_dump(stdout, prm->ins, prm->nb_ins); > +} > + > +static int > +test_bpf_match(pcap_t *pcap, const char *str, bool expected) > +{ > + struct bpf_program fcode; > + struct rte_bpf_prm *prm =3D NULL; > + struct rte_bpf *bpf =3D NULL; > + uint8_t tbuf[sizeof(struct dummy_mbuf)]; > + int ret =3D -1; > + uint64_t rc; > + > + if (pcap_compile(pcap, &fcode, str, 1, PCAP_NETMASK_UNKNOWN)) { > + printf("%s@%d: pcap_compile(\"%s\") failed: %s;\n", > + __func__, __LINE__, str, pcap_geterr(pcap)); > + return -1; > + } > + > + prm =3D rte_bpf_convert(&fcode); > + if (prm =3D=3D NULL) { > + printf("%s@%d: bpf_convert('%s') failed,, error=3D%d(%s);\n", > + __func__, __LINE__, str, rte_errno, strerror(rte_errno)); > + goto error; > + } > + > + bpf =3D rte_bpf_load(prm); > + if (bpf =3D=3D NULL) { > + printf("%s@%d: failed to load bpf code, error=3D%d(%s);\n", > + __func__, __LINE__, rte_errno, strerror(rte_errno)); > + goto error; > + } > + > + test_ld_mbuf1_prepare(tbuf); > + rc =3D rte_bpf_exec(bpf, tbuf); > + if ((rc =3D=3D 0) =3D=3D expected) > + ret =3D 0; > + else > + printf("%s@%d: failed match: expect %s 0 got %"PRIu64"\n", > + __func__, __LINE__, expected ? "=3D=3D" : "<>", rc); > +error: > + if (bpf) > + rte_bpf_destroy(bpf); > + rte_free(prm); > + pcap_freecode(&fcode); > + return ret; > +} > + > +/* Basic sanity test can we match a IP packet */ > +static int > +test_bpf_filter_sanity(pcap_t *pcap) > +{ > + int ret; > + > + ret =3D test_bpf_match(pcap, "ip", true); > + ret |=3D test_bpf_match(pcap, "not ip", false); > + > + return ret; > +} > + > +/* > + * Some sample pcap filter strings from > + * https://wiki.wireshark.org/CaptureFilters > + */ > +static const char * const sample_filters[] =3D { > + "host 172.18.5.4", > + "net 192.168.0.0/24", > + "src net 192.168.0.0/24", > + "src net 192.168.0.0 mask 255.255.255.0", > + "dst net 192.168.0.0/24", > + "dst net 192.168.0.0 mask 255.255.255.0", > + "port 53", > + "host www.example.com and not (port 80 or port 25)", > + "host www.example.com and not port 80 and not port 25", > + "port not 53 and not arp", > + "(tcp[0:2] > 1500 and tcp[0:2] < 1550) or (tcp[2:2] > 1500 and tcp[2:2]= < 1550)", > + "ether proto 0x888e", > + "ether[0] & 1 =3D 0 and ip[16] >=3D 224", > + "icmp[icmptype] !=3D icmp-echo and icmp[icmptype] !=3D icmp-echoreply", > + "tcp[tcpflags] & (tcp-syn|tcp-fin) !=3D 0 and not src and dst net 127.0= .0.1", > + "not ether dst 01:80:c2:00:00:0e", > + "not broadcast and not multicast", > + "dst host ff02::1", > + "port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] =3D 0x47455420", > + /* Worms */ > + "dst port 135 and tcp port 135 and ip[2:2]=3D=3D48", > + "icmp[icmptype]=3D=3Dicmp-echo and ip[2:2]=3D=3D92 and icmp[8:4]=3D=3D0= xAAAAAAAA", > + "dst port 135 or dst port 445 or dst port 1433" > + " and tcp[tcpflags] & (tcp-syn) !=3D 0" > + " and tcp[tcpflags] & (tcp-ack) =3D 0 and src net 192.168.0.0/24", > + "tcp src port 443 and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4] =3D 0x18)" > + " and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4 + 1] =3D 0x03)" > + " and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4 + 2] < 0x04)" > + " and ((ip[2:2] - 4 * (ip[0] & 0x0F) - 4 * ((tcp[12] & 0xF0) >> 4) > 69= ))", > + /* Other */ > + "len =3D 128", > +}; > + > +static int > +test_bpf_filter(pcap_t *pcap, const char *s) > +{ > + struct bpf_program fcode; > + struct rte_bpf_prm *prm =3D NULL; > + struct rte_bpf *bpf =3D NULL; > + > + if (pcap_compile(pcap, &fcode, s, 1, PCAP_NETMASK_UNKNOWN)) { > + printf("%s@%d: pcap_compile('%s') failed: %s;\n", > + __func__, __LINE__, s, pcap_geterr(pcap)); > + return -1; > + } > + > + prm =3D rte_bpf_convert(&fcode); > + if (prm =3D=3D NULL) { > + printf("%s@%d: bpf_convert('%s') failed,, error=3D%d(%s);\n", > + __func__, __LINE__, s, rte_errno, strerror(rte_errno)); > + goto error; > + } > + > + bpf =3D rte_bpf_load(prm); > + if (bpf =3D=3D NULL) { > + printf("%s@%d: failed to load bpf code, error=3D%d(%s);\n", > + __func__, __LINE__, rte_errno, strerror(rte_errno)); > + goto error; > + } > + > +error: > + if (bpf) > + rte_bpf_destroy(bpf); > + else { > + printf("%s \"%s\"\n", __func__, s); > + test_bpf_dump(&fcode, prm); > + } > + > + rte_free(prm); > + pcap_freecode(&fcode); > + return (bpf =3D=3D NULL) ? -1 : 0; > +} > + > +static int > +test_bpf_convert(void) > +{ > + unsigned int i; > + pcap_t *pcap; > + int rc; > + > + pcap =3D pcap_open_dead(DLT_EN10MB, 262144); > + if (!pcap) { > + printf("pcap_open_dead failed\n"); > + return -1; > + } > + > + rc =3D test_bpf_filter_sanity(pcap); > + for (i =3D 0; i < RTE_DIM(sample_filters); i++) > + rc |=3D test_bpf_filter(pcap, sample_filters[i]); > + > + pcap_close(pcap); > + return rc; > +} > + > +REGISTER_TEST_COMMAND(bpf_convert_autotest, test_bpf_convert); > +#endif /* RTE_PORT_PCAP */ > -- Acked-by: Konstantin Ananyev > 2.30.2