2 * SNMP service broadcast connection tracking helper
4 * (c) 2011 Jiri Olsa <jolsa@redhat.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
16 #include <net/netfilter/nf_conntrack.h>
17 #include <net/netfilter/nf_conntrack_helper.h>
18 #include <net/netfilter/nf_conntrack_expect.h>
19 #include <linux/netfilter/nf_conntrack_snmp.h>
23 MODULE_AUTHOR("Jiri Olsa <jolsa@redhat.com>");
24 MODULE_DESCRIPTION("SNMP service broadcast connection tracking helper");
25 MODULE_LICENSE("GPL");
26 MODULE_ALIAS_NFCT_HELPER("snmp");
28 static unsigned int timeout __read_mostly
= 30;
29 module_param(timeout
, uint
, S_IRUSR
);
30 MODULE_PARM_DESC(timeout
, "timeout for master connection/replies in seconds");
32 int (*nf_nat_snmp_hook
)(struct sk_buff
*skb
,
35 enum ip_conntrack_info ctinfo
);
36 EXPORT_SYMBOL_GPL(nf_nat_snmp_hook
);
38 static int snmp_conntrack_help(struct sk_buff
*skb
, unsigned int protoff
,
39 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
)
41 typeof(nf_nat_snmp_hook
) nf_nat_snmp
;
43 nf_conntrack_broadcast_help(skb
, protoff
, ct
, ctinfo
, timeout
);
45 nf_nat_snmp
= rcu_dereference(nf_nat_snmp_hook
);
46 if (nf_nat_snmp
&& ct
->status
& IPS_NAT_MASK
)
47 return nf_nat_snmp(skb
, protoff
, ct
, ctinfo
);
52 static struct nf_conntrack_expect_policy exp_policy
= {
56 static struct nf_conntrack_helper helper __read_mostly
= {
58 .tuple
.src
.l3num
= NFPROTO_IPV4
,
59 .tuple
.src
.u
.udp
.port
= cpu_to_be16(SNMP_PORT
),
60 .tuple
.dst
.protonum
= IPPROTO_UDP
,
62 .help
= snmp_conntrack_help
,
63 .expect_policy
= &exp_policy
,
66 static int __init
nf_conntrack_snmp_init(void)
68 exp_policy
.timeout
= timeout
;
69 return nf_conntrack_helper_register(&helper
);
72 static void __exit
nf_conntrack_snmp_fini(void)
74 nf_conntrack_helper_unregister(&helper
);
77 module_init(nf_conntrack_snmp_init
);
78 module_exit(nf_conntrack_snmp_fini
);