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