blob: 50e3a52d3b31006421bd4ad32f6a63d1305c5925 [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>
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010016
17MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
Jan Engelhardt2ae15b62008-01-14 23:42:28 -080018MODULE_DESCRIPTION("Xtables: packet logging to netlink using NFLOG");
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010019MODULE_LICENSE("GPL");
20MODULE_ALIAS("ipt_NFLOG");
21MODULE_ALIAS("ip6t_NFLOG");
22
23static unsigned int
Jan Engelhardt7eb35582008-10-08 11:35:19 +020024nflog_tg(struct sk_buff *skb, const struct xt_target_param *par)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010025{
Jan Engelhardt7eb35582008-10-08 11:35:19 +020026 const struct xt_nflog_info *info = par->targinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010027 struct nf_loginfo li;
28
29 li.type = NF_LOG_TYPE_ULOG;
30 li.u.ulog.copy_len = info->len;
31 li.u.ulog.group = info->group;
32 li.u.ulog.qthreshold = info->threshold;
33
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020034 nf_log_packet(par->family, par->hooknum, skb, par->in,
Jan Engelhardt7eb35582008-10-08 11:35:19 +020035 par->out, &li, "%s", info->prefix);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010036 return XT_CONTINUE;
37}
38
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020039static bool nflog_tg_check(const struct xt_tgchk_param *par)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010040{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020041 const struct xt_nflog_info *info = par->targinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010042
43 if (info->flags & ~XT_NFLOG_MASK)
Jan Engelhardte1931b72007-07-07 22:16:26 -070044 return false;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010045 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
Jan Engelhardte1931b72007-07-07 22:16:26 -070046 return false;
47 return true;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010048}
49
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020050static struct xt_target nflog_tg_reg __read_mostly = {
51 .name = "NFLOG",
52 .revision = 0,
53 .family = NFPROTO_UNSPEC,
54 .checkentry = nflog_tg_check,
55 .target = nflog_tg,
56 .targetsize = sizeof(struct xt_nflog_info),
57 .me = THIS_MODULE,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010058};
59
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080060static int __init nflog_tg_init(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010061{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020062 return xt_register_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010063}
64
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080065static void __exit nflog_tg_exit(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010066{
Jan Engelhardt92f3b2b2008-10-08 11:35:20 +020067 xt_unregister_target(&nflog_tg_reg);
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010068}
69
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080070module_init(nflog_tg_init);
71module_exit(nflog_tg_exit);