linux/net/bridge/netfilter/nf_log_bridge.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * (C) 2014 by Pablo Neira Ayuso <pablo@netfilter.org>
   4 */
   5
   6#include <linux/module.h>
   7#include <linux/spinlock.h>
   8#include <linux/skbuff.h>
   9#include <linux/if_bridge.h>
  10#include <linux/ip.h>
  11#include <net/route.h>
  12
  13#include <linux/netfilter.h>
  14#include <net/netfilter/nf_log.h>
  15
  16static void nf_log_bridge_packet(struct net *net, u_int8_t pf,
  17                                 unsigned int hooknum,
  18                                 const struct sk_buff *skb,
  19                                 const struct net_device *in,
  20                                 const struct net_device *out,
  21                                 const struct nf_loginfo *loginfo,
  22                                 const char *prefix)
  23{
  24        nf_log_l2packet(net, pf, eth_hdr(skb)->h_proto, hooknum, skb,
  25                        in, out, loginfo, prefix);
  26}
  27
  28static struct nf_logger nf_bridge_logger __read_mostly = {
  29        .name           = "nf_log_bridge",
  30        .type           = NF_LOG_TYPE_LOG,
  31        .logfn          = nf_log_bridge_packet,
  32        .me             = THIS_MODULE,
  33};
  34
  35static int __net_init nf_log_bridge_net_init(struct net *net)
  36{
  37        return nf_log_set(net, NFPROTO_BRIDGE, &nf_bridge_logger);
  38}
  39
  40static void __net_exit nf_log_bridge_net_exit(struct net *net)
  41{
  42        nf_log_unset(net, &nf_bridge_logger);
  43}
  44
  45static struct pernet_operations nf_log_bridge_net_ops = {
  46        .init = nf_log_bridge_net_init,
  47        .exit = nf_log_bridge_net_exit,
  48};
  49
  50static int __init nf_log_bridge_init(void)
  51{
  52        int ret;
  53
  54        /* Request to load the real packet loggers. */
  55        nf_logger_request_module(NFPROTO_IPV4, NF_LOG_TYPE_LOG);
  56        nf_logger_request_module(NFPROTO_IPV6, NF_LOG_TYPE_LOG);
  57        nf_logger_request_module(NFPROTO_ARP, NF_LOG_TYPE_LOG);
  58
  59        ret = register_pernet_subsys(&nf_log_bridge_net_ops);
  60        if (ret < 0)
  61                return ret;
  62
  63        nf_log_register(NFPROTO_BRIDGE, &nf_bridge_logger);
  64        return 0;
  65}
  66
  67static void __exit nf_log_bridge_exit(void)
  68{
  69        unregister_pernet_subsys(&nf_log_bridge_net_ops);
  70        nf_log_unregister(&nf_bridge_logger);
  71}
  72
  73module_init(nf_log_bridge_init);
  74module_exit(nf_log_bridge_exit);
  75
  76MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
  77MODULE_DESCRIPTION("Netfilter bridge packet logging");
  78MODULE_LICENSE("GPL");
  79MODULE_ALIAS_NF_LOGGER(AF_BRIDGE, 0);
  80