]>
Commit | Line | Data |
---|---|---|
9fb9cbb1 YK |
1 | /* |
2 | * connection tracking helpers. | |
3 | * | |
4 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | |
5 | * - generalize L3 protocol dependent part. | |
6 | * | |
7 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_helper.h | |
8 | */ | |
9 | ||
10 | #ifndef _NF_CONNTRACK_HELPER_H | |
11 | #define _NF_CONNTRACK_HELPER_H | |
12 | #include <net/netfilter/nf_conntrack.h> | |
ceceae1b | 13 | #include <net/netfilter/nf_conntrack_extend.h> |
1afc5679 | 14 | #include <net/netfilter/nf_conntrack_expect.h> |
9fb9cbb1 YK |
15 | |
16 | struct module; | |
17 | ||
12f7a505 PNA |
18 | enum nf_ct_helper_flags { |
19 | NF_CT_HELPER_F_USERSPACE = (1 << 0), | |
20 | NF_CT_HELPER_F_CONFIGURED = (1 << 1), | |
21 | }; | |
22 | ||
af9d32ad HE |
23 | #define NF_CT_HELPER_NAME_LEN 16 |
24 | ||
fd2c3ef7 | 25 | struct nf_conntrack_helper { |
b8a7fe6c | 26 | struct hlist_node hnode; /* Internal use. */ |
9fb9cbb1 | 27 | |
3a8fc53a | 28 | char name[NF_CT_HELPER_NAME_LEN]; /* name of the module */ |
9fb9cbb1 | 29 | struct module *me; /* pointer to self */ |
6002f266 | 30 | const struct nf_conntrack_expect_policy *expect_policy; |
9fb9cbb1 | 31 | |
1afc5679 PNA |
32 | /* length of internal data, ie. sizeof(struct nf_ct_*_master) */ |
33 | size_t data_len; | |
34 | ||
d4156e8c | 35 | /* Tuple of things we will help (compared against server response) */ |
9fb9cbb1 | 36 | struct nf_conntrack_tuple tuple; |
d4156e8c | 37 | |
9fb9cbb1 YK |
38 | /* Function to call when data passes; return verdict, or -1 to |
39 | invalidate. */ | |
3db05fea | 40 | int (*help)(struct sk_buff *skb, |
9fb9cbb1 YK |
41 | unsigned int protoff, |
42 | struct nf_conn *ct, | |
43 | enum ip_conntrack_info conntrackinfo); | |
c1d10adb | 44 | |
f09943fe PM |
45 | void (*destroy)(struct nf_conn *ct); |
46 | ||
ae243bee | 47 | int (*from_nlattr)(struct nlattr *attr, struct nf_conn *ct); |
fdf70832 | 48 | int (*to_nlattr)(struct sk_buff *skb, const struct nf_conn *ct); |
6002f266 | 49 | unsigned int expect_class_max; |
12f7a505 PNA |
50 | |
51 | unsigned int flags; | |
52 | unsigned int queue_num; /* For user-space helpers. */ | |
9fb9cbb1 YK |
53 | }; |
54 | ||
906535b0 FW |
55 | /* Must be kept in sync with the classes defined by helpers */ |
56 | #define NF_CT_MAX_EXPECT_CLASSES 4 | |
57 | ||
58 | /* nf_conn feature for connections that have a helper */ | |
59 | struct nf_conn_help { | |
60 | /* Helper. if any */ | |
61 | struct nf_conntrack_helper __rcu *helper; | |
62 | ||
63 | struct hlist_head expectations; | |
64 | ||
65 | /* Current number of expected connections */ | |
66 | u8 expecting[NF_CT_MAX_EXPECT_CLASSES]; | |
67 | ||
68 | /* private helper information. */ | |
69 | char data[]; | |
70 | }; | |
71 | ||
4e77be46 JP |
72 | struct nf_conntrack_helper *__nf_conntrack_helper_find(const char *name, |
73 | u16 l3num, u8 protonum); | |
7e5d03bb | 74 | |
4e77be46 JP |
75 | struct nf_conntrack_helper *nf_conntrack_helper_try_module_get(const char *name, |
76 | u16 l3num, | |
77 | u8 protonum); | |
82de0be6 GF |
78 | void nf_ct_helper_init(struct nf_conntrack_helper *helper, |
79 | u16 l3num, u16 protonum, const char *name, | |
80 | u16 default_port, u16 spec_port, u32 id, | |
81 | const struct nf_conntrack_expect_policy *exp_pol, | |
82 | u32 expect_class_max, u32 data_len, | |
83 | int (*help)(struct sk_buff *skb, unsigned int protoff, | |
84 | struct nf_conn *ct, | |
85 | enum ip_conntrack_info ctinfo), | |
86 | int (*from_nlattr)(struct nlattr *attr, | |
87 | struct nf_conn *ct), | |
88 | struct module *module); | |
84f3bb9a | 89 | |
4e77be46 JP |
90 | int nf_conntrack_helper_register(struct nf_conntrack_helper *); |
91 | void nf_conntrack_helper_unregister(struct nf_conntrack_helper *); | |
9fb9cbb1 | 92 | |
82de0be6 GF |
93 | int nf_conntrack_helpers_register(struct nf_conntrack_helper *, unsigned int); |
94 | void nf_conntrack_helpers_unregister(struct nf_conntrack_helper *, | |
95 | unsigned int); | |
96 | ||
4e77be46 JP |
97 | struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, |
98 | struct nf_conntrack_helper *helper, | |
99 | gfp_t gfp); | |
b560580a | 100 | |
4e77be46 JP |
101 | int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, |
102 | gfp_t flags); | |
226c0c0e | 103 | |
4e77be46 | 104 | void nf_ct_helper_destroy(struct nf_conn *ct); |
9858a3ae | 105 | |
ceceae1b YK |
106 | static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct) |
107 | { | |
108 | return nf_ct_ext_find(ct, NF_CT_EXT_HELPER); | |
109 | } | |
b334aadc | 110 | |
1afc5679 PNA |
111 | static inline void *nfct_help_data(const struct nf_conn *ct) |
112 | { | |
113 | struct nf_conn_help *help; | |
114 | ||
115 | help = nf_ct_ext_find(ct, NF_CT_EXT_HELPER); | |
116 | ||
117 | return (void *)help->data; | |
118 | } | |
119 | ||
4e77be46 JP |
120 | int nf_conntrack_helper_pernet_init(struct net *net); |
121 | void nf_conntrack_helper_pernet_fini(struct net *net); | |
5e615b22 | 122 | |
4e77be46 JP |
123 | int nf_conntrack_helper_init(void); |
124 | void nf_conntrack_helper_fini(void); | |
b334aadc | 125 | |
4e77be46 JP |
126 | int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff, |
127 | struct nf_conn *ct, | |
128 | enum ip_conntrack_info ctinfo, | |
129 | unsigned int timeout); | |
93557f53 | 130 | |
544d5c7d PNA |
131 | struct nf_ct_helper_expectfn { |
132 | struct list_head head; | |
133 | const char *name; | |
134 | void (*expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp); | |
135 | }; | |
136 | ||
b20ab9cc PNA |
137 | __printf(3,4) |
138 | void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct, | |
139 | const char *fmt, ...); | |
140 | ||
544d5c7d PNA |
141 | void nf_ct_helper_expectfn_register(struct nf_ct_helper_expectfn *n); |
142 | void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n); | |
143 | struct nf_ct_helper_expectfn * | |
144 | nf_ct_helper_expectfn_find_by_name(const char *name); | |
145 | struct nf_ct_helper_expectfn * | |
146 | nf_ct_helper_expectfn_find_by_symbol(const void *symbol); | |
147 | ||
12f7a505 PNA |
148 | extern struct hlist_head *nf_ct_helper_hash; |
149 | extern unsigned int nf_ct_helper_hsize; | |
150 | ||
9fb9cbb1 | 151 | #endif /*_NF_CONNTRACK_HELPER_H*/ |