nf_conntrack_netbios_ns.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * NetBIOS name service broadcast connection tracking helper
  3. *
  4. * (c) 2005 Patrick McHardy <kaber@trash.net>
  5. *
  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.
  10. */
  11. /*
  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.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/in.h>
  22. #include <net/netfilter/nf_conntrack.h>
  23. #include <net/netfilter/nf_conntrack_helper.h>
  24. #include <net/netfilter/nf_conntrack_expect.h>
  25. #define NMBD_PORT 137
  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("netbios_ns");
  31. static unsigned int timeout __read_mostly = 3;
  32. module_param(timeout, uint, S_IRUSR);
  33. MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
  34. static struct nf_conntrack_expect_policy exp_policy = {
  35. .max_expected = 1,
  36. };
  37. static int netbios_ns_help(struct sk_buff *skb, unsigned int protoff,
  38. struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  39. {
  40. return nf_conntrack_broadcast_help(skb, protoff, ct, ctinfo, timeout);
  41. }
  42. static struct nf_conntrack_helper helper __read_mostly = {
  43. .name = "netbios-ns",
  44. .tuple.src.l3num = NFPROTO_IPV4,
  45. .tuple.src.u.udp.port = cpu_to_be16(NMBD_PORT),
  46. .tuple.dst.protonum = IPPROTO_UDP,
  47. .me = THIS_MODULE,
  48. .help = netbios_ns_help,
  49. .expect_policy = &exp_policy,
  50. };
  51. static int __init nf_conntrack_netbios_ns_init(void)
  52. {
  53. exp_policy.timeout = timeout;
  54. return nf_conntrack_helper_register(&helper);
  55. }
  56. static void __exit nf_conntrack_netbios_ns_fini(void)
  57. {
  58. nf_conntrack_helper_unregister(&helper);
  59. }
  60. module_init(nf_conntrack_netbios_ns_init);
  61. module_exit(nf_conntrack_netbios_ns_fini);