blob: 866facfa4f43ada46b394bd2789d6d0976342cb6 [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>");
18MODULE_DESCRIPTION("x_tables NFLOG target");
19MODULE_LICENSE("GPL");
20MODULE_ALIAS("ipt_NFLOG");
21MODULE_ALIAS("ip6t_NFLOG");
22
23static unsigned int
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080024nflog_tg(struct sk_buff *skb, const struct net_device *in,
25 const struct net_device *out, unsigned int hooknum,
26 const struct xt_target *target, const void *targinfo)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010027{
28 const struct xt_nflog_info *info = targinfo;
29 struct nf_loginfo li;
30
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
Herbert Xu3db05fe2007-10-15 00:53:15 -070036 nf_log_packet(target->family, hooknum, skb, in, out, &li,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010037 "%s", info->prefix);
38 return XT_CONTINUE;
39}
40
Jan Engelhardte1931b72007-07-07 22:16:26 -070041static bool
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080042nflog_tg_check(const char *tablename, const void *entry,
43 const struct xt_target *target, void *targetinfo,
44 unsigned int hookmask)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010045{
Jan Engelhardta47362a2007-07-07 22:16:55 -070046 const struct xt_nflog_info *info = targetinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010047
48 if (info->flags & ~XT_NFLOG_MASK)
Jan Engelhardte1931b72007-07-07 22:16:26 -070049 return false;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010050 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
Jan Engelhardte1931b72007-07-07 22:16:26 -070051 return false;
52 return true;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010053}
54
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080055static struct xt_target nflog_tg_reg[] __read_mostly = {
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010056 {
57 .name = "NFLOG",
58 .family = AF_INET,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080059 .checkentry = nflog_tg_check,
60 .target = nflog_tg,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010061 .targetsize = sizeof(struct xt_nflog_info),
62 .me = THIS_MODULE,
63 },
64 {
65 .name = "NFLOG",
66 .family = AF_INET6,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080067 .checkentry = nflog_tg_check,
68 .target = nflog_tg,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010069 .targetsize = sizeof(struct xt_nflog_info),
70 .me = THIS_MODULE,
71 },
72};
73
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080074static int __init nflog_tg_init(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010075{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080076 return xt_register_targets(nflog_tg_reg, ARRAY_SIZE(nflog_tg_reg));
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010077}
78
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080079static void __exit nflog_tg_exit(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010080{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080081 xt_unregister_targets(nflog_tg_reg, ARRAY_SIZE(nflog_tg_reg));
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010082}
83
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080084module_init(nflog_tg_init);
85module_exit(nflog_tg_exit);