From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id B101BDED for ; Mon, 30 Apr 2018 16:07:48 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id o15-v6so8165854wro.11 for ; Mon, 30 Apr 2018 07:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=021i4oTLMKsinC7A0iNttEYXggRkF93oSBMX8y82FHY=; b=LkTNcId5l3D1NWDkzh5lqRl6tWYuBcpFCLZg/dCISfHP7iG6X+ZS3kTmYpNY5Imq2J JMJibJEzf1A5GvQXQ/JJ5Nfn+aGSqqCOq8yfH9F1N9e3Gb4TTLh7jkk9JU3SGVy6m2gA NIw4K8JgfhUEnW1Fkon4rXu30ygRp1VmaG8iVyKCbjC49B6QDMAY9KDRotfCEZOo1wAT ZAqg3Xc3d+r1/cNmV+C9nz7fXzY4J8WJAzjEpuBL/yfutsi2q/oI/OMerqyjOGqVI3Zc X2Eo3a/q1rkX4679QTLpTD7Gudop76JODSk0fbSQ4GGl2RijfDR+O0Vh2nEd305QMdg2 ER4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=021i4oTLMKsinC7A0iNttEYXggRkF93oSBMX8y82FHY=; b=LDo0EKJiqJwAg1+B0WKc3FLEf73PAbdFZjuSbcOUl5j7HvOKGxe+q5HCPUl52AvCTV gougiyM45G8eeDRTMLYVte2jOyOhGkTSa3XD+9mUQ2FdYBZ0JU7lLRSBWQQlCNhrHBkV LLqPjSnOoKl4U+JW0KOhqgmooH3ku54Hm+ccQWFr2UcH55OM+vDDJd+AJXis/olOheV6 4Ec7gIACfsMWGoTQX5c7DwJp5HugPPKbvU4hVntkgbENR/Hz39KGL/QlKy8m3xI1k9VK mK/oNSl/HYAFtYn93SX+G6bHoYDYpnD0irXqZmLeFVoUO33JkF1f9PLGyTdkZoBB1guS L90w== X-Gm-Message-State: ALQs6tD1ib7mg1Vng+jRXeZLLopsz+jTM8N3/MIQN6lhL/3E91wUeGOc pFjEJ8WvekvHRKK5yev/Gnz+IGJbijI= X-Google-Smtp-Source: AB8JxZqON8xBPHXpEzStApDTuewYRq67lBaa0sTUSLacK+J1SSLhgzUZVISfl+q0fM1e2CA9KpTIVg== X-Received: by 2002:adf:8e44:: with SMTP id n62-v6mr8927103wrb.159.1525097268437; Mon, 30 Apr 2018 07:07:48 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id o12-v6sm7366309wri.78.2018.04.30.07.07.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Apr 2018 07:07:47 -0700 (PDT) From: luca.boccassi@gmail.com To: Matan Azrad Cc: Stephen Hemminger , dpdk stable Date: Mon, 30 Apr 2018 15:03:31 +0100 Message-Id: <20180430140606.4615-53-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180430140606.4615-1-luca.boccassi@gmail.com> References: <20180430140606.4615-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'net/vdev_netvsc: fix routed devices probing' has been queued to stable release 18.02.2 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Apr 2018 14:07:48 -0000 Hi, FYI, your patch has been queued to stable release 18.02.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/02/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From c7a62713a2b1e0b287a56986a161fdc94556b15c Mon Sep 17 00:00:00 2001 From: Matan Azrad Date: Tue, 27 Feb 2018 14:22:03 +0000 Subject: [PATCH] net/vdev_netvsc: fix routed devices probing [ upstream commit b0c0efb4fdea0807ed43e59ca4f07b1fd2a807da ] NetVSC netdevices which are already routed should not be probed because they are used for management purposes by the HyperV. The corrupted code got the routed devices from the system file /proc/net/route and wrongly parsed only the odd lines, so devices which their routes were in even lines, were considered as unrouted devices and were probed. Use linux netlink lib to detect the routed NetVSC devices instead of file parsing. Fixes: 31182fadfb21 ("net/vdev_netvsc: skip routed netvsc probing") Suggested-by: Stephen Hemminger Signed-off-by: Matan Azrad --- drivers/net/vdev_netvsc/vdev_netvsc.c | 109 +++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c b/drivers/net/vdev_netvsc/vdev_netvsc.c index cbf4d590a..db0080a18 100644 --- a/drivers/net/vdev_netvsc/vdev_netvsc.c +++ b/drivers/net/vdev_netvsc/vdev_netvsc.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -207,36 +209,96 @@ vdev_netvsc_iface_is_netvsc(const struct if_nameindex *iface) * * @param[in] name * Network device name. + * @param[in] family + * Address family: AF_INET for IPv4 or AF_INET6 for IPv6. * * @return - * A nonzero value when interface has an route. In case of error, - * rte_errno is updated and 0 returned. + * 1 when interface has a route, negative errno value in case of error and + * 0 otherwise. */ static int -vdev_netvsc_has_route(const char *name) +vdev_netvsc_has_route(const struct if_nameindex *iface, + const unsigned char family) { - FILE *fp; + /* + * The implementation can be simpler by getifaddrs() function usage but + * it works for IPv6 only starting from glibc 2.3.3. + */ + char buf[4096]; + int len; int ret = 0; - char route[NETVSC_MAX_ROUTE_LINE_SIZE]; - char *netdev; + int res; + int sock; + struct nlmsghdr *retmsg = (struct nlmsghdr *)buf; + struct sockaddr_nl sa; + struct { + struct nlmsghdr nlhdr; + struct ifaddrmsg addrmsg; + } msg; - fp = fopen("/proc/net/route", "r"); - if (!fp) { - rte_errno = errno; - return 0; - } - while (fgets(route, NETVSC_MAX_ROUTE_LINE_SIZE, fp) != NULL) { - netdev = strtok(route, "\t"); - if (strcmp(netdev, name) == 0) { - ret = 1; - break; + if (!iface || (family != AF_INET && family != AF_INET6)) { + DRV_LOG(ERR, "%s", rte_strerror(EINVAL)); + return -EINVAL; + } + sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (sock == -1) { + DRV_LOG(ERR, "cannot open socket: %s", rte_strerror(errno)); + return -errno; + } + memset(&sa, 0, sizeof(sa)); + sa.nl_family = AF_NETLINK; + sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR; + res = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); + if (res == -1) { + ret = -errno; + DRV_LOG(ERR, "cannot bind socket: %s", rte_strerror(errno)); + goto close; + } + memset(&msg, 0, sizeof(msg)); + msg.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + msg.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; + msg.nlhdr.nlmsg_type = RTM_GETADDR; + msg.nlhdr.nlmsg_pid = getpid(); + msg.addrmsg.ifa_family = family; + msg.addrmsg.ifa_index = iface->if_index; + res = send(sock, &msg, msg.nlhdr.nlmsg_len, 0); + if (res == -1) { + ret = -errno; + DRV_LOG(ERR, "cannot send socket message: %s", + rte_strerror(errno)); + goto close; + } + memset(buf, 0, sizeof(buf)); + len = recv(sock, buf, sizeof(buf), 0); + if (len == -1) { + ret = -errno; + DRV_LOG(ERR, "cannot receive socket message: %s", + rte_strerror(errno)); + goto close; + } + while (NLMSG_OK(retmsg, (unsigned int)len)) { + struct ifaddrmsg *retaddr = + (struct ifaddrmsg *)NLMSG_DATA(retmsg); + + if (retaddr->ifa_family == family && + retaddr->ifa_index == iface->if_index) { + struct rtattr *retrta = IFA_RTA(retaddr); + int attlen = IFA_PAYLOAD(retmsg); + + while (RTA_OK(retrta, attlen)) { + if (retrta->rta_type == IFA_ADDRESS) { + ret = 1; + DRV_LOG(DEBUG, "interface %s has IP", + iface->if_name); + goto close; + } + retrta = RTA_NEXT(retrta, attlen); + } } - /* Move file pointer to the next line. */ - while (strchr(route, '\n') == NULL && - fgets(route, NETVSC_MAX_ROUTE_LINE_SIZE, fp) != NULL) - ; + retmsg = NLMSG_NEXT(retmsg, len); } - fclose(fp); +close: + close(sock); return ret; } @@ -505,10 +567,11 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, iface->if_name, iface->if_index); } /* Routed NetVSC should not be probed. */ - if (vdev_netvsc_has_route(iface->if_name)) { + if (vdev_netvsc_has_route(iface, AF_INET) || + vdev_netvsc_has_route(iface, AF_INET6)) { if (!specified || !force) return 0; - DRV_LOG(WARNING, "using routed NetVSC interface \"%s\"" + DRV_LOG(WARNING, "probably using routed NetVSC interface \"%s\"" " (index %u)", iface->if_name, iface->if_index); } /* Create interface context. */ -- 2.14.2