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. @@ -47,6 +47,7 @@ struct br_ip_list {
  16. #define BR_PROXYARP_WIFI BIT(10)
  17. #define BR_MCAST_FLOOD BIT(11)
  18. #define BR_MULTICAST_TO_UNICAST BIT(12)
  19. +#define BR_ISOLATE_MODE BIT(13)
  20. #define BR_DEFAULT_AGEING_TIME (300 * HZ)
  21. --- a/net/bridge/br_forward.c
  22. +++ b/net/bridge/br_forward.c
  23. @@ -140,6 +140,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. @@ -205,6 +208,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 */
  39. if (pkt_type == BR_PKT_UNICAST && !(p->flags & BR_FLOOD))
  40. continue;
  41. --- a/net/bridge/br_input.c
  42. +++ b/net/bridge/br_input.c
  43. @@ -175,6 +175,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. @@ -172,6 +172,7 @@ BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD
  55. BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
  56. BRPORT_ATTR_FLAG(proxyarp_wifi, BR_PROXYARP_WIFI);
  57. BRPORT_ATTR_FLAG(multicast_flood, BR_MCAST_FLOOD);
  58. +BRPORT_ATTR_FLAG(isolated, BR_ISOLATE_MODE);
  59. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  60. static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
  61. @@ -220,6 +221,7 @@ static const struct brport_attribute *br
  62. &brport_attr_proxyarp,
  63. &brport_attr_proxyarp_wifi,
  64. &brport_attr_multicast_flood,
  65. + &brport_attr_isolated,
  66. NULL
  67. };