blob: 83af124e88cd818556a6504c3227d4f202e11060 [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>
15
16MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
17MODULE_DESCRIPTION("x_tables NFLOG target");
18MODULE_LICENSE("GPL");
19MODULE_ALIAS("ipt_NFLOG");
20MODULE_ALIAS("ip6t_NFLOG");
21
22static unsigned int
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080023nflog_tg(struct sk_buff *skb, const struct net_device *in,
24 const struct net_device *out, unsigned int hooknum,
25 const struct xt_target *target, const void *targinfo)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010026{
27 const struct xt_nflog_info *info = targinfo;
28 struct nf_loginfo li;
29
30 li.type = NF_LOG_TYPE_ULOG;
31 li.u.ulog.copy_len = info->len;
32 li.u.ulog.group = info->group;
33 li.u.ulog.qthreshold = info->threshold;
34
Herbert Xu3db05fe2007-10-15 00:53:15 -070035 nf_log_packet(target->family, hooknum, skb, in, out, &li,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010036 "%s", info->prefix);
37 return XT_CONTINUE;
38}
39
Jan Engelhardte1931b72007-07-07 22:16:26 -070040static bool
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080041nflog_tg_check(const char *tablename, const void *entry,
42 const struct xt_target *target, void *targetinfo,
43 unsigned int hookmask)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010044{
Jan Engelhardta47362a2007-07-07 22:16:55 -070045 const struct xt_nflog_info *info = targetinfo;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010046
47 if (info->flags & ~XT_NFLOG_MASK)
Jan Engelhardte1931b72007-07-07 22:16:26 -070048 return false;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010049 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
Jan Engelhardte1931b72007-07-07 22:16:26 -070050 return false;
51 return true;
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010052}
53
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080054static struct xt_target nflog_tg_reg[] __read_mostly = {
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010055 {
56 .name = "NFLOG",
57 .family = AF_INET,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080058 .checkentry = nflog_tg_check,
59 .target = nflog_tg,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010060 .targetsize = sizeof(struct xt_nflog_info),
61 .me = THIS_MODULE,
62 },
63 {
64 .name = "NFLOG",
65 .family = AF_INET6,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080066 .checkentry = nflog_tg_check,
67 .target = nflog_tg,
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010068 .targetsize = sizeof(struct xt_nflog_info),
69 .me = THIS_MODULE,
70 },
71};
72
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080073static int __init nflog_tg_init(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010074{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080075 return xt_register_targets(nflog_tg_reg, ARRAY_SIZE(nflog_tg_reg));
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010076}
77
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080078static void __exit nflog_tg_exit(void)
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010079{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080080 xt_unregister_targets(nflog_tg_reg, ARRAY_SIZE(nflog_tg_reg));
Patrick McHardybaf7b1e2006-11-29 02:35:38 +010081}
82
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080083module_init(nflog_tg_init);
84module_exit(nflog_tg_exit);