From: Vlad Yasevich <vyasevic@redhat.com>
To: netdev@vger.kernel.org
Cc: bridge@lists.linux-foundation.org, shemminger@vyatta.com,
davem@davemloft.net, mirqus@gmail.com
Subject: [PATCH v10 net-next 03/12] bridge: Verify that a vlan is allowed to egress on given port
Date: Wed, 13 Feb 2013 12:41:40 -0500 [thread overview]
Message-ID: <1360777309-25522-4-git-send-email-vyasevic@redhat.com> (raw)
In-Reply-To: <1360777309-25522-1-git-send-email-vyasevic@redhat.com>
When bridge forwards a frame, make sure that a frame is allowed
to egress on that port.
Signed-off-by: Vlad Yasevich <vyasevic@redhat.com>
---
net/bridge/br_forward.c | 1 +
net/bridge/br_input.c | 10 ++++++++++
net/bridge/br_private.h | 10 ++++++++++
net/bridge/br_vlan.c | 20 ++++++++++++++++++++
4 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 02015a5..35b0671 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -31,6 +31,7 @@ static inline int should_deliver(const struct net_bridge_port *p,
const struct sk_buff *skb)
{
return (((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) &&
+ br_allowed_egress(p->br, nbp_get_vlan_info(p), skb) &&
p->state == BR_STATE_FORWARDING);
}
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 4ef3f6b..787d7da 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -35,6 +35,16 @@ static int br_pass_frame_up(struct sk_buff *skb)
brstats->rx_bytes += skb->len;
u64_stats_update_end(&brstats->syncp);
+ /* Bridge is just like any other port. Make sure the
+ * packet is allowed except in promisc modue when someone
+ * may be running packet capture.
+ */
+ if (!(brdev->flags & IFF_PROMISC) &&
+ !br_allowed_egress(br, br_get_vlan_info(br), skb)) {
+ kfree_skb(skb);
+ return NET_RX_DROP;
+ }
+
indev = skb->dev;
skb->dev = brdev;
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index edac5d1..a18d6a5 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -557,6 +557,9 @@ static inline void br_mdb_uninit(void)
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
extern bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
struct sk_buff *skb);
+extern bool br_allowed_egress(struct net_bridge *br,
+ const struct net_port_vlans *v,
+ const struct sk_buff *skb);
extern int br_vlan_add(struct net_bridge *br, u16 vid);
extern int br_vlan_delete(struct net_bridge *br, u16 vid);
extern void br_vlan_flush(struct net_bridge *br);
@@ -601,6 +604,13 @@ static inline bool br_allowed_ingress(struct net_bridge *br,
return true;
}
+static inline bool br_allowed_egress(struct net_bridge *br,
+ const struct net_port_vlans *v,
+ const struct sk_buff *skb)
+{
+ return true;
+}
+
static inline int br_vlan_add(struct net_bridge *br, u16 vid)
{
return -EOPNOTSUPP;
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 8b4bcd8..d8690bf 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -89,6 +89,26 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
return false;
}
+/* Called under RCU. */
+bool br_allowed_egress(struct net_bridge *br,
+ const struct net_port_vlans *v,
+ const struct sk_buff *skb)
+{
+ u16 vid;
+
+ if (!br->vlan_enabled)
+ return true;
+
+ if (!v)
+ return false;
+
+ br_vlan_get_tag(skb, &vid);
+ if (test_bit(vid, v->vlan_bitmap))
+ return true;
+
+ return false;
+}
+
/* Must be protected by RTNL */
int br_vlan_add(struct net_bridge *br, u16 vid)
{
--
1.7.7.6
next prev parent reply other threads:[~2013-02-13 17:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-13 17:41 [PATCH v10 net-next 00/12] VLAN filtering/VLAN aware bridge Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 01/12] bridge: Add vlan filtering infrastructure Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 02/12] bridge: Validate that vlan is permitted on ingress Vlad Yasevich
2013-02-13 17:41 ` Vlad Yasevich [this message]
2013-02-13 17:41 ` [PATCH v10 net-next 04/12] bridge: Add netlink interface to configure vlans on bridge ports Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 05/12] bridge: Dump vlan information from a bridge port Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 06/12] bridge: Implement vlan ingress/egress policy with PVID Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 07/12] bridge: Add the ability to configure pvid Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 08/12] bridge: Add vlan to unicast fdb entries Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 09/12] bridge: Add vlan id to multicast groups Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 10/12] bridge: Add vlan support to static neighbors Vlad Yasevich
2013-02-13 19:25 ` Greg Rose
2013-02-13 17:41 ` [PATCH v10 net-next 11/12] bridge: Add vlan support for local fdb entries Vlad Yasevich
2013-02-13 17:41 ` [PATCH v10 net-next 12/12] bridge: Separate egress policy bitmap Vlad Yasevich
2013-02-13 19:08 ` [PATCH v10 net-next 00/12] VLAN filtering/VLAN aware bridge David Miller
2013-02-13 19:43 ` Vlad Yasevich
2013-02-13 19:48 ` David Miller
2013-02-13 20:14 ` [Bridge] " Jonathan Thibault
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=1360777309-25522-4-git-send-email-vyasevic@redhat.com \
--to=vyasevic@redhat.com \
--cc=bridge@lists.linux-foundation.org \
--cc=davem@davemloft.net \
--cc=mirqus@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.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).