tc_pedit.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. u32 tcfp_off_max_hint;
  15. unsigned char tcfp_nkeys;
  16. unsigned char tcfp_flags;
  17. struct rcu_head rcu;
  18. };
  19. struct tcf_pedit {
  20. struct tc_action common;
  21. struct tcf_pedit_parms __rcu *parms;
  22. };
  23. #define to_pedit(a) ((struct tcf_pedit *)a)
  24. #define to_pedit_parms(a) (rcu_dereference(to_pedit(a)->parms))
  25. static inline bool is_tcf_pedit(const struct tc_action *a)
  26. {
  27. #ifdef CONFIG_NET_CLS_ACT
  28. if (a->ops && a->ops->id == TCA_ID_PEDIT)
  29. return true;
  30. #endif
  31. return false;
  32. }
  33. static inline int tcf_pedit_nkeys(const struct tc_action *a)
  34. {
  35. struct tcf_pedit_parms *parms;
  36. int nkeys;
  37. rcu_read_lock();
  38. parms = to_pedit_parms(a);
  39. nkeys = parms->tcfp_nkeys;
  40. rcu_read_unlock();
  41. return nkeys;
  42. }
  43. static inline u32 tcf_pedit_htype(const struct tc_action *a, int index)
  44. {
  45. u32 htype = TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
  46. struct tcf_pedit_parms *parms;
  47. rcu_read_lock();
  48. parms = to_pedit_parms(a);
  49. if (parms->tcfp_keys_ex)
  50. htype = parms->tcfp_keys_ex[index].htype;
  51. rcu_read_unlock();
  52. return htype;
  53. }
  54. static inline u32 tcf_pedit_cmd(const struct tc_action *a, int index)
  55. {
  56. struct tcf_pedit_parms *parms;
  57. u32 cmd = __PEDIT_CMD_MAX;
  58. rcu_read_lock();
  59. parms = to_pedit_parms(a);
  60. if (parms->tcfp_keys_ex)
  61. cmd = parms->tcfp_keys_ex[index].cmd;
  62. rcu_read_unlock();
  63. return cmd;
  64. }
  65. static inline u32 tcf_pedit_mask(const struct tc_action *a, int index)
  66. {
  67. struct tcf_pedit_parms *parms;
  68. u32 mask;
  69. rcu_read_lock();
  70. parms = to_pedit_parms(a);
  71. mask = parms->tcfp_keys[index].mask;
  72. rcu_read_unlock();
  73. return mask;
  74. }
  75. static inline u32 tcf_pedit_val(const struct tc_action *a, int index)
  76. {
  77. struct tcf_pedit_parms *parms;
  78. u32 val;
  79. rcu_read_lock();
  80. parms = to_pedit_parms(a);
  81. val = parms->tcfp_keys[index].val;
  82. rcu_read_unlock();
  83. return val;
  84. }
  85. static inline u32 tcf_pedit_offset(const struct tc_action *a, int index)
  86. {
  87. struct tcf_pedit_parms *parms;
  88. u32 off;
  89. rcu_read_lock();
  90. parms = to_pedit_parms(a);
  91. off = parms->tcfp_keys[index].off;
  92. rcu_read_unlock();
  93. return off;
  94. }
  95. #endif /* __NET_TC_PED_H */