From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20073.outbound.protection.outlook.com [40.107.2.73]) by dpdk.org (Postfix) with ESMTP id 217BB1B1EE for ; Thu, 1 Nov 2018 13:19:37 +0100 (CET) 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=z5k7SAPMlyIFC/BZyJN+qXlNnds4WthQHDXGGjio9Ow=; b=AD8pEqvhwYZKpE6hx8TdEd8DLc8WA/R5NVP9CebMJ208S0t34q0x6X5N/Bwq7ZUSrp8QBeFR2zoqeagT4UPUGkJulHpskAK2L5AJJBzAmqgFoJ7HI9PIyi4hiWeJA2Ufd8OQskP/qE2JYzc1FuHs7O3aFj5GeeP1cTL3+QXvvjY= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.186.150) by AM4PR05MB1457.eurprd05.prod.outlook.com (10.164.79.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1273.20; Thu, 1 Nov 2018 12:19:35 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::544b:a68d:e6a5:ba6e]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::544b:a68d:e6a5:ba6e%2]) with mapi id 15.20.1273.030; Thu, 1 Nov 2018 12:19:35 +0000 From: Slava Ovsiienko To: Shahaf Shuler CC: "dev@dpdk.org" , Yongseok Koh , Slava Ovsiienko Thread-Topic: [PATCH v3 13/13] net/mlx5: add e-switch VXLAN rule cleanup routines Thread-Index: AQHUcd0mpqcllQ/GR0WlBhhGWWopaQ== Date: Thu, 1 Nov 2018 12:19:35 +0000 Message-ID: <1541074741-41368-14-git-send-email-viacheslavo@mellanox.com> References: <1539612815-47199-1-git-send-email-viacheslavo@mellanox.com> <1541074741-41368-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1541074741-41368-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: LO2P265CA0079.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::19) 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; AM4PR05MB1457; 6:X7MJ7ffM9JBkN3Ww+M5DBTQynZJoaDO0xHWkN23jeAICL1uWosAg59LfGfscaq4YLj/o2ioR2yZ6LygilzdYALFHbyGKKX6h6wYw8nV8/VzbDTtrpLz3RXSQOKCnejRI31mbONnrsFa+CUZ61krJCIQ9duslgIHNQVQ0+8LYFW5xVspRP7hccWr4nxvwphJfliXxjibAtlGX0Er7VKJMkqCkLj2uozsxA46q13uq32QUTcvwFh3om+ZzY8IE3liBXNXneyDAlGpzo7f04JuqVW+ISyc/I+qspo1FzFNdcXgBsSUUGvEqFjSuWugyCfV4CpXtYF4mNh+4DewkPd7UOxYmothjdkON29m6k1LHgB4ZFro87yrT+QZlexjSaryGpFlt8asviL0EasV41H26rEN0LYWK/yhNMXYiC4rZjVSSanAYNpYILubnRDk2OSIkAYCVlg2voq1cxirImncMug==; 5:D2X/JbfENoQ0zNKzCxNAd8SXnhgzQE2+bZI7djTm0O3VmjqPgVCh6u4m2R37dDsqqxsDGe41tzxrWDquGFJ/K/p7DDkgCobuUC4K/N8UnuOTLF4Ubu10PX2xBgi32WkmLXA7FOfeRo1P6oY9w212kYcOKrL7w00wL4WuSUo6APY=; 7:ZTgF/OG+QUzZm9rv4HwOLyDAiixiXffLYcy8Fzgjcu6XWQJ5xvf9ovwGKoTXT5ZE2Z9+gHqpNZc7XJOzqsNEGrOdym+6zMbR7+vcmaxJX0pwN2kuiYUO2FkTDt3ujEakKe5ucXWMWGUnB8LpGhRFkQ== x-ms-office365-filtering-correlation-id: 73887710-a54f-4bfb-9b81-08d63ff4492c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB1457; x-ms-traffictypediagnostic: AM4PR05MB1457: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231382)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:AM4PR05MB1457; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB1457; x-forefront-prvs: 0843C17679 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(39860400002)(346002)(136003)(366004)(199004)(189003)(11346002)(446003)(106356001)(476003)(105586002)(4326008)(97736004)(2616005)(478600001)(6636002)(5250100002)(99286004)(486006)(66066001)(6862004)(2900100001)(25786009)(37006003)(54906003)(5660300001)(316002)(8936002)(8676002)(81156014)(81166006)(4744004)(68736007)(7736002)(305945005)(3846002)(6116002)(76176011)(2906002)(102836004)(26005)(186003)(386003)(6506007)(107886003)(14454004)(6486002)(52116002)(53946003)(6512007)(53936002)(6436002)(36756003)(86362001)(71190400001)(71200400001)(14444005)(5024004)(256004)(21314003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB1457; H:AM4PR05MB3265.eurprd05.prod.outlook.com; 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-antispam-message-info: vOjc2O3EO18l+qjmiA4e/Bn1yEVkLrijggBCl/tKUzlYzVDIMa4UZvG4FCZwoXdEYIEUsKjY4BYJKtmgMjIPZ4jEyewWZsD9rW2zvtSqd8ztJzBbIxUFUYKjwEx5PKKr7w2tQLYTKsPBrc9R9t+4ix9KqHG5/ngHkvylznBQCCFtGo+yULKmbMe482LFr5D7MSFbtyf6nbS0TGk19iGbXXPKirqLTyAjPq4X+QIdYVCw23XzVgOmXteyo3ELGk4ZRguRor829OYBD9gGKynOMD99GX+HYlu9rl44H9SNzeOWVIBTPeVXlD7pl+w4D4vgs/YxZUO2SCIIJQYfR4mXjsTW6ymu23tNb9cLuLFe8xo= 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: 73887710-a54f-4bfb-9b81-08d63ff4492c X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Nov 2018 12:19:35.6265 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB1457 Subject: [dpdk-dev] [PATCH v3 13/13] net/mlx5: add e-switch VXLAN rule cleanup routines 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, 01 Nov 2018 12:19:37 -0000 The last part of patchset contains the rule cleanup routines. These ones is the part of outer interface initialization at the moment of VXLAN VTEP attaching. These routines query the list of attached VXLAN devices, the list of local IP addresses with peer and link scope attribute and the list of permanent neigh rules, then all found abovementioned items on the specified outer device are flushed. Suggested-by: Adrien Mazarguil Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_flow_tcf.c | 495 +++++++++++++++++++++++++++++++++++= +++- 1 file changed, 494 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_= tcf.c index eae80ae..420816f 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -3756,6 +3756,496 @@ struct pedit_parser { #define MNL_REQUEST_SIZE RTE_MIN(RTE_MAX(sysconf(_SC_PAGESIZE), \ MNL_REQUEST_SIZE_MIN), MNL_REQUEST_SIZE_MAX) =20 +/* Data structures used by flow_tcf_xxx_cb() routines. */ +struct tcf_nlcb_buf { + LIST_ENTRY(tcf_nlcb_buf) next; + uint32_t size; + alignas(struct nlmsghdr) + uint8_t msg[]; /**< Netlink message data. */ +}; + +struct tcf_nlcb_context { + unsigned int ifindex; /**< Base interface index. */ + uint32_t bufsize; + LIST_HEAD(, tcf_nlcb_buf) nlbuf; +}; + +/** + * Allocate space for netlink command in buffer list + * + * @param[in, out] ctx + * Pointer to callback context with command buffers list. + * @param[in] size + * Required size of data buffer to be allocated. + * + * @return + * Pointer to allocated memory, aligned as message header. + * NULL if some error occurred. + */ +static struct nlmsghdr * +flow_tcf_alloc_nlcmd(struct tcf_nlcb_context *ctx, uint32_t size) +{ + struct tcf_nlcb_buf *buf; + struct nlmsghdr *nlh; + + size =3D NLMSG_ALIGN(size); + buf =3D LIST_FIRST(&ctx->nlbuf); + if (buf && (buf->size + size) <=3D ctx->bufsize) { + nlh =3D (struct nlmsghdr *)&buf->msg[buf->size]; + buf->size +=3D size; + return nlh; + } + if (size > ctx->bufsize) { + DRV_LOG(WARNING, "netlink: too long command buffer requested"); + return NULL; + } + buf =3D rte_malloc(__func__, + ctx->bufsize + sizeof(struct tcf_nlcb_buf), + alignof(struct tcf_nlcb_buf)); + if (!buf) { + DRV_LOG(WARNING, "netlink: no memory for command buffer"); + return NULL; + } + LIST_INSERT_HEAD(&ctx->nlbuf, buf, next); + buf->size =3D size; + nlh =3D (struct nlmsghdr *)&buf->msg[0]; + return nlh; +} + +/** + * Set NLM_F_ACK flags in the last netlink command in buffer. + * Only last command in the buffer will be acked by system. + * + * @param[in, out] buf + * Pointer to buffer with netlink commands. + */ +static void +flow_tcf_setack_nlcmd(struct tcf_nlcb_buf *buf) +{ + struct nlmsghdr *nlh; + uint32_t size =3D 0; + + assert(buf->size); + do { + nlh =3D (struct nlmsghdr *)&buf->msg[size]; + size +=3D NLMSG_ALIGN(nlh->nlmsg_len); + if (size >=3D buf->size) { + nlh->nlmsg_flags |=3D NLM_F_ACK; + break; + } + } while (true); +} + +/** + * Send the buffers with prepared netlink commands. Scans the list and + * sends all found buffers. Buffers are sent and freed anyway in order + * to prevent memory leakage if some every message in received packet. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_context_create(). + * @param[in, out] ctx + * Pointer to callback context with command buffers list. + * + * @return + * Zero value on success, negative errno value otherwise + * and rte_errno is set. + */ +static int +flow_tcf_send_nlcmd(struct mlx5_flow_tcf_context *tcf, + struct tcf_nlcb_context *ctx) +{ + struct tcf_nlcb_buf *bc, *bn; + struct nlmsghdr *nlh; + int ret =3D 0; + + bc =3D LIST_FIRST(&ctx->nlbuf); + while (bc) { + int rc; + + bn =3D LIST_NEXT(bc, next); + if (bc->size) { + flow_tcf_setack_nlcmd(bc); + nlh =3D (struct nlmsghdr *)&bc->msg; + rc =3D flow_tcf_nl_ack(tcf, nlh, bc->size, NULL, NULL); + if (rc && !ret) + ret =3D rc; + } + rte_free(bc); + bc =3D bn; + } + LIST_INIT(&ctx->nlbuf); + return ret; +} + +/** + * Collect local IP address rules with scope link attribute on specified + * network device. This is callback routine called by libmnl mnl_cb_run() + * in loop for every message in received packet. + * + * @param[in] nlh + * Pointer to reply header. + * @param[in, out] arg + * Opaque data pointer for this callback. + * + * @return + * A positive, nonzero value on success, negative errno value otherwise + * and rte_errno is set. + */ +static int +flow_tcf_collect_local_cb(const struct nlmsghdr *nlh, void *arg) +{ + struct tcf_nlcb_context *ctx =3D arg; + struct nlmsghdr *cmd; + struct ifaddrmsg *ifa; + struct nlattr *na; + struct nlattr *na_local =3D NULL; + struct nlattr *na_peer =3D NULL; + unsigned char family; + + if (nlh->nlmsg_type !=3D RTM_NEWADDR) { + rte_errno =3D EINVAL; + return -rte_errno; + } + ifa =3D mnl_nlmsg_get_payload(nlh); + family =3D ifa->ifa_family; + if (ifa->ifa_index !=3D ctx->ifindex || + ifa->ifa_scope !=3D RT_SCOPE_LINK || + !(ifa->ifa_flags & IFA_F_PERMANENT) || + (family !=3D AF_INET && family !=3D AF_INET6)) + return 1; + mnl_attr_for_each(na, nlh, sizeof(*ifa)) { + switch (mnl_attr_get_type(na)) { + case IFA_LOCAL: + na_local =3D na; + break; + case IFA_ADDRESS: + na_peer =3D na; + break; + } + if (na_local && na_peer) + break; + } + if (!na_local || !na_peer) + return 1; + /* Local rule found with scope link, permanent and assigned peer. */ + cmd =3D flow_tcf_alloc_nlcmd(ctx, MNL_ALIGN(sizeof(struct nlmsghdr)) + + MNL_ALIGN(sizeof(struct ifaddrmsg)) + + (family =3D=3D AF_INET6 + ? 2 * SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) + : 2 * SZ_NLATTR_TYPE_OF(uint32_t))); + if (!cmd) { + rte_errno =3D ENOMEM; + return -rte_errno; + } + cmd =3D mnl_nlmsg_put_header(cmd); + cmd->nlmsg_type =3D RTM_DELADDR; + cmd->nlmsg_flags =3D NLM_F_REQUEST; + ifa =3D mnl_nlmsg_put_extra_header(cmd, sizeof(*ifa)); + ifa->ifa_flags =3D IFA_F_PERMANENT; + ifa->ifa_scope =3D RT_SCOPE_LINK; + ifa->ifa_index =3D ctx->ifindex; + if (family =3D=3D AF_INET) { + ifa->ifa_family =3D AF_INET; + ifa->ifa_prefixlen =3D 32; + mnl_attr_put_u32(cmd, IFA_LOCAL, mnl_attr_get_u32(na_local)); + mnl_attr_put_u32(cmd, IFA_ADDRESS, mnl_attr_get_u32(na_peer)); + } else { + ifa->ifa_family =3D AF_INET6; + ifa->ifa_prefixlen =3D 128; + mnl_attr_put(cmd, IFA_LOCAL, IPV6_ADDR_LEN, + mnl_attr_get_payload(na_local)); + mnl_attr_put(cmd, IFA_ADDRESS, IPV6_ADDR_LEN, + mnl_attr_get_payload(na_peer)); + } + return 1; +} + +/** + * Cleanup the local IP addresses on outer interface. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_context_create(). + * @param[in] ifindex + * Network inferface index to perform cleanup. + */ +static void +flow_tcf_encap_local_cleanup(struct mlx5_flow_tcf_context *tcf, + unsigned int ifindex) +{ + struct nlmsghdr *nlh; + struct ifaddrmsg *ifa; + struct tcf_nlcb_context ctx =3D { + .ifindex =3D ifindex, + .bufsize =3D MNL_REQUEST_SIZE, + .nlbuf =3D LIST_HEAD_INITIALIZER(), + }; + int ret; + + assert(ifindex); + /* + * Seek and destroy leftovers of local IP addresses with + * matching properties "scope link". + */ + nlh =3D mnl_nlmsg_put_header(tcf->buf); + nlh->nlmsg_type =3D RTM_GETADDR; + nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_DUMP; + ifa =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*ifa)); + ifa->ifa_family =3D AF_UNSPEC; + ifa->ifa_index =3D ifindex; + ifa->ifa_scope =3D RT_SCOPE_LINK; + ret =3D flow_tcf_nl_ack(tcf, nlh, 0, flow_tcf_collect_local_cb, &ctx); + if (ret) + DRV_LOG(WARNING, "netlink: query device list error %d", ret); + ret =3D flow_tcf_send_nlcmd(tcf, &ctx); + if (ret) + DRV_LOG(WARNING, "netlink: device delete error %d", ret); +} + +/** + * Collect neigh permament rules on specified network device. + * This is callback routine called by libmnl mnl_cb_run() in loop for + * every message in received packet. + * + * @param[in] nlh + * Pointer to reply header. + * @param[in, out] arg + * Opaque data pointer for this callback. + * + * @return + * A positive, nonzero value on success, negative errno value otherwise + * and rte_errno is set. + */ +static int +flow_tcf_collect_neigh_cb(const struct nlmsghdr *nlh, void *arg) +{ + struct tcf_nlcb_context *ctx =3D arg; + struct nlmsghdr *cmd; + struct ndmsg *ndm; + struct nlattr *na; + struct nlattr *na_ip =3D NULL; + struct nlattr *na_mac =3D NULL; + unsigned char family; + + if (nlh->nlmsg_type !=3D RTM_NEWNEIGH) { + rte_errno =3D EINVAL; + return -rte_errno; + } + ndm =3D mnl_nlmsg_get_payload(nlh); + family =3D ndm->ndm_family; + if (ndm->ndm_ifindex !=3D (int)ctx->ifindex || + !(ndm->ndm_state & NUD_PERMANENT) || + (family !=3D AF_INET && family !=3D AF_INET6)) + return 1; + mnl_attr_for_each(na, nlh, sizeof(*ndm)) { + switch (mnl_attr_get_type(na)) { + case NDA_DST: + na_ip =3D na; + break; + case NDA_LLADDR: + na_mac =3D na; + break; + } + if (na_mac && na_ip) + break; + } + if (!na_mac || !na_ip) + return 1; + /* Neigh rule with permenent attribute found. */ + cmd =3D flow_tcf_alloc_nlcmd(ctx, MNL_ALIGN(sizeof(struct nlmsghdr)) + + MNL_ALIGN(sizeof(struct ndmsg)) + + SZ_NLATTR_DATA_OF(ETHER_ADDR_LEN) + + (family =3D=3D AF_INET6 + ? SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) + : SZ_NLATTR_TYPE_OF(uint32_t))); + if (!cmd) { + rte_errno =3D ENOMEM; + return -rte_errno; + } + cmd =3D mnl_nlmsg_put_header(cmd); + cmd->nlmsg_type =3D RTM_DELNEIGH; + cmd->nlmsg_flags =3D NLM_F_REQUEST; + ndm =3D mnl_nlmsg_put_extra_header(cmd, sizeof(*ndm)); + ndm->ndm_ifindex =3D ctx->ifindex; + ndm->ndm_state =3D NUD_PERMANENT; + ndm->ndm_flags =3D 0; + ndm->ndm_type =3D 0; + if (family =3D=3D AF_INET) { + ndm->ndm_family =3D AF_INET; + mnl_attr_put_u32(cmd, NDA_DST, mnl_attr_get_u32(na_ip)); + } else { + ndm->ndm_family =3D AF_INET6; + mnl_attr_put(cmd, NDA_DST, IPV6_ADDR_LEN, + mnl_attr_get_payload(na_ip)); + } + mnl_attr_put(cmd, NDA_LLADDR, ETHER_ADDR_LEN, + mnl_attr_get_payload(na_mac)); + return 1; +} + +/** + * Cleanup the neigh rules on outer interface. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_context_create(). + * @param[in] ifindex + * Network inferface index to perform cleanup. + */ +static void +flow_tcf_encap_neigh_cleanup(struct mlx5_flow_tcf_context *tcf, + unsigned int ifindex) +{ + struct nlmsghdr *nlh; + struct ndmsg *ndm; + struct tcf_nlcb_context ctx =3D { + .ifindex =3D ifindex, + .bufsize =3D MNL_REQUEST_SIZE, + .nlbuf =3D LIST_HEAD_INITIALIZER(), + }; + int ret; + + assert(ifindex); + /* Seek and destroy leftovers of neigh rules. */ + nlh =3D mnl_nlmsg_put_header(tcf->buf); + nlh->nlmsg_type =3D RTM_GETNEIGH; + nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_DUMP; + ndm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*ndm)); + ndm->ndm_family =3D AF_UNSPEC; + ndm->ndm_ifindex =3D ifindex; + ndm->ndm_state =3D NUD_PERMANENT; + ret =3D flow_tcf_nl_ack(tcf, nlh, 0, flow_tcf_collect_neigh_cb, &ctx); + if (ret) + DRV_LOG(WARNING, "netlink: query device list error %d", ret); + ret =3D flow_tcf_send_nlcmd(tcf, &ctx); + if (ret) + DRV_LOG(WARNING, "netlink: device delete error %d", ret); +} + +/** + * Collect indices of VXLAN encap/decap interfaces associated with device. + * This is callback routine called by libmnl mnl_cb_run() in loop for + * every message in received packet. + * + * @param[in] nlh + * Pointer to reply header. + * @param[in, out] arg + * Opaque data pointer for this callback. + * + * @return + * A positive, nonzero value on success, negative errno value otherwise + * and rte_errno is set. + */ +static int +flow_tcf_collect_vxlan_cb(const struct nlmsghdr *nlh, void *arg) +{ + struct tcf_nlcb_context *ctx =3D arg; + struct nlmsghdr *cmd; + struct ifinfomsg *ifm; + struct nlattr *na; + struct nlattr *na_info =3D NULL; + struct nlattr *na_vxlan =3D NULL; + bool found =3D false; + unsigned int vxindex; + + if (nlh->nlmsg_type !=3D RTM_NEWLINK) { + rte_errno =3D EINVAL; + return -rte_errno; + } + ifm =3D mnl_nlmsg_get_payload(nlh); + if (!ifm->ifi_index) { + rte_errno =3D EINVAL; + return -rte_errno; + } + mnl_attr_for_each(na, nlh, sizeof(*ifm)) + if (mnl_attr_get_type(na) =3D=3D IFLA_LINKINFO) { + na_info =3D na; + break; + } + if (!na_info) + return 1; + mnl_attr_for_each_nested(na, na_info) { + switch (mnl_attr_get_type(na)) { + case IFLA_INFO_KIND: + if (!strncmp("vxlan", mnl_attr_get_str(na), + mnl_attr_get_len(na))) + found =3D true; + break; + case IFLA_INFO_DATA: + na_vxlan =3D na; + break; + } + if (found && na_vxlan) + break; + } + if (!found || !na_vxlan) + return 1; + found =3D false; + mnl_attr_for_each_nested(na, na_vxlan) { + if (mnl_attr_get_type(na) =3D=3D IFLA_VXLAN_LINK && + mnl_attr_get_u32(na) =3D=3D ctx->ifindex) { + found =3D true; + break; + } + } + if (!found) + return 1; + /* Attached VXLAN device found, store the command to delete. */ + vxindex =3D ifm->ifi_index; + cmd =3D flow_tcf_alloc_nlcmd(ctx, MNL_ALIGN(sizeof(struct nlmsghdr)) + + MNL_ALIGN(sizeof(struct ifinfomsg))); + if (!nlh) { + rte_errno =3D ENOMEM; + return -rte_errno; + } + cmd =3D mnl_nlmsg_put_header(cmd); + cmd->nlmsg_type =3D RTM_DELLINK; + cmd->nlmsg_flags =3D NLM_F_REQUEST; + ifm =3D mnl_nlmsg_put_extra_header(cmd, sizeof(*ifm)); + ifm->ifi_family =3D AF_UNSPEC; + ifm->ifi_index =3D vxindex; + return 1; +} + +/** + * Cleanup the outer interface. Removes all found vxlan devices + * attached to specified index, flushes the meigh and local IP + * datavase. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_context_create(). + * @param[in] ifindex + * Network inferface index to perform cleanup. + */ +static void +flow_tcf_encap_iface_cleanup(struct mlx5_flow_tcf_context *tcf, + unsigned int ifindex) +{ + struct nlmsghdr *nlh; + struct ifinfomsg *ifm; + struct tcf_nlcb_context ctx =3D { + .ifindex =3D ifindex, + .bufsize =3D MNL_REQUEST_SIZE, + .nlbuf =3D LIST_HEAD_INITIALIZER(), + }; + int ret; + + assert(ifindex); + /* + * Seek and destroy leftover VXLAN encap/decap interfaces with + * matching properties. + */ + nlh =3D mnl_nlmsg_put_header(tcf->buf); + nlh->nlmsg_type =3D RTM_GETLINK; + nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_DUMP; + ifm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); + ifm->ifi_family =3D AF_UNSPEC; + ret =3D flow_tcf_nl_ack(tcf, nlh, 0, flow_tcf_collect_vxlan_cb, &ctx); + if (ret) + DRV_LOG(WARNING, "netlink: query device list error %d", ret); + ret =3D flow_tcf_send_nlcmd(tcf, &ctx); + if (ret) + DRV_LOG(WARNING, "netlink: device delete error %d", ret); +} + /** * Emit Netlink message to add/remove local address to the outer device. * The address being added is visible within the link only (scope link). @@ -4325,7 +4815,7 @@ struct pedit_parser { rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "netlink: failed to create VTEP, " - "VXLAN metadata are not supported by kernel"); + "vxlan metadata are not supported by kernel"); return NULL; } #endif /* HAVE_IFLA_VXLAN_COLLECT_METADATA */ @@ -4415,6 +4905,9 @@ struct pedit_parser { uint16_t pcnt; =20 /* Not found, we should create the new attached VTEP. */ + flow_tcf_encap_iface_cleanup(tcf, ifouter); + flow_tcf_encap_local_cleanup(tcf, ifouter); + flow_tcf_encap_neigh_cleanup(tcf, ifouter); for (pcnt =3D 0; pcnt <=3D (MLX5_VXLAN_PORT_MAX - MLX5_VXLAN_PORT_MIN); pcnt++) { encap_port++; --=20 1.8.3.1