From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0064.outbound.protection.outlook.com [104.47.2.64]) by dpdk.org (Postfix) with ESMTP id F073744BE for ; Tue, 2 Oct 2018 08:30:37 +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=o2LRQqt4xmlG9ZvbLLyVMGuUx6zB0cahN+jYzdeTPq0=; b=InFJ1lcSpSnAw09RpH+2kbgM5MmUh9y9GtuB3zkzh2TtRMeIIawmS2pgrzrvK5AN/pnibTP0hbo4xzj2QO/FPurgYkGuTDlTNxvNUuzRpuOy1rj6K70NHxxVjvQ6OSh4zEcdQ7Qaq1QX8Xg0jGIDy2Jj11/THIrtHWZdYDdtQ0M= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.186.150) by AM4PR05MB3443.eurprd05.prod.outlook.com (10.171.187.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Tue, 2 Oct 2018 06:30:36 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::81a1:b719:2345:50e5]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::81a1:b719:2345:50e5%5]) with mapi id 15.20.1185.024; Tue, 2 Oct 2018 06:30:36 +0000 From: Slava Ovsiienko To: "dev@dpdk.org" CC: Shahaf Shuler , Slava Ovsiienko Thread-Topic: [PATCH 2/5] net/mlx5: e-switch VXLAN netlink routines update Thread-Index: AQHUWhltm+DQLIgIZUK7lo+WLLLXLw== Date: Tue, 2 Oct 2018 06:30:36 +0000 Message-ID: <1538461807-37507-2-git-send-email-viacheslavo@mellanox.com> References: <1538461807-37507-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1538461807-37507-1-git-send-email-viacheslavo@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR02CA0019.eurprd02.prod.outlook.com (2603:10a6:208:3e::32) To AM4PR05MB3265.eurprd05.prod.outlook.com (2603:10a6:205:4::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR05MB3443; 6:3YfMn9GB2b4EnpV96VEGsjHqSadDJObU6K6CU3CovXXMgk3q4f/4lVVc3u48RtAdutkNL8it5jJEgP9fa2fFaa6oLu6oYgSz2O4bHdautf9pUSLIMTmTyWGFiyEE1T3/sbri/85zXQe0LYjLQj7rvOfnR5tl1xFgcsIh18QoVB5kdQr2GS6jGHW5Gxzh62slAuzjGrQUcxEN6WlxgQD3evy8SPH980Ik4ZbJZnegyHAcgC4pPXPp1UUK+dbcUTmsiaMDQORm6IsRAfaeAHED6rV3B1yZ8Kc4M6bNoT+A11RpS3ISMmw49+AJsi+oTZB7zvjvBptKzuJhZHlmTEhT54ZUhQsZPqx5GyU1oabRgL7Xjx0HxwB3/TCu7cZjc+ZuzRfVVKp3+fishaUPVw2PP6NScQd7+CFoHNCEcA6IUihT7NDqtqcck6US9FKgk9ynZIZhnzzf+0+2J8oYcjY8DA==; 5:ib2vGdqNJChVkdJF4R4dF+wqlEy4LgkqRLlnMq9lhaNV2UovE0a8fIHP6PDQEIvwDtNHIew/8QK6BenkX9gLMdJwdL2VonnJk0fjppbUNA9pWxMRaWWnP3hPaLyarvluwOciFwRNH3+SnWBTvEfK7QlNxiyo+t254FL+Jh5B3jQ=; 7:no4kJHKPH8UB4wBPDWhCPwSNloT068dxIA1cPUVHsifEkhvPIgsBexad1xsyMIBp3bta0GjY8W1jC2DlW/dbahkNxI3NV2+1EW7Pu225kWe7jaX4F1aZHKruniojb3B/1LqJHottPmC2peJMyEP4FYO+gp8ORW9nXfbFd6lPepK18Pu7tqeTFIUAUMc22p3HxhYZAZgec7b9fEt1fefPi7SCVm3AgTiA9YLMuNQypv1x/ogGWDKq2DYG08lvkcqq x-ms-office365-filtering-correlation-id: 36653fcd-a60b-4c53-3a22-08d62830904b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB3443; x-ms-traffictypediagnostic: AM4PR05MB3443: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(269456686620040)(211171220733660); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:AM4PR05MB3443; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB3443; x-forefront-prvs: 0813C68E65 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(136003)(39860400002)(376002)(366004)(346002)(189003)(199004)(5024004)(5640700003)(256004)(25786009)(14444005)(26005)(106356001)(54906003)(186003)(316002)(102836004)(68736007)(105586002)(6116002)(3846002)(97736004)(14454004)(81156014)(1730700003)(86362001)(2351001)(2900100001)(8676002)(575784001)(7736002)(2616005)(8936002)(476003)(305945005)(446003)(11346002)(81166006)(6486002)(52116002)(386003)(6436002)(6506007)(15650500001)(53936002)(2906002)(4326008)(71200400001)(36756003)(478600001)(486006)(99286004)(5250100002)(66066001)(76176011)(5660300001)(6512007)(2501003)(6916009)(4744004)(71190400001)(107886003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3443; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: pwel+OyXD8PG5SoM8fM5ciRb9CzHG+qNWfYmDWJiTs/90w095Lu57lb2QHtF6BSqMHG+7TYa8g8tTYBf6reoArYYl0UVFsNuBM5CTVH0g6puMjONWgVnxjB/U6gkua5YD330JAqJ2Zpsq5h7DxHR8FzktSRSTlwghiH6Qzk7zRhi0bxJbQbRqCyMszqju6/0tRaI3vORdQdSY+GP64re2FBYTN1DTIjF0faovINTSN6xIiKJh/xtl9kAKvmMNi048k6Moc7qldtKNhanpz9InM+t2DQg+zngWf8/XKF5qy5WLFzDIhwwsYZ1d2gmbd1a1GvGkAXh71z5+c3DMJbQbnTVvm14eqzfK1Zuo2FpN9g= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36653fcd-a60b-4c53-3a22-08d62830904b X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Oct 2018 06:30:36.7376 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3443 Subject: [dpdk-dev] [PATCH 2/5] net/mlx5: e-switch VXLAN netlink routines update 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: Tue, 02 Oct 2018 06:30:38 -0000 This part of patchset updates Netlink exchange routines. Message sequence numbers became not random ones, the multipart reply messages are supported, not propagating errors to the following socket calls, Netlink replies buffer size is increased to MNL_SOCKET_BUFFER_SIZE. Suggested-by: Adrien Mazarguil Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.c | 18 ++-- drivers/net/mlx5/mlx5.h | 7 +- drivers/net/mlx5/mlx5_flow.h | 9 +- drivers/net/mlx5/mlx5_flow_tcf.c | 214 +++++++++++++++++++++++------------= ---- 4 files changed, 147 insertions(+), 101 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 4be6a1c..201a26e 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -287,8 +287,7 @@ close(priv->nl_socket_route); if (priv->nl_socket_rdma >=3D 0) close(priv->nl_socket_rdma); - if (priv->mnl_socket) - mlx5_flow_tcf_socket_destroy(priv->mnl_socket); + mlx5_flow_tcf_socket_close(&priv->tcf_socket); ret =3D mlx5_hrxq_ibv_verify(dev); if (ret) DRV_LOG(WARNING, "port %u some hash Rx queue still remain", @@ -1138,8 +1137,9 @@ claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); if (vf && config.vf_nl_en) mlx5_nl_mac_addr_sync(eth_dev); - priv->mnl_socket =3D mlx5_flow_tcf_socket_create(); - if (!priv->mnl_socket) { + /* Initialize Netlink socket for e-switch control */ + err =3D mlx5_flow_tcf_socket_open(&priv->tcf_socket); + if (err) { err =3D -rte_errno; DRV_LOG(WARNING, "flow rules relying on switch offloads will not be" @@ -1154,16 +1154,15 @@ error.message =3D "cannot retrieve network interface index"; } else { - err =3D mlx5_flow_tcf_init(priv->mnl_socket, ifindex, - &error); + err =3D mlx5_flow_tcf_ifindex_init(&priv->tcf_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_flow_tcf_socket_destroy(priv->mnl_socket); - priv->mnl_socket =3D NULL; + mlx5_flow_tcf_socket_close(&priv->tcf_socket); } } TAILQ_INIT(&priv->flows); @@ -1218,8 +1217,7 @@ close(priv->nl_socket_route); if (priv->nl_socket_rdma >=3D 0) close(priv->nl_socket_rdma); - if (priv->mnl_socket) - mlx5_flow_tcf_socket_destroy(priv->mnl_socket); + mlx5_flow_tcf_socket_close(&priv->tcf_socket); if (own_domain_id) claim_zero(rte_eth_switch_domain_free(priv->domain_id)); rte_free(priv); diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 8de0d74..b327a39 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -160,6 +160,11 @@ struct mlx5_drop { =20 struct mnl_socket; =20 +struct mlx5_tcf_socket { + uint32_t seq; /* Message sequence number. */ + struct mnl_socket *nl; /* NETLINK_ROUTE libmnl 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. */ @@ -220,12 +225,12 @@ struct priv { int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */ int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */ uint32_t nl_sn; /* Netlink message sequence number. */ + struct mlx5_tcf_socket tcf_socket; /* Libmnl socket for tcf. */ #ifndef RTE_ARCH_64 rte_spinlock_t uar_lock_cq; /* CQs share a common distinct UAR */ rte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX]; /* UAR same-page access control required in 32bit implementations. */ #endif - struct mnl_socket *mnl_socket; /* Libmnl socket. */ }; =20 #define PORT_ID(priv) ((priv)->dev_data->port_id) diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 2d56ced..fff905a 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -348,9 +348,10 @@ int mlx5_flow_validate_item_vxlan_gpe(const struct rte= _flow_item *item, =20 /* mlx5_flow_tcf.c */ =20 -int mlx5_flow_tcf_init(struct mnl_socket *nl, unsigned int ifindex, - struct rte_flow_error *error); -struct mnl_socket *mlx5_flow_tcf_socket_create(void); -void mlx5_flow_tcf_socket_destroy(struct mnl_socket *nl); +int mlx5_flow_tcf_ifindex_init(struct mlx5_tcf_socket *tcf, + unsigned int ifindex, + struct rte_flow_error *error); +int mlx5_flow_tcf_socket_open(struct mlx5_tcf_socket *tcf); +void mlx5_flow_tcf_socket_close(struct mlx5_tcf_socket *tcf); =20 #endif /* RTE_PMD_MLX5_FLOW_H_ */ diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_= tcf.c index 5c93412..15e250c 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -1552,8 +1552,8 @@ struct flow_tcf_ptoi { /** * Send Netlink message with acknowledgment. * - * @param nl - * Libmnl socket to use. + * @param tcf + * Libmnl socket context to use. * @param nlh * Message to send. This function always raises the NLM_F_ACK flag befor= e * sending. @@ -1562,26 +1562,108 @@ struct flow_tcf_ptoi { * 0 on success, a negative errno value otherwise and rte_errno is set. */ static int -flow_tcf_nl_ack(struct mnl_socket *nl, struct nlmsghdr *nlh) +flow_tcf_nl_ack(struct mlx5_tcf_socket *tcf, struct nlmsghdr *nlh) { alignas(struct nlmsghdr) - uint8_t ans[mnl_nlmsg_size(sizeof(struct nlmsgerr)) + - nlh->nlmsg_len - sizeof(*nlh)]; - uint32_t seq =3D random(); - int ret; - + uint8_t ans[MNL_SOCKET_BUFFER_SIZE]; + unsigned int portid =3D mnl_socket_get_portid(tcf->nl); + uint32_t seq =3D tcf->seq++; + struct mnl_socket *nl =3D tcf->nl; + int err, ret; + + assert(nl); + if (!seq) + seq =3D tcf->seq++; nlh->nlmsg_flags |=3D NLM_F_ACK; nlh->nlmsg_seq =3D seq; ret =3D mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); - if (ret !=3D -1) - ret =3D mnl_socket_recvfrom(nl, ans, sizeof(ans)); - if (ret !=3D -1) - ret =3D mnl_cb_run - (ans, ret, seq, mnl_socket_get_portid(nl), NULL, NULL); + err =3D (ret <=3D 0) ? -errno : 0; + nlh =3D (struct nlmsghdr *)ans; + /* + * The following loop postpones non-fatal errors until multipart + * messages are complete. + */ if (ret > 0) + while (true) { + ret =3D mnl_socket_recvfrom(nl, ans, sizeof(ans)); + if (ret < 0) { + err =3D errno; + if (err !=3D ENOSPC) + break; + } + if (!err) { + ret =3D mnl_cb_run(nlh, ret, seq, portid, + NULL, NULL); + if (ret < 0) { + err =3D errno; + break; + } + } + /* Will receive till end of multipart message */ + if (!(nlh->nlmsg_flags & NLM_F_MULTI) || + nlh->nlmsg_type =3D=3D NLMSG_DONE) + break; + } + if (!err) return 0; - rte_errno =3D errno; - return -rte_errno; + rte_errno =3D err; + return -err; +} + +/** + * Initialize ingress qdisc of a given network interface. + * + * @param tcf + * Libmnl socket context object. + * @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_flow_tcf_ifindex_init(struct mlx5_tcf_socket *tcf, unsigned int ifind= ex, + struct rte_flow_error *error) +{ + struct nlmsghdr *nlh; + struct tcmsg *tcm; + alignas(struct nlmsghdr) + uint8_t buf[mnl_nlmsg_size(sizeof(*tcm) + 128)]; + + /* Destroy existing ingress qdisc and everything attached to it. */ + nlh =3D mnl_nlmsg_put_header(buf); + nlh->nlmsg_type =3D RTM_DELQDISC; + nlh->nlmsg_flags =3D NLM_F_REQUEST; + tcm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); + tcm->tcm_family =3D AF_UNSPEC; + tcm->tcm_ifindex =3D ifindex; + tcm->tcm_handle =3D TC_H_MAKE(TC_H_INGRESS, 0); + tcm->tcm_parent =3D TC_H_INGRESS; + /* Ignore errors when qdisc is already absent. */ + if (flow_tcf_nl_ack(tcf, nlh) && + rte_errno !=3D EINVAL && rte_errno !=3D 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 =3D mnl_nlmsg_put_header(buf); + nlh->nlmsg_type =3D RTM_NEWQDISC; + nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; + tcm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); + tcm->tcm_family =3D AF_UNSPEC; + tcm->tcm_ifindex =3D ifindex; + tcm->tcm_handle =3D TC_H_MAKE(TC_H_INGRESS, 0); + tcm->tcm_parent =3D TC_H_INGRESS; + mnl_attr_put_strz_check(nlh, sizeof(buf), TCA_KIND, "ingress"); + if (flow_tcf_nl_ack(tcf, nlh)) + return rte_flow_error_set(error, rte_errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "netlink: failed to create ingress" + " qdisc"); + return 0; } =20 /** @@ -1602,18 +1684,25 @@ struct flow_tcf_ptoi { struct rte_flow_error *error) { struct priv *priv =3D dev->data->dev_private; - struct mnl_socket *nl =3D priv->mnl_socket; + struct mlx5_tcf_socket *tcf =3D &priv->tcf_socket; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; + int ret; =20 dev_flow =3D LIST_FIRST(&flow->dev_flows); /* E-Switch flow can't be expanded. */ assert(!LIST_NEXT(dev_flow, next)); + if (dev_flow->tcf.applied) + return 0; nlh =3D dev_flow->tcf.nlh; nlh->nlmsg_type =3D RTM_NEWTFILTER; nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; - if (!flow_tcf_nl_ack(nl, nlh)) + ret =3D flow_tcf_nl_ack(tcf, nlh); + if (!ret) { + dev_flow->tcf.applied =3D 1; return 0; + } + DRV_LOG(WARNING, "Failed to create TC rule (%d)", rte_errno); return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "netlink: failed to create TC flow rule"); @@ -1631,7 +1720,7 @@ struct flow_tcf_ptoi { flow_tcf_remove(struct rte_eth_dev *dev, struct rte_flow *flow) { struct priv *priv =3D dev->data->dev_private; - struct mnl_socket *nl =3D priv->mnl_socket; + struct mlx5_tcf_socket *tcf =3D &priv->tcf_socket; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; =20 @@ -1645,7 +1734,8 @@ struct flow_tcf_ptoi { nlh =3D dev_flow->tcf.nlh; nlh->nlmsg_type =3D RTM_DELTFILTER; nlh->nlmsg_flags =3D NLM_F_REQUEST; - flow_tcf_nl_ack(nl, nlh); + flow_tcf_nl_ack(tcf, nlh); + dev_flow->tcf.applied =3D 0; } =20 /** @@ -1683,93 +1773,45 @@ struct flow_tcf_ptoi { }; =20 /** - * 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. + * Creates and configures a libmnl socket for Netlink flow rules. * + * @param tcf + * tcf socket object to be initialized by function. * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ int -mlx5_flow_tcf_init(struct mnl_socket *nl, unsigned int ifindex, - struct rte_flow_error *error) -{ - struct nlmsghdr *nlh; - struct tcmsg *tcm; - alignas(struct nlmsghdr) - uint8_t buf[mnl_nlmsg_size(sizeof(*tcm) + 128)]; - - /* Destroy existing ingress qdisc and everything attached to it. */ - nlh =3D mnl_nlmsg_put_header(buf); - nlh->nlmsg_type =3D RTM_DELQDISC; - nlh->nlmsg_flags =3D NLM_F_REQUEST; - tcm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); - tcm->tcm_family =3D AF_UNSPEC; - tcm->tcm_ifindex =3D ifindex; - tcm->tcm_handle =3D TC_H_MAKE(TC_H_INGRESS, 0); - tcm->tcm_parent =3D TC_H_INGRESS; - /* Ignore errors when qdisc is already absent. */ - if (flow_tcf_nl_ack(nl, nlh) && - rte_errno !=3D EINVAL && rte_errno !=3D 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 =3D mnl_nlmsg_put_header(buf); - nlh->nlmsg_type =3D RTM_NEWQDISC; - nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; - tcm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); - tcm->tcm_family =3D AF_UNSPEC; - tcm->tcm_ifindex =3D ifindex; - tcm->tcm_handle =3D TC_H_MAKE(TC_H_INGRESS, 0); - tcm->tcm_parent =3D TC_H_INGRESS; - mnl_attr_put_strz_check(nlh, sizeof(buf), TCA_KIND, "ingress"); - if (flow_tcf_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_flow_tcf_socket_create(void) +mlx5_flow_tcf_socket_open(struct mlx5_tcf_socket *tcf) { struct mnl_socket *nl =3D mnl_socket_open(NETLINK_ROUTE); =20 + tcf->nl =3D NULL; if (nl) { mnl_socket_setsockopt(nl, NETLINK_CAP_ACK, &(int){ 1 }, sizeof(int)); - if (!mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID)) - return nl; + if (!mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID)) { + tcf->nl =3D nl; + tcf->seq =3D random(); + return 0; + } } rte_errno =3D errno; if (nl) mnl_socket_close(nl); - return NULL; + return -rte_errno; } =20 /** - * Destroy a libmnl socket. + * Destroys tcf object (closes MNL socket). * - * @param nl - * Libmnl socket of the @p NETLINK_ROUTE kind. + * @param tcf + * tcf socket object to be destroyed by function. */ void -mlx5_flow_tcf_socket_destroy(struct mnl_socket *nl) +mlx5_flow_tcf_socket_close(struct mlx5_tcf_socket *tcf) { - mnl_socket_close(nl); + if (tcf->nl) { + mnl_socket_close(tcf->nl); + tcf->nl =3D NULL; + } } --=20 1.8.3.1