tc_ct.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NET_TC_CT_H
  3. #define __NET_TC_CT_H
  4. #include <net/act_api.h>
  5. #include <uapi/linux/tc_act/tc_ct.h>
  6. #if IS_ENABLED(CONFIG_NF_CONNTRACK)
  7. #include <net/netfilter/nf_nat.h>
  8. #include <net/netfilter/nf_conntrack_labels.h>
  9. struct tcf_ct_params {
  10. struct nf_conntrack_helper *helper;
  11. struct nf_conn *tmpl;
  12. u16 zone;
  13. u32 mark;
  14. u32 mark_mask;
  15. u32 labels[NF_CT_LABELS_MAX_SIZE / sizeof(u32)];
  16. u32 labels_mask[NF_CT_LABELS_MAX_SIZE / sizeof(u32)];
  17. struct nf_nat_range2 range;
  18. bool ipv4_range;
  19. bool put_labels;
  20. u16 ct_action;
  21. struct rcu_head rcu;
  22. struct tcf_ct_flow_table *ct_ft;
  23. struct nf_flowtable *nf_ft;
  24. };
  25. struct tcf_ct {
  26. struct tc_action common;
  27. struct tcf_ct_params __rcu *params;
  28. };
  29. #define to_ct(a) ((struct tcf_ct *)a)
  30. #define to_ct_params(a) \
  31. ((struct tcf_ct_params *) \
  32. rcu_dereference_protected(to_ct(a)->params, \
  33. lockdep_is_held(&a->tcfa_lock)))
  34. static inline uint16_t tcf_ct_zone(const struct tc_action *a)
  35. {
  36. return to_ct_params(a)->zone;
  37. }
  38. static inline int tcf_ct_action(const struct tc_action *a)
  39. {
  40. return to_ct_params(a)->ct_action;
  41. }
  42. static inline struct nf_flowtable *tcf_ct_ft(const struct tc_action *a)
  43. {
  44. return to_ct_params(a)->nf_ft;
  45. }
  46. static inline struct nf_conntrack_helper *tcf_ct_helper(const struct tc_action *a)
  47. {
  48. return to_ct_params(a)->helper;
  49. }
  50. #else
  51. static inline uint16_t tcf_ct_zone(const struct tc_action *a) { return 0; }
  52. static inline int tcf_ct_action(const struct tc_action *a) { return 0; }
  53. static inline struct nf_flowtable *tcf_ct_ft(const struct tc_action *a)
  54. {
  55. return NULL;
  56. }
  57. static inline struct nf_conntrack_helper *tcf_ct_helper(const struct tc_action *a)
  58. {
  59. return NULL;
  60. }
  61. #endif /* CONFIG_NF_CONNTRACK */
  62. #if IS_ENABLED(CONFIG_NET_ACT_CT)
  63. static inline void
  64. tcf_ct_flow_table_restore_skb(struct sk_buff *skb, unsigned long cookie)
  65. {
  66. enum ip_conntrack_info ctinfo = cookie & NFCT_INFOMASK;
  67. struct nf_conn *ct;
  68. ct = (struct nf_conn *)(cookie & NFCT_PTRMASK);
  69. nf_conntrack_get(&ct->ct_general);
  70. nf_ct_set(skb, ct, ctinfo);
  71. }
  72. #else
  73. static inline void
  74. tcf_ct_flow_table_restore_skb(struct sk_buff *skb, unsigned long cookie) { }
  75. #endif
  76. static inline bool is_tcf_ct(const struct tc_action *a)
  77. {
  78. #if defined(CONFIG_NET_CLS_ACT) && IS_ENABLED(CONFIG_NF_CONNTRACK)
  79. if (a->ops && a->ops->id == TCA_ID_CT)
  80. return true;
  81. #endif
  82. return false;
  83. }
  84. #endif /* __NET_TC_CT_H */