From patchwork Fri Sep 30 13:21:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16715 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id EA46883025; Fri, 30 Sep 2016 15:22:02 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=open-mesh.com Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=open-mesh-com.20150623.gappssmtp.com header.i=@open-mesh-com.20150623.gappssmtp.com header.b=x7aCzXjP; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received-SPF: Neutral (access neither permitted nor denied) identity=mailfrom; client-ip=2a00:1450:4010:c07::22d; helo=mail-lf0-x22d.google.com; envelope-from=sven.eckelmann@open-mesh.com; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=none header.from=open-mesh.com Received: from mail-lf0-x22d.google.com (mail-lf0-x22d.google.com [IPv6:2a00:1450:4010:c07::22d]) by open-mesh.org (Postfix) with ESMTPS id 02EE682FE5 for ; Fri, 30 Sep 2016 15:21:17 +0200 (CEST) Received: by mail-lf0-x22d.google.com with SMTP id l131so106268352lfl.2 for ; Fri, 30 Sep 2016 06:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ySl7yeF3qMX0ywTJocOnOQLZEswrCK3x2eprbT70wJo=; b=x7aCzXjPR012+u10dnNfliK5vw+iXqbT05/K9qkG9YAV222NNlYZ5/xBdneWhyBgJY NjG/MVnbBFNdGR59POxRSHNJdJFCDQB9CWPDlUN/PpbnjZLqscGsTemb3eT4/+lzj7ZW FyYzQPqgoPCXVjCJin+hsxv+oGZu+g9+p3tYZDShwnbVZ3v1V6B294lmMKzr0x2u553t JhXTmOjHGcGY+03u1V+Ti45ZaPiVGCqRhPxS9hzMajqoesYIPRDvuAJASOpIbhelb/Vb bChh/eYrVmAtulAej9GhEGZEQbjhksj1YW9yEGkkruTvDj6DXA3dOXRdEjMWjx4lzcz8 Z98g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ySl7yeF3qMX0ywTJocOnOQLZEswrCK3x2eprbT70wJo=; b=aMolqQkLFi8bZme+6CQrkItiYnA4Ju+zS7UyhmVENZ2w+4QwgmXdk+Rqkl728v4EiB JJWMDYE0wuhzYdmcdhvfgkCZr2LV6UJTiJQiZhcKO8aIJ0W8ZwuC0ZfBHzL1XNSIA+pp tvr8bEcw+35psOnDH4NlE66CCNetyy28uBCSREzbQVsKH1VMCvGmBG0ZqVT7Tn2QMqs2 v17SbI+diTnbFwgo0zf5xPwb2jyei0G6SBGvAIxY/4fOlmmKDpbSHWG/aNtX3jSu2+59 gAJCh33bMfVyjKk1GMIWrsenLVwBiyzzWbwSjiTxziKXKnyyZpZvVNwzKObSUzRJzfy9 YkDQ== X-Gm-Message-State: AA6/9RkRyGGjYvxIORDybyb7H/AFkEZUi4sbfo2E4a90WMC7hlpaufwhIOdVbI6QffN/19ws X-Received: by 10.194.75.37 with SMTP id z5mr6883547wjv.102.1475241677327; Fri, 30 Sep 2016 06:21:17 -0700 (PDT) Received: from sven-desktop.home.narfation.org (p2003007C6F5097FECB62B7744C7C7C8D.dip0.t-ipconnect.de. [2003:7c:6f50:97fe:cb62:b774:4c7c:7c8d]) by smtp.gmail.com with ESMTPSA id o2sm19624094wjo.3.2016.09.30.06.21.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Sep 2016 06:21:16 -0700 (PDT) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 30 Sep 2016 15:21:04 +0200 Message-Id: <20160930132106.5798-5-sven.eckelmann@open-mesh.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <2666783.nl87Kib46y@bentobox> References: <2666783.nl87Kib46y@bentobox> Cc: Sven Eckelmann , Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH v2 5/7] batman-adv: additional checks for virtual interfaces on top of WiFi X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" From: Marek Lindner In a few situations batman-adv tries to determine whether a given interface is a WiFi interface to enable specific WiFi optimizations. If the interface batman-adv has been configured with is a virtual interface (e.g. VLAN) it would not be properly detected as WiFi interface and thus not benefit from the special WiFi treatment. This patch changes that by peeking under the hood whenever a virtual interface is in play. Signed-off-by: Marek Lindner [sven.eckelmann@open-mesh.com: integrate in wifi_flags caching, retrieve namespace of link interface] Signed-off-by: Sven Eckelmann --- v2: - introduced batadv_get_real_netdevice which can be used inside rtnl locked contexts - replace check functions with ones that use the wifi_flags cache - use batadv_getlink_net to get the iflink net_namespace --- net/batman-adv/hard-interface.c | 58 +++++++++++++++++++++++++++++++++++++++++ net/batman-adv/types.h | 4 +++ 2 files changed, 62 insertions(+) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 341fbb5..ba587fb 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -202,6 +202,47 @@ static bool batadv_is_valid_iface(const struct net_device *net_dev) } /** + * batadv_get_real_netdevice - check if the given netdev struct is a virtual + * interface on top of another 'real' interface + * @netdev: the device to check + * + * Return: the 'real' net device or the original net device and NULL in case + * of an error. + */ +static struct net_device *batadv_get_real_netdevice(struct net_device *netdev) +{ + struct batadv_hard_iface *hard_iface = NULL; + struct net_device *real_netdev = NULL; + struct net *real_net; + struct net *net; + int ifindex; + + ASSERT_RTNL(); + + if (!netdev) + return NULL; + + if (netdev->ifindex == dev_get_iflink(netdev)) { + dev_hold(netdev); + return netdev; + } + + hard_iface = batadv_hardif_get_by_netdev(netdev); + if (!hard_iface || !hard_iface->soft_iface) + goto out; + + net = dev_net(hard_iface->soft_iface); + ifindex = dev_get_iflink(netdev); + real_net = batadv_getlink_net(netdev, net); + real_netdev = dev_get_by_index(real_net, ifindex); + +out: + if (hard_iface) + batadv_hardif_put(hard_iface); + return real_netdev; +} + +/** * batadv_is_wext_netdev - check if the given net_device struct is a * wext wifi interface * @net_device: the device to check @@ -254,6 +295,7 @@ static bool batadv_is_cfg80211_netdev(struct net_device *net_device) static u32 batadv_wifi_flags_evaluate(struct net_device *net_device) { u32 wifi_flags = 0; + struct net_device *real_netdev; if (batadv_is_wext_netdev(net_device)) wifi_flags |= BATADV_HARDIF_WIFI_WEXT_DIRECT; @@ -261,6 +303,21 @@ static u32 batadv_wifi_flags_evaluate(struct net_device *net_device) if (batadv_is_cfg80211_netdev(net_device)) wifi_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT; + real_netdev = batadv_get_real_netdevice(net_device); + if (!real_netdev) + return wifi_flags; + + if (real_netdev == net_device) + goto out; + + if (batadv_is_wext_netdev(real_netdev)) + wifi_flags |= BATADV_HARDIF_WIFI_WEXT_INDIRECT; + + if (batadv_is_cfg80211_netdev(real_netdev)) + wifi_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT; + +out: + dev_put(real_netdev); return wifi_flags; } @@ -277,6 +334,7 @@ bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface) u32 allowed_flags = 0; allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT; + allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT; return !!(hard_iface->wifi_flags & allowed_flags); } diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index fe64669..a6d8c98 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -123,10 +123,14 @@ struct batadv_hard_iface_bat_v { * of a batadv_hard_iface * @BATADV_HARDIF_WIFI_WEXT_DIRECT: it is a wext wifi device * @BATADV_HARDIF_WIFI_CFG80211_DIRECT: it is a cfg80211 wifi device + * @BATADV_HARDIF_WIFI_WEXT_INDIRECT: link device is a wext wifi device + * @BATADV_HARDIF_WIFI_CFG80211_INDIRECT: link device is a cfg80211 wifi device */ enum batadv_hard_iface_wifi_flags { BATADV_HARDIF_WIFI_WEXT_DIRECT = BIT(0), BATADV_HARDIF_WIFI_CFG80211_DIRECT = BIT(1), + BATADV_HARDIF_WIFI_WEXT_INDIRECT = BIT(2), + BATADV_HARDIF_WIFI_CFG80211_INDIRECT = BIT(3), }; /**