tc_ct.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. int action;
  14. u32 mark;
  15. u32 mark_mask;
  16. u32 labels[NF_CT_LABELS_MAX_SIZE / sizeof(u32)];
  17. u32 labels_mask[NF_CT_LABELS_MAX_SIZE / sizeof(u32)];
  18. struct nf_nat_range2 range;
  19. bool ipv4_range;
  20. bool put_labels;
  21. u16 ct_action;
  22. struct rcu_head rcu;
  23. struct tcf_ct_flow_table *ct_ft;
  24. struct nf_flowtable *nf_ft;
  25. };
  26. struct tcf_ct {
  27. struct tc_action common;
  28. struct tcf_ct_params __rcu *params;
  29. };
  30. #define to_ct(a) ((struct tcf_ct *)a)
  31. #define to_ct_params(a) \
  32. ((struct tcf_ct_params *) \
  33. rcu_dereference_protected(to_ct(a)->params, \
  34. lockdep_is_held(&a->tcfa_lock)))
  35. static inline uint16_t tcf_ct_zone(const struct tc_action *a)
  36. {
  37. return to_ct_params(a)->zone;
  38. }
  39. static inline int tcf_ct_action(const struct tc_action *a)
  40. {
  41. return to_ct_params(a)->ct_action;
  42. }
  43. static inline struct nf_flowtable *tcf_ct_ft(const struct tc_action *a)
  44. {
  45. return to_ct_params(a)->nf_ft;
  46. }
  47. static inline struct nf_conntrack_helper *tcf_ct_helper(const struct tc_action *a)
  48. {
  49. return to_ct_params(a)->helper;
  50. }
  51. #else
  52. static inline uint16_t tcf_ct_zone(const struct tc_action *a) { return 0; }
  53. static inline int tcf_ct_action(const struct tc_action *a) { return 0; }
  54. static inline struct nf_flowtable *tcf_ct_ft(const struct tc_action *a)
  55. {
  56. return NULL;
  57. }
  58. static inline struct nf_conntrack_helper *tcf_ct_helper(const struct tc_action *a)
  59. {
  60. return NULL;
  61. }
  62. #endif /* CONFIG_NF_CONNTRACK */
  63. #if IS_ENABLED(CONFIG_NET_ACT_CT)
  64. static inline void
  65. tcf_ct_flow_table_restore_skb(struct sk_buff *skb, unsigned long cookie)
  66. {
  67. enum ip_conntrack_info ctinfo = cookie & NFCT_INFOMASK;
  68. struct nf_conn *ct;
  69. ct = (struct nf_conn *)(cookie & NFCT_PTRMASK);
  70. nf_conntrack_get(&ct->ct_general);
  71. nf_ct_set(skb, ct, ctinfo);
  72. }
  73. #else
  74. static inline void
  75. tcf_ct_flow_table_restore_skb(struct sk_buff *skb, unsigned long cookie) { }
  76. #endif
  77. #endif /* __NET_TC_CT_H */