nf_log_netdev.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * (C) 2016 by Pablo Neira Ayuso <pablo@netfilter.org>
  4. */
  5. #include <linux/module.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/skbuff.h>
  8. #include <linux/ip.h>
  9. #include <net/route.h>
  10. #include <linux/netfilter.h>
  11. #include <net/netfilter/nf_log.h>
  12. static void nf_log_netdev_packet(struct net *net, u_int8_t pf,
  13. unsigned int hooknum,
  14. const struct sk_buff *skb,
  15. const struct net_device *in,
  16. const struct net_device *out,
  17. const struct nf_loginfo *loginfo,
  18. const char *prefix)
  19. {
  20. nf_log_l2packet(net, pf, skb->protocol, hooknum, skb, in, out,
  21. loginfo, prefix);
  22. }
  23. static struct nf_logger nf_netdev_logger __read_mostly = {
  24. .name = "nf_log_netdev",
  25. .type = NF_LOG_TYPE_LOG,
  26. .logfn = nf_log_netdev_packet,
  27. .me = THIS_MODULE,
  28. };
  29. static int __net_init nf_log_netdev_net_init(struct net *net)
  30. {
  31. return nf_log_set(net, NFPROTO_NETDEV, &nf_netdev_logger);
  32. }
  33. static void __net_exit nf_log_netdev_net_exit(struct net *net)
  34. {
  35. nf_log_unset(net, &nf_netdev_logger);
  36. }
  37. static struct pernet_operations nf_log_netdev_net_ops = {
  38. .init = nf_log_netdev_net_init,
  39. .exit = nf_log_netdev_net_exit,
  40. };
  41. static int __init nf_log_netdev_init(void)
  42. {
  43. int ret;
  44. /* Request to load the real packet loggers. */
  45. nf_logger_request_module(NFPROTO_IPV4, NF_LOG_TYPE_LOG);
  46. nf_logger_request_module(NFPROTO_IPV6, NF_LOG_TYPE_LOG);
  47. nf_logger_request_module(NFPROTO_ARP, NF_LOG_TYPE_LOG);
  48. ret = register_pernet_subsys(&nf_log_netdev_net_ops);
  49. if (ret < 0)
  50. return ret;
  51. nf_log_register(NFPROTO_NETDEV, &nf_netdev_logger);
  52. return 0;
  53. }
  54. static void __exit nf_log_netdev_exit(void)
  55. {
  56. unregister_pernet_subsys(&nf_log_netdev_net_ops);
  57. nf_log_unregister(&nf_netdev_logger);
  58. }
  59. module_init(nf_log_netdev_init);
  60. module_exit(nf_log_netdev_exit);
  61. MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
  62. MODULE_DESCRIPTION("Netfilter netdev packet logging");
  63. MODULE_LICENSE("GPL");
  64. MODULE_ALIAS_NF_LOGGER(5, 0); /* NFPROTO_NETDEV */