blob: a1fa2c800cb9122eeaf6cd477ea43ed409379795 [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
Hans Schillstrom8cdb46d2013-05-15 01:23:45 +000036 nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
Eric Leblond5f7340e2008-11-04 14:21:08 +010037 par->out, &li, info->prefix);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010038 return XT_CONTINUE;
39}
40
Jan Engelhardt135367b2010-03-19 17:16:42 +010041static int nflog_tg_check(const struct xt_tgchk_param *par)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010042{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020043 const struct xt_nflog_info *info = par->targinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010044
45 if (info->flags & ~XT_NFLOG_MASK)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010046 return -EINVAL;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010047 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010048 return -EINVAL;
49 return 0;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010050}
51
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020052static struct xt_target nflog_tg_reg __read_mostly = {
53 .name = "NFLOG",
54 .revision = 0,
55 .family = NFPROTO_UNSPEC,
56 .checkentry = nflog_tg_check,
57 .target = nflog_tg,
58 .targetsize = sizeof(struct xt_nflog_info),
59 .me = THIS_MODULE,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010060};
61
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080062static int __init nflog_tg_init(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010063{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020064 return xt_register_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010065}
66
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080067static void __exit nflog_tg_exit(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010068{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020069 xt_unregister_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010070}
71
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080072module_init(nflog_tg_init);
73module_exit(nflog_tg_exit);