xt_NFLOG.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 = dev_net(par->in ? par->in : par->out);
  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. nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
  31. par->out, &li, info->prefix);
  32. return XT_CONTINUE;
  33. }
  34. static int nflog_tg_check(const struct xt_tgchk_param *par)
  35. {
  36. const struct xt_nflog_info *info = par->targinfo;
  37. if (info->flags & ~XT_NFLOG_MASK)
  38. return -EINVAL;
  39. if (info->prefix[sizeof(info->prefix) - 1] != '\0')
  40. return -EINVAL;
  41. return 0;
  42. }
  43. static struct xt_target nflog_tg_reg __read_mostly = {
  44. .name = "NFLOG",
  45. .revision = 0,
  46. .family = NFPROTO_UNSPEC,
  47. .checkentry = nflog_tg_check,
  48. .target = nflog_tg,
  49. .targetsize = sizeof(struct xt_nflog_info),
  50. .me = THIS_MODULE,
  51. };
  52. static int __init nflog_tg_init(void)
  53. {
  54. return xt_register_target(&nflog_tg_reg);
  55. }
  56. static void __exit nflog_tg_exit(void)
  57. {
  58. xt_unregister_target(&nflog_tg_reg);
  59. }
  60. module_init(nflog_tg_init);
  61. module_exit(nflog_tg_exit);