2019-06-04 02:11:33 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-02-10 15:10:52 -07:00
|
|
|
/*
|
|
|
|
* This is a module which is used for logging packets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* (C) 1999-2001 Paul `Rusty' Russell
|
|
|
|
* (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <net/ipv6.h>
|
|
|
|
#include <net/icmp.h>
|
|
|
|
#include <net/udp.h>
|
|
|
|
#include <net/tcp.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <linux/netfilter.h>
|
|
|
|
#include <linux/netfilter/x_tables.h>
|
|
|
|
#include <linux/netfilter/xt_LOG.h>
|
|
|
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
|
|
|
#include <net/netfilter/nf_log.h>
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
log_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
|
|
|
{
|
|
|
|
const struct xt_log_info *loginfo = par->targinfo;
|
2016-11-03 03:56:21 -06:00
|
|
|
struct net *net = xt_net(par);
|
2012-02-10 15:10:52 -07:00
|
|
|
struct nf_loginfo li;
|
|
|
|
|
|
|
|
li.type = NF_LOG_TYPE_LOG;
|
|
|
|
li.u.log.level = loginfo->level;
|
|
|
|
li.u.log.logflags = loginfo->logflags;
|
|
|
|
|
2016-11-03 03:56:21 -06:00
|
|
|
nf_log_packet(net, xt_family(par), xt_hooknum(par), skb, xt_in(par),
|
|
|
|
xt_out(par), &li, "%s", loginfo->prefix);
|
2012-02-10 15:10:52 -07:00
|
|
|
return XT_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int log_tg_check(const struct xt_tgchk_param *par)
|
|
|
|
{
|
|
|
|
const struct xt_log_info *loginfo = par->targinfo;
|
|
|
|
|
|
|
|
if (par->family != NFPROTO_IPV4 && par->family != NFPROTO_IPV6)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (loginfo->level >= 8) {
|
|
|
|
pr_debug("level %u >= 8\n", loginfo->level);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
|
|
|
|
pr_debug("prefix is not null-terminated\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-06-18 11:38:25 -06:00
|
|
|
return nf_logger_find_get(par->family, NF_LOG_TYPE_LOG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void log_tg_destroy(const struct xt_tgdtor_param *par)
|
|
|
|
{
|
|
|
|
nf_logger_put(par->family, NF_LOG_TYPE_LOG);
|
2012-02-10 15:10:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct xt_target log_tg_regs[] __read_mostly = {
|
|
|
|
{
|
|
|
|
.name = "LOG",
|
|
|
|
.family = NFPROTO_IPV4,
|
|
|
|
.target = log_tg,
|
|
|
|
.targetsize = sizeof(struct xt_log_info),
|
|
|
|
.checkentry = log_tg_check,
|
2014-06-18 11:38:25 -06:00
|
|
|
.destroy = log_tg_destroy,
|
2012-02-10 15:10:52 -07:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
},
|
2012-03-10 04:15:15 -07:00
|
|
|
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
|
2012-02-10 15:10:52 -07:00
|
|
|
{
|
|
|
|
.name = "LOG",
|
|
|
|
.family = NFPROTO_IPV6,
|
|
|
|
.target = log_tg,
|
|
|
|
.targetsize = sizeof(struct xt_log_info),
|
|
|
|
.checkentry = log_tg_check,
|
2014-06-18 11:38:25 -06:00
|
|
|
.destroy = log_tg_destroy,
|
2012-02-10 15:10:52 -07:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init log_tg_init(void)
|
|
|
|
{
|
2014-06-19 12:47:14 -06:00
|
|
|
return xt_register_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
|
2012-02-10 15:10:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit log_tg_exit(void)
|
|
|
|
{
|
|
|
|
xt_unregister_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(log_tg_init);
|
|
|
|
module_exit(log_tg_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
|
|
|
|
MODULE_AUTHOR("Jan Rekorajski <baggins@pld.org.pl>");
|
|
|
|
MODULE_DESCRIPTION("Xtables: IPv4/IPv6 packet logging");
|
|
|
|
MODULE_ALIAS("ipt_LOG");
|
|
|
|
MODULE_ALIAS("ip6t_LOG");
|