642-bridge_port_isolate.patch 3.2 KB

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