Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / generic / hack-4.9 / 641-bridge_port_isolate.patch
1 From e988390850731aa1697ed09d47b0932fac1af175 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Fri, 7 Jul 2017 17:20:03 +0200
4 Subject: bridge: port isolate
5
6 Isolating individual bridge ports
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10  include/linux/if_bridge.h | 1 +
11  net/bridge/br_forward.c   | 5 +++++
12  net/bridge/br_input.c     | 3 +++
13  net/bridge/br_sysfs_if.c  | 2 ++
14  4 files changed, 11 insertions(+)
15
16 --- a/include/linux/if_bridge.h
17 +++ b/include/linux/if_bridge.h
18 @@ -47,6 +47,7 @@ struct br_ip_list {
19  #define BR_PROXYARP_WIFI       BIT(10)
20  #define BR_MCAST_FLOOD         BIT(11)
21  #define BR_MULTICAST_TO_UNICAST        BIT(12)
22 +#define BR_ISOLATE_MODE                BIT(13)
23  
24  #define BR_DEFAULT_AGEING_TIME (300 * HZ)
25  
26 --- a/net/bridge/br_forward.c
27 +++ b/net/bridge/br_forward.c
28 @@ -141,6 +141,9 @@ static int deliver_clone(const struct ne
29  void br_forward(const struct net_bridge_port *to,
30                 struct sk_buff *skb, bool local_rcv, bool local_orig)
31  {
32 +       if (to->flags & BR_ISOLATE_MODE && !local_orig)
33 +               to = NULL;
34 +
35         if (to && should_deliver(to, skb)) {
36                 if (local_rcv)
37                         deliver_clone(to, skb, local_orig);
38 @@ -206,6 +209,8 @@ void br_flood(struct net_bridge *br, str
39         struct net_bridge_port *p;
40  
41         list_for_each_entry_rcu(p, &br->port_list, list) {
42 +               if (!local_orig && (p->flags & BR_ISOLATE_MODE))
43 +                       continue;
44                 /* Do not flood unicast traffic to ports that turn it off */
45                 if (pkt_type == BR_PKT_UNICAST && !(p->flags & BR_FLOOD))
46                         continue;
47 --- a/net/bridge/br_input.c
48 +++ b/net/bridge/br_input.c
49 @@ -175,6 +175,9 @@ int br_handle_frame_finish(struct net *n
50         if (IS_ENABLED(CONFIG_INET) && skb->protocol == htons(ETH_P_ARP))
51                 br_do_proxy_arp(skb, br, vid, p);
52  
53 +       if (p->flags & BR_ISOLATE_MODE)
54 +               return br_pass_frame_up(skb);
55 +
56         switch (pkt_type) {
57         case BR_PKT_MULTICAST:
58                 mdst = br_mdb_get(br, skb, vid);
59 --- a/net/bridge/br_sysfs_if.c
60 +++ b/net/bridge/br_sysfs_if.c
61 @@ -172,6 +172,7 @@ BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD
62  BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
63  BRPORT_ATTR_FLAG(proxyarp_wifi, BR_PROXYARP_WIFI);
64  BRPORT_ATTR_FLAG(multicast_flood, BR_MCAST_FLOOD);
65 +BRPORT_ATTR_FLAG(isolated, BR_ISOLATE_MODE);
66  
67  #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
68  static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
69 @@ -220,6 +221,7 @@ static const struct brport_attribute *br
70         &brport_attr_proxyarp,
71         &brport_attr_proxyarp_wifi,
72         &brport_attr_multicast_flood,
73 +       &brport_attr_isolated,
74         NULL
75  };
76