32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/module.h>
35 #include <linux/socket.h>
36 #include <linux/slab.h>
38 #include <linux/kernel.h>
40 #include <linux/netlink.h>
41 #include <linux/netdevice.h>
44 #include <linux/netfilter.h>
45 #include <linux/netfilter/x_tables.h>
49 #include <linux/bitops.h>
50 #include <asm/unaligned.h>
57 #define ULOG_NL_EVENT 111
58 #define ULOG_MAXNLGROUPS 32
64 static unsigned int flushtimeout = 10;
66 MODULE_PARM_DESC(flushtimeout,
"buffer flush timeout (hundredths of a second)");
68 static bool nflog =
true;
83 static struct sock *nflognl;
87 static void ulog_send(
unsigned int nlgroupnum)
91 if (timer_pending(&ub->
timer)) {
92 pr_debug(
"ulog_send: timer was pending, deleting\n");
97 pr_debug(
"ulog_send: nothing to send\n");
106 pr_debug(
"throwing %d packets to netlink group %u\n",
107 ub->
qlen, nlgroupnum + 1);
117 static void ulog_timer(
unsigned long data)
119 pr_debug(
"timer function called, calling ulog_send\n");
123 spin_lock_bh(&ulog_lock);
125 spin_unlock_bh(&ulog_lock);
128 static struct sk_buff *ulog_alloc_skb(
unsigned int size)
137 n =
max(size, nlbufsiz);
146 pr_debug(
"cannot even allocate %ub\n", size);
153 static void ipt_ulog_packet(
unsigned int hooknum,
162 size_t size, copy_len;
169 unsigned int groupnum =
ffs(loginfo->
nl_group) - 1;
179 ub = &ulog_buffers[groupnum];
181 spin_lock_bh(&ulog_lock);
184 if (!(ub->
skb = ulog_alloc_skb(size)))
187 size > skb_tailroom(ub->
skb)) {
193 if (!(ub->
skb = ulog_alloc_skb(size)))
200 sizeof(*pm)+copy_len, 0);
202 pr_debug(
"error during nlmsg_put\n");
207 pm = nlmsg_data(nlh);
211 __net_timestamp((
struct sk_buff *)skb);
215 tv = ktime_to_timeval(skb->
tstamp);
222 else if (loginfo->
prefix[0] !=
'\0')
256 if (!timer_pending(&ub->
timer)) {
268 spin_unlock_bh(&ulog_lock);
273 pr_debug(
"Error building netlink message\n");
274 spin_unlock_bh(&ulog_lock);
286 unsigned int hooknum,
307 ipt_ulog_packet(hooknum, skb, in, out, &loginfo, prefix);
314 if (loginfo->
prefix[
sizeof(loginfo->
prefix) - 1] !=
'\0') {
315 pr_debug(
"prefix not null-terminated\n");
319 pr_debug(
"queue threshold %Zu > MAX_QLEN\n",
327 struct compat_ipt_ulog_info {
334 static void ulog_tg_compat_from_user(
void *
dst,
const void *
src)
336 const struct compat_ipt_ulog_info *
cl =
src;
338 .nl_group = cl->nl_group,
339 .copy_range = cl->copy_range,
340 .qthreshold = cl->qthreshold,
344 memcpy(dst, &l,
sizeof(l));
347 static int ulog_tg_compat_to_user(
void __user *dst,
const void *src)
350 struct compat_ipt_ulog_info cl = {
366 .checkentry = ulog_tg_check,
368 .compatsize =
sizeof(
struct compat_ipt_ulog_info),
369 .compat_from_user = ulog_tg_compat_from_user,
370 .compat_to_user = ulog_tg_compat_to_user,
375 static struct nf_logger ipt_ulog_logger __read_mostly = {
381 static int __init ulog_tg_init(
void)
390 if (nlbufsiz > 128*1024) {
391 pr_warning(
"Netlink buffer has to be <= 128kB\n");
414 static void __exit ulog_tg_exit(
void)
428 ub = &ulog_buffers[
i];
429 if (timer_pending(&ub->
timer)) {
430 pr_debug(
"timer was pending, deleting\n");