tc_vlan.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2014 Jiri Pirko <[email protected]>
  4. */
  5. #ifndef __NET_TC_VLAN_H
  6. #define __NET_TC_VLAN_H
  7. #include <net/act_api.h>
  8. #include <linux/tc_act/tc_vlan.h>
  9. struct tcf_vlan_params {
  10. int tcfv_action;
  11. unsigned char tcfv_push_dst[ETH_ALEN];
  12. unsigned char tcfv_push_src[ETH_ALEN];
  13. u16 tcfv_push_vid;
  14. __be16 tcfv_push_proto;
  15. u8 tcfv_push_prio;
  16. bool tcfv_push_prio_exists;
  17. struct rcu_head rcu;
  18. };
  19. struct tcf_vlan {
  20. struct tc_action common;
  21. struct tcf_vlan_params __rcu *vlan_p;
  22. };
  23. #define to_vlan(a) ((struct tcf_vlan *)a)
  24. static inline bool is_tcf_vlan(const struct tc_action *a)
  25. {
  26. #ifdef CONFIG_NET_CLS_ACT
  27. if (a->ops && a->ops->id == TCA_ID_VLAN)
  28. return true;
  29. #endif
  30. return false;
  31. }
  32. static inline u32 tcf_vlan_action(const struct tc_action *a)
  33. {
  34. u32 tcfv_action;
  35. rcu_read_lock();
  36. tcfv_action = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_action;
  37. rcu_read_unlock();
  38. return tcfv_action;
  39. }
  40. static inline u16 tcf_vlan_push_vid(const struct tc_action *a)
  41. {
  42. u16 tcfv_push_vid;
  43. rcu_read_lock();
  44. tcfv_push_vid = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_vid;
  45. rcu_read_unlock();
  46. return tcfv_push_vid;
  47. }
  48. static inline __be16 tcf_vlan_push_proto(const struct tc_action *a)
  49. {
  50. __be16 tcfv_push_proto;
  51. rcu_read_lock();
  52. tcfv_push_proto = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_proto;
  53. rcu_read_unlock();
  54. return tcfv_push_proto;
  55. }
  56. static inline u8 tcf_vlan_push_prio(const struct tc_action *a)
  57. {
  58. u8 tcfv_push_prio;
  59. rcu_read_lock();
  60. tcfv_push_prio = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_prio;
  61. rcu_read_unlock();
  62. return tcfv_push_prio;
  63. }
  64. static inline void tcf_vlan_push_eth(unsigned char *src, unsigned char *dest,
  65. const struct tc_action *a)
  66. {
  67. rcu_read_lock();
  68. memcpy(dest, rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_dst, ETH_ALEN);
  69. memcpy(src, rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_src, ETH_ALEN);
  70. rcu_read_unlock();
  71. }
  72. #endif /* __NET_TC_VLAN_H */