Commit 11538d03 authored by Roopa Prabhu's avatar Roopa Prabhu Committed by David S. Miller

bridge: vlan dst_metadata hooks in ingress and egress paths

- ingress hook:
    - if port is a tunnel port, use tunnel info in
      attached dst_metadata to map it to a local vlan
- egress hook:
    - if port is a tunnel port, use tunnel info attached to
      vlan to set dst_metadata on the skb

CC: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarRoopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent efa5356b
...@@ -80,7 +80,7 @@ static void __br_forward(const struct net_bridge_port *to, ...@@ -80,7 +80,7 @@ static void __br_forward(const struct net_bridge_port *to,
int br_hook; int br_hook;
vg = nbp_vlan_group_rcu(to); vg = nbp_vlan_group_rcu(to);
skb = br_handle_vlan(to->br, vg, skb); skb = br_handle_vlan(to->br, to, vg, skb);
if (!skb) if (!skb)
return; return;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/rculist.h> #include <linux/rculist.h>
#include "br_private.h" #include "br_private.h"
#include "br_private_tunnel.h"
/* Hook for brouter */ /* Hook for brouter */
br_should_route_hook_t __rcu *br_should_route_hook __read_mostly; br_should_route_hook_t __rcu *br_should_route_hook __read_mostly;
...@@ -57,7 +58,7 @@ static int br_pass_frame_up(struct sk_buff *skb) ...@@ -57,7 +58,7 @@ static int br_pass_frame_up(struct sk_buff *skb)
indev = skb->dev; indev = skb->dev;
skb->dev = brdev; skb->dev = brdev;
skb = br_handle_vlan(br, vg, skb); skb = br_handle_vlan(br, NULL, vg, skb);
if (!skb) if (!skb)
return NET_RX_DROP; return NET_RX_DROP;
/* update the multicast stats if the packet is IGMP/MLD */ /* update the multicast stats if the packet is IGMP/MLD */
...@@ -261,6 +262,11 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb) ...@@ -261,6 +262,11 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
return RX_HANDLER_CONSUMED; return RX_HANDLER_CONSUMED;
p = br_port_get_rcu(skb->dev); p = br_port_get_rcu(skb->dev);
if (p->flags & BR_VLAN_TUNNEL) {
if (br_handle_ingress_vlan_tunnel(skb, p,
nbp_vlan_group_rcu(p)))
goto drop;
}
if (unlikely(is_link_local_ether_addr(dest))) { if (unlikely(is_link_local_ether_addr(dest))) {
u16 fwd_mask = p->br->group_fwd_mask_required; u16 fwd_mask = p->br->group_fwd_mask_required;
......
...@@ -775,6 +775,7 @@ bool br_allowed_egress(struct net_bridge_vlan_group *vg, ...@@ -775,6 +775,7 @@ bool br_allowed_egress(struct net_bridge_vlan_group *vg,
const struct sk_buff *skb); const struct sk_buff *skb);
bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
struct sk_buff *br_handle_vlan(struct net_bridge *br, struct sk_buff *br_handle_vlan(struct net_bridge *br,
const struct net_bridge_port *port,
struct net_bridge_vlan_group *vg, struct net_bridge_vlan_group *vg,
struct sk_buff *skb); struct sk_buff *skb);
int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags); int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags);
...@@ -874,6 +875,7 @@ static inline bool br_should_learn(struct net_bridge_port *p, ...@@ -874,6 +875,7 @@ static inline bool br_should_learn(struct net_bridge_port *p,
} }
static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
const struct net_bridge_port *port,
struct net_bridge_vlan_group *vg, struct net_bridge_vlan_group *vg,
struct sk_buff *skb) struct sk_buff *skb)
{ {
......
...@@ -40,6 +40,11 @@ int nbp_vlan_tunnel_info_add(struct net_bridge_port *port, u16 vid, u32 tun_id); ...@@ -40,6 +40,11 @@ int nbp_vlan_tunnel_info_add(struct net_bridge_port *port, u16 vid, u32 tun_id);
void nbp_vlan_tunnel_info_flush(struct net_bridge_port *port); void nbp_vlan_tunnel_info_flush(struct net_bridge_port *port);
void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg, void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg,
struct net_bridge_vlan *vlan); struct net_bridge_vlan *vlan);
int br_handle_ingress_vlan_tunnel(struct sk_buff *skb,
struct net_bridge_port *p,
struct net_bridge_vlan_group *vg);
int br_handle_egress_vlan_tunnel(struct sk_buff *skb,
struct net_bridge_vlan *vlan);
#else #else
static inline int vlan_tunnel_init(struct net_bridge_vlan_group *vg) static inline int vlan_tunnel_init(struct net_bridge_vlan_group *vg)
{ {
...@@ -67,6 +72,12 @@ static inline void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg, ...@@ -67,6 +72,12 @@ static inline void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg,
{ {
} }
static inline int br_handle_ingress_vlan_tunnel(struct sk_buff *skb,
struct net_bridge_port *p,
struct net_bridge_vlan_group *vg)
{
return 0;
}
#endif #endif
#endif #endif
...@@ -341,6 +341,7 @@ static void __vlan_flush(struct net_bridge_vlan_group *vg) ...@@ -341,6 +341,7 @@ static void __vlan_flush(struct net_bridge_vlan_group *vg)
} }
struct sk_buff *br_handle_vlan(struct net_bridge *br, struct sk_buff *br_handle_vlan(struct net_bridge *br,
const struct net_bridge_port *p,
struct net_bridge_vlan_group *vg, struct net_bridge_vlan_group *vg,
struct sk_buff *skb) struct sk_buff *skb)
{ {
...@@ -381,6 +382,12 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br, ...@@ -381,6 +382,12 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
skb->vlan_tci = 0; skb->vlan_tci = 0;
if (p && (p->flags & BR_VLAN_TUNNEL) &&
br_handle_egress_vlan_tunnel(skb, v)) {
kfree_skb(skb);
return NULL;
}
out: out:
return skb; return skb;
} }
......
...@@ -39,6 +39,13 @@ static const struct rhashtable_params br_vlan_tunnel_rht_params = { ...@@ -39,6 +39,13 @@ static const struct rhashtable_params br_vlan_tunnel_rht_params = {
.automatic_shrinking = true, .automatic_shrinking = true,
}; };
static struct net_bridge_vlan *br_vlan_tunnel_lookup(struct rhashtable *tbl,
u64 tunnel_id)
{
return rhashtable_lookup_fast(tbl, &tunnel_id,
br_vlan_tunnel_rht_params);
}
void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg, void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg,
struct net_bridge_vlan *vlan) struct net_bridge_vlan *vlan)
{ {
...@@ -147,3 +154,50 @@ void vlan_tunnel_deinit(struct net_bridge_vlan_group *vg) ...@@ -147,3 +154,50 @@ void vlan_tunnel_deinit(struct net_bridge_vlan_group *vg)
{ {
rhashtable_destroy(&vg->tunnel_hash); rhashtable_destroy(&vg->tunnel_hash);
} }
int br_handle_ingress_vlan_tunnel(struct sk_buff *skb,
struct net_bridge_port *p,
struct net_bridge_vlan_group *vg)
{
struct ip_tunnel_info *tinfo = skb_tunnel_info(skb);
struct net_bridge_vlan *vlan;
if (!vg || !tinfo)
return 0;
/* if already tagged, ignore */
if (skb_vlan_tagged(skb))
return 0;
/* lookup vid, given tunnel id */
vlan = br_vlan_tunnel_lookup(&vg->tunnel_hash, tinfo->key.tun_id);
if (!vlan)
return 0;
skb_dst_drop(skb);
__vlan_hwaccel_put_tag(skb, p->br->vlan_proto, vlan->vid);
return 0;
}
int br_handle_egress_vlan_tunnel(struct sk_buff *skb,
struct net_bridge_vlan *vlan)
{
int err;
if (!vlan || !vlan->tinfo.tunnel_id)
return 0;
if (unlikely(!skb_vlan_tag_present(skb)))
return 0;
skb_dst_drop(skb);
err = skb_vlan_pop(skb);
if (err)
return err;
skb_dst_set(skb, dst_clone(&vlan->tinfo.tunnel_dst->dst));
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment