641-bridge_port_isolate.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From e988390850731aa1697ed09d47b0932fac1af175 Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <[email protected]>
  3. Date: Fri, 7 Jul 2017 17:20:03 +0200
  4. Subject: bridge: port isolate
  5. Isolating individual bridge ports
  6. Signed-off-by: Felix Fietkau <[email protected]>
  7. ---
  8. include/linux/if_bridge.h | 1 +
  9. net/bridge/br_forward.c | 5 +++++
  10. net/bridge/br_input.c | 3 +++
  11. net/bridge/br_sysfs_if.c | 2 ++
  12. 4 files changed, 11 insertions(+)
  13. --- a/include/linux/if_bridge.h
  14. +++ b/include/linux/if_bridge.h
  15. @@ -49,6 +49,7 @@ struct br_ip_list {
  16. #define BR_MULTICAST_TO_UNICAST BIT(12)
  17. #define BR_VLAN_TUNNEL BIT(13)
  18. #define BR_BCAST_FLOOD BIT(14)
  19. +#define BR_ISOLATE_MODE BIT(15)
  20. #define BR_DEFAULT_AGEING_TIME (300 * HZ)
  21. --- a/net/bridge/br_forward.c
  22. +++ b/net/bridge/br_forward.c
  23. @@ -141,6 +141,9 @@ static int deliver_clone(const struct ne
  24. void br_forward(const struct net_bridge_port *to,
  25. struct sk_buff *skb, bool local_rcv, bool local_orig)
  26. {
  27. + if (to->flags & BR_ISOLATE_MODE && !local_orig)
  28. + to = NULL;
  29. +
  30. if (to && should_deliver(to, skb)) {
  31. if (local_rcv)
  32. deliver_clone(to, skb, local_orig);
  33. @@ -183,6 +186,8 @@ void br_flood(struct net_bridge *br, str
  34. struct net_bridge_port *p;
  35. list_for_each_entry_rcu(p, &br->port_list, list) {
  36. + if (!local_orig && (p->flags & BR_ISOLATE_MODE))
  37. + continue;
  38. /* Do not flood unicast traffic to ports that turn it off, nor
  39. * other traffic if flood off, except for traffic we originate
  40. */
  41. --- a/net/bridge/br_input.c
  42. +++ b/net/bridge/br_input.c
  43. @@ -177,6 +177,9 @@ int br_handle_frame_finish(struct net *n
  44. if (IS_ENABLED(CONFIG_INET) && skb->protocol == htons(ETH_P_ARP))
  45. br_do_proxy_arp(skb, br, vid, p);
  46. + if (p->flags & BR_ISOLATE_MODE)
  47. + return br_pass_frame_up(skb);
  48. +
  49. switch (pkt_type) {
  50. case BR_PKT_MULTICAST:
  51. mdst = br_mdb_get(br, skb, vid);
  52. --- a/net/bridge/br_sysfs_if.c
  53. +++ b/net/bridge/br_sysfs_if.c
  54. @@ -174,6 +174,7 @@ BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
  55. BRPORT_ATTR_FLAG(proxyarp_wifi, BR_PROXYARP_WIFI);
  56. BRPORT_ATTR_FLAG(multicast_flood, BR_MCAST_FLOOD);
  57. BRPORT_ATTR_FLAG(broadcast_flood, BR_BCAST_FLOOD);
  58. +BRPORT_ATTR_FLAG(isolate_mode, BR_ISOLATE_MODE);
  59. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  60. static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
  61. @@ -223,6 +224,7 @@ static const struct brport_attribute *br
  62. &brport_attr_proxyarp_wifi,
  63. &brport_attr_multicast_flood,
  64. &brport_attr_broadcast_flood,
  65. + &brport_attr_isolate_mode,
  66. NULL
  67. };