allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / net / netfilter / nf_conntrack_netbios_ns.c
blob2243d5267c7e88f0911060da79d55404b4b80af3
1 /*
2 * NetBIOS name service broadcast connection tracking helper
4 * (c) 2005 Patrick McHardy <kaber@trash.net>
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.
12 * This helper tracks locally originating NetBIOS name service
13 * requests by issuing permanent expectations (valid until
14 * timing out) matching all reply connections from the
15 * destination network. The only NetBIOS specific thing is
16 * actually the port number.
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/inetdevice.h>
24 #include <linux/if_addr.h>
25 #include <linux/in.h>
26 #include <linux/ip.h>
27 #include <linux/netfilter.h>
28 #include <net/route.h>
30 #include <net/netfilter/nf_conntrack.h>
31 #include <net/netfilter/nf_conntrack_helper.h>
32 #include <net/netfilter/nf_conntrack_expect.h>
34 #define NMBD_PORT 137
36 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
37 MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper");
38 MODULE_LICENSE("GPL");
39 MODULE_ALIAS("ip_conntrack_netbios_ns");
41 static unsigned int timeout __read_mostly = 3;
42 module_param(timeout, uint, 0400);
43 MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
45 static int help(struct sk_buff *skb, unsigned int protoff,
46 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
48 struct nf_conntrack_expect *exp;
49 struct iphdr *iph = ip_hdr(skb);
50 struct rtable *rt = (struct rtable *)skb->dst;
51 struct in_device *in_dev;
52 __be32 mask = 0;
54 /* we're only interested in locally generated packets */
55 if (skb->sk == NULL)
56 goto out;
57 if (rt == NULL || !(rt->rt_flags & RTCF_BROADCAST))
58 goto out;
59 if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL)
60 goto out;
62 rcu_read_lock();
63 in_dev = __in_dev_get_rcu(rt->u.dst.dev);
64 if (in_dev != NULL) {
65 for_primary_ifa(in_dev) {
66 if (ifa->ifa_broadcast == iph->daddr) {
67 mask = ifa->ifa_mask;
68 break;
70 } endfor_ifa(in_dev);
72 rcu_read_unlock();
74 if (mask == 0)
75 goto out;
77 exp = nf_conntrack_expect_alloc(ct);
78 if (exp == NULL)
79 goto out;
81 exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple;
82 exp->tuple.src.u.udp.port = htons(NMBD_PORT);
84 exp->mask.src.u3.ip = mask;
85 exp->mask.src.u.udp.port = htons(0xFFFF);
86 exp->mask.dst.u3.ip = htonl(0xFFFFFFFF);
87 exp->mask.dst.u.udp.port = htons(0xFFFF);
88 exp->mask.dst.protonum = 0xFF;
90 exp->expectfn = NULL;
91 exp->flags = NF_CT_EXPECT_PERMANENT;
92 exp->class = NF_CT_EXPECT_CLASS_DEFAULT;
93 exp->helper = NULL;
95 nf_conntrack_expect_related(exp);
96 nf_conntrack_expect_put(exp);
98 nf_ct_refresh(ct, skb, timeout * HZ);
99 out:
100 return NF_ACCEPT;
103 static struct nf_conntrack_expect_policy exp_policy = {
104 .max_expected = 1,
107 static struct nf_conntrack_helper helper __read_mostly = {
108 .name = "netbios-ns",
109 .tuple.src.l3num = AF_INET,
110 .tuple.src.u.udp.port = __constant_htons(NMBD_PORT),
111 .tuple.dst.protonum = IPPROTO_UDP,
112 .mask.src.l3num = 0xFFFF,
113 .mask.src.u.udp.port = __constant_htons(0xFFFF),
114 .mask.dst.protonum = 0xFF,
115 .me = THIS_MODULE,
116 .help = help,
117 .expect_policy = &exp_policy,
120 static int __init nf_conntrack_netbios_ns_init(void)
122 exp_policy.timeout = timeout;
123 return nf_conntrack_helper_register(&helper);
126 static void __exit nf_conntrack_netbios_ns_fini(void)
128 nf_conntrack_helper_unregister(&helper);
131 module_init(nf_conntrack_netbios_ns_init);
132 module_exit(nf_conntrack_netbios_ns_fini);