2 * NetBIOS name service broadcast connection tracking helper
4 * (c) 2007 Jiri Bohac <jbohac@suse.cz>
5 * (c) 2005 Patrick McHardy <kaber@trash.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 * This helper tracks locally originating NetBIOS name service
14 * requests by issuing permanent expectations (valid until
15 * timing out) matching all reply connections from the
16 * destination network. The only NetBIOS specific thing is
17 * actually the port number.
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/inetdevice.h>
25 #include <linux/if_addr.h>
28 #include <linux/netfilter.h>
29 #include <net/route.h>
31 #include <net/netfilter/nf_conntrack.h>
32 #include <net/netfilter/nf_conntrack_helper.h>
33 #include <net/netfilter/nf_conntrack_expect.h>
37 MODULE_AUTHOR("Jiri Bohac <jbohac@suse.cz>");
38 MODULE_DESCRIPTION("SLP broadcast connection tracking helper");
39 MODULE_LICENSE("GPL");
40 MODULE_ALIAS("ip_conntrack_slp");
42 static unsigned int timeout __read_mostly = 3;
43 module_param(timeout, uint, 0400);
44 MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
46 static int help(struct sk_buff *skb, unsigned int protoff,
47 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
49 struct nf_conntrack_expect *exp;
50 struct rtable *rt = skb_rtable(skb);
51 struct in_device *in_dev;
55 /* we're only interested in locally generated packets */
58 if (rt == NULL || !(rt->rt_flags & (RTCF_MULTICAST|RTCF_BROADCAST)))
60 if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL)
64 in_dev = __in_dev_get_rcu(rt->dst.dev);
66 for_primary_ifa(in_dev) {
67 /* this is a hack as slp uses multicast we can't match
68 * the destination address to some broadcast address. So
69 * just take the first one. Better would be to install
70 * expectations for all addresses */
72 src = ifa->ifa_broadcast;
78 if (mask == 0 || src == 0)
81 exp = nf_ct_expect_alloc(ct);
85 exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple;
86 exp->tuple.src.u3.ip = src;
87 exp->tuple.src.u.udp.port = htons(SLP_PORT);
89 exp->mask.src.u3.ip = mask;
90 exp->mask.src.u.udp.port = htons(0xFFFF);
93 exp->flags = NF_CT_EXPECT_PERMANENT;
94 exp->class = NF_CT_EXPECT_CLASS_DEFAULT;
97 nf_ct_expect_related(exp);
98 nf_ct_expect_put(exp);
100 nf_ct_refresh(ct, skb, timeout * HZ);
105 static struct nf_conntrack_expect_policy exp_policy = {
109 static struct nf_conntrack_helper helper __read_mostly = {
111 .tuple.src.l3num = AF_INET,
112 .tuple.src.u.udp.port = __constant_htons(SLP_PORT),
113 .tuple.dst.protonum = IPPROTO_UDP,
116 .expect_policy = &exp_policy,
119 static int __init nf_conntrack_slp_init(void)
121 exp_policy.timeout = timeout;
122 return nf_conntrack_helper_register(&helper);
125 static void __exit nf_conntrack_slp_fini(void)
127 nf_conntrack_helper_unregister(&helper);
130 module_init(nf_conntrack_slp_init);
131 module_exit(nf_conntrack_slp_fini);