642-bridge_port_isolate.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. --- a/include/linux/if_bridge.h
  2. +++ b/include/linux/if_bridge.h
  3. @@ -44,6 +44,7 @@ struct br_ip_list {
  4. #define BR_PROMISC BIT(7)
  5. #define BR_PROXYARP BIT(8)
  6. #define BR_LEARNING_SYNC BIT(9)
  7. +#define BR_ISOLATE_MODE BIT(10)
  8. extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
  9. --- a/net/bridge/br_sysfs_if.c
  10. +++ b/net/bridge/br_sysfs_if.c
  11. @@ -172,6 +172,22 @@ BRPORT_ATTR_FLAG(learning, BR_LEARNING);
  12. BRPORT_ATTR_FLAG(unicast_flood, BR_FLOOD);
  13. BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
  14. +static ssize_t show_isolate_mode(struct net_bridge_port *p, char *buf)
  15. +{
  16. + int isolate_mode = (p->flags & BR_ISOLATE_MODE) ? 1 : 0;
  17. + return sprintf(buf, "%d\n", isolate_mode);
  18. +}
  19. +static ssize_t store_isolate_mode(struct net_bridge_port *p, unsigned long v)
  20. +{
  21. + if (v)
  22. + p->flags |= BR_ISOLATE_MODE;
  23. + else
  24. + p->flags &= ~BR_ISOLATE_MODE;
  25. + return 0;
  26. +}
  27. +static BRPORT_ATTR(isolate_mode, S_IRUGO | S_IWUSR,
  28. + show_isolate_mode, store_isolate_mode);
  29. +
  30. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  31. static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
  32. {
  33. @@ -215,6 +231,7 @@ static const struct brport_attribute *br
  34. &brport_attr_multicast_fast_leave,
  35. #endif
  36. &brport_attr_proxyarp,
  37. + &brport_attr_isolate_mode,
  38. NULL
  39. };
  40. --- a/net/bridge/br_input.c
  41. +++ b/net/bridge/br_input.c
  42. @@ -181,8 +181,8 @@ int br_handle_frame_finish(struct sk_buf
  43. unicast = false;
  44. br->dev->stats.multicast++;
  45. - } else if ((dst = __br_fdb_get(br, dest, vid)) &&
  46. - dst->is_local) {
  47. + } else if ((p->flags & BR_ISOLATE_MODE) ||
  48. + ((dst = __br_fdb_get(br, dest, vid)) && 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. @@ -117,7 +117,7 @@ EXPORT_SYMBOL_GPL(br_deliver);
  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. @@ -173,7 +173,7 @@ static void br_flood(struct net_bridge *
  64. struct sk_buff *skb0,
  65. void (*__packet_hook)(const struct net_bridge_port *p,
  66. struct sk_buff *skb),
  67. - bool unicast)
  68. + bool unicast, bool forward)
  69. {
  70. struct net_bridge_port *p;
  71. struct net_bridge_port *prev;
  72. @@ -181,6 +181,8 @@ static void br_flood(struct net_bridge *
  73. prev = NULL;
  74. list_for_each_entry_rcu(p, &br->port_list, list) {
  75. + if (forward && (p->flags & BR_ISOLATE_MODE))
  76. + continue;
  77. /* Do not flood unicast traffic to ports that turn it off */
  78. if (unicast && !(p->flags & BR_FLOOD))
  79. continue;
  80. @@ -212,14 +214,14 @@ out:
  81. /* called with rcu_read_lock */
  82. void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, bool unicast)
  83. {
  84. - br_flood(br, skb, NULL, __br_deliver, unicast);
  85. + br_flood(br, skb, NULL, __br_deliver, unicast, false);
  86. }
  87. /* called under bridge lock */
  88. void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
  89. struct sk_buff *skb2, bool unicast)
  90. {
  91. - br_flood(br, skb, skb2, __br_forward, unicast);
  92. + br_flood(br, skb, skb2, __br_forward, unicast, true);
  93. }
  94. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING