Blame view
net/netfilter/nf_conntrack_netbios_ns.c
3.44 KB
92703eee4
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* * NetBIOS name service broadcast connection tracking helper * * (c) 2005 Patrick McHardy <kaber@trash.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ /* * This helper tracks locally originating NetBIOS name service * requests by issuing permanent expectations (valid until * timing out) matching all reply connections from the * destination network. The only NetBIOS specific thing is * actually the port number. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/inetdevice.h> #include <linux/if_addr.h> #include <linux/in.h> #include <linux/ip.h> |
1863f0965
|
27 |
#include <linux/netfilter.h> |
92703eee4
|
28 29 30 31 32 33 34 35 36 37 38 39 |
#include <net/route.h> #include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_expect.h> #define NMBD_PORT 137 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper"); MODULE_LICENSE("GPL"); MODULE_ALIAS("ip_conntrack_netbios_ns"); |
4dc06f963
|
40 |
MODULE_ALIAS_NFCT_HELPER("netbios_ns"); |
92703eee4
|
41 42 43 44 |
static unsigned int timeout __read_mostly = 3; module_param(timeout, uint, 0400); MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds"); |
3db05fea5
|
45 |
static int help(struct sk_buff *skb, unsigned int protoff, |
601e68e10
|
46 |
struct nf_conn *ct, enum ip_conntrack_info ctinfo) |
92703eee4
|
47 48 |
{ struct nf_conntrack_expect *exp; |
3db05fea5
|
49 |
struct iphdr *iph = ip_hdr(skb); |
511c3f92a
|
50 |
struct rtable *rt = skb_rtable(skb); |
92703eee4
|
51 52 53 54 |
struct in_device *in_dev; __be32 mask = 0; /* we're only interested in locally generated packets */ |
3db05fea5
|
55 |
if (skb->sk == NULL) |
92703eee4
|
56 57 58 59 60 61 62 |
goto out; if (rt == NULL || !(rt->rt_flags & RTCF_BROADCAST)) goto out; if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) goto out; rcu_read_lock(); |
d8d1f30b9
|
63 |
in_dev = __in_dev_get_rcu(rt->dst.dev); |
92703eee4
|
64 65 66 67 68 69 70 71 72 73 74 75 |
if (in_dev != NULL) { for_primary_ifa(in_dev) { if (ifa->ifa_broadcast == iph->daddr) { mask = ifa->ifa_mask; break; } } endfor_ifa(in_dev); } rcu_read_unlock(); if (mask == 0) goto out; |
6823645d6
|
76 |
exp = nf_ct_expect_alloc(ct); |
92703eee4
|
77 78 79 80 81 82 83 84 |
if (exp == NULL) goto out; exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple; exp->tuple.src.u.udp.port = htons(NMBD_PORT); exp->mask.src.u3.ip = mask; exp->mask.src.u.udp.port = htons(0xFFFF); |
92703eee4
|
85 86 87 |
exp->expectfn = NULL; exp->flags = NF_CT_EXPECT_PERMANENT; |
6002f266b
|
88 |
exp->class = NF_CT_EXPECT_CLASS_DEFAULT; |
88044c8c9
|
89 |
exp->helper = NULL; |
92703eee4
|
90 |
|
6823645d6
|
91 92 |
nf_ct_expect_related(exp); nf_ct_expect_put(exp); |
92703eee4
|
93 |
|
3db05fea5
|
94 |
nf_ct_refresh(ct, skb, timeout * HZ); |
92703eee4
|
95 96 97 |
out: return NF_ACCEPT; } |
6002f266b
|
98 99 100 |
static struct nf_conntrack_expect_policy exp_policy = { .max_expected = 1, }; |
92703eee4
|
101 102 103 |
static struct nf_conntrack_helper helper __read_mostly = { .name = "netbios-ns", .tuple.src.l3num = AF_INET, |
09640e636
|
104 |
.tuple.src.u.udp.port = cpu_to_be16(NMBD_PORT), |
92703eee4
|
105 |
.tuple.dst.protonum = IPPROTO_UDP, |
92703eee4
|
106 107 |
.me = THIS_MODULE, .help = help, |
6002f266b
|
108 |
.expect_policy = &exp_policy, |
92703eee4
|
109 110 111 112 |
}; static int __init nf_conntrack_netbios_ns_init(void) { |
6002f266b
|
113 |
exp_policy.timeout = timeout; |
92703eee4
|
114 115 116 117 118 119 120 121 122 123 |
return nf_conntrack_helper_register(&helper); } static void __exit nf_conntrack_netbios_ns_fini(void) { nf_conntrack_helper_unregister(&helper); } module_init(nf_conntrack_netbios_ns_init); module_exit(nf_conntrack_netbios_ns_fini); |