13f84ae13eb882f42754820b96d3ff76718ab310
[openwrt.git] / target / linux / generic / patches-4.1 / 642-bridge_port_isolate.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Subject: [PATCH] bridge: port isolate
3
4 Isolating individual bridge ports
5 ---
6 --- a/include/linux/if_bridge.h
7 +++ b/include/linux/if_bridge.h
8 @@ -45,6 +45,7 @@ struct br_ip_list {
9  #define BR_PROXYARP            BIT(8)
10  #define BR_LEARNING_SYNC       BIT(9)
11  #define BR_PROXYARP_WIFI       BIT(10)
12 +#define BR_ISOLATE_MODE        BIT(11)
13  
14  extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
15  
16 --- a/net/bridge/br_sysfs_if.c
17 +++ b/net/bridge/br_sysfs_if.c
18 @@ -173,6 +173,22 @@ BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD
19  BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
20  BRPORT_ATTR_FLAG(proxyarp_wifi, BR_PROXYARP_WIFI);
21  
22 +static ssize_t show_isolate_mode(struct net_bridge_port *p, char *buf)
23 +{
24 +       int isolate_mode = (p->flags & BR_ISOLATE_MODE) ? 1 : 0;
25 +       return sprintf(buf, "%d\n", isolate_mode);
26 +}
27 +static ssize_t store_isolate_mode(struct net_bridge_port *p, unsigned long v)
28 +{
29 +       if (v)
30 +               p->flags |= BR_ISOLATE_MODE;
31 +       else
32 +               p->flags &= ~BR_ISOLATE_MODE;
33 +       return 0;
34 +}
35 +static BRPORT_ATTR(isolate_mode, S_IRUGO | S_IWUSR,
36 +                  show_isolate_mode, store_isolate_mode);
37 +
38  #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
39  static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
40  {
41 @@ -217,6 +233,7 @@ static const struct brport_attribute *br
42  #endif
43         &brport_attr_proxyarp,
44         &brport_attr_proxyarp_wifi,
45 +       &brport_attr_isolate_mode,
46         NULL
47  };
48  
49 --- a/net/bridge/br_input.c
50 +++ b/net/bridge/br_input.c
51 @@ -185,8 +185,8 @@ int br_handle_frame_finish(struct sock *
52  
53                 unicast = false;
54                 br->dev->stats.multicast++;
55 -       } else if ((dst = __br_fdb_get(br, dest, vid)) &&
56 -                       dst->is_local) {
57 +       } else if ((p->flags & BR_ISOLATE_MODE) ||
58 +                  ((dst = __br_fdb_get(br, dest, vid)) && dst->is_local)) {
59                 skb2 = skb;
60                 /* Do not forward the packet since it's local. */
61                 skb = NULL;
62 --- a/net/bridge/br_forward.c
63 +++ b/net/bridge/br_forward.c
64 @@ -119,7 +119,7 @@ EXPORT_SYMBOL_GPL(br_deliver);
65  /* called with rcu_read_lock */
66  void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0)
67  {
68 -       if (should_deliver(to, skb)) {
69 +       if (should_deliver(to, skb) && !(to->flags & BR_ISOLATE_MODE)) {
70                 if (skb0)
71                         deliver_clone(to, skb, __br_forward);
72                 else
73 @@ -175,7 +175,7 @@ static void br_flood(struct net_bridge *
74                      struct sk_buff *skb0,
75                      void (*__packet_hook)(const struct net_bridge_port *p,
76                                            struct sk_buff *skb),
77 -                    bool unicast)
78 +                                               bool unicast, bool forward)
79  {
80         struct net_bridge_port *p;
81         struct net_bridge_port *prev;
82 @@ -183,6 +183,8 @@ static void br_flood(struct net_bridge *
83         prev = NULL;
84  
85         list_for_each_entry_rcu(p, &br->port_list, list) {
86 +               if (forward && (p->flags & BR_ISOLATE_MODE))
87 +                       continue;
88                 /* Do not flood unicast traffic to ports that turn it off */
89                 if (unicast && !(p->flags & BR_FLOOD))
90                         continue;
91 @@ -217,14 +219,14 @@ out:
92  /* called with rcu_read_lock */
93  void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, bool unicast)
94  {
95 -       br_flood(br, skb, NULL, __br_deliver, unicast);
96 +       br_flood(br, skb, NULL, __br_deliver, unicast, false);
97  }
98  
99  /* called under bridge lock */
100  void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
101                       struct sk_buff *skb2, bool unicast)
102  {
103 -       br_flood(br, skb, skb2, __br_forward, unicast);
104 +       br_flood(br, skb, skb2, __br_forward, unicast, true);
105  }
106  
107  #ifdef CONFIG_BRIDGE_IGMP_SNOOPING