tc_pedit.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NET_TC_PED_H
  3. #define __NET_TC_PED_H
  4. #include <net/act_api.h>
  5. #include <linux/tc_act/tc_pedit.h>
  6. #include <linux/types.h>
  7. struct tcf_pedit_key_ex {
  8. enum pedit_header_type htype;
  9. enum pedit_cmd cmd;
  10. };
  11. struct tcf_pedit_parms {
  12. struct tc_pedit_key *tcfp_keys;
  13. struct tcf_pedit_key_ex *tcfp_keys_ex;
  14. int action;
  15. u32 tcfp_off_max_hint;
  16. unsigned char tcfp_nkeys;
  17. unsigned char tcfp_flags;
  18. struct rcu_head rcu;
  19. };
  20. struct tcf_pedit {
  21. struct tc_action common;
  22. struct tcf_pedit_parms __rcu *parms;
  23. };
  24. #define to_pedit(a) ((struct tcf_pedit *)a)
  25. #define to_pedit_parms(a) (rcu_dereference(to_pedit(a)->parms))
  26. static inline bool is_tcf_pedit(const struct tc_action *a)
  27. {
  28. #ifdef CONFIG_NET_CLS_ACT
  29. if (a->ops && a->ops->id == TCA_ID_PEDIT)
  30. return true;
  31. #endif
  32. return false;
  33. }
  34. static inline int tcf_pedit_nkeys(const struct tc_action *a)
  35. {
  36. struct tcf_pedit_parms *parms;
  37. int nkeys;
  38. rcu_read_lock();
  39. parms = to_pedit_parms(a);
  40. nkeys = parms->tcfp_nkeys;
  41. rcu_read_unlock();
  42. return nkeys;
  43. }
  44. static inline u32 tcf_pedit_htype(const struct tc_action *a, int index)
  45. {
  46. u32 htype = TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
  47. struct tcf_pedit_parms *parms;
  48. rcu_read_lock();
  49. parms = to_pedit_parms(a);
  50. if (parms->tcfp_keys_ex)
  51. htype = parms->tcfp_keys_ex[index].htype;
  52. rcu_read_unlock();
  53. return htype;
  54. }
  55. static inline u32 tcf_pedit_cmd(const struct tc_action *a, int index)
  56. {
  57. struct tcf_pedit_parms *parms;
  58. u32 cmd = __PEDIT_CMD_MAX;
  59. rcu_read_lock();
  60. parms = to_pedit_parms(a);
  61. if (parms->tcfp_keys_ex)
  62. cmd = parms->tcfp_keys_ex[index].cmd;
  63. rcu_read_unlock();
  64. return cmd;
  65. }
  66. static inline u32 tcf_pedit_mask(const struct tc_action *a, int index)
  67. {
  68. struct tcf_pedit_parms *parms;
  69. u32 mask;
  70. rcu_read_lock();
  71. parms = to_pedit_parms(a);
  72. mask = parms->tcfp_keys[index].mask;
  73. rcu_read_unlock();
  74. return mask;
  75. }
  76. static inline u32 tcf_pedit_val(const struct tc_action *a, int index)
  77. {
  78. struct tcf_pedit_parms *parms;
  79. u32 val;
  80. rcu_read_lock();
  81. parms = to_pedit_parms(a);
  82. val = parms->tcfp_keys[index].val;
  83. rcu_read_unlock();
  84. return val;
  85. }
  86. static inline u32 tcf_pedit_offset(const struct tc_action *a, int index)
  87. {
  88. struct tcf_pedit_parms *parms;
  89. u32 off;
  90. rcu_read_lock();
  91. parms = to_pedit_parms(a);
  92. off = parms->tcfp_keys[index].off;
  93. rcu_read_unlock();
  94. return off;
  95. }
  96. #endif /* __NET_TC_PED_H */