tc_skbedit.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2008, Intel Corporation.
  4. *
  5. * Author: Alexander Duyck <alexander.h.duyck@intel.com>
  6. */
  7. #ifndef __NET_TC_SKBEDIT_H
  8. #define __NET_TC_SKBEDIT_H
  9. #include <net/act_api.h>
  10. #include <linux/tc_act/tc_skbedit.h>
  11. struct tcf_skbedit_params {
  12. int action;
  13. u32 flags;
  14. u32 priority;
  15. u32 mark;
  16. u32 mask;
  17. u16 queue_mapping;
  18. u16 mapping_mod;
  19. u16 ptype;
  20. struct rcu_head rcu;
  21. };
  22. struct tcf_skbedit {
  23. struct tc_action common;
  24. struct tcf_skbedit_params __rcu *params;
  25. };
  26. #define to_skbedit(a) ((struct tcf_skbedit *)a)
  27. /* Return true iff action is the one identified by FLAG. */
  28. static inline bool is_tcf_skbedit_with_flag(const struct tc_action *a, u32 flag)
  29. {
  30. #ifdef CONFIG_NET_CLS_ACT
  31. u32 flags;
  32. if (a->ops && a->ops->id == TCA_ID_SKBEDIT) {
  33. rcu_read_lock();
  34. flags = rcu_dereference(to_skbedit(a)->params)->flags;
  35. rcu_read_unlock();
  36. return flags == flag;
  37. }
  38. #endif
  39. return false;
  40. }
  41. /* Return true iff action is mark */
  42. static inline bool is_tcf_skbedit_mark(const struct tc_action *a)
  43. {
  44. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_MARK);
  45. }
  46. static inline u32 tcf_skbedit_mark(const struct tc_action *a)
  47. {
  48. u32 mark;
  49. rcu_read_lock();
  50. mark = rcu_dereference(to_skbedit(a)->params)->mark;
  51. rcu_read_unlock();
  52. return mark;
  53. }
  54. /* Return true iff action is ptype */
  55. static inline bool is_tcf_skbedit_ptype(const struct tc_action *a)
  56. {
  57. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PTYPE);
  58. }
  59. static inline u32 tcf_skbedit_ptype(const struct tc_action *a)
  60. {
  61. u16 ptype;
  62. rcu_read_lock();
  63. ptype = rcu_dereference(to_skbedit(a)->params)->ptype;
  64. rcu_read_unlock();
  65. return ptype;
  66. }
  67. /* Return true iff action is priority */
  68. static inline bool is_tcf_skbedit_priority(const struct tc_action *a)
  69. {
  70. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PRIORITY);
  71. }
  72. static inline u32 tcf_skbedit_priority(const struct tc_action *a)
  73. {
  74. u32 priority;
  75. rcu_read_lock();
  76. priority = rcu_dereference(to_skbedit(a)->params)->priority;
  77. rcu_read_unlock();
  78. return priority;
  79. }
  80. static inline u16 tcf_skbedit_rx_queue_mapping(const struct tc_action *a)
  81. {
  82. u16 rx_queue;
  83. rcu_read_lock();
  84. rx_queue = rcu_dereference(to_skbedit(a)->params)->queue_mapping;
  85. rcu_read_unlock();
  86. return rx_queue;
  87. }
  88. /* Return true iff action is queue_mapping */
  89. static inline bool is_tcf_skbedit_queue_mapping(const struct tc_action *a)
  90. {
  91. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_QUEUE_MAPPING);
  92. }
  93. /* Return true if action is on ingress traffic */
  94. static inline bool is_tcf_skbedit_ingress(u32 flags)
  95. {
  96. return flags & TCA_ACT_FLAGS_AT_INGRESS;
  97. }
  98. static inline bool is_tcf_skbedit_tx_queue_mapping(const struct tc_action *a)
  99. {
  100. return is_tcf_skbedit_queue_mapping(a) &&
  101. !is_tcf_skbedit_ingress(a->tcfa_flags);
  102. }
  103. static inline bool is_tcf_skbedit_rx_queue_mapping(const struct tc_action *a)
  104. {
  105. return is_tcf_skbedit_queue_mapping(a) &&
  106. is_tcf_skbedit_ingress(a->tcfa_flags);
  107. }
  108. /* Return true iff action is inheritdsfield */
  109. static inline bool is_tcf_skbedit_inheritdsfield(const struct tc_action *a)
  110. {
  111. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_INHERITDSFIELD);
  112. }
  113. #endif /* __NET_TC_SKBEDIT_H */