tc_ct.h 2.1 KB

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