tc_skbedit.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2008, Intel Corporation.
  4. *
  5. * Author: Alexander Duyck <[email protected]>
  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. u32 flags;
  13. u32 priority;
  14. u32 mark;
  15. u32 mask;
  16. u16 queue_mapping;
  17. u16 mapping_mod;
  18. u16 ptype;
  19. struct rcu_head rcu;
  20. };
  21. struct tcf_skbedit {
  22. struct tc_action common;
  23. struct tcf_skbedit_params __rcu *params;
  24. };
  25. #define to_skbedit(a) ((struct tcf_skbedit *)a)
  26. /* Return true iff action is the one identified by FLAG. */
  27. static inline bool is_tcf_skbedit_with_flag(const struct tc_action *a, u32 flag)
  28. {
  29. #ifdef CONFIG_NET_CLS_ACT
  30. u32 flags;
  31. if (a->ops && a->ops->id == TCA_ID_SKBEDIT) {
  32. rcu_read_lock();
  33. flags = rcu_dereference(to_skbedit(a)->params)->flags;
  34. rcu_read_unlock();
  35. return flags == flag;
  36. }
  37. #endif
  38. return false;
  39. }
  40. /* Return true iff action is mark */
  41. static inline bool is_tcf_skbedit_mark(const struct tc_action *a)
  42. {
  43. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_MARK);
  44. }
  45. static inline u32 tcf_skbedit_mark(const struct tc_action *a)
  46. {
  47. u32 mark;
  48. rcu_read_lock();
  49. mark = rcu_dereference(to_skbedit(a)->params)->mark;
  50. rcu_read_unlock();
  51. return mark;
  52. }
  53. /* Return true iff action is ptype */
  54. static inline bool is_tcf_skbedit_ptype(const struct tc_action *a)
  55. {
  56. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PTYPE);
  57. }
  58. static inline u32 tcf_skbedit_ptype(const struct tc_action *a)
  59. {
  60. u16 ptype;
  61. rcu_read_lock();
  62. ptype = rcu_dereference(to_skbedit(a)->params)->ptype;
  63. rcu_read_unlock();
  64. return ptype;
  65. }
  66. /* Return true iff action is priority */
  67. static inline bool is_tcf_skbedit_priority(const struct tc_action *a)
  68. {
  69. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PRIORITY);
  70. }
  71. static inline u32 tcf_skbedit_priority(const struct tc_action *a)
  72. {
  73. u32 priority;
  74. rcu_read_lock();
  75. priority = rcu_dereference(to_skbedit(a)->params)->priority;
  76. rcu_read_unlock();
  77. return priority;
  78. }
  79. /* Return true iff action is queue_mapping */
  80. static inline bool is_tcf_skbedit_queue_mapping(const struct tc_action *a)
  81. {
  82. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_QUEUE_MAPPING);
  83. }
  84. /* Return true iff action is inheritdsfield */
  85. static inline bool is_tcf_skbedit_inheritdsfield(const struct tc_action *a)
  86. {
  87. return is_tcf_skbedit_with_flag(a, SKBEDIT_F_INHERITDSFIELD);
  88. }
  89. #endif /* __NET_TC_SKBEDIT_H */