xt_NFLOG.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2006 Patrick McHardy <kaber@trash.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/skbuff.h>
  11. #include <linux/netfilter/x_tables.h>
  12. #include <linux/netfilter/xt_NFLOG.h>
  13. #include <net/netfilter/nf_log.h>
  14. #include <net/netfilter/nfnetlink_log.h>
  15. MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
  16. MODULE_DESCRIPTION("Xtables: packet logging to netlink using NFLOG");
  17. MODULE_LICENSE("GPL");
  18. MODULE_ALIAS("ipt_NFLOG");
  19. MODULE_ALIAS("ip6t_NFLOG");
  20. static unsigned int
  21. nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
  22. {
  23. const struct xt_nflog_info *info = par->targinfo;
  24. struct nf_loginfo li;
  25. struct net *net = par->net;
  26. li.type = NF_LOG_TYPE_ULOG;
  27. li.u.ulog.copy_len = info->len;
  28. li.u.ulog.group = info->group;
  29. li.u.ulog.qthreshold = info->threshold;
  30. li.u.ulog.flags = 0;
  31. if (info->flags & XT_NFLOG_F_COPY_LEN)
  32. li.u.ulog.flags |= NF_LOG_F_COPY_LEN;
  33. nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
  34. par->out, &li, info->prefix);
  35. return XT_CONTINUE;
  36. }
  37. static int nflog_tg_check(const struct xt_tgchk_param *par)
  38. {
  39. const struct xt_nflog_info *info = par->targinfo;
  40. if (info->flags & ~XT_NFLOG_MASK)
  41. return -EINVAL;
  42. if (info->prefix[sizeof(info->prefix) - 1] != '\0')
  43. return -EINVAL;
  44. return 0;
  45. }
  46. static struct xt_target nflog_tg_reg __read_mostly = {
  47. .name = "NFLOG",
  48. .revision = 0,
  49. .family = NFPROTO_UNSPEC,
  50. .checkentry = nflog_tg_check,
  51. .target = nflog_tg,
  52. .targetsize = sizeof(struct xt_nflog_info),
  53. .me = THIS_MODULE,
  54. };
  55. static int __init nflog_tg_init(void)
  56. {
  57. return xt_register_target(&nflog_tg_reg);
  58. }
  59. static void __exit nflog_tg_exit(void)
  60. {
  61. xt_unregister_target(&nflog_tg_reg);
  62. }
  63. module_init(nflog_tg_init);
  64. module_exit(nflog_tg_exit);