From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01hn0228.outbound.protection.outlook.com [104.47.2.228]) by dpdk.org (Postfix) with ESMTP id 9C1B91B57C for ; Thu, 12 Jul 2018 02:17: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=Yug4QFFBC4jCu9cVpJytt3rs3NVbPO6ie+qqMAzWMfI=; b=Ra3ypOTR/VzMpc0IqHC15XitWAEzRp42R7uuiKPLwKW1uwHw8MJ4XU+sQV8+3DJX8obf3h5nEA3uOuZamc379txm+SktvjtROs1U2kl9kvvgdERcGODmUaElN2oaW/yQO2JRHFM5CNq6SCH7idg9jAhtAcTz/XZwhOsbBvoOdxE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; Received: from yongseok-MBP.local (209.116.155.178) by VI1PR0501MB2045.eurprd05.prod.outlook.com (2603:10a6:800:36::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.18; Thu, 12 Jul 2018 00:17:22 +0000 Date: Wed, 11 Jul 2018 17:17:09 -0700 From: Yongseok Koh To: Adrien Mazarguil Cc: Shahaf Shuler , Nelio Laranjeiro , dev@dpdk.org Message-ID: <20180712001652.GC69686@yongseok-MBP.local> References: <20180627173355.4718-1-adrien.mazarguil@6wind.com> <20180627173355.4718-2-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180627173355.4718-2-adrien.mazarguil@6wind.com> User-Agent: Mutt/1.9.3 (2018-01-21) X-Originating-IP: [209.116.155.178] X-ClientProxiedBy: BN6PR2001CA0034.namprd20.prod.outlook.com (2603:10b6:405:16::20) To VI1PR0501MB2045.eurprd05.prod.outlook.com (2603:10a6:800:36::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 987138d1-3b59-47ab-0f13-08d5e78cd750 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600053)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2045; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2045; 3:GbgCWkb0jOwvC0HkbmxHnbq2N6DwRwWRyhZB0ynpd3Pyp4+cTFh2WvLYOdvfKZjTd+lgOOLd+GIY2RPiUBoihFCkYvAwy+rzPFdO5Wq4meYyyvhfiCl8C77O73Bx8brOkXVlDIJUunXXSH8UspUuaHvl9uysE7JerIG5G89JmfdOeO572AX7nmKDWLqJv6DiRHupWDzs1tqQ1NJoM9VrcjZG2dliswTuf7bwCg3kDKZj12H6uXrTJNOxTotPI3X6; 25:RGqaPk53tOOMg/YO43Undcin0E+4vNbyUez7o4RjmS4FyWBpU+2LZIvAXvuh7CWN3+DOfL7BHWfh32DvAi+cOFOkSwcl/Yq9RSsezd4f0gYmaIJ1PlcFL+/F5viSl3R3J4DktoigfH3+7wJLuEaniCfuqemrTGGYxPBB9D1BZip9ztEruWKg2zeQQpAFGdbiF1OBDHJxDod4Vgymm6PJTpqzZfEfxb9HA1Nj91aVK6/eJXm9W2tCghjci133xIbvlDNZq+c9BmMcfHkTY19/VX/NxzAmFu/hfo0o0RoptqAYTrMsuYOCkYl1z1UlWMNUNkBCqN/SU6tHbXsLxo3BUA==; 31:s+NfwqqdVDg/Es9wz1ykyWI+FZRknxzGHZcCwv2xwod+b2Gmg2h+jAA87uxCTK7iqolN5bvdFUk3WL1D+14OK5JSM6EnQmUhhzaAl0MWqwh+7clJ8AtZGpGc3ke1TWvxYZmL6P1i8bWY3itdJuPb7vLjJFP/pkhYBuRXevVq9FzHHAqUP2Uav6sjAXjJwEgFDMFFUgZYmNjRcarqe4JQAzJqrrEhbELTjflbDlBMX9Y= X-MS-TrafficTypeDiagnostic: VI1PR0501MB2045:|VI1PR0501MB2045: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2045; 20:VEIq/4oGNrUlzcGAh+HGyouqJBB+5aTUv78aYqP6VUAFMZmN6GcYoyx21B3jp/zhEjxhbba/CS6BkfH6kKwFfiDKGaa8Qh2/wfHItRStpjXQcWtN7reLpShf8/hXrZtcj37AFp74CWeO9UnODINKeGRLqDOejwvdpuef44HtGdI5lfLRA5NGPNni6AY9xo1bXPcwt4guhs/EiisxxUKvDkjxfLwEYM/Y0pmmNO6PUg0zSmI9ED6iwMvD5O0PjxY/D51Ebk56L4m224uY/6FCs5v3qFmogzVO6jguitG1RJXTdckNsR4iRxlecwBx1p2657INfMuuMnMdVoSvU2s813OTPObA0gkYa/2on8woXeaIIVJeynpa5xokMoUXULByOBzal1FIja+qoaoVYbIzbC6gBuxLLZ57yk80OUZrGiZS642bLMEila9dJlujkYmfk0j2ngbQDWaqyDBLoLl+J2T6aoOPRmeuUHf4QKy96CGy7JzuAdzyDOdqlSzgnsxT; 4:eOFSxvPtjjSUI3mjeUFbcjDeIWG+jC0oOKa1fhKgHNyug8XWsMuEOVvqccGKftMCrA1L5zqdGhjVz+KVo5dXs8sa9Ur5ievKQPAUio/jP090uTbtC0m34qoUkJfaB4Mpje95wwvVFPDYL9Arxio7w8mpOGn2DOyjIfZgl/dZ1QBoYfqjUoQ5tDl6oZbSVeCucCzA7c24NlrpjvT+EXnNRNGRgkK421OgTUqEpLx/LINS5yHog5TQEiUYbt60n4ORfNcsec+fZ5M4j6nn15AO8EbY13GeIuyqJ8RYDz5jgU1NWPrAIk8inIdJvyAzfwrDcAbtW39MvmiDgfRGQECvVlM7f7MBWliVZP0rRY4VE/XRf+1IFARJgyb5b0KbweeeEiS+Qh//hTMjJN9I7o/iYZuFS03nArqQSxE7zj+2pNM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(189930954265078)(66839620246622)(45079756050767)(211171220733660); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231311)(2232096)(944501410)(52105095)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:VI1PR0501MB2045; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2045; X-Forefront-PRVS: 0731AA2DE6 X-Forefront-Antispam-Report: SFV:SPM; SFS:(10009020)(39860400002)(366004)(376002)(136003)(396003)(346002)(199004)(189003)(14444005)(97736004)(7736002)(23726003)(5024004)(3846002)(6116002)(8936002)(1076002)(229853002)(305945005)(4326008)(486006)(68736007)(25786009)(47776003)(386003)(33656002)(446003)(5660300001)(52116002)(11346002)(6246003)(66066001)(76176011)(86362001)(575784001)(81166006)(7696005)(316002)(53936002)(956004)(45080400002)(16586007)(81156014)(55016002)(478600001)(58126008)(476003)(8676002)(966005)(54906003)(6306002)(9686003)(33896004)(98436002)(6506007)(16526019)(6666003)(2906002)(6916009)(105586002)(186003)(106356001)(50466002)(26005)(59010400001); DIR:OUT; SFP:1501; SCL:5; SRVR:VI1PR0501MB2045; H:yongseok-MBP.local; 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-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2045; 23:WHNF+iP4SsE1IVTMUffFLaKUucJRilvPSGl0eYx?= =?us-ascii?Q?IpM9EF8qAWE4gX9yv1ZvatfXETAtyzDqFpCwoWFKZtNyyKqIhwghLr2bNO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+idv2INwRaUBqGyJQaQT1ZTIeT6l6V01cxC+IT5SI0RQ== SpamDiagnosticOutput: 1:22 X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2045; 7:5jY/YW0c+f9RTTAvGvje65sewlJoGEI4wahZBoR2qRvrQxEnnfBLLfj2JP4St9AWf2BuJzF8K0qIYlK1sBwgkpZVz97uaUyaTLCF3S87L54y4K5IW++MOwVDeIpihL9+s678e8zp6qUz5TO9L+s0EAWPjT3vuLIQLhc7x7MqBX0sZPQiCpGrtaEFHtAsX92m8JsnQinDWK73JaR0Z8em+y5E+Iln/C0bTuodZM9i06NGj/RxNcP6PB7tw8IFTZ72 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2018 00:17:22.6350 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 987138d1-3b59-47ab-0f13-08d5e78cd750 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2045 Subject: Re: [dpdk-dev] [PATCH 1/6] net/mlx5: lay groundwork for switch offloads 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: Thu, 12 Jul 2018 00:17:35 -0000 On Wed, Jun 27, 2018 at 08:08:10PM +0200, Adrien Mazarguil wrote: > With mlx5, unlike normal flow rules implemented through Verbs for traffic > emitted and received by the application, those targeting different logical > ports of the device (VF representors for instance) are offloaded at the > switch level and must be configured through Netlink (TC interface). > > This patch adds preliminary support to manage such flow rules through the > flow API (rte_flow). > > Instead of rewriting tons of Netlink helpers and as previously suggested by > Stephen [1], this patch introduces a new dependency to libmnl [2] > (LGPL-2.1) when compiling mlx5. > > [1] https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmails.dpdk.org%2Farchives%2Fdev%2F2018-March%2F092676.html&data=02%7C01%7Cyskoh%40mellanox.com%7C1250093eca0c4ad6d9f008d5dc58fbb4%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636657197116524482&sdata=JrAyzK1s3JG5CnuquNcA7XRN4d2WYtHUi1KXyloGdvA%3D&reserved=0 > [2] https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fnetfilter.org%2Fprojects%2Flibmnl%2F&data=02%7C01%7Cyskoh%40mellanox.com%7C1250093eca0c4ad6d9f008d5dc58fbb4%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636657197116524482&sdata=yLYa0NzsTyE62BHDCZDoDah31snt6w4Coq47pY913Oo%3D&reserved=0 > > Signed-off-by: Adrien Mazarguil > --- > drivers/net/mlx5/Makefile | 2 + > drivers/net/mlx5/mlx5.c | 32 ++++++++ > drivers/net/mlx5/mlx5.h | 10 +++ > drivers/net/mlx5/mlx5_nl_flow.c | 139 +++++++++++++++++++++++++++++++++++ > mk/rte.app.mk | 2 +- > 5 files changed, 184 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile > index 8a5229e61..3325eed06 100644 > --- a/drivers/net/mlx5/Makefile > +++ b/drivers/net/mlx5/Makefile > @@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_mr.c > SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_flow.c > SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_socket.c > SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_nl.c > +SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_nl_flow.c > > ifeq ($(CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS),y) > INSTALL-$(CONFIG_RTE_LIBRTE_MLX5_PMD)-lib += $(LIB_GLUE) > @@ -56,6 +57,7 @@ LDLIBS += -ldl > else > LDLIBS += -libverbs -lmlx5 > endif > +LDLIBS += -lmnl > LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring > LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs > LDLIBS += -lrte_bus_pci > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c > index 665a3c31f..d9b9097b1 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -279,6 +279,8 @@ mlx5_dev_close(struct rte_eth_dev *dev) > mlx5_nl_mac_addr_flush(dev); > if (priv->nl_socket >= 0) > close(priv->nl_socket); > + if (priv->mnl_socket) > + mlx5_nl_flow_socket_destroy(priv->mnl_socket); > ret = mlx5_hrxq_ibv_verify(dev); > if (ret) > DRV_LOG(WARNING, "port %u some hash Rx queue still remain", > @@ -1077,6 +1079,34 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev, > priv->nl_socket = -1; > mlx5_nl_mac_addr_sync(eth_dev); > } > + priv->mnl_socket = mlx5_nl_flow_socket_create(); > + if (!priv->mnl_socket) { > + err = -rte_errno; > + DRV_LOG(WARNING, > + "flow rules relying on switch offloads will not be" > + " supported: cannot open libmnl socket: %s", > + strerror(rte_errno)); > + } else { > + struct rte_flow_error error; > + unsigned int ifindex = mlx5_ifindex(eth_dev); > + > + if (!ifindex) { > + err = -rte_errno; > + error.message = > + "cannot retrieve network interface index"; > + } else { > + err = mlx5_nl_flow_init(priv->mnl_socket, ifindex, > + &error); > + } > + if (err) { > + DRV_LOG(WARNING, > + "flow rules relying on switch offloads will" > + " not be supported: %s: %s", > + error.message, strerror(rte_errno)); > + mlx5_nl_flow_socket_destroy(priv->mnl_socket); > + priv->mnl_socket = NULL; > + } > + } > TAILQ_INIT(&priv->flows); > TAILQ_INIT(&priv->ctrl_flows); > /* Hint libmlx5 to use PMD allocator for data plane resources */ > @@ -1127,6 +1157,8 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev, > if (priv) { > unsigned int i; > > + if (priv->mnl_socket) > + mlx5_nl_flow_socket_destroy(priv->mnl_socket); > i = mlx5_domain_to_port_id(priv->domain_id, NULL, 0); > if (i == 1) > claim_zero(rte_eth_switch_domain_free(priv->domain_id)); > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h > index 1d8e156c8..390249adb 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -148,6 +148,8 @@ struct mlx5_drop { > struct mlx5_rxq_ibv *rxq; /* Verbs Rx queue. */ > }; > > +struct mnl_socket; > + > struct priv { > LIST_ENTRY(priv) mem_event_cb; /* Called by memory event callback. */ > struct rte_eth_dev_data *dev_data; /* Pointer to device data. */ > @@ -207,6 +209,7 @@ struct priv { > /* Context for Verbs allocator. */ > int nl_socket; /* Netlink socket. */ > uint32_t nl_sn; /* Netlink message sequence number. */ > + struct mnl_socket *mnl_socket; /* Libmnl socket. */ > }; > > #define PORT_ID(priv) ((priv)->dev_data->port_id) > @@ -369,4 +372,11 @@ void mlx5_nl_mac_addr_flush(struct rte_eth_dev *dev); > int mlx5_nl_promisc(struct rte_eth_dev *dev, int enable); > int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable); > > +/* mlx5_nl_flow.c */ > + > +int mlx5_nl_flow_init(struct mnl_socket *nl, unsigned int ifindex, > + struct rte_flow_error *error); > +struct mnl_socket *mlx5_nl_flow_socket_create(void); > +void mlx5_nl_flow_socket_destroy(struct mnl_socket *nl); > + > #endif /* RTE_PMD_MLX5_H_ */ > diff --git a/drivers/net/mlx5/mlx5_nl_flow.c b/drivers/net/mlx5/mlx5_nl_flow.c > new file mode 100644 > index 000000000..7a8683b03 > --- /dev/null > +++ b/drivers/net/mlx5/mlx5_nl_flow.c > @@ -0,0 +1,139 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright 2018 6WIND S.A. > + * Copyright 2018 Mellanox Technologies, Ltd > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include "mlx5.h" > + > +/** > + * Send Netlink message with acknowledgment. > + * > + * @param nl > + * Libmnl socket to use. > + * @param nlh > + * Message to send. This function always raises the NLM_F_ACK flag before > + * sending. > + * > + * @return > + * 0 on success, a negative errno value otherwise and rte_errno is set. > + */ > +static int > +mlx5_nl_flow_nl_ack(struct mnl_socket *nl, struct nlmsghdr *nlh) > +{ > + alignas(struct nlmsghdr) > + uint8_t ans[MNL_SOCKET_BUFFER_SIZE]; There are total 3 of this buffer. On a certain host having large pagesize, this can be 8kB * 3 = 24kB. This is not a gigantic buffer but as all the functions here are sequentially accessed, how about having just one global buffer instead? > + uint32_t seq = random(); > + int ret; > + > + nlh->nlmsg_flags |= NLM_F_ACK; > + nlh->nlmsg_seq = seq; > + ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); > + if (ret != -1) > + ret = mnl_socket_recvfrom(nl, ans, sizeof(ans)); > + if (ret != -1) > + ret = mnl_cb_run > + (ans, ret, seq, mnl_socket_get_portid(nl), NULL, NULL); > + if (!ret) > + return 0; > + rte_errno = errno; > + return -rte_errno; > +} > + > +/** > + * Initialize ingress qdisc of a given network interface. > + * > + * @param nl > + * Libmnl socket of the @p NETLINK_ROUTE kind. > + * @param ifindex > + * Index of network interface to initialize. > + * @param[out] error > + * Perform verbose error reporting if not NULL. > + * > + * @return > + * 0 on success, a negative errno value otherwise and rte_errno is set. > + */ > +int > +mlx5_nl_flow_init(struct mnl_socket *nl, unsigned int ifindex, > + struct rte_flow_error *error) > +{ > + uint8_t buf[MNL_SOCKET_BUFFER_SIZE]; > + struct nlmsghdr *nlh; > + struct tcmsg *tcm; > + > + /* Destroy existing ingress qdisc and everything attached to it. */ > + nlh = mnl_nlmsg_put_header(buf); > + nlh->nlmsg_type = RTM_DELQDISC; > + nlh->nlmsg_flags = NLM_F_REQUEST; > + tcm = mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); > + tcm->tcm_family = AF_UNSPEC; > + tcm->tcm_ifindex = ifindex; > + tcm->tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0); > + tcm->tcm_parent = TC_H_INGRESS; > + /* Ignore errors when qdisc is already absent. */ > + if (mlx5_nl_flow_nl_ack(nl, nlh) && > + rte_errno != EINVAL && rte_errno != ENOENT) > + return rte_flow_error_set > + (error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > + NULL, "netlink: failed to remove ingress qdisc"); > + /* Create fresh ingress qdisc. */ > + nlh = mnl_nlmsg_put_header(buf); > + nlh->nlmsg_type = RTM_NEWQDISC; > + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; > + tcm = mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); > + tcm->tcm_family = AF_UNSPEC; > + tcm->tcm_ifindex = ifindex; > + tcm->tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0); > + tcm->tcm_parent = TC_H_INGRESS; > + mnl_attr_put_strz_check(nlh, sizeof(buf), TCA_KIND, "ingress"); > + if (mlx5_nl_flow_nl_ack(nl, nlh)) > + return rte_flow_error_set > + (error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > + NULL, "netlink: failed to create ingress qdisc"); > + return 0; > +} > + > +/** > + * Create and configure a libmnl socket for Netlink flow rules. > + * > + * @return > + * A valid libmnl socket object pointer on success, NULL otherwise and > + * rte_errno is set. > + */ > +struct mnl_socket * > +mlx5_nl_flow_socket_create(void) > +{ > + struct mnl_socket *nl = mnl_socket_open(NETLINK_ROUTE); > + > + if (nl && > + !mnl_socket_setsockopt(nl, NETLINK_CAP_ACK, &(int){ 1 }, > + sizeof(int)) && > + !mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID)) > + return nl; > + rte_errno = errno; > + if (nl) > + mnl_socket_close(nl); > + return NULL; > +} > + > +/** > + * Destroy a libmnl socket. > + */ > +void > +mlx5_nl_flow_socket_destroy(struct mnl_socket *nl) > +{ > + mnl_socket_close(nl); > +} > diff --git a/mk/rte.app.mk b/mk/rte.app.mk > index 7bcf6308d..414f1b967 100644 > --- a/mk/rte.app.mk > +++ b/mk/rte.app.mk > @@ -145,7 +145,7 @@ endif > ifeq ($(CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS),y) > _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -ldl > else > -_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -libverbs -lmlx5 > +_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -libverbs -lmlx5 -lmnl > endif > _LDLIBS-$(CONFIG_RTE_LIBRTE_MVPP2_PMD) += -lrte_pmd_mvpp2 -L$(LIBMUSDK_PATH)/lib -lmusdk > _LDLIBS-$(CONFIG_RTE_LIBRTE_NFP_PMD) += -lrte_pmd_nfp > -- > 2.11.0