• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NMBD_PORT	137
24 
25 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
26 MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper");
27 MODULE_LICENSE("GPL");
28 MODULE_ALIAS("ip_conntrack_netbios_ns");
29 MODULE_ALIAS_NFCT_HELPER("netbios_ns");
30 
31 static unsigned int timeout __read_mostly = 3;
32 module_param(timeout, uint, 0400);
33 MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
34 
35 static struct nf_conntrack_expect_policy exp_policy = {
36 	.max_expected	= 1,
37 };
38 
netbios_ns_help(struct sk_buff * skb,unsigned int protoff,struct nf_conn * ct,enum ip_conntrack_info ctinfo)39 static int netbios_ns_help(struct sk_buff *skb, unsigned int protoff,
40 			   struct nf_conn *ct,
41 			   enum ip_conntrack_info ctinfo)
42 {
43 	return nf_conntrack_broadcast_help(skb, ct, ctinfo, timeout);
44 }
45 
46 static struct nf_conntrack_helper helper __read_mostly = {
47 	.name			= "netbios-ns",
48 	.tuple.src.l3num	= NFPROTO_IPV4,
49 	.tuple.src.u.udp.port	= cpu_to_be16(NMBD_PORT),
50 	.tuple.dst.protonum	= IPPROTO_UDP,
51 	.me			= THIS_MODULE,
52 	.help			= netbios_ns_help,
53 	.expect_policy		= &exp_policy,
54 };
55 
nf_conntrack_netbios_ns_init(void)56 static int __init nf_conntrack_netbios_ns_init(void)
57 {
58 	NF_CT_HELPER_BUILD_BUG_ON(0);
59 
60 	exp_policy.timeout = timeout;
61 	return nf_conntrack_helper_register(&helper);
62 }
63 
nf_conntrack_netbios_ns_fini(void)64 static void __exit nf_conntrack_netbios_ns_fini(void)
65 {
66 	nf_conntrack_helper_unregister(&helper);
67 }
68 
69 module_init(nf_conntrack_netbios_ns_init);
70 module_exit(nf_conntrack_netbios_ns_fini);
71