]> err.no Git - linux-2.6/blobdiff - net/netfilter/nfnetlink_queue.c
[NETFILTER]: nf_log: move logging stuff to seperate header
[linux-2.6] / net / netfilter / nfnetlink_queue.c
index c3aba1e8c5c43d1ae068c018985a5fae3aafeb32..d94de48f6cdbe910e524242f44f037484a7c0c21 100644 (file)
@@ -3,6 +3,7 @@
  * userspace via nfetlink.
  *
  * (C) 2005 by Harald Welte <laforge@netfilter.org>
+ * (C) 2007 by Patrick McHardy <kaber@trash.net>
  *
  * Based on the old ipv4-only ip_queue.c:
  * (C) 2000-2002 James Morris <jmorris@intercode.com.au>
@@ -63,7 +64,7 @@ typedef int (*nfqnl_cmpfn)(struct nf_queue_entry *, unsigned long);
 static DEFINE_SPINLOCK(instances_lock);
 
 #define INSTANCE_BUCKETS       16
-static struct hlist_head instance_table[INSTANCE_BUCKETS];
+static struct hlist_head instance_table[INSTANCE_BUCKETS] __read_mostly;
 
 static inline u_int8_t instance_hashfn(u_int16_t queue_num)
 {
@@ -203,7 +204,7 @@ nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn, unsigned long data)
 
 static struct sk_buff *
 nfqnl_build_packet_message(struct nfqnl_instance *queue,
-                          struct nf_queue_entry *entry, int *errp)
+                          struct nf_queue_entry *entry)
 {
        sk_buff_data_t old_tail;
        size_t size;
@@ -215,7 +216,6 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
        struct sk_buff *entskb = entry->skb;
        struct net_device *indev;
        struct net_device *outdev;
-       __be32 tmp_uint;
 
        size =    NLMSG_ALIGN(sizeof(struct nfgenmsg))
                + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
@@ -233,7 +233,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
 
        spin_lock_bh(&queue->lock);
 
-       switch (queue->copy_mode) {
+       switch ((enum nfqnl_config_mode)queue->copy_mode) {
        case NFQNL_COPY_META:
        case NFQNL_COPY_NONE:
                data_len = 0;
@@ -242,7 +242,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
        case NFQNL_COPY_PACKET:
                if ((entskb->ip_summed == CHECKSUM_PARTIAL ||
                     entskb->ip_summed == CHECKSUM_COMPLETE) &&
-                   (*errp = skb_checksum_help(entskb))) {
+                   skb_checksum_help(entskb)) {
                        spin_unlock_bh(&queue->lock);
                        return NULL;
                }
@@ -254,11 +254,6 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
 
                size += nla_total_size(data_len);
                break;
-
-       default:
-               *errp = -EINVAL;
-               spin_unlock_bh(&queue->lock);
-               return NULL;
        }
 
        entry->id = queue->id_sequence++;
@@ -286,69 +281,57 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
 
        indev = entry->indev;
        if (indev) {
-               tmp_uint = htonl(indev->ifindex);
 #ifndef CONFIG_BRIDGE_NETFILTER
-               NLA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint);
+               NLA_PUT_BE32(skb, NFQA_IFINDEX_INDEV, htonl(indev->ifindex));
 #else
                if (entry->pf == PF_BRIDGE) {
                        /* Case 1: indev is physical input device, we need to
                         * look for bridge group (when called from
                         * netfilter_bridge) */
-                       NLA_PUT(skb, NFQA_IFINDEX_PHYSINDEV, sizeof(tmp_uint),
-                               &tmp_uint);
+                       NLA_PUT_BE32(skb, NFQA_IFINDEX_PHYSINDEV,
+                                    htonl(indev->ifindex));
                        /* this is the bridge group "brX" */
-                       tmp_uint = htonl(indev->br_port->br->dev->ifindex);
-                       NLA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint),
-                               &tmp_uint);
+                       NLA_PUT_BE32(skb, NFQA_IFINDEX_INDEV,
+                                    htonl(indev->br_port->br->dev->ifindex));
                } else {
                        /* Case 2: indev is bridge group, we need to look for
                         * physical device (when called from ipv4) */
-                       NLA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint),
-                               &tmp_uint);
-                       if (entskb->nf_bridge
-                           && entskb->nf_bridge->physindev) {
-                               tmp_uint = htonl(entskb->nf_bridge->physindev->ifindex);
-                               NLA_PUT(skb, NFQA_IFINDEX_PHYSINDEV,
-                                       sizeof(tmp_uint), &tmp_uint);
-                       }
+                       NLA_PUT_BE32(skb, NFQA_IFINDEX_INDEV,
+                                    htonl(indev->ifindex));
+                       if (entskb->nf_bridge && entskb->nf_bridge->physindev)
+                               NLA_PUT_BE32(skb, NFQA_IFINDEX_PHYSINDEV,
+                                            htonl(entskb->nf_bridge->physindev->ifindex));
                }
 #endif
        }
 
        if (outdev) {
-               tmp_uint = htonl(outdev->ifindex);
 #ifndef CONFIG_BRIDGE_NETFILTER
-               NLA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint);
+               NLA_PUT_BE32(skb, NFQA_IFINDEX_OUTDEV, htonl(outdev->ifindex));
 #else
                if (entry->pf == PF_BRIDGE) {
                        /* Case 1: outdev is physical output device, we need to
                         * look for bridge group (when called from
                         * netfilter_bridge) */
-                       NLA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV, sizeof(tmp_uint),
-                               &tmp_uint);
+                       NLA_PUT_BE32(skb, NFQA_IFINDEX_PHYSOUTDEV,
+                                    htonl(outdev->ifindex));
                        /* this is the bridge group "brX" */
-                       tmp_uint = htonl(outdev->br_port->br->dev->ifindex);
-                       NLA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint),
-                               &tmp_uint);
+                       NLA_PUT_BE32(skb, NFQA_IFINDEX_OUTDEV,
+                                    htonl(outdev->br_port->br->dev->ifindex));
                } else {
                        /* Case 2: outdev is bridge group, we need to look for
                         * physical output device (when called from ipv4) */
-                       NLA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint),
-                               &tmp_uint);
-                       if (entskb->nf_bridge
-                           && entskb->nf_bridge->physoutdev) {
-                               tmp_uint = htonl(entskb->nf_bridge->physoutdev->ifindex);
-                               NLA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV,
-                                       sizeof(tmp_uint), &tmp_uint);
-                       }
+                       NLA_PUT_BE32(skb, NFQA_IFINDEX_OUTDEV,
+                                    htonl(outdev->ifindex));
+                       if (entskb->nf_bridge && entskb->nf_bridge->physoutdev)
+                               NLA_PUT_BE32(skb, NFQA_IFINDEX_PHYSOUTDEV,
+                                            htonl(entskb->nf_bridge->physoutdev->ifindex));
                }
 #endif
        }
 
-       if (entskb->mark) {
-               tmp_uint = htonl(entskb->mark);
-               NLA_PUT(skb, NFQA_MARK, sizeof(u_int32_t), &tmp_uint);
-       }
+       if (entskb->mark)
+               NLA_PUT_BE32(skb, NFQA_MARK, htonl(entskb->mark));
 
        if (indev && entskb->dev) {
                struct nfqnl_msg_packet_hw phw;
@@ -392,7 +375,6 @@ nlmsg_failure:
 nla_put_failure:
        if (skb)
                kfree_skb(skb);
-       *errp = -EINVAL;
        if (net_ratelimit())
                printk(KERN_ERR "nf_queue: error creating packet message\n");
        return NULL;
@@ -401,21 +383,21 @@ nla_put_failure:
 static int
 nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
 {
-       int status = -EINVAL;
        struct sk_buff *nskb;
        struct nfqnl_instance *queue;
+       int err;
 
        /* rcu_read_lock()ed by nf_hook_slow() */
        queue = instance_lookup(queuenum);
        if (!queue)
-               return -EINVAL;
+               goto err_out;
 
        if (queue->copy_mode == NFQNL_COPY_NONE)
-               return -EAGAIN;
+               goto err_out;
 
-       nskb = nfqnl_build_packet_message(queue, entry, &status);
+       nskb = nfqnl_build_packet_message(queue, entry);
        if (nskb == NULL)
-               return status;
+               goto err_out;
 
        spin_lock_bh(&queue->lock);
 
@@ -424,7 +406,6 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
 
        if (queue->queue_total >= queue->queue_maxlen) {
                queue->queue_dropped++;
-               status = -ENOSPC;
                if (net_ratelimit())
                          printk(KERN_WARNING "nf_queue: full at %d entries, "
                                 "dropping packets(s). Dropped: %d\n",
@@ -433,8 +414,8 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
        }
 
        /* nfnetlink_unicast will either free the nskb or add it to a socket */
-       status = nfnetlink_unicast(nskb, queue->peer_pid, MSG_DONTWAIT);
-       if (status < 0) {
+       err = nfnetlink_unicast(nskb, queue->peer_pid, MSG_DONTWAIT);
+       if (err < 0) {
                queue->queue_user_dropped++;
                goto err_out_unlock;
        }
@@ -442,14 +423,14 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
        __enqueue_entry(queue, entry);
 
        spin_unlock_bh(&queue->lock);
-       return status;
+       return 0;
 
 err_out_free_nskb:
        kfree_skb(nskb);
-
 err_out_unlock:
        spin_unlock_bh(&queue->lock);
-       return status;
+err_out:
+       return -1;
 }
 
 static int
@@ -670,8 +651,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,
        }
 
        if (nfqa[NFQA_MARK])
-               entry->skb->mark = ntohl(*(__be32 *)
-                                        nla_data(nfqa[NFQA_MARK]));
+               entry->skb->mark = ntohl(nla_get_be32(nfqa[NFQA_MARK]));
 
        nf_reinject(entry, verdict);
        return 0;