blob: 018eed7e1ff1e6f6c60dbe43a504e24c3860cf4d [file] [log] [blame]
Patrick McHardybaf7b1e2006-11-29 02:35:38 +01001/*
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
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/skbuff.h>
12
13#include <linux/netfilter/x_tables.h>
14#include <linux/netfilter/xt_NFLOG.h>
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080015#include <net/netfilter/nf_log.h>
Eric Leblond5f7340e2008-11-04 14:21:08 +010016#include <net/netfilter/nfnetlink_log.h>
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010017
18MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
Jan Engelhardt2ae15b62008-01-14 23:42:28 -080019MODULE_DESCRIPTION("Xtables: packet logging to netlink using NFLOG");
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010020MODULE_LICENSE("GPL");
21MODULE_ALIAS("ipt_NFLOG");
22MODULE_ALIAS("ip6t_NFLOG");
23
24static unsigned int
Jan Engelhardt4b560b42009-07-05 19:43:26 +020025nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010026{
Jan Engelhardt7eb35582008-10-08 11:35:19 +020027 const struct xt_nflog_info *info = par->targinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010028 struct nf_loginfo li;
Eric W. Biederman686c9b52015-09-18 14:32:59 -050029 struct net *net = par->net;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010030
31 li.type = NF_LOG_TYPE_ULOG;
32 li.u.ulog.copy_len = info->len;
33 li.u.ulog.group = info->group;
34 li.u.ulog.qthreshold = info->threshold;
35
Vishwanath Pai76435072016-06-21 14:58:46 -040036 if (info->flags & XT_NFLOG_F_COPY_LEN)
37 li.u.ulog.flags |= NF_LOG_F_COPY_LEN;
38
Hans Schillstrom8cdb46d2013-05-15 01:23:45 +000039 nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
Eric Leblond5f7340e2008-11-04 14:21:08 +010040 par->out, &li, info->prefix);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010041 return XT_CONTINUE;
42}
43
Jan Engelhardt135367b2010-03-19 17:16:42 +010044static int nflog_tg_check(const struct xt_tgchk_param *par)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010045{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020046 const struct xt_nflog_info *info = par->targinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010047
48 if (info->flags & ~XT_NFLOG_MASK)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010049 return -EINVAL;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010050 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010051 return -EINVAL;
52 return 0;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010053}
54
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020055static struct xt_target nflog_tg_reg __read_mostly = {
56 .name = "NFLOG",
57 .revision = 0,
58 .family = NFPROTO_UNSPEC,
59 .checkentry = nflog_tg_check,
60 .target = nflog_tg,
61 .targetsize = sizeof(struct xt_nflog_info),
62 .me = THIS_MODULE,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010063};
64
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080065static int __init nflog_tg_init(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010066{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020067 return xt_register_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010068}
69
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080070static void __exit nflog_tg_exit(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010071{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020072 xt_unregister_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010073}
74
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080075module_init(nflog_tg_init);
76module_exit(nflog_tg_exit);