642-bridge_port_isolate.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. @@ -171,6 +171,22 @@ BRPORT_ATTR_FLAG(root_block, BR_ROOT_BLO
  17. BRPORT_ATTR_FLAG(learning, BR_LEARNING);
  18. BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD);
  19. +static ssize_t show_isolate_mode(struct net_bridge_port *p, char *buf)
  20. +{
  21. + int isolate_mode = (p->flags & BR_ISOLATE_MODE) ? 1 : 0;
  22. + return sprintf(buf, "%d\n", isolate_mode);
  23. +}
  24. +static ssize_t store_isolate_mode(struct net_bridge_port *p, unsigned long v)
  25. +{
  26. + if (v)
  27. + p->flags |= BR_ISOLATE_MODE;
  28. + else
  29. + p->flags &= ~BR_ISOLATE_MODE;
  30. + return 0;
  31. +}
  32. +static BRPORT_ATTR(isolate_mode, S_IRUGO | S_IWUSR,
  33. + show_isolate_mode, store_isolate_mode);
  34. +
  35. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  36. static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
  37. {
  38. @@ -213,6 +229,7 @@ static const struct brport_attribute *br
  39. &brport_attr_multicast_router,
  40. &brport_attr_multicast_fast_leave,
  41. #endif
  42. + &brport_attr_isolate_mode,
  43. NULL
  44. };
  45. --- a/net/bridge/br_input.c
  46. +++ b/net/bridge/br_input.c
  47. @@ -120,8 +120,8 @@ int br_handle_frame_finish(struct sk_buf
  48. unicast = false;
  49. br->dev->stats.multicast++;
  50. - } else if ((dst = __br_fdb_get(br, dest, vid)) &&
  51. - dst->is_local) {
  52. + } else if ((p->flags & BR_ISOLATE_MODE) ||
  53. + ((dst = __br_fdb_get(br, dest, vid)) && dst->is_local)) {
  54. skb2 = skb;
  55. /* Do not forward the packet since it's local. */
  56. skb = NULL;
  57. --- a/net/bridge/br_forward.c
  58. +++ b/net/bridge/br_forward.c
  59. @@ -117,7 +117,7 @@ EXPORT_SYMBOL_GPL(br_deliver);
  60. /* called with rcu_read_lock */
  61. void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0)
  62. {
  63. - if (should_deliver(to, skb)) {
  64. + if (should_deliver(to, skb) && !(to->flags & BR_ISOLATE_MODE)) {
  65. if (skb0)
  66. deliver_clone(to, skb, __br_forward);
  67. else
  68. @@ -173,7 +173,7 @@ static void br_flood(struct net_bridge *
  69. struct sk_buff *skb0,
  70. void (*__packet_hook)(const struct net_bridge_port *p,
  71. struct sk_buff *skb),
  72. - bool unicast)
  73. + bool unicast, bool forward)
  74. {
  75. struct net_bridge_port *p;
  76. struct net_bridge_port *prev;
  77. @@ -181,6 +181,8 @@ static void br_flood(struct net_bridge *
  78. prev = NULL;
  79. list_for_each_entry_rcu(p, &br->port_list, list) {
  80. + if (forward && (p->flags & BR_ISOLATE_MODE))
  81. + continue;
  82. /* Do not flood unicast traffic to ports that turn it off */
  83. if (unicast && !(p->flags & BR_FLOOD))
  84. continue;
  85. @@ -207,14 +209,14 @@ out:
  86. /* called with rcu_read_lock */
  87. void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, bool unicast)
  88. {
  89. - br_flood(br, skb, NULL, __br_deliver, unicast);
  90. + br_flood(br, skb, NULL, __br_deliver, unicast, false);
  91. }
  92. /* called under bridge lock */
  93. void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
  94. struct sk_buff *skb2, bool unicast)
  95. {
  96. - br_flood(br, skb, skb2, __br_forward, unicast);
  97. + br_flood(br, skb, skb2, __br_forward, unicast, true);
  98. }
  99. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING