641-bridge_port_isolate.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Index: linux-4.9.34/include/linux/if_bridge.h
  14. ===================================================================
  15. --- linux-4.9.34.orig/include/linux/if_bridge.h
  16. +++ linux-4.9.34/include/linux/if_bridge.h
  17. @@ -47,6 +47,7 @@ struct br_ip_list {
  18. #define BR_PROXYARP_WIFI BIT(10)
  19. #define BR_MCAST_FLOOD BIT(11)
  20. #define BR_MULTICAST_TO_UNICAST BIT(12)
  21. +#define BR_ISOLATE_MODE BIT(13)
  22. #define BR_DEFAULT_AGEING_TIME (300 * HZ)
  23. Index: linux-4.9.34/net/bridge/br_forward.c
  24. ===================================================================
  25. --- linux-4.9.34.orig/net/bridge/br_forward.c
  26. +++ linux-4.9.34/net/bridge/br_forward.c
  27. @@ -141,6 +141,9 @@ static int deliver_clone(const struct ne
  28. void br_forward(const struct net_bridge_port *to,
  29. struct sk_buff *skb, bool local_rcv, bool local_orig)
  30. {
  31. + if (to->flags & BR_ISOLATE_MODE)
  32. + to = NULL;
  33. +
  34. if (to && should_deliver(to, skb)) {
  35. if (local_rcv)
  36. deliver_clone(to, skb, local_orig);
  37. @@ -206,6 +209,8 @@ void br_flood(struct net_bridge *br, str
  38. struct net_bridge_port *p;
  39. list_for_each_entry_rcu(p, &br->port_list, list) {
  40. + if (!local_orig && (p->flags & BR_ISOLATE_MODE))
  41. + continue;
  42. /* Do not flood unicast traffic to ports that turn it off */
  43. if (pkt_type == BR_PKT_UNICAST && !(p->flags & BR_FLOOD))
  44. continue;
  45. Index: linux-4.9.34/net/bridge/br_input.c
  46. ===================================================================
  47. --- linux-4.9.34.orig/net/bridge/br_input.c
  48. +++ linux-4.9.34/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. + if (p->flags & BR_ISOLATE_MODE)
  53. + return br_pass_frame_up(skb);
  54. +
  55. switch (pkt_type) {
  56. case BR_PKT_MULTICAST:
  57. mdst = br_mdb_get(br, skb, vid);
  58. Index: linux-4.9.34/net/bridge/br_sysfs_if.c
  59. ===================================================================
  60. --- linux-4.9.34.orig/net/bridge/br_sysfs_if.c
  61. +++ linux-4.9.34/net/bridge/br_sysfs_if.c
  62. @@ -172,6 +172,7 @@ BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD
  63. BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
  64. BRPORT_ATTR_FLAG(proxyarp_wifi, BR_PROXYARP_WIFI);
  65. BRPORT_ATTR_FLAG(multicast_flood, BR_MCAST_FLOOD);
  66. +BRPORT_ATTR_FLAG(isolate_mode, BR_ISOLATE_MODE);
  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_isolate_mode,
  74. NULL
  75. };