1
2
3
4
5
6
7
8
9
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/in.h>
15
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>
20
21#define SNMP_PORT 161
22
23MODULE_AUTHOR("Jiri Olsa <jolsa@redhat.com>");
24MODULE_DESCRIPTION("SNMP service broadcast connection tracking helper");
25MODULE_LICENSE("GPL");
26MODULE_ALIAS_NFCT_HELPER("snmp");
27
28static unsigned int timeout __read_mostly = 30;
29module_param(timeout, uint, S_IRUSR);
30MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
31
32int (*nf_nat_snmp_hook)(struct sk_buff *skb,
33 unsigned int protoff,
34 struct nf_conn *ct,
35 enum ip_conntrack_info ctinfo);
36EXPORT_SYMBOL_GPL(nf_nat_snmp_hook);
37
38static int snmp_conntrack_help(struct sk_buff *skb, unsigned int protoff,
39 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
40{
41 typeof(nf_nat_snmp_hook) nf_nat_snmp;
42
43 nf_conntrack_broadcast_help(skb, protoff, ct, ctinfo, timeout);
44
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);
48
49 return NF_ACCEPT;
50}
51
52static struct nf_conntrack_expect_policy exp_policy = {
53 .max_expected = 1,
54};
55
56static struct nf_conntrack_helper helper __read_mostly = {
57 .name = "snmp",
58 .tuple.src.l3num = NFPROTO_IPV4,
59 .tuple.src.u.udp.port = cpu_to_be16(SNMP_PORT),
60 .tuple.dst.protonum = IPPROTO_UDP,
61 .me = THIS_MODULE,
62 .help = snmp_conntrack_help,
63 .expect_policy = &exp_policy,
64};
65
66static int __init nf_conntrack_snmp_init(void)
67{
68 exp_policy.timeout = timeout;
69 return nf_conntrack_helper_register(&helper);
70}
71
72static void __exit nf_conntrack_snmp_fini(void)
73{
74 nf_conntrack_helper_unregister(&helper);
75}
76
77module_init(nf_conntrack_snmp_init);
78module_exit(nf_conntrack_snmp_fini);
79