br_switchdev.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <linux/kernel.h>
  2. #include <linux/list.h>
  3. #include <linux/netdevice.h>
  4. #include <linux/rtnetlink.h>
  5. #include <linux/skbuff.h>
  6. #include <net/switchdev.h>
  7. #include "br_private.h"
  8. static int br_switchdev_mark_get(struct net_bridge *br, struct net_device *dev)
  9. {
  10. struct net_bridge_port *p;
  11. /* dev is yet to be added to the port list. */
  12. list_for_each_entry(p, &br->port_list, list) {
  13. if (switchdev_port_same_parent_id(dev, p->dev))
  14. return p->offload_fwd_mark;
  15. }
  16. return ++br->offload_fwd_mark;
  17. }
  18. int nbp_switchdev_mark_set(struct net_bridge_port *p)
  19. {
  20. struct switchdev_attr attr = {
  21. .orig_dev = p->dev,
  22. .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
  23. };
  24. int err;
  25. ASSERT_RTNL();
  26. err = switchdev_port_attr_get(p->dev, &attr);
  27. if (err) {
  28. if (err == -EOPNOTSUPP)
  29. return 0;
  30. return err;
  31. }
  32. p->offload_fwd_mark = br_switchdev_mark_get(p->br, p->dev);
  33. return 0;
  34. }
  35. void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
  36. struct sk_buff *skb)
  37. {
  38. if (skb->offload_fwd_mark && !WARN_ON_ONCE(!p->offload_fwd_mark))
  39. BR_INPUT_SKB_CB(skb)->offload_fwd_mark = p->offload_fwd_mark;
  40. }
  41. bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
  42. const struct sk_buff *skb)
  43. {
  44. return !skb->offload_fwd_mark ||
  45. BR_INPUT_SKB_CB(skb)->offload_fwd_mark != p->offload_fwd_mark;
  46. }