blob: 8668a5c18dc3fd7595c0c752e9f01ff0d085be66 [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;
Liping Zhang6d193752016-10-11 21:03:45 +080035 li.u.ulog.flags = 0;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010036
Vishwanath Pai76435072016-06-21 14:58:46 -040037 if (info->flags & XT_NFLOG_F_COPY_LEN)
38 li.u.ulog.flags |= NF_LOG_F_COPY_LEN;
39
Hans Schillstrom8cdb46d2013-05-15 01:23:45 +000040 nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
Eric Leblond5f7340e2008-11-04 14:21:08 +010041 par->out, &li, info->prefix);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010042 return XT_CONTINUE;
43}
44
Jan Engelhardt135367b2010-03-19 17:16:42 +010045static int nflog_tg_check(const struct xt_tgchk_param *par)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010046{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020047 const struct xt_nflog_info *info = par->targinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010048
49 if (info->flags & ~XT_NFLOG_MASK)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010050 return -EINVAL;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010051 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010052 return -EINVAL;
53 return 0;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010054}
55
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020056static struct xt_target nflog_tg_reg __read_mostly = {
57 .name = "NFLOG",
58 .revision = 0,
59 .family = NFPROTO_UNSPEC,
60 .checkentry = nflog_tg_check,
61 .target = nflog_tg,
62 .targetsize = sizeof(struct xt_nflog_info),
63 .me = THIS_MODULE,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010064};
65
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080066static int __init nflog_tg_init(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010067{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020068 return xt_register_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010069}
70
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080071static void __exit nflog_tg_exit(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010072{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020073 xt_unregister_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010074}
75
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080076module_init(nflog_tg_init);
77module_exit(nflog_tg_exit);