]> Pileus Git - ~andy/linux/commitdiff
netfilter: nfnetlink_queue: cleanup copy_range usage
authorFlorian Westphal <fw@strlen.de>
Tue, 4 Jun 2013 22:22:15 +0000 (22:22 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 5 Jun 2013 10:40:28 +0000 (12:40 +0200)
For every packet queued, we check if configured copy_range
is 0, and treat that as 'copy entire packet'.

We can move this check to the queue configuration, and can
set copy_range appropriately.

Also, convert repetitive '0xffff - NLA_HDRLEN' to a macro.

[ queue initialization still used 0xffff, although its harmless
  since the initial setting is overwritten on queue config ]

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nfnetlink_queue_core.c

index cff4449f01d24188d990e616c308f3ac2d333776..3c4218141d7006f405278f50688f4eb38e3aed4d 100644 (file)
 
 #define NFQNL_QMAX_DEFAULT 1024
 
+/* We're using struct nlattr which has 16bit nla_len. Note that nla_len
+ * includes the header length. Thus, the maximum packet length that we
+ * support is 65531 bytes. We send truncated packets if the specified length
+ * is larger than that.  Userspace can check for presence of NFQA_CAP_LEN
+ * attribute to detect truncation.
+ */
+#define NFQNL_MAX_COPY_RANGE (0xffff - NLA_HDRLEN)
+
 struct nfqnl_instance {
        struct hlist_node hlist;                /* global list of queues */
        struct rcu_head rcu;
@@ -122,7 +130,7 @@ instance_create(struct nfnl_queue_net *q, u_int16_t queue_num,
        inst->queue_num = queue_num;
        inst->peer_portid = portid;
        inst->queue_maxlen = NFQNL_QMAX_DEFAULT;
-       inst->copy_range = 0xffff;
+       inst->copy_range = NFQNL_MAX_COPY_RANGE;
        inst->copy_mode = NFQNL_COPY_NONE;
        spin_lock_init(&inst->lock);
        INIT_LIST_HEAD(&inst->queue_list);
@@ -333,10 +341,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
                        return NULL;
 
                data_len = ACCESS_ONCE(queue->copy_range);
-               if (data_len == 0 || data_len > entskb->len)
+               if (data_len > entskb->len)
                        data_len = entskb->len;
 
-
                if (!entskb->head_frag ||
                    skb_headlen(entskb) < L1_CACHE_BYTES ||
                    skb_shinfo(entskb)->nr_frags >= MAX_SKB_FRAGS)
@@ -727,13 +734,8 @@ nfqnl_set_mode(struct nfqnl_instance *queue,
 
        case NFQNL_COPY_PACKET:
                queue->copy_mode = mode;
-               /* We're using struct nlattr which has 16bit nla_len. Note that
-                * nla_len includes the header length. Thus, the maximum packet
-                * length that we support is 65531 bytes. We send truncated
-                * packets if the specified length is larger than that.
-                */
-               if (range > 0xffff - NLA_HDRLEN)
-                       queue->copy_range = 0xffff - NLA_HDRLEN;
+               if (range == 0 || range > NFQNL_MAX_COPY_RANGE)
+                       queue->copy_range = NFQNL_MAX_COPY_RANGE;
                else
                        queue->copy_range = range;
                break;