From: Vladislav Yasevich <vyasevich@gmail.com>
To: netdev@vger.kernel.org
Cc: Vladislav Yasevich <vyasevic@redhat.com>,
shemminger@vyatta.com, bridge@lists.linux-foundation.org
Subject: [Bridge] [PATCH 3/3] bridge; Automatically filter vlans configured on top of bridge
Date: Fri, 12 Sep 2014 16:44:51 -0400 [thread overview]
Message-ID: <1410554691-18467-4-git-send-email-vyasevic@redhat.com> (raw)
In-Reply-To: <1410554691-18467-1-git-send-email-vyasevic@redhat.com>
If the user configures vlan devices on top of the bridge,
automatically set up filter entries for it as long as
bridge vlan protocol matches that of the vlan.
This allows the user to atomatically receive vlan traffic
for the vlans that are convifgured.
Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
---
net/bridge/br_device.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
net/bridge/br_private.h | 20 ++++++++++++++++++++
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index af8f706..1e8caec 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -307,6 +307,45 @@ static int br_del_slave(struct net_device *dev, struct net_device *slave_dev)
return br_del_if(br, slave_dev);
}
+static int br_vlan_rx_add_vid(struct net_device *br_dev,
+ __be16 proto, u16 vid)
+{
+ struct net_bridge *br = netdev_priv(br_dev);
+
+ if (proto != br_vlan_protocol(br))
+ return 0;
+
+ /* vid 0 is special and will be added by the vlan layer to lower
+ * devices. Don't do anything here.
+ */
+ if (vid == 0)
+ return 0;
+
+ return br_vlan_add(br, vid, 0);
+}
+
+static int br_vlan_rx_kill_vid(struct net_device *br_dev,
+ __be16 proto, u16 vid)
+{
+ struct net_bridge *br = netdev_priv(br_dev);
+
+ if (proto != br_vlan_protocol(br))
+ return 0;
+
+ /* vid 0 is special and will be removed by the vlan layer from lower
+ * devices. Don't do anything here.
+ */
+ if (vid == 0)
+ return 0;
+
+ /* Don't report error. This will fail if the vlan was
+ * previousely remove by some other means and we don't
+ * wan't to polute the log/bug the user.
+ */
+ br_vlan_delete(br, vid);
+ return 0;
+}
+
static const struct ethtool_ops br_ethtool_ops = {
.get_drvinfo = br_getinfo,
.get_link = ethtool_op_get_link,
@@ -337,6 +376,8 @@ static const struct net_device_ops br_netdev_ops = {
.ndo_bridge_getlink = br_getlink,
.ndo_bridge_setlink = br_setlink,
.ndo_bridge_dellink = br_dellink,
+ .ndo_vlan_rx_add_vid = br_vlan_rx_add_vid,
+ .ndo_vlan_rx_kill_vid = br_vlan_rx_kill_vid,
};
static void br_dev_free(struct net_device *dev)
@@ -366,9 +407,8 @@ void br_dev_setup(struct net_device *dev)
dev->priv_flags = IFF_EBRIDGE;
dev->features = COMMON_FEATURES | NETIF_F_LLTX | NETIF_F_NETNS_LOCAL |
- NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
- dev->hw_features = COMMON_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
- NETIF_F_HW_VLAN_STAG_TX;
+ BRIDGE_VLAN_FEATURES;
+ dev->hw_features = COMMON_FEATURES | BRIDGE_VLAN_FEATURES;
dev->vlan_features = COMMON_FEATURES;
br->dev = dev;
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index bb4abdf..73a1563 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -29,6 +29,16 @@
#define BR_MAX_PORTS (1<<BR_PORT_BITS)
#define BR_VLAN_BITMAP_LEN BITS_TO_LONGS(VLAN_N_VID)
+#ifdef CONFIG_BRIDGE_VLAN_FILTERING
+#define BRIDGE_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_TX | \
+ NETIF_F_HW_VLAN_CTAG_FILTER | \
+ NETIF_F_HW_VLAN_STAG_TX | \
+ NETIF_F_HW_VLAN_STAG_FILTER)
+#else
+#define BRIDGE_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_TX | \
+ NETIF_F_HW_VLAN_STAG_TX)
+#endif
+
#define BR_VERSION "2.3"
/* Control of forwarding link local multicast */
@@ -654,6 +664,11 @@ static inline int br_vlan_enabled(struct net_bridge *br)
{
return br->vlan_enabled;
}
+
+static inline __be16 br_vlan_protocol(struct net_bridge *br)
+{
+ return br->vlan_proto;
+}
#else
static inline bool br_allowed_ingress(struct net_bridge *br,
struct net_port_vlans *v,
@@ -759,6 +774,11 @@ static inline int br_vlan_enabled(struct net_bridge *br)
{
return 0;
}
+
+static inline __be16 br_vlan_protocol(struct net_bridge *br)
+{
+ return 0;
+}
#endif
/* br_netfilter.c */
--
1.9.3
next prev parent reply other threads:[~2014-09-12 20:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-12 20:44 [Bridge] [PATCH 0/3] bridge: Some nice new things for vlan filtering Vladislav Yasevich
2014-09-12 20:44 ` [Bridge] [PATCH 1/3] bridge: Add a default_pvid sysfs attribute Vladislav Yasevich
2014-09-12 20:44 ` [Bridge] [PATCH 2/3] bridge: Add filtering support for default_pvid Vladislav Yasevich
2014-09-14 15:21 ` Toshiaki Makita
2014-09-15 15:09 ` Vlad Yasevich
2014-09-16 11:10 ` Toshiaki Makita
2014-09-16 13:23 ` Vlad Yasevich
2014-09-12 20:44 ` Vladislav Yasevich [this message]
2014-09-14 15:39 ` [Bridge] [PATCH 3/3] bridge; Automatically filter vlans configured on top of bridge Toshiaki Makita
2014-09-15 15:19 ` Vlad Yasevich
2014-09-16 11:28 ` Toshiaki Makita
2014-09-16 13:31 ` Vlad Yasevich
2014-09-16 14:39 ` Toshiaki Makita
2014-09-16 15:00 ` Vlad Yasevich
2014-09-17 0:25 ` Toshiaki Makita
2014-09-17 14:14 ` Vlad Yasevich
2014-09-18 9:47 ` Toshiaki Makita
2014-09-15 16:24 ` [Bridge] [PATCH 0/3] bridge: Some nice new things for vlan filtering Stephen Hemminger
2014-09-16 11:38 ` Toshiaki Makita
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410554691-18467-4-git-send-email-vyasevic@redhat.com \
--to=vyasevich@gmail.com \
--cc=bridge@lists.linux-foundation.org \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
--cc=vyasevic@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).