090-net-bridge-add-support-for-port-isolation.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
  2. Date: Thu, 24 May 2018 11:56:48 +0300
  3. Subject: [PATCH] net: bridge: add support for port isolation
  4. This patch adds support for a new port flag - BR_ISOLATED. If it is set
  5. then isolated ports cannot communicate between each other, but they can
  6. still communicate with non-isolated ports. The same can be achieved via
  7. ACLs but they can't scale with large number of ports and also the
  8. complexity of the rules grows. This feature can be used to achieve
  9. isolated vlan functionality (similar to pvlan) as well, though currently
  10. it will be port-wide (for all vlans on the port). The new test in
  11. should_deliver uses data that is already cache hot and the new boolean
  12. is used to avoid an additional source port test in should_deliver.
  13. Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
  14. Reviewed-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
  15. Signed-off-by: David S. Miller <davem@davemloft.net>
  16. ---
  17. --- a/include/uapi/linux/if_link.h
  18. +++ b/include/uapi/linux/if_link.h
  19. @@ -326,6 +326,8 @@ enum {
  20. IFLA_BRPORT_MCAST_TO_UCAST,
  21. IFLA_BRPORT_VLAN_TUNNEL,
  22. IFLA_BRPORT_BCAST_FLOOD,
  23. + IFLA_BRPORT_NEIGH_SUPPRESS,
  24. + IFLA_BRPORT_ISOLATED,
  25. __IFLA_BRPORT_MAX
  26. };
  27. #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
  28. --- a/net/bridge/br_forward.c
  29. +++ b/net/bridge/br_forward.c
  30. @@ -30,7 +30,8 @@ static inline int should_deliver(const s
  31. vg = nbp_vlan_group_rcu(p);
  32. return ((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) &&
  33. br_allowed_egress(vg, skb) && p->state == BR_STATE_FORWARDING &&
  34. - nbp_switchdev_allowed_egress(p, skb);
  35. + nbp_switchdev_allowed_egress(p, skb) &&
  36. + !br_skb_isolated(p, skb);
  37. }
  38. int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
  39. --- a/net/bridge/br_input.c
  40. +++ b/net/bridge/br_input.c
  41. @@ -170,6 +170,7 @@ int br_handle_frame_finish(struct net *n
  42. goto drop;
  43. BR_INPUT_SKB_CB(skb)->brdev = br->dev;
  44. + BR_INPUT_SKB_CB(skb)->src_port_isolated = !!(p->flags & BR_ISOLATED);
  45. if (IS_ENABLED(CONFIG_INET) && skb->protocol == htons(ETH_P_ARP))
  46. br_do_proxy_arp(skb, br, vid, p);
  47. --- a/net/bridge/br_netlink.c
  48. +++ b/net/bridge/br_netlink.c
  49. @@ -138,6 +138,7 @@ static inline size_t br_port_info_size(v
  50. + nla_total_size(1) /* IFLA_BRPORT_PROXYARP */
  51. + nla_total_size(1) /* IFLA_BRPORT_PROXYARP_WIFI */
  52. + nla_total_size(1) /* IFLA_BRPORT_VLAN_TUNNEL */
  53. + + nla_total_size(1) /* IFLA_BRPORT_ISOLATED */
  54. + nla_total_size(sizeof(struct ifla_bridge_id)) /* IFLA_BRPORT_ROOT_ID */
  55. + nla_total_size(sizeof(struct ifla_bridge_id)) /* IFLA_BRPORT_BRIDGE_ID */
  56. + nla_total_size(sizeof(u16)) /* IFLA_BRPORT_DESIGNATED_PORT */
  57. @@ -208,7 +209,8 @@ static int br_port_fill_attrs(struct sk_
  58. p->topology_change_ack) ||
  59. nla_put_u8(skb, IFLA_BRPORT_CONFIG_PENDING, p->config_pending) ||
  60. nla_put_u8(skb, IFLA_BRPORT_VLAN_TUNNEL, !!(p->flags &
  61. - BR_VLAN_TUNNEL)))
  62. + BR_VLAN_TUNNEL)) ||
  63. + nla_put_u8(skb, IFLA_BRPORT_ISOLATED, !!(p->flags & BR_ISOLATED)))
  64. return -EMSGSIZE;
  65. timerval = br_timer_value(&p->message_age_timer);
  66. @@ -637,6 +639,7 @@ static const struct nla_policy br_port_p
  67. [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NLA_U8 },
  68. [IFLA_BRPORT_MCAST_FLOOD] = { .type = NLA_U8 },
  69. [IFLA_BRPORT_BCAST_FLOOD] = { .type = NLA_U8 },
  70. + [IFLA_BRPORT_ISOLATED] = { .type = NLA_U8 },
  71. };
  72. /* Change the state of the port and notify spanning tree */
  73. @@ -773,6 +776,11 @@ static int br_setport(struct net_bridge_
  74. return err;
  75. }
  76. #endif
  77. +
  78. + err = br_set_port_flag(p, tb, IFLA_BRPORT_ISOLATED, BR_ISOLATED);
  79. + if (err)
  80. + return err;
  81. +
  82. br_port_flags_change(p, old_flags ^ p->flags);
  83. return 0;
  84. }
  85. --- a/net/bridge/br_private.h
  86. +++ b/net/bridge/br_private.h
  87. @@ -407,6 +407,7 @@ struct br_input_skb_cb {
  88. #endif
  89. bool proxyarp_replied;
  90. + bool src_port_isolated;
  91. #ifdef CONFIG_BRIDGE_VLAN_FILTERING
  92. bool vlan_filtered;
  93. @@ -554,6 +555,14 @@ int br_forward_finish(struct net *net, s
  94. void br_flood(struct net_bridge *br, struct sk_buff *skb,
  95. enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
  96. +/* return true if both source port and dest port are isolated */
  97. +static inline bool br_skb_isolated(const struct net_bridge_port *to,
  98. + const struct sk_buff *skb)
  99. +{
  100. + return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
  101. + (to->flags & BR_ISOLATED);
  102. +}
  103. +
  104. /* br_if.c */
  105. void br_port_carrier_check(struct net_bridge_port *p);
  106. int br_add_bridge(struct net *net, const char *name);
  107. --- a/net/bridge/br_sysfs_if.c
  108. +++ b/net/bridge/br_sysfs_if.c
  109. @@ -174,6 +174,7 @@ BRPORT_ATTR_FLAG(proxyarp, BR_PROXYARP);
  110. BRPORT_ATTR_FLAG(proxyarp_wifi, BR_PROXYARP_WIFI);
  111. BRPORT_ATTR_FLAG(multicast_flood, BR_MCAST_FLOOD);
  112. BRPORT_ATTR_FLAG(broadcast_flood, BR_BCAST_FLOOD);
  113. +BRPORT_ATTR_FLAG(isolated, BR_ISOLATED);
  114. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  115. static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
  116. @@ -223,6 +224,7 @@ static const struct brport_attribute *br
  117. &brport_attr_proxyarp_wifi,
  118. &brport_attr_multicast_flood,
  119. &brport_attr_broadcast_flood,
  120. + &brport_attr_isolated,
  121. NULL
  122. };
  123. --- a/include/linux/if_bridge.h
  124. +++ b/include/linux/if_bridge.h
  125. @@ -49,6 +49,7 @@ struct br_ip_list {
  126. #define BR_MULTICAST_TO_UNICAST BIT(12)
  127. #define BR_VLAN_TUNNEL BIT(13)
  128. #define BR_BCAST_FLOOD BIT(14)
  129. +#define BR_ISOLATED BIT(16)
  130. #define BR_DEFAULT_AGEING_TIME (300 * HZ)