drivers/edac: mod assert_error check
[safe/jmp/linux-2.6] / net / netfilter / nfnetlink_log.c
index 1750f0d..e185a5b 100644 (file)
@@ -10,7 +10,6 @@
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
- *
  */
 #include <linux/module.h>
 #include <linux/skbuff.h>
 
 #include <asm/atomic.h>
 
-#define NFULNL_NLBUFSIZ_DEFAULT        4096
+#ifdef CONFIG_BRIDGE_NETFILTER
+#include "../bridge/br_private.h"
+#endif
+
+#define NFULNL_NLBUFSIZ_DEFAULT        NLMSG_GOODSIZE
 #define NFULNL_TIMEOUT_DEFAULT         100     /* every second */
 #define NFULNL_QTHRESH_DEFAULT         100     /* 100 packets */
 
@@ -64,11 +67,14 @@ struct nfulnl_instance {
        unsigned int nlbufsiz;          /* netlink buffer allocation size */
        unsigned int qthreshold;        /* threshold of the queue */
        u_int32_t copy_range;
+       u_int32_t seq;                  /* instance-local sequential counter */
        u_int16_t group_num;            /* number of this queue */
-       u_int8_t copy_mode;     
+       u_int16_t flags;
+       u_int8_t copy_mode;
 };
 
 static DEFINE_RWLOCK(instances_lock);
+static atomic_t global_seq;
 
 #define INSTANCE_BUCKETS       16
 static struct hlist_head instance_table[INSTANCE_BUCKETS];
@@ -122,6 +128,7 @@ instance_put(struct nfulnl_instance *inst)
        if (inst && atomic_dec_and_test(&inst->use)) {
                UDEBUG("kfree(inst=%p)\n", inst);
                kfree(inst);
+               module_put(THIS_MODULE);
        }
 }
 
@@ -135,27 +142,23 @@ instance_create(u_int16_t group_num, int pid)
        UDEBUG("entering (group_num=%u, pid=%d)\n", group_num,
                pid);
 
-       write_lock_bh(&instances_lock); 
+       write_lock_bh(&instances_lock);
        if (__instance_lookup(group_num)) {
                inst = NULL;
                UDEBUG("aborting, instance already exists\n");
                goto out_unlock;
        }
 
-       inst = kmalloc(sizeof(*inst), GFP_ATOMIC);
+       inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
        if (!inst)
                goto out_unlock;
 
-       memset(inst, 0, sizeof(*inst));
        INIT_HLIST_NODE(&inst->hlist);
-       inst->lock = SPIN_LOCK_UNLOCKED;
+       spin_lock_init(&inst->lock);
        /* needs to be two, since we _put() after creation */
        atomic_set(&inst->use, 2);
 
-       init_timer(&inst->timer);
-       inst->timer.function = nfulnl_timer;
-       inst->timer.data = (unsigned long)inst;
-       /* don't start timer yet. (re)start it  with every packet */
+       setup_timer(&inst->timer, nfulnl_timer, (unsigned long)inst);
 
        inst->peer_pid = pid;
        inst->group_num = group_num;
@@ -169,10 +172,10 @@ instance_create(u_int16_t group_num, int pid)
        if (!try_module_get(THIS_MODULE))
                goto out_free;
 
-       hlist_add_head(&inst->hlist, 
+       hlist_add_head(&inst->hlist,
                       &instance_table[instance_hashfn(group_num)]);
 
-       UDEBUG("newly added node: %p, next=%p\n", &inst->hlist, 
+       UDEBUG("newly added node: %p, next=%p\n", &inst->hlist,
                inst->hlist.next);
 
        write_unlock_bh(&instances_lock);
@@ -189,24 +192,21 @@ out_unlock:
 static int __nfulnl_send(struct nfulnl_instance *inst);
 
 static void
-_instance_destroy2(struct nfulnl_instance *inst, int lock)
+__instance_destroy(struct nfulnl_instance *inst)
 {
        /* first pull it out of the global list */
-       if (lock)
-               write_lock_bh(&instances_lock);
-
        UDEBUG("removing instance %p (queuenum=%u) from hash\n",
                inst, inst->group_num);
 
        hlist_del(&inst->hlist);
 
-       if (lock)
-               write_unlock_bh(&instances_lock);
-
        /* then flush all pending packets from skb */
 
        spin_lock_bh(&inst->lock);
        if (inst->skb) {
+               /* timer "holds" one reference (we have one more) */
+               if (del_timer(&inst->timer))
+                       instance_put(inst);
                if (inst->qlen)
                        __nfulnl_send(inst);
                if (inst->skb) {
@@ -218,20 +218,14 @@ _instance_destroy2(struct nfulnl_instance *inst, int lock)
 
        /* and finally put the refcount */
        instance_put(inst);
-
-       module_put(THIS_MODULE);
-}
-
-static inline void
-__instance_destroy(struct nfulnl_instance *inst)
-{
-       _instance_destroy2(inst, 0);
 }
 
 static inline void
 instance_destroy(struct nfulnl_instance *inst)
 {
-       _instance_destroy2(inst, 1);
+       write_lock_bh(&instances_lock);
+       __instance_destroy(inst);
+       write_unlock_bh(&instances_lock);
 }
 
 static int
@@ -241,14 +235,14 @@ nfulnl_set_mode(struct nfulnl_instance *inst, u_int8_t mode,
        int status = 0;
 
        spin_lock_bh(&inst->lock);
-       
+
        switch (mode) {
        case NFULNL_COPY_NONE:
        case NFULNL_COPY_META:
                inst->copy_mode = mode;
                inst->copy_range = 0;
                break;
-               
+
        case NFULNL_COPY_PACKET:
                inst->copy_mode = mode;
                /* we're using struct nfattr which has 16bit nfa_len */
@@ -257,7 +251,7 @@ nfulnl_set_mode(struct nfulnl_instance *inst, u_int8_t mode,
                else
                        inst->copy_range = range;
                break;
-               
+
        default:
                status = -EINVAL;
                break;
@@ -307,28 +301,42 @@ nfulnl_set_qthresh(struct nfulnl_instance *inst, u_int32_t qthresh)
        return 0;
 }
 
-static struct sk_buff *nfulnl_alloc_skb(unsigned int inst_size, 
+static int
+nfulnl_set_flags(struct nfulnl_instance *inst, u_int16_t flags)
+{
+       spin_lock_bh(&inst->lock);
+       inst->flags = flags;
+       spin_unlock_bh(&inst->lock);
+
+       return 0;
+}
+
+static struct sk_buff *nfulnl_alloc_skb(unsigned int inst_size,
                                        unsigned int pkt_size)
 {
        struct sk_buff *skb;
+       unsigned int n;
 
        UDEBUG("entered (%u, %u)\n", inst_size, pkt_size);
 
        /* alloc skb which should be big enough for a whole multipart
         * message.  WARNING: has to be <= 128k due to slab restrictions */
 
-       skb = alloc_skb(inst_size, GFP_ATOMIC);
+       n = max(inst_size, pkt_size);
+       skb = alloc_skb(n, GFP_ATOMIC);
        if (!skb) {
                PRINTR("nfnetlink_log: can't alloc whole buffer (%u bytes)\n",
                        inst_size);
 
-               /* try to allocate only as much as we need for current
-                * packet */
+               if (n > pkt_size) {
+                       /* try to allocate only as much as we need for current
+                        * packet */
 
-               skb = alloc_skb(pkt_size, GFP_ATOMIC);
-               if (!skb)
-                       PRINTR("nfnetlink_log: can't even alloc %u bytes\n",
-                               pkt_size);
+                       skb = alloc_skb(pkt_size, GFP_ATOMIC);
+                       if (!skb)
+                               PRINTR("nfnetlink_log: can't even alloc %u "
+                                      "bytes\n", pkt_size);
+               }
        }
 
        return skb;
@@ -339,9 +347,6 @@ __nfulnl_send(struct nfulnl_instance *inst)
 {
        int status;
 
-       if (timer_pending(&inst->timer))
-               del_timer(&inst->timer);
-
        if (inst->qlen > 1)
                inst->lastnlh->nlmsg_type = NLMSG_DONE;
 
@@ -360,37 +365,39 @@ __nfulnl_send(struct nfulnl_instance *inst)
 
 static void nfulnl_timer(unsigned long data)
 {
-       struct nfulnl_instance *inst = (struct nfulnl_instance *)data; 
+       struct nfulnl_instance *inst = (struct nfulnl_instance *)data;
 
        UDEBUG("timer function called, flushing buffer\n");
 
        spin_lock_bh(&inst->lock);
-       __nfulnl_send(inst);
-       instance_put(inst);
+       if (inst->skb)
+               __nfulnl_send(inst);
        spin_unlock_bh(&inst->lock);
+       instance_put(inst);
 }
 
-static inline int 
+/* This is an inline function, we don't really care about a long
+ * list of arguments */
+static inline int
 __build_packet_message(struct nfulnl_instance *inst,
-                       const struct sk_buff *skb, 
+                       const struct sk_buff *skb,
                        unsigned int data_len,
                        unsigned int pf,
                        unsigned int hooknum,
                        const struct net_device *indev,
                        const struct net_device *outdev,
                        const struct nf_loginfo *li,
-                       const char *prefix)
+                       const char *prefix, unsigned int plen)
 {
-       unsigned char *old_tail;
        struct nfulnl_msg_packet_hdr pmsg;
        struct nlmsghdr *nlh;
        struct nfgenmsg *nfmsg;
-       u_int32_t tmp_uint;
+       __be32 tmp_uint;
+       sk_buff_data_t old_tail = inst->skb->tail;
 
        UDEBUG("entered\n");
-               
-       old_tail = inst->skb->tail;
-       nlh = NLMSG_PUT(inst->skb, 0, 0, 
+
+       nlh = NLMSG_PUT(inst->skb, 0, 0,
                        NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET,
                        sizeof(struct nfgenmsg));
        nfmsg = NLMSG_DATA(nlh);
@@ -398,50 +405,94 @@ __build_packet_message(struct nfulnl_instance *inst,
        nfmsg->version = NFNETLINK_V0;
        nfmsg->res_id = htons(inst->group_num);
 
-       pmsg.hw_protocol        = htons(skb->protocol);
+       pmsg.hw_protocol        = skb->protocol;
        pmsg.hook               = hooknum;
 
        NFA_PUT(inst->skb, NFULA_PACKET_HDR, sizeof(pmsg), &pmsg);
 
-       if (prefix) {
-               int slen = strlen(prefix);
-               if (slen > NFULNL_PREFIXLEN)
-                       slen = NFULNL_PREFIXLEN;
-               NFA_PUT(inst->skb, NFULA_PREFIX, slen, prefix);
-       }
+       if (prefix)
+               NFA_PUT(inst->skb, NFULA_PREFIX, plen, prefix);
 
        if (indev) {
                tmp_uint = htonl(indev->ifindex);
+#ifndef CONFIG_BRIDGE_NETFILTER
                NFA_PUT(inst->skb, NFULA_IFINDEX_INDEV, sizeof(tmp_uint),
                        &tmp_uint);
+#else
+               if (pf == PF_BRIDGE) {
+                       /* Case 1: outdev is physical input device, we need to
+                        * look for bridge group (when called from
+                        * netfilter_bridge) */
+                       NFA_PUT(inst->skb, NFULA_IFINDEX_PHYSINDEV,
+                               sizeof(tmp_uint), &tmp_uint);
+                       /* this is the bridge group "brX" */
+                       tmp_uint = htonl(indev->br_port->br->dev->ifindex);
+                       NFA_PUT(inst->skb, NFULA_IFINDEX_INDEV,
+                               sizeof(tmp_uint), &tmp_uint);
+               } else {
+                       /* Case 2: indev is bridge group, we need to look for
+                        * physical device (when called from ipv4) */
+                       NFA_PUT(inst->skb, NFULA_IFINDEX_INDEV,
+                               sizeof(tmp_uint), &tmp_uint);
+                       if (skb->nf_bridge && skb->nf_bridge->physindev) {
+                               tmp_uint =
+                                   htonl(skb->nf_bridge->physindev->ifindex);
+                               NFA_PUT(inst->skb, NFULA_IFINDEX_PHYSINDEV,
+                                       sizeof(tmp_uint), &tmp_uint);
+                       }
+               }
+#endif
        }
 
        if (outdev) {
                tmp_uint = htonl(outdev->ifindex);
+#ifndef CONFIG_BRIDGE_NETFILTER
                NFA_PUT(inst->skb, NFULA_IFINDEX_OUTDEV, sizeof(tmp_uint),
                        &tmp_uint);
+#else
+               if (pf == PF_BRIDGE) {
+                       /* Case 1: outdev is physical output device, we need to
+                        * look for bridge group (when called from
+                        * netfilter_bridge) */
+                       NFA_PUT(inst->skb, NFULA_IFINDEX_PHYSOUTDEV,
+                               sizeof(tmp_uint), &tmp_uint);
+                       /* this is the bridge group "brX" */
+                       tmp_uint = htonl(outdev->br_port->br->dev->ifindex);
+                       NFA_PUT(inst->skb, NFULA_IFINDEX_OUTDEV,
+                               sizeof(tmp_uint), &tmp_uint);
+               } else {
+                       /* Case 2: indev is a bridge group, we need to look
+                        * for physical device (when called from ipv4) */
+                       NFA_PUT(inst->skb, NFULA_IFINDEX_OUTDEV,
+                               sizeof(tmp_uint), &tmp_uint);
+                       if (skb->nf_bridge && skb->nf_bridge->physoutdev) {
+                               tmp_uint =
+                                   htonl(skb->nf_bridge->physoutdev->ifindex);
+                               NFA_PUT(inst->skb, NFULA_IFINDEX_PHYSOUTDEV,
+                                       sizeof(tmp_uint), &tmp_uint);
+                       }
+               }
+#endif
        }
 
-       if (skb->nfmark) {
-               tmp_uint = htonl(skb->nfmark);
+       if (skb->mark) {
+               tmp_uint = htonl(skb->mark);
                NFA_PUT(inst->skb, NFULA_MARK, sizeof(tmp_uint), &tmp_uint);
        }
 
        if (indev && skb->dev && skb->dev->hard_header_parse) {
                struct nfulnl_msg_packet_hw phw;
-
-               phw.hw_addrlen = 
-                       skb->dev->hard_header_parse((struct sk_buff *)skb, 
+               int len = skb->dev->hard_header_parse((struct sk_buff *)skb,
                                                    phw.hw_addr);
-               phw.hw_addrlen = htons(phw.hw_addrlen);
+               phw.hw_addrlen = htons(len);
                NFA_PUT(inst->skb, NFULA_HWADDR, sizeof(phw), &phw);
        }
 
-       if (skb->stamp.tv_sec) {
+       if (skb->tstamp.tv64) {
                struct nfulnl_msg_packet_timestamp ts;
-
-               ts.sec = cpu_to_be64(skb->stamp.tv_sec);
-               ts.usec = cpu_to_be64(skb->stamp.tv_usec);
+               struct timeval tv = ktime_to_timeval(skb->tstamp);
+               ts.sec = cpu_to_be64(tv.tv_sec);
+               ts.usec = cpu_to_be64(tv.tv_usec);
 
                NFA_PUT(inst->skb, NFULA_TIMESTAMP, sizeof(ts), &ts);
        }
@@ -450,7 +501,7 @@ __build_packet_message(struct nfulnl_instance *inst,
        if (skb->sk) {
                read_lock_bh(&skb->sk->sk_callback_lock);
                if (skb->sk->sk_socket && skb->sk->sk_socket->file) {
-                       u_int32_t uid = htonl(skb->sk->sk_socket->file->f_uid);
+                       __be32 uid = htonl(skb->sk->sk_socket->file->f_uid);
                        /* need to unlock here since NFA_PUT may goto */
                        read_unlock_bh(&skb->sk->sk_callback_lock);
                        NFA_PUT(inst->skb, NFULA_UID, sizeof(uid), &uid);
@@ -458,6 +509,17 @@ __build_packet_message(struct nfulnl_instance *inst,
                        read_unlock_bh(&skb->sk->sk_callback_lock);
        }
 
+       /* local sequence number */
+       if (inst->flags & NFULNL_CFG_F_SEQ) {
+               tmp_uint = htonl(inst->seq++);
+               NFA_PUT(inst->skb, NFULA_SEQ, sizeof(tmp_uint), &tmp_uint);
+       }
+       /* global sequence number */
+       if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) {
+               tmp_uint = htonl(atomic_inc_return(&global_seq));
+               NFA_PUT(inst->skb, NFULA_SEQ_GLOBAL, sizeof(tmp_uint), &tmp_uint);
+       }
+
        if (data_len) {
                struct nfattr *nfa;
                int size = NFA_LENGTH(data_len);
@@ -474,8 +536,9 @@ __build_packet_message(struct nfulnl_instance *inst,
                if (skb_copy_bits(skb, 0, NFA_DATA(nfa), data_len))
                        BUG();
        }
-               
+
        nlh->nlmsg_len = inst->skb->tail - old_tail;
+       inst->lastnlh = nlh;
        return 0;
 
 nlmsg_failure:
@@ -512,21 +575,20 @@ nfulnl_log_packet(unsigned int pf,
        struct nfulnl_instance *inst;
        const struct nf_loginfo *li;
        unsigned int qthreshold;
-       unsigned int nlbufsiz;
+       unsigned int plen;
 
-       if (li_user && li_user->type == NF_LOG_TYPE_ULOG) 
+       if (li_user && li_user->type == NF_LOG_TYPE_ULOG)
                li = li_user;
        else
                li = &default_loginfo;
 
        inst = instance_lookup_get(li->u.ulog.group);
        if (!inst)
-               inst = instance_lookup_get(0);
-       if (!inst) {
-               PRINTR("nfnetlink_log: trying to log packet, "
-                       "but no instance for group %u\n", li->u.ulog.group);
                return;
-       }
+
+       plen = 0;
+       if (prefix)
+               plen = strlen(prefix) + 1;
 
        /* all macros expand to constant values at compile time */
        /* FIXME: do we want to make the size calculation conditional based on
@@ -536,9 +598,13 @@ nfulnl_log_packet(unsigned int pf,
                + NFA_SPACE(sizeof(struct nfulnl_msg_packet_hdr))
                + NFA_SPACE(sizeof(u_int32_t))  /* ifindex */
                + NFA_SPACE(sizeof(u_int32_t))  /* ifindex */
+#ifdef CONFIG_BRIDGE_NETFILTER
+               + NFA_SPACE(sizeof(u_int32_t))  /* ifindex */
+               + NFA_SPACE(sizeof(u_int32_t))  /* ifindex */
+#endif
                + NFA_SPACE(sizeof(u_int32_t))  /* mark */
                + NFA_SPACE(sizeof(u_int32_t))  /* uid */
-               + NFA_SPACE(NFULNL_PREFIXLEN)   /* prefix */
+               + NFA_SPACE(plen)               /* prefix */
                + NFA_SPACE(sizeof(struct nfulnl_msg_packet_hw))
                + NFA_SPACE(sizeof(struct nfulnl_msg_packet_timestamp));
 
@@ -546,65 +612,60 @@ nfulnl_log_packet(unsigned int pf,
 
        spin_lock_bh(&inst->lock);
 
+       if (inst->flags & NFULNL_CFG_F_SEQ)
+               size += NFA_SPACE(sizeof(u_int32_t));
+       if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
+               size += NFA_SPACE(sizeof(u_int32_t));
+
        qthreshold = inst->qthreshold;
        /* per-rule qthreshold overrides per-instance */
        if (qthreshold > li->u.ulog.qthreshold)
                qthreshold = li->u.ulog.qthreshold;
-       
+
        switch (inst->copy_mode) {
        case NFULNL_COPY_META:
        case NFULNL_COPY_NONE:
                data_len = 0;
                break;
-       
+
        case NFULNL_COPY_PACKET:
-               if (inst->copy_range == 0 
+               if (inst->copy_range == 0
                    || inst->copy_range > skb->len)
                        data_len = skb->len;
                else
                        data_len = inst->copy_range;
-               
+
                size += NFA_SPACE(data_len);
                UDEBUG("copy_packet, therefore size now %u\n", size);
                break;
-       
+
        default:
-               spin_unlock_bh(&inst->lock);
-               instance_put(inst);
-               return;
+               goto unlock_and_release;
        }
 
-       if (size > inst->nlbufsiz)
-               nlbufsiz = size;
-       else
-               nlbufsiz = inst->nlbufsiz;
-
-       if (!inst->skb) {
-               if (!(inst->skb = nfulnl_alloc_skb(nlbufsiz, size))) {
-                       UDEBUG("error in nfulnl_alloc_skb(%u, %u)\n",
-                               inst->nlbufsiz, size);
-                       goto alloc_failure;
-               }
-       } else if (inst->qlen >= qthreshold ||
-                  size > skb_tailroom(inst->skb)) {
+       if (inst->qlen >= qthreshold ||
+           (inst->skb && size > skb_tailroom(inst->skb))) {
                /* either the queue len is too high or we don't have
                 * enough room in the skb left. flush to userspace. */
                UDEBUG("flushing old skb\n");
 
+               /* timer "holds" one reference (we have another one) */
+               if (del_timer(&inst->timer))
+                       instance_put(inst);
                __nfulnl_send(inst);
+       }
 
-               if (!(inst->skb = nfulnl_alloc_skb(nlbufsiz, size))) {
-                       UDEBUG("error in nfulnl_alloc_skb(%u, %u)\n",
-                               inst->nlbufsiz, size);
+       if (!inst->skb) {
+               inst->skb = nfulnl_alloc_skb(inst->nlbufsiz, size);
+               if (!inst->skb)
                        goto alloc_failure;
-               }
        }
 
        UDEBUG("qlen %d, qthreshold %d\n", inst->qlen, qthreshold);
        inst->qlen++;
 
        __build_packet_message(inst, skb, data_len, pf,
-                               hooknum, in, out, li, prefix);
+                               hooknum, in, out, li, prefix, plen);
 
        /* timer_pending always called within inst->lock, so there
         * is no chance of a race here */
@@ -613,15 +674,16 @@ nfulnl_log_packet(unsigned int pf,
                inst->timer.expires = jiffies + (inst->flushtimeout*HZ/100);
                add_timer(&inst->timer);
        }
-       spin_unlock_bh(&inst->lock);
 
+unlock_and_release:
+       spin_unlock_bh(&inst->lock);
+       instance_put(inst);
        return;
 
 alloc_failure:
-       spin_unlock_bh(&inst->lock);
-       instance_put(inst);
        UDEBUG("error allocating skb\n");
        /* FIXME: statistics */
+       goto unlock_and_release;
 }
 
 static int
@@ -658,7 +720,7 @@ static struct notifier_block nfulnl_rtnl_notifier = {
 
 static int
 nfulnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb,
-                 struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp)
+                 struct nlmsghdr *nlh, struct nfattr *nfqa[])
 {
        return -ENOTSUPP;
 }
@@ -675,10 +737,14 @@ static const int nfula_min[NFULA_MAX] = {
        [NFULA_TIMESTAMP-1]     = sizeof(struct nfulnl_msg_packet_timestamp),
        [NFULA_IFINDEX_INDEV-1] = sizeof(u_int32_t),
        [NFULA_IFINDEX_OUTDEV-1]= sizeof(u_int32_t),
+       [NFULA_IFINDEX_PHYSINDEV-1]     = sizeof(u_int32_t),
+       [NFULA_IFINDEX_PHYSOUTDEV-1]    = sizeof(u_int32_t),
        [NFULA_HWADDR-1]        = sizeof(struct nfulnl_msg_packet_hw),
        [NFULA_PAYLOAD-1]       = 0,
        [NFULA_PREFIX-1]        = 0,
        [NFULA_UID-1]           = sizeof(u_int32_t),
+       [NFULA_SEQ-1]           = sizeof(u_int32_t),
+       [NFULA_SEQ_GLOBAL-1]    = sizeof(u_int32_t),
 };
 
 static const int nfula_cfg_min[NFULA_CFG_MAX] = {
@@ -687,11 +753,12 @@ static const int nfula_cfg_min[NFULA_CFG_MAX] = {
        [NFULA_CFG_TIMEOUT-1]   = sizeof(u_int32_t),
        [NFULA_CFG_QTHRESH-1]   = sizeof(u_int32_t),
        [NFULA_CFG_NLBUFSIZ-1]  = sizeof(u_int32_t),
+       [NFULA_CFG_FLAGS-1]     = sizeof(u_int16_t),
 };
 
 static int
 nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
-                  struct nlmsghdr *nlh, struct nfattr *nfula[], int *errp)
+                  struct nlmsghdr *nlh, struct nfattr *nfula[])
 {
        struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
        u_int16_t group_num = ntohs(nfmsg->res_id);
@@ -723,13 +790,13 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
                                               NETLINK_CB(skb).pid);
                        if (!inst) {
                                ret = -EINVAL;
-                               goto out_put;
+                               goto out;
                        }
                        break;
                case NFULNL_CFG_CMD_UNBIND:
                        if (!inst) {
                                ret = -ENODEV;
-                               goto out_put;
+                               goto out;
                        }
 
                        if (inst->peer_pid != NETLINK_CB(skb).pid) {
@@ -738,7 +805,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
                        }
 
                        instance_destroy(inst);
-                       break;
+                       goto out;
                case NFULNL_CFG_CMD_PF_BIND:
                        UDEBUG("registering log handler for pf=%u\n", pf);
                        ret = nf_log_register(pf, &nfulnl_logger);
@@ -753,13 +820,16 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
                        ret = -EINVAL;
                        break;
                }
+
+               if (!inst)
+                       goto out;
        } else {
                if (!inst) {
                        UDEBUG("no config command, and no instance for "
                                "group=%u pid=%u =>ENOENT\n",
                                group_num, NETLINK_CB(skb).pid);
                        ret = -ENOENT;
-                       goto out_put;
+                       goto out;
                }
 
                if (inst->peer_pid != NETLINK_CB(skb).pid) {
@@ -774,42 +844,47 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
                params = NFA_DATA(nfula[NFULA_CFG_MODE-1]);
 
                nfulnl_set_mode(inst, params->copy_mode,
-                               ntohs(params->copy_range));
+                               ntohl(params->copy_range));
        }
 
        if (nfula[NFULA_CFG_TIMEOUT-1]) {
-               u_int32_t timeout = 
-                       *(u_int32_t *)NFA_DATA(nfula[NFULA_CFG_TIMEOUT-1]);
+               __be32 timeout =
+                       *(__be32 *)NFA_DATA(nfula[NFULA_CFG_TIMEOUT-1]);
 
                nfulnl_set_timeout(inst, ntohl(timeout));
        }
 
        if (nfula[NFULA_CFG_NLBUFSIZ-1]) {
-               u_int32_t nlbufsiz = 
-                       *(u_int32_t *)NFA_DATA(nfula[NFULA_CFG_NLBUFSIZ-1]);
+               __be32 nlbufsiz =
+                       *(__be32 *)NFA_DATA(nfula[NFULA_CFG_NLBUFSIZ-1]);
 
                nfulnl_set_nlbufsiz(inst, ntohl(nlbufsiz));
        }
 
        if (nfula[NFULA_CFG_QTHRESH-1]) {
-               u_int32_t qthresh = 
-                       *(u_int16_t *)NFA_DATA(nfula[NFULA_CFG_QTHRESH-1]);
+               __be32 qthresh =
+                       *(__be32 *)NFA_DATA(nfula[NFULA_CFG_QTHRESH-1]);
 
                nfulnl_set_qthresh(inst, ntohl(qthresh));
        }
 
+       if (nfula[NFULA_CFG_FLAGS-1]) {
+               __be16 flags =
+                       *(__be16 *)NFA_DATA(nfula[NFULA_CFG_FLAGS-1]);
+               nfulnl_set_flags(inst, ntohs(flags));
+       }
+
 out_put:
        instance_put(inst);
+out:
        return ret;
 }
 
 static struct nfnl_callback nfulnl_cb[NFULNL_MSG_MAX] = {
        [NFULNL_MSG_PACKET]     = { .call = nfulnl_recv_unsupp,
-                                   .attr_count = NFULA_MAX,
-                                   .cap_required = CAP_NET_ADMIN, },
+                                   .attr_count = NFULA_MAX, },
        [NFULNL_MSG_CONFIG]     = { .call = nfulnl_recv_config,
-                                   .attr_count = NFULA_CFG_MAX,
-                                   .cap_required = CAP_NET_ADMIN },
+                                   .attr_count = NFULA_CFG_MAX, },
 };
 
 static struct nfnetlink_subsystem nfulnl_subsys = {
@@ -824,10 +899,8 @@ struct iter_state {
        unsigned int bucket;
 };
 
-static struct hlist_node *get_first(struct seq_file *seq)
+static struct hlist_node *get_first(struct iter_state *st)
 {
-       struct iter_state *st = seq->private;
-
        if (!st)
                return NULL;
 
@@ -838,10 +911,8 @@ static struct hlist_node *get_first(struct seq_file *seq)
        return NULL;
 }
 
-static struct hlist_node *get_next(struct seq_file *seq, struct hlist_node *h)
+static struct hlist_node *get_next(struct iter_state *st, struct hlist_node *h)
 {
-       struct iter_state *st = seq->private;
-
        h = h->next;
        while (!h) {
                if (++st->bucket >= INSTANCE_BUCKETS)
@@ -852,13 +923,13 @@ static struct hlist_node *get_next(struct seq_file *seq, struct hlist_node *h)
        return h;
 }
 
-static struct hlist_node *get_idx(struct seq_file *seq, loff_t pos)
+static struct hlist_node *get_idx(struct iter_state *st, loff_t pos)
 {
        struct hlist_node *head;
-       head = get_first(seq);
+       head = get_first(st);
 
        if (head)
-               while (pos && (head = get_next(seq, head)))
+               while (pos && (head = get_next(st, head)))
                        pos--;
        return pos ? NULL : head;
 }
@@ -866,13 +937,13 @@ static struct hlist_node *get_idx(struct seq_file *seq, loff_t pos)
 static void *seq_start(struct seq_file *seq, loff_t *pos)
 {
        read_lock_bh(&instances_lock);
-       return get_idx(seq, *pos);
+       return get_idx(seq->private, *pos);
 }
 
 static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
 {
        (*pos)++;
-       return get_next(s, v);
+       return get_next(s->private, v);
 }
 
 static void seq_stop(struct seq_file *s, void *v)
@@ -884,14 +955,14 @@ static int seq_show(struct seq_file *s, void *v)
 {
        const struct nfulnl_instance *inst = v;
 
-       return seq_printf(s, "%5d %6d %5d %1d %5d %6d %2d\n", 
+       return seq_printf(s, "%5d %6d %5d %1d %5d %6d %2d\n",
                          inst->group_num,
-                         inst->peer_pid, inst->qlen, 
+                         inst->peer_pid, inst->qlen,
                          inst->copy_mode, inst->copy_range,
                          inst->flushtimeout, atomic_read(&inst->use));
 }
 
-static struct seq_operations nful_seq_ops = {
+static const struct seq_operations nful_seq_ops = {
        .start  = seq_start,
        .next   = seq_next,
        .stop   = seq_stop,
@@ -904,10 +975,9 @@ static int nful_open(struct inode *inode, struct file *file)
        struct iter_state *is;
        int ret;
 
-       is = kmalloc(sizeof(*is), GFP_KERNEL);
+       is = kzalloc(sizeof(*is), GFP_KERNEL);
        if (!is)
                return -ENOMEM;
-       memset(is, 0, sizeof(*is));
        ret = seq_open(file, &nful_seq_ops);
        if (ret < 0)
                goto out_free;
@@ -919,7 +989,7 @@ out_free:
        return ret;
 }
 
-static struct file_operations nful_file_ops = {
+static const struct file_operations nful_file_ops = {
        .owner   = THIS_MODULE,
        .open    = nful_open,
        .read    = seq_read,
@@ -929,20 +999,16 @@ static struct file_operations nful_file_ops = {
 
 #endif /* PROC_FS */
 
-static int
-init_or_cleanup(int init)
+static int __init nfnetlink_log_init(void)
 {
        int i, status = -ENOMEM;
 #ifdef CONFIG_PROC_FS
        struct proc_dir_entry *proc_nful;
 #endif
-       
-       if (!init)
-               goto cleanup;
 
        for (i = 0; i < INSTANCE_BUCKETS; i++)
                INIT_HLIST_HEAD(&instance_table[i]);
-       
+
        /* it's not really all that important to have a random value, so
         * we can do this from the init function, even if there hasn't
         * been that much entropy yet */
@@ -962,35 +1028,31 @@ init_or_cleanup(int init)
                goto cleanup_subsys;
        proc_nful->proc_fops = &nful_file_ops;
 #endif
-
        return status;
 
-cleanup:
-       nf_log_unregister_logger(&nfulnl_logger);
 #ifdef CONFIG_PROC_FS
-       remove_proc_entry("nfnetlink_log", proc_net_netfilter);
 cleanup_subsys:
-#endif
        nfnetlink_subsys_unregister(&nfulnl_subsys);
+#endif
 cleanup_netlink_notifier:
        netlink_unregister_notifier(&nfulnl_rtnl_notifier);
        return status;
 }
 
-static int __init init(void)
-{
-       
-       return init_or_cleanup(1);
-}
-
-static void __exit fini(void)
+static void __exit nfnetlink_log_fini(void)
 {
-       init_or_cleanup(0);
+       nf_log_unregister(&nfulnl_logger);
+#ifdef CONFIG_PROC_FS
+       remove_proc_entry("nfnetlink_log", proc_net_netfilter);
+#endif
+       nfnetlink_subsys_unregister(&nfulnl_subsys);
+       netlink_unregister_notifier(&nfulnl_rtnl_notifier);
 }
 
 MODULE_DESCRIPTION("netfilter userspace logging");
 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_ULOG);
 
-module_init(init);
-module_exit(fini);
+module_init(nfnetlink_log_init);
+module_exit(nfnetlink_log_fini);