ebt_nflog.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ebt_nflog
  4. *
  5. * Author:
  6. * Peter Warasin <peter@endian.com>
  7. *
  8. * February, 2008
  9. *
  10. * Based on:
  11. * xt_NFLOG.c, (C) 2006 by Patrick McHardy <kaber@trash.net>
  12. * ebt_ulog.c, (C) 2004 by Bart De Schuymer <bdschuym@pandora.be>
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/netfilter/x_tables.h>
  18. #include <linux/netfilter_bridge/ebtables.h>
  19. #include <linux/netfilter_bridge/ebt_nflog.h>
  20. #include <net/netfilter/nf_log.h>
  21. static unsigned int
  22. ebt_nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
  23. {
  24. const struct ebt_nflog_info *info = par->targinfo;
  25. struct net *net = xt_net(par);
  26. struct nf_loginfo li;
  27. li.type = NF_LOG_TYPE_ULOG;
  28. li.u.ulog.copy_len = info->len;
  29. li.u.ulog.group = info->group;
  30. li.u.ulog.qthreshold = info->threshold;
  31. li.u.ulog.flags = 0;
  32. nf_log_packet(net, PF_BRIDGE, xt_hooknum(par), skb, xt_in(par),
  33. xt_out(par), &li, "%s", info->prefix);
  34. return EBT_CONTINUE;
  35. }
  36. static int ebt_nflog_tg_check(const struct xt_tgchk_param *par)
  37. {
  38. struct ebt_nflog_info *info = par->targinfo;
  39. if (info->flags & ~EBT_NFLOG_MASK)
  40. return -EINVAL;
  41. info->prefix[EBT_NFLOG_PREFIX_SIZE - 1] = '\0';
  42. return 0;
  43. }
  44. static struct xt_target ebt_nflog_tg_reg __read_mostly = {
  45. .name = "nflog",
  46. .revision = 0,
  47. .family = NFPROTO_BRIDGE,
  48. .target = ebt_nflog_tg,
  49. .checkentry = ebt_nflog_tg_check,
  50. .targetsize = sizeof(struct ebt_nflog_info),
  51. .me = THIS_MODULE,
  52. };
  53. static int __init ebt_nflog_init(void)
  54. {
  55. return xt_register_target(&ebt_nflog_tg_reg);
  56. }
  57. static void __exit ebt_nflog_fini(void)
  58. {
  59. xt_unregister_target(&ebt_nflog_tg_reg);
  60. }
  61. module_init(ebt_nflog_init);
  62. module_exit(ebt_nflog_fini);
  63. MODULE_LICENSE("GPL");
  64. MODULE_AUTHOR("Peter Warasin <peter@endian.com>");
  65. MODULE_DESCRIPTION("ebtables NFLOG netfilter logging module");