642-bridge_port_isolate.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Subject: [PATCH] bridge: port isolate
  3. Isolating individual bridge ports
  4. ---
  5. --- a/net/bridge/br_private.h
  6. +++ b/net/bridge/br_private.h
  7. @@ -172,6 +172,7 @@ struct net_bridge_port
  8. #define BR_FLOOD 0x00000040
  9. #define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING)
  10. #define BR_PROMISC 0x00000080
  11. +#define BR_ISOLATE_MODE 0x00000100
  12. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  13. struct bridge_mcast_own_query ip4_own_query;
  14. --- a/net/bridge/br_sysfs_if.c
  15. +++ b/net/bridge/br_sysfs_if.c
  16. @@ -170,6 +170,7 @@ BRPORT_ATTR_FLAG(bpdu_guard, BR_BPDU_GUA
  17. BRPORT_ATTR_FLAG(root_block, BR_ROOT_BLOCK);
  18. BRPORT_ATTR_FLAG(learning, BR_LEARNING);
  19. BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD);
  20. +BRPORT_ATTR_FLAG(isolated, BR_ISOLATE_MODE);
  21. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  22. static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
  23. @@ -213,6 +214,7 @@ static const struct brport_attribute *br
  24. &brport_attr_multicast_router,
  25. &brport_attr_multicast_fast_leave,
  26. #endif
  27. + &brport_attr_isolated,
  28. NULL
  29. };
  30. --- a/net/bridge/br_input.c
  31. +++ b/net/bridge/br_input.c
  32. @@ -120,8 +120,8 @@ int br_handle_frame_finish(struct sk_buf
  33. unicast = false;
  34. br->dev->stats.multicast++;
  35. - } else if ((dst = __br_fdb_get(br, dest, vid)) &&
  36. - dst->is_local) {
  37. + } else if ((p->flags & BR_ISOLATE_MODE) ||
  38. + ((dst = __br_fdb_get(br, dest, vid)) && dst->is_local)) {
  39. skb2 = skb;
  40. /* Do not forward the packet since it's local. */
  41. skb = NULL;
  42. --- a/net/bridge/br_forward.c
  43. +++ b/net/bridge/br_forward.c
  44. @@ -117,7 +117,7 @@ EXPORT_SYMBOL_GPL(br_deliver);
  45. /* called with rcu_read_lock */
  46. void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0)
  47. {
  48. - if (should_deliver(to, skb)) {
  49. + if (should_deliver(to, skb) && !(to->flags & BR_ISOLATE_MODE)) {
  50. if (skb0)
  51. deliver_clone(to, skb, __br_forward);
  52. else
  53. @@ -173,7 +173,7 @@ static void br_flood(struct net_bridge *
  54. struct sk_buff *skb0,
  55. void (*__packet_hook)(const struct net_bridge_port *p,
  56. struct sk_buff *skb),
  57. - bool unicast)
  58. + bool unicast, bool forward)
  59. {
  60. struct net_bridge_port *p;
  61. struct net_bridge_port *prev;
  62. @@ -181,6 +181,8 @@ static void br_flood(struct net_bridge *
  63. prev = NULL;
  64. list_for_each_entry_rcu(p, &br->port_list, list) {
  65. + if (forward && (p->flags & BR_ISOLATE_MODE))
  66. + continue;
  67. /* Do not flood unicast traffic to ports that turn it off */
  68. if (unicast && !(p->flags & BR_FLOOD))
  69. continue;
  70. @@ -207,14 +209,14 @@ out:
  71. /* called with rcu_read_lock */
  72. void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, bool unicast)
  73. {
  74. - br_flood(br, skb, NULL, __br_deliver, unicast);
  75. + br_flood(br, skb, NULL, __br_deliver, unicast, false);
  76. }
  77. /* called under bridge lock */
  78. void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
  79. struct sk_buff *skb2, bool unicast)
  80. {
  81. - br_flood(br, skb, skb2, __br_forward, unicast);
  82. + br_flood(br, skb, skb2, __br_forward, unicast, true);
  83. }
  84. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING