642-bridge_port_isolate.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --- a/net/bridge/br_private.h
  2. +++ b/net/bridge/br_private.h
  3. @@ -139,6 +139,7 @@ struct net_bridge_port
  4. #define BR_BPDU_GUARD 0x00000002
  5. #define BR_ROOT_BLOCK 0x00000004
  6. #define BR_MULTICAST_FAST_LEAVE 0x00000008
  7. +#define BR_ISOLATE_MODE 0x00000010
  8. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  9. u32 multicast_startup_queries_sent;
  10. --- a/net/bridge/br_sysfs_if.c
  11. +++ b/net/bridge/br_sysfs_if.c
  12. @@ -159,6 +159,22 @@ BRPORT_ATTR_FLAG(hairpin_mode, BR_HAIRPI
  13. BRPORT_ATTR_FLAG(bpdu_guard, BR_BPDU_GUARD);
  14. BRPORT_ATTR_FLAG(root_block, BR_ROOT_BLOCK);
  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. @@ -199,6 +215,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. @@ -95,7 +95,8 @@ int br_handle_frame_finish(struct sk_buf
  44. skb2 = skb;
  45. br->dev->stats.multicast++;
  46. - } else if ((dst = __br_fdb_get(br, dest)) && dst->is_local) {
  47. + } else if ((p->flags & BR_ISOLATE_MODE) ||
  48. + ((dst = __br_fdb_get(br, dest)) && dst->is_local)) {
  49. skb2 = skb;
  50. /* Do not forward the packet since it's local. */
  51. skb = NULL;
  52. --- a/net/bridge/br_forward.c
  53. +++ b/net/bridge/br_forward.c
  54. @@ -110,7 +110,7 @@ void br_deliver(const struct net_bridge_
  55. /* called with rcu_read_lock */
  56. void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0)
  57. {
  58. - if (should_deliver(to, skb)) {
  59. + if (should_deliver(to, skb) && !(to->flags & BR_ISOLATE_MODE)) {
  60. if (skb0)
  61. deliver_clone(to, skb, __br_forward);
  62. else
  63. @@ -165,7 +165,8 @@ out:
  64. static void br_flood(struct net_bridge *br, struct sk_buff *skb,
  65. struct sk_buff *skb0,
  66. void (*__packet_hook)(const struct net_bridge_port *p,
  67. - struct sk_buff *skb))
  68. + struct sk_buff *skb),
  69. + bool forward)
  70. {
  71. struct net_bridge_port *p;
  72. struct net_bridge_port *prev;
  73. @@ -173,6 +174,9 @@ 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. +
  79. prev = maybe_deliver(prev, p, skb, __packet_hook);
  80. if (IS_ERR(prev))
  81. goto out;
  82. @@ -196,14 +200,14 @@ out:
  83. /* called with rcu_read_lock */
  84. void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb)
  85. {
  86. - br_flood(br, skb, NULL, __br_deliver);
  87. + br_flood(br, skb, NULL, __br_deliver, false);
  88. }
  89. /* called under bridge lock */
  90. void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
  91. struct sk_buff *skb2)
  92. {
  93. - br_flood(br, skb, skb2, __br_forward);
  94. + br_flood(br, skb, skb2, __br_forward, true);
  95. }
  96. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING