From patchwork Tue Oct 2 06:30:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 45804 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 64B2E4CB3; Tue, 2 Oct 2018 08:30:46 +0200 (CEST) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00073.outbound.protection.outlook.com [40.107.0.73]) by dpdk.org (Postfix) with ESMTP id AD66A4D3A for ; Tue, 2 Oct 2018 08:30:43 +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=qdlpXxt+XYi6k2UZ/mmLdPvjnX1dQJqx9OiOVckhrsQ=; b=eC7la7d5lA/ypUaH9XgVNhBZTKphVayMUvPeSGLBO2Hsa9MxDSO4zgNrT3nxmZwArikpi9i4OjoMticdThqek2nO81p+HL0Uv06M7Om6PtCXMipHTSAjlRBuWUymtf9jsdaFtcv2pdu++xvJYPjIX9gXKIwUpE1uDJIY73sSF+U= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.186.150) by AM4PR05MB3284.eurprd05.prod.outlook.com (10.171.186.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.22; Tue, 2 Oct 2018 06:30:42 +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:42 +0000 From: Slava Ovsiienko To: "dev@dpdk.org" CC: Shahaf Shuler , Slava Ovsiienko Thread-Topic: [PATCH 5/5] net/mlx5: e-switch VXLAN tunnel devices management Thread-Index: AQHUWhlxq79e/tSVaEucP+fG+hh4Dg== Date: Tue, 2 Oct 2018 06:30:42 +0000 Message-ID: <1538461807-37507-5-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; AM4PR05MB3284; 6:V+KhsqPh7IJsMFZKCq6C3Bg5ssPxUfR3vzJEYOaJwYRlHzuFStT6tU1trtfFbVCBBVLpCwGFvGv2DXCakTY3/k7F07vD62Bec1GMZdP4yGmHr4LQuxG8k708MiWZOvRKQejMAMmVu5fW71JkSiNxt7QUUOV18cmOlOuKxHNkb1yndqpS/gmZ0V8PjWEY+ELb1ttafhmK2957FDFpEUEdTwS7x9MH97tvWYAt/qSknwZWyVn4g658DKJhYOne8PoqhgPJAtxbT1knv49QzAAHtHbsGmsWcfDM+DevveZHvuf4YkNkVOzTxcSisTezF94wzH43rZPHMC2YuHsvpUYWl7XQnURoT9rxXI95ez4Yx+8bnfx6lPkKefF9dKJtAiyN/9RU3pW9tIn4OUW18NKkIDXHv33xB0og7AHWIr9sJLG2snZau+Fuw+62dpfxRSSsUuhNYKjSUmHB8rVS5Qa/VQ==; 5:upWyKs6PgrQ6TuyQJnFFS55zhQ19Jem5lzrckR4kj2AV1Jc0cJ52ZIZf3h4M80jI9gDeMHpbxoKoXGHENs8Bj0bwVUYPAn5T69u8PZu2tp8nCp3/IhwwwTvq32ssHewXgOl6Hqr7WTYqoHZkqVelAZX8gQewe86cop14eG7HZlc=; 7:M7SdFbpCjL7hiYa1KM5bV3D2Ox3Fp3fru5AZ0r94iZOt7u1vAvpaUWOljorffZULTqF3jeJEoxAXDKrJql1mFKBWViHHoc3VHEk8W9evOZ/EbHThJCL3MgqRAyTgplCbgGVcKWSwkeu1WJRuw8PBCpeee1Tc+eVSIpG2lwy9B5ziPiNNb/mJMb0Q7g/iWbV6PNpbtoINmeXJydGLg4fbVfMUZZb+mjjN3EyJXP448xj4FV2pA8e9Hd1/4JKqt9Ga x-ms-office365-filtering-correlation-id: 3bd80dd8-f4d9-48eb-6bd0-08d628309377 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:AM4PR05MB3284; x-ms-traffictypediagnostic: AM4PR05MB3284: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(211171220733660)(788757137089); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231355)(944501410)(52105095)(3002001)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051); SRVR:AM4PR05MB3284; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB3284; x-forefront-prvs: 0813C68E65 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(376002)(366004)(396003)(136003)(39860400002)(189003)(199004)(386003)(97736004)(186003)(26005)(52116002)(6512007)(36756003)(6506007)(2351001)(99286004)(6916009)(68736007)(446003)(3846002)(305945005)(6116002)(7736002)(102836004)(76176011)(11346002)(5640700003)(486006)(86362001)(5660300001)(2616005)(476003)(2900100001)(106356001)(316002)(1730700003)(25786009)(478600001)(81166006)(81156014)(5250100002)(2501003)(54906003)(6436002)(8936002)(14444005)(71200400001)(71190400001)(2906002)(107886003)(8676002)(256004)(66066001)(4326008)(14454004)(6486002)(105586002)(53936002)(4744004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3284; 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: mwAzW31/BOvqbYp1gz7YskUtkMWwndqyxdQPRh874B/NelC4faQQ7Ts4iK+6M9OqoTxE2QSxkBjl8mH6ru2JJRLXOUlD14WQSsl1aUrAdNHX9xjFnBUEwFs7ypJbafjS5sWcXzAB6ItEfYIoIqngaKXRviNhxUeEv58zPaPEkfPjUHBRV9jzu6A3TIKaqKJhZAsArCuoFWqZUgWJMIpl24ESn9rqSWQbIV4uvdVN+a+LbZTMApIbpfem6w05f8qyIkpc8vnIBYQU70B2xmHHXiJGEl11dFlV7Oy5cZnjAjDAlHujVs8Z4VjKp2zkP0nDHdUV/uVddH57RlBHvbfF+Csr7rsn+iUI3GXSQ+MRWjc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3bd80dd8-f4d9-48eb-6bd0-08d628309377 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Oct 2018 06:30:42.0264 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3284 Subject: [dpdk-dev] [PATCH 5/5] net/mlx5: e-switch VXLAN tunnel devices management 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" VXLAN interfaces are dynamically created for each local UDP port of outer networks and then used as targets for TC "flower" filters in order to perform encapsulation. These VXLAN interfaces are system-wide, the only one device with given UDP port can exist in the system (the attempt of creating another device with the same UDP local port returns EEXIST), so PMD should support the shared device instances database for PMD instances. These VXLAN implicitly created devices are called VTEPs (Virtual Tunnel End Points). Creation of the VTEP occurs at the moment of rule applying. The link is set up, root ingress qdisc is also initialized. One VTEP is shared for all encapsulation rules in the DPDK application instance. For decapsulaton one VTEP is created per every unique UDP local port to accept tunnel traffic. The name of created VTEP consists of prefix "vmlx_" and the number of UDP port in decimal digits without leading zeros (vmlx_4789). The VTEP can be preliminary created in the system before the launching application, it allows to share UDP ports between primary and secondary processes. Suggested-by: Adrien Mazarguil Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_flow_tcf.c | 344 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 343 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c index dfffc50..0e62fe9 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -1482,7 +1482,7 @@ struct flow_tcf_ptoi { default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, - NULL, "item not supported"); + items, "item not supported"); } } for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { @@ -2886,6 +2886,291 @@ struct flow_tcf_ptoi { return 0; } +/* VTEP device list is shared between PMD port instances. */ +static LIST_HEAD(, mlx5_flow_tcf_vtep) + vtep_list_vxlan = LIST_HEAD_INITIALIZER(); +static pthread_mutex_t vtep_list_mutex = PTHREAD_MUTEX_INITIALIZER; +static struct mlx5_flow_tcf_vtep *vtep_encap; + +/** + * Deletes VTEP network device. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_socket_open(). + * @param[in] vtep + * Flow tcf object with tunnel device structure to delete. + */ +static void +flow_tcf_delete_iface(struct mlx5_tcf_socket *tcf, + struct mlx5_flow_tcf_vtep *vtep) +{ + struct nlmsghdr *nlh; + struct ifinfomsg *ifm; + alignas(struct nlmsghdr) + uint8_t buf[mnl_nlmsg_size(MNL_ALIGN(sizeof(*ifm))) + 8]; + int ret; + + DRV_LOG(NOTICE, "VTEP delete (%d)", vtep->port); + nlh = mnl_nlmsg_put_header(buf); + nlh->nlmsg_type = RTM_DELLINK; + nlh->nlmsg_flags = NLM_F_REQUEST; + ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); + ifm->ifi_family = AF_UNSPEC; + ifm->ifi_index = vtep->ifindex; + ret = flow_tcf_nl_ack(tcf, nlh); + if (ret) + DRV_LOG(DEBUG, "error deleting VXLAN encap/decap ifindex %u", + ifm->ifi_index); +} + +/** + * Creates VTEP network device. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_socket_open(). + * @param[in] port + * UDP port of created VTEP device. + * @param[out] error + * Perform verbose error reporting if not NULL. + * + * @return + * Pointer to created device structure on success, NULL otherwise + * and rte_errno is set. + */ +static struct mlx5_flow_tcf_vtep* +flow_tcf_create_iface(struct mlx5_tcf_socket *tcf, uint16_t port, + struct rte_flow_error *error) +{ + struct mlx5_flow_tcf_vtep *vtep; + struct nlmsghdr *nlh; + struct ifinfomsg *ifm; + alignas(struct nlmsghdr) + char name[sizeof(MLX5_VXLAN_DEVICE_PFX) + 24]; + uint8_t buf[mnl_nlmsg_size(sizeof(*ifm)) + + SZ_NLATTR_DATA_OF(sizeof(name)) + + SZ_NLATTR_NEST * 2 + + SZ_NLATTR_STRZ_OF("vxlan") + + SZ_NLATTR_TYPE_OF_UINT32 + + SZ_NLATTR_TYPE_OF_UINT16 + + SZ_NLATTR_TYPE_OF_UINT8 + 128]; + struct nlattr *na_info; + struct nlattr *na_vxlan; + rte_be16_t vxlan_port = RTE_BE16(port); + int ret; + + vtep = rte_zmalloc(__func__, sizeof(*vtep), + alignof(struct mlx5_flow_tcf_vtep)); + if (!vtep) { + rte_flow_error_set + (error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "unadble to allocate memory for VTEP desc"); + return NULL; + } + *vtep = (struct mlx5_flow_tcf_vtep){ + .refcnt = 0, + .port = port, + .notcreated = 0, + }; + memset(buf, 0, sizeof(buf)); + nlh = mnl_nlmsg_put_header(buf); + nlh->nlmsg_type = RTM_NEWLINK; + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; + ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); + ifm->ifi_family = AF_UNSPEC; + ifm->ifi_type = 0; + ifm->ifi_index = 0; + ifm->ifi_flags = IFF_UP; + ifm->ifi_change = 0xffffffff; + snprintf(name, sizeof(name), "%s%u", MLX5_VXLAN_DEVICE_PFX, port); + mnl_attr_put_strz(nlh, IFLA_IFNAME, name); + na_info = mnl_attr_nest_start(nlh, IFLA_LINKINFO); + assert(na_info); + mnl_attr_put_strz(nlh, IFLA_INFO_KIND, "vxlan"); + na_vxlan = mnl_attr_nest_start(nlh, IFLA_INFO_DATA); + assert(na_vxlan); + mnl_attr_put_u8(nlh, IFLA_VXLAN_COLLECT_METADATA, 1); + mnl_attr_put_u8(nlh, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 1); + mnl_attr_put_u8(nlh, IFLA_VXLAN_LEARNING, 0); + mnl_attr_put_u16(nlh, IFLA_VXLAN_PORT, vxlan_port); + mnl_attr_nest_end(nlh, na_vxlan); + mnl_attr_nest_end(nlh, na_info); + assert(sizeof(buf) >= nlh->nlmsg_len); + ret = flow_tcf_nl_ack(tcf, nlh); + if (ret) { + DRV_LOG(WARNING, + "VTEP %s create failure (%d)", + name, rte_errno); + vtep->notcreated = 1; /* Assume the device exists. */ + } + ret = if_nametoindex(name); + if (ret) { + vtep->ifindex = ret; + memset(buf, 0, sizeof(buf)); + nlh = mnl_nlmsg_put_header(buf); + nlh->nlmsg_type = RTM_NEWLINK; + nlh->nlmsg_flags = NLM_F_REQUEST; + ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); + ifm->ifi_family = AF_UNSPEC; + ifm->ifi_type = 0; + ifm->ifi_index = vtep->ifindex; + ifm->ifi_flags = IFF_UP; + ifm->ifi_change = IFF_UP; + ret = flow_tcf_nl_ack(tcf, nlh); + if (ret) { + DRV_LOG(WARNING, + "VTEP %s set link up failure (%d)", name, rte_errno); + rte_free(vtep); + rte_flow_error_set + (error, -errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "netlink: failed to set VTEP link up"); + vtep = NULL; + } else { + ret = mlx5_flow_tcf_ifindex_init(tcf, + vtep->ifindex, error); + if (ret) + DRV_LOG(WARNING, + "VTEP %s init failure (%d)", name, rte_errno); + } + } else { + DRV_LOG(WARNING, + "VTEP %s failed to get index (%d)", name, errno); + rte_flow_error_set + (error, -errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + vtep->notcreated ? "netlink: failed to create VTEP" : + "netlink: failed to retrieve VTEP ifindex"); + ret = 1; + } + if (ret) { + if (!vtep->notcreated && vtep->ifindex) + flow_tcf_delete_iface(tcf, vtep); + rte_free(vtep); + vtep = NULL; + } + DRV_LOG(NOTICE, "VTEP create (%d, %s)", vtep->port, vtep ? "OK" : "error"); + return vtep; +} + +/** + * Creates target interface index for tunneling. + * + * @param tcf + * Context object initialized by mlx5_flow_tcf_socket_open(). + * @param[in] dev_flow + * Flow tcf object with tunnel structure pointer set. + * @param[out] error + * Perform verbose error reporting if not NULL. + * + * @return + * Interface index on success, zero otherwise and rte_errno is set. + */ +static unsigned int +flow_tcf_tunnel_vtep_create(struct mlx5_tcf_socket *tcf, + struct mlx5_flow *dev_flow, + struct rte_flow_error *error) +{ + unsigned int ret; + + assert(dev_flow->tcf.tunnel); + pthread_mutex_lock(&vtep_list_mutex); + switch (dev_flow->tcf.tunnel->type) { + case MLX5_FLOW_TCF_TUNACT_VXLAN_ENCAP: + if (!vtep_encap) { + vtep_encap = flow_tcf_create_iface(tcf, + MLX5_VXLAN_DEFAULT_PORT, error); + if (!vtep_encap) { + ret = 0; + break; + } + LIST_INSERT_HEAD(&vtep_list_vxlan, vtep_encap, next); + } + vtep_encap->refcnt++; + ret = vtep_encap->ifindex; + assert(ret); + break; + case MLX5_FLOW_TCF_TUNACT_VXLAN_DECAP: { + struct mlx5_flow_tcf_vtep *vtep; + uint16_t port = dev_flow->tcf.vxlan_decap->udp_port; + + LIST_FOREACH(vtep, &vtep_list_vxlan, next) { + if (vtep->port == port) + break; + } + if (!vtep) { + vtep = flow_tcf_create_iface(tcf, port, error); + if (!vtep) { + ret = 0; + break; + } + LIST_INSERT_HEAD(&vtep_list_vxlan, vtep, next); + } + vtep->refcnt++; + ret = vtep->ifindex; + assert(ret); + break; + } + default: + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "unsupported tunnel type"); + ret = 0; + break; + } + pthread_mutex_unlock(&vtep_list_mutex); + return ret; +} + +/** + * Deletes tunneling interface by UDP port. + * + * @param tx + * Context object initialized by mlx5_flow_tcf_socket_open(). + * @param[in] dev_flow + * Flow tcf object with tunnel structure pointer set. + */ +static void +flow_tcf_tunnel_vtep_delete(struct mlx5_tcf_socket *tcf, + struct mlx5_flow *dev_flow) +{ + struct mlx5_flow_tcf_vtep *vtep; + uint16_t port = MLX5_VXLAN_DEFAULT_PORT; + + assert(dev_flow->tcf.tunnel); + pthread_mutex_lock(&vtep_list_mutex); + switch (dev_flow->tcf.tunnel->type) { + case MLX5_FLOW_TCF_TUNACT_VXLAN_DECAP: + port = dev_flow->tcf.vxlan_decap->udp_port; + /* There is no break operator intentionally. */ + case MLX5_FLOW_TCF_TUNACT_VXLAN_ENCAP: + LIST_FOREACH(vtep, &vtep_list_vxlan, next) { + if (vtep->port == port) + break; + } + if (!vtep) { + DRV_LOG(WARNING, + "No VTEP device found in the list"); + break; + } + assert(dev_flow->tcf.tunnel->ifindex_tun == vtep->ifindex); + assert(vtep->refcnt); + if (vtep->refcnt && --vtep->refcnt) + break; + if (!vtep->notcreated) + flow_tcf_delete_iface(tcf, vtep); + LIST_REMOVE(vtep, next); + if (vtep_encap == vtep) + vtep_encap = NULL; + rte_free(vtep); + break; + default: + assert(false); + DRV_LOG(WARNING, "Unsupported tunnel type"); + break; + } + pthread_mutex_unlock(&vtep_list_mutex); +} + /** * Apply flow to E-Switch by sending Netlink message. * @@ -2917,12 +3202,45 @@ struct flow_tcf_ptoi { nlh = dev_flow->tcf.nlh; nlh->nlmsg_type = RTM_NEWTFILTER; nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; + if (dev_flow->tcf.tunnel) { + /* + * Replace the interface index, target for + * encapsulation, source for decapsulation + */ + assert(!dev_flow->tcf.tunnel->ifindex_tun); + assert(dev_flow->tcf.tunnel->ifindex_ptr); + /* Create actual VTEP device when rule is being applied. */ + dev_flow->tcf.tunnel->ifindex_tun + = flow_tcf_tunnel_vtep_create(&priv->tcf_socket, + dev_flow, error); + DRV_LOG(INFO, "Replace ifindex: %d->%d", + dev_flow->tcf.tunnel->ifindex_tun, + *dev_flow->tcf.tunnel->ifindex_ptr); + if (!dev_flow->tcf.tunnel->ifindex_tun) + return -rte_errno; + dev_flow->tcf.tunnel->ifindex_org + = *dev_flow->tcf.tunnel->ifindex_ptr; + *dev_flow->tcf.tunnel->ifindex_ptr + = dev_flow->tcf.tunnel->ifindex_tun; + } ret = flow_tcf_nl_ack(tcf, nlh); + if (dev_flow->tcf.tunnel) { + DRV_LOG(INFO, "Restore ifindex: %d->%d", + dev_flow->tcf.tunnel->ifindex_org, + *dev_flow->tcf.tunnel->ifindex_ptr); + *dev_flow->tcf.tunnel->ifindex_ptr + = dev_flow->tcf.tunnel->ifindex_org; + dev_flow->tcf.tunnel->ifindex_org = 0; + } if (!ret) { dev_flow->tcf.applied = 1; return 0; } DRV_LOG(WARNING, "Failed to create TC rule (%d)", rte_errno); + if (dev_flow->tcf.tunnel->ifindex_tun) { + flow_tcf_tunnel_vtep_delete(&priv->tcf_socket, dev_flow); + dev_flow->tcf.tunnel->ifindex_tun = 0; + } return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "netlink: failed to create TC flow rule"); @@ -2951,10 +3269,34 @@ struct flow_tcf_ptoi { return; /* E-Switch flow can't be expanded. */ assert(!LIST_NEXT(dev_flow, next)); + if (!dev_flow->tcf.applied) + return; + if (dev_flow->tcf.tunnel) { + /* + * Replace the interface index, target for + * encapsulation, source for decapsulation + */ + assert(dev_flow->tcf.tunnel->ifindex_tun); + assert(dev_flow->tcf.tunnel->ifindex_ptr); + dev_flow->tcf.tunnel->ifindex_org + = *dev_flow->tcf.tunnel->ifindex_ptr; + *dev_flow->tcf.tunnel->ifindex_ptr + = dev_flow->tcf.tunnel->ifindex_tun; + } nlh = dev_flow->tcf.nlh; nlh->nlmsg_type = RTM_DELTFILTER; nlh->nlmsg_flags = NLM_F_REQUEST; flow_tcf_nl_ack(tcf, nlh); + if (dev_flow->tcf.tunnel) { + *dev_flow->tcf.tunnel->ifindex_ptr + = dev_flow->tcf.tunnel->ifindex_org; + dev_flow->tcf.tunnel->ifindex_org = 0; + if (dev_flow->tcf.tunnel->ifindex_tun) { + flow_tcf_tunnel_vtep_delete(&priv->tcf_socket, + dev_flow); + dev_flow->tcf.tunnel->ifindex_tun = 0; + } + } dev_flow->tcf.applied = 0; }