1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * NetBIOS name service broadcast connection tracking helper
4 *
5 * (c) 2005 Patrick McHardy <kaber@trash.net>
6 */
7 /*
8 * This helper tracks locally originating NetBIOS name service
9 * requests by issuing permanent expectations (valid until
10 * timing out) matching all reply connections from the
11 * destination network. The only NetBIOS specific thing is
12 * actually the port number.
13 */
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/in.h>
18
19 #include <net/netfilter/nf_conntrack.h>
20 #include <net/netfilter/nf_conntrack_helper.h>
21 #include <net/netfilter/nf_conntrack_expect.h>
22
23 #define HELPER_NAME "netbios-ns"
24 #define NMBD_PORT 137
25
26 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
27 MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper");
28 MODULE_LICENSE("GPL");
29 MODULE_ALIAS("ip_conntrack_netbios_ns");
30 MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
31
32 static unsigned int timeout __read_mostly = 3;
33 module_param(timeout, uint, 0400);
34 MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
35
36 static struct nf_conntrack_expect_policy exp_policy = {
37 .max_expected = 1,
38 };
39
netbios_ns_help(struct sk_buff * skb,unsigned int protoff,struct nf_conn * ct,enum ip_conntrack_info ctinfo)40 static int netbios_ns_help(struct sk_buff *skb, unsigned int protoff,
41 struct nf_conn *ct,
42 enum ip_conntrack_info ctinfo)
43 {
44 return nf_conntrack_broadcast_help(skb, ct, ctinfo, timeout);
45 }
46
47 static struct nf_conntrack_helper helper __read_mostly = {
48 .name = HELPER_NAME,
49 .tuple.src.l3num = NFPROTO_IPV4,
50 .tuple.src.u.udp.port = cpu_to_be16(NMBD_PORT),
51 .tuple.dst.protonum = IPPROTO_UDP,
52 .me = THIS_MODULE,
53 .help = netbios_ns_help,
54 .expect_policy = &exp_policy,
55 };
56
nf_conntrack_netbios_ns_init(void)57 static int __init nf_conntrack_netbios_ns_init(void)
58 {
59 NF_CT_HELPER_BUILD_BUG_ON(0);
60
61 exp_policy.timeout = timeout;
62 return nf_conntrack_helper_register(&helper);
63 }
64
nf_conntrack_netbios_ns_fini(void)65 static void __exit nf_conntrack_netbios_ns_fini(void)
66 {
67 nf_conntrack_helper_unregister(&helper);
68 }
69
70 module_init(nf_conntrack_netbios_ns_init);
71 module_exit(nf_conntrack_netbios_ns_fini);
72