0001
0002
0003
0004
0005
0006 #include <linux/module.h>
0007 #include <linux/init.h>
0008 #include <linux/skbuff.h>
0009
0010 #include <linux/netfilter/x_tables.h>
0011 #include <linux/netfilter/xt_NFLOG.h>
0012 #include <net/netfilter/nf_log.h>
0013
0014 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
0015 MODULE_DESCRIPTION("Xtables: packet logging to netlink using NFLOG");
0016 MODULE_LICENSE("GPL");
0017 MODULE_ALIAS("ipt_NFLOG");
0018 MODULE_ALIAS("ip6t_NFLOG");
0019
0020 static unsigned int
0021 nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
0022 {
0023 const struct xt_nflog_info *info = par->targinfo;
0024 struct net *net = xt_net(par);
0025 struct nf_loginfo li;
0026
0027 li.type = NF_LOG_TYPE_ULOG;
0028 li.u.ulog.copy_len = info->len;
0029 li.u.ulog.group = info->group;
0030 li.u.ulog.qthreshold = info->threshold;
0031 li.u.ulog.flags = 0;
0032
0033 if (info->flags & XT_NFLOG_F_COPY_LEN)
0034 li.u.ulog.flags |= NF_LOG_F_COPY_LEN;
0035
0036 nf_log_packet(net, xt_family(par), xt_hooknum(par), skb, xt_in(par),
0037 xt_out(par), &li, "%s", info->prefix);
0038
0039 return XT_CONTINUE;
0040 }
0041
0042 static int nflog_tg_check(const struct xt_tgchk_param *par)
0043 {
0044 const struct xt_nflog_info *info = par->targinfo;
0045 int ret;
0046
0047 if (info->flags & ~XT_NFLOG_MASK)
0048 return -EINVAL;
0049 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
0050 return -EINVAL;
0051
0052 ret = nf_logger_find_get(par->family, NF_LOG_TYPE_ULOG);
0053 if (ret != 0 && !par->nft_compat) {
0054 request_module("%s", "nfnetlink_log");
0055
0056 ret = nf_logger_find_get(par->family, NF_LOG_TYPE_ULOG);
0057 }
0058
0059 return ret;
0060 }
0061
0062 static void nflog_tg_destroy(const struct xt_tgdtor_param *par)
0063 {
0064 nf_logger_put(par->family, NF_LOG_TYPE_ULOG);
0065 }
0066
0067 static struct xt_target nflog_tg_reg __read_mostly = {
0068 .name = "NFLOG",
0069 .revision = 0,
0070 .family = NFPROTO_UNSPEC,
0071 .checkentry = nflog_tg_check,
0072 .destroy = nflog_tg_destroy,
0073 .target = nflog_tg,
0074 .targetsize = sizeof(struct xt_nflog_info),
0075 .me = THIS_MODULE,
0076 };
0077
0078 static int __init nflog_tg_init(void)
0079 {
0080 return xt_register_target(&nflog_tg_reg);
0081 }
0082
0083 static void __exit nflog_tg_exit(void)
0084 {
0085 xt_unregister_target(&nflog_tg_reg);
0086 }
0087
0088 module_init(nflog_tg_init);
0089 module_exit(nflog_tg_exit);
0090 MODULE_SOFTDEP("pre: nfnetlink_log");