| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
#ifndef _NF_CONNTRACK_EXTEND_H |
| 3 |
#define _NF_CONNTRACK_EXTEND_H |
| 4 |
|
| 5 |
#include <linux/slab.h> |
| 6 |
|
| 7 |
#include <net/netfilter/nf_conntrack.h> |
| 8 |
|
| 9 |
enum nf_ct_ext_id { |
| 10 |
NF_CT_EXT_HELPER, |
| 11 |
#if IS_ENABLED(CONFIG_NF_NAT) |
| 12 |
NF_CT_EXT_NAT, |
| 13 |
#endif |
| 14 |
NF_CT_EXT_SEQADJ, |
| 15 |
NF_CT_EXT_ACCT, |
| 16 |
#ifdef CONFIG_NF_CONNTRACK_EVENTS |
| 17 |
NF_CT_EXT_ECACHE, |
| 18 |
#endif |
| 19 |
#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP |
| 20 |
NF_CT_EXT_TSTAMP, |
| 21 |
#endif |
| 22 |
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT |
| 23 |
NF_CT_EXT_TIMEOUT, |
| 24 |
#endif |
| 25 |
#ifdef CONFIG_NF_CONNTRACK_LABELS |
| 26 |
NF_CT_EXT_LABELS, |
| 27 |
#endif |
| 28 |
#if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY) |
| 29 |
NF_CT_EXT_SYNPROXY, |
| 30 |
#endif |
| 31 |
#if IS_ENABLED(CONFIG_NET_ACT_CT) |
| 32 |
NF_CT_EXT_ACT_CT, |
| 33 |
#endif |
| 34 |
NF_CT_EXT_NUM, |
| 35 |
}; |
| 36 |
|
| 37 |
/* Extensions: optional stuff which isn't permanently in struct. */ |
| 38 |
struct nf_ct_ext { |
| 39 |
u8 offset[NF_CT_EXT_NUM]; |
| 40 |
u8 len; |
| 41 |
unsigned int gen_id; |
| 42 |
char data[] __aligned(8); |
| 43 |
}; |
| 44 |
|
| 45 |
static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id) |
| 46 |
{ |
| 47 |
return !!ext->offset[id]; |
| 48 |
} |
| 49 |
|
| 50 |
static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id) |
| 51 |
{ |
| 52 |
return (ct->ext && __nf_ct_ext_exist(ct->ext, id)); |
| 53 |
} |
| 54 |
|
| 55 |
void *__nf_ct_ext_find(const struct nf_ct_ext *ext, u8 id); |
| 56 |
|
| 57 |
static inline void *nf_ct_ext_find(const struct nf_conn *ct, u8 id) |
| 58 |
{ |
| 59 |
struct nf_ct_ext *ext = ct->ext; |
| 60 |
|
| 61 |
if (!ext || !__nf_ct_ext_exist(ext, id)) |
| 62 |
return NULL; |
| 63 |
|
| 64 |
if (unlikely(ext->gen_id)) |
| 65 |
return __nf_ct_ext_find(ext, id); |
| 66 |
|
| 67 |
return (void *)ct->ext + ct->ext->offset[id]; |
| 68 |
} |
| 69 |
|
| 70 |
/* Add this type, returns pointer to data or NULL. */ |
| 71 |
void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp); |
| 72 |
|
| 73 |
/* ext genid. if ext->id != ext_genid, extensions cannot be used |
| 74 |
* anymore unless conntrack has CONFIRMED bit set. |
| 75 |
*/ |
| 76 |
extern atomic_t nf_conntrack_ext_genid; |
| 77 |
void nf_ct_ext_bump_genid(void); |
| 78 |
|
| 79 |
#endif /* _NF_CONNTRACK_EXTEND_H */ |