20 #include <linux/module.h>
22 #include <linux/netfilter.h>
23 #include <linux/slab.h>
25 #include <linux/tcp.h>
36 static char *sane_buffer;
42 static unsigned int ports_c;
47 #define SANE_NET_START 7
54 #define SANE_STATUS_SUCCESS 0
72 struct nf_ct_sane_master *ct_sane_info = nfct_help_data(ct);
84 th = skb_header_pointer(skb, protoff,
sizeof(_tcph), &_tcph);
89 dataoff = protoff + th->doff * 4;
90 if (dataoff >= skb->
len)
93 datalen = skb->
len - dataoff;
95 spin_lock_bh(&nf_sane_lock);
96 sb_ptr = skb_header_pointer(skb, dataoff, datalen, sane_buffer);
106 ct_sane_info->state = SANE_STATE_NORMAL;
111 ct_sane_info->state = SANE_STATE_START_REQUESTED;
116 if (ct_sane_info->state != SANE_STATE_START_REQUESTED)
120 ct_sane_info->state = SANE_STATE_NORMAL;
123 pr_debug(
"nf_ct_sane: NET_START reply too short\n");
130 pr_debug(
"nf_ct_sane: unsuccessful SANE_STATUS = %u\n",
136 if (reply->
zero != 0)
147 &tuple->
src.u3, &tuple->
dst.u3,
151 nf_ct_dump_tuple(&exp->
tuple);
154 if (nf_ct_expect_related(exp) != 0)
160 spin_unlock_bh(&nf_sane_lock);
172 static void nf_conntrack_sane_fini(
void)
176 for (i = 0; i < ports_c; i++) {
177 for (j = 0; j < 2; j++) {
178 pr_debug(
"nf_ct_sane: unregistering helper for pf: %d "
180 sane[i][j].tuple.
src.l3num, ports[i]);
188 static int __init nf_conntrack_sane_init(
void)
190 int i, j = -1, ret = 0;
197 ports[ports_c++] = SANE_PORT;
201 for (i = 0; i < ports_c; i++) {
202 sane[
i][0].tuple.src.l3num =
PF_INET;
204 for (j = 0; j < 2; j++) {
205 sane[
i][
j].data_len =
sizeof(
struct nf_ct_sane_master);
206 sane[
i][
j].tuple.src.u.tcp.port =
htons(ports[i]);
208 sane[
i][
j].expect_policy = &sane_exp_policy;
210 sane[
i][
j].help = help;
211 if (ports[i] == SANE_PORT)
216 pr_debug(
"nf_ct_sane: registering helper for pf: %d "
218 sane[i][j].tuple.
src.l3num, ports[i]);
222 "register helper for pf: %d port: %d\n",
223 sane[i][j].tuple.
src.l3num, ports[i]);
224 nf_conntrack_sane_fini();