Commit 3e4ead4f authored by Jesper Juhl's avatar Jesper Juhl Committed by David S. Miller

[NETFILTER]: Decrease number of pointer derefs in nfnetlink_queue.c

Benefits of the patch:
 - Fewer pointer dereferences should make the code slightly faster.
 - Size of generated code is smaller
 - improved readability
Signed-off-by: default avatarJesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4ffd2e49
...@@ -345,6 +345,10 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -345,6 +345,10 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
struct nfqnl_msg_packet_hdr pmsg; struct nfqnl_msg_packet_hdr pmsg;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct nfgenmsg *nfmsg; struct nfgenmsg *nfmsg;
struct nf_info *entinf = entry->info;
struct sk_buff *entskb = entry->skb;
struct net_device *indev;
struct net_device *outdev;
unsigned int tmp_uint; unsigned int tmp_uint;
QDEBUG("entered\n"); QDEBUG("entered\n");
...@@ -361,6 +365,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -361,6 +365,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
+ NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_hw)) + NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_hw))
+ NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_timestamp)); + NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_timestamp));
outdev = entinf->outdev;
spin_lock_bh(&queue->lock); spin_lock_bh(&queue->lock);
switch (queue->copy_mode) { switch (queue->copy_mode) {
...@@ -370,15 +376,15 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -370,15 +376,15 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
break; break;
case NFQNL_COPY_PACKET: case NFQNL_COPY_PACKET:
if (entry->skb->ip_summed == CHECKSUM_HW && if (entskb->ip_summed == CHECKSUM_HW &&
(*errp = skb_checksum_help(entry->skb, (*errp = skb_checksum_help(entskb,
entry->info->outdev == NULL))) { outdev == NULL))) {
spin_unlock_bh(&queue->lock); spin_unlock_bh(&queue->lock);
return NULL; return NULL;
} }
if (queue->copy_range == 0 if (queue->copy_range == 0
|| queue->copy_range > entry->skb->len) || queue->copy_range > entskb->len)
data_len = entry->skb->len; data_len = entskb->len;
else else
data_len = queue->copy_range; data_len = queue->copy_range;
...@@ -402,29 +408,30 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -402,29 +408,30 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET, NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET,
sizeof(struct nfgenmsg)); sizeof(struct nfgenmsg));
nfmsg = NLMSG_DATA(nlh); nfmsg = NLMSG_DATA(nlh);
nfmsg->nfgen_family = entry->info->pf; nfmsg->nfgen_family = entinf->pf;
nfmsg->version = NFNETLINK_V0; nfmsg->version = NFNETLINK_V0;
nfmsg->res_id = htons(queue->queue_num); nfmsg->res_id = htons(queue->queue_num);
pmsg.packet_id = htonl(entry->id); pmsg.packet_id = htonl(entry->id);
pmsg.hw_protocol = htons(entry->skb->protocol); pmsg.hw_protocol = htons(entskb->protocol);
pmsg.hook = entry->info->hook; pmsg.hook = entinf->hook;
NFA_PUT(skb, NFQA_PACKET_HDR, sizeof(pmsg), &pmsg); NFA_PUT(skb, NFQA_PACKET_HDR, sizeof(pmsg), &pmsg);
if (entry->info->indev) { indev = entinf->indev;
tmp_uint = htonl(entry->info->indev->ifindex); if (indev) {
tmp_uint = htonl(indev->ifindex);
#ifndef CONFIG_BRIDGE_NETFILTER #ifndef CONFIG_BRIDGE_NETFILTER
NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint); NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint);
#else #else
if (entry->info->pf == PF_BRIDGE) { if (entinf->pf == PF_BRIDGE) {
/* Case 1: indev is physical input device, we need to /* Case 1: indev is physical input device, we need to
* look for bridge group (when called from * look for bridge group (when called from
* netfilter_bridge) */ * netfilter_bridge) */
NFA_PUT(skb, NFQA_IFINDEX_PHYSINDEV, sizeof(tmp_uint), NFA_PUT(skb, NFQA_IFINDEX_PHYSINDEV, sizeof(tmp_uint),
&tmp_uint); &tmp_uint);
/* this is the bridge group "brX" */ /* this is the bridge group "brX" */
tmp_uint = htonl(entry->info->indev->br_port->br->dev->ifindex); tmp_uint = htonl(indev->br_port->br->dev->ifindex);
NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint),
&tmp_uint); &tmp_uint);
} else { } else {
...@@ -432,9 +439,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -432,9 +439,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
* physical device (when called from ipv4) */ * physical device (when called from ipv4) */
NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint),
&tmp_uint); &tmp_uint);
if (entry->skb->nf_bridge if (entskb->nf_bridge
&& entry->skb->nf_bridge->physindev) { && entskb->nf_bridge->physindev) {
tmp_uint = htonl(entry->skb->nf_bridge->physindev->ifindex); tmp_uint = htonl(entskb->nf_bridge->physindev->ifindex);
NFA_PUT(skb, NFQA_IFINDEX_PHYSINDEV, NFA_PUT(skb, NFQA_IFINDEX_PHYSINDEV,
sizeof(tmp_uint), &tmp_uint); sizeof(tmp_uint), &tmp_uint);
} }
...@@ -442,19 +449,19 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -442,19 +449,19 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
#endif #endif
} }
if (entry->info->outdev) { if (outdev) {
tmp_uint = htonl(entry->info->outdev->ifindex); tmp_uint = htonl(outdev->ifindex);
#ifndef CONFIG_BRIDGE_NETFILTER #ifndef CONFIG_BRIDGE_NETFILTER
NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint); NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint);
#else #else
if (entry->info->pf == PF_BRIDGE) { if (entinf->pf == PF_BRIDGE) {
/* Case 1: outdev is physical output device, we need to /* Case 1: outdev is physical output device, we need to
* look for bridge group (when called from * look for bridge group (when called from
* netfilter_bridge) */ * netfilter_bridge) */
NFA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV, sizeof(tmp_uint), NFA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV, sizeof(tmp_uint),
&tmp_uint); &tmp_uint);
/* this is the bridge group "brX" */ /* this is the bridge group "brX" */
tmp_uint = htonl(entry->info->outdev->br_port->br->dev->ifindex); tmp_uint = htonl(outdev->br_port->br->dev->ifindex);
NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint),
&tmp_uint); &tmp_uint);
} else { } else {
...@@ -462,9 +469,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -462,9 +469,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
* physical output device (when called from ipv4) */ * physical output device (when called from ipv4) */
NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint),
&tmp_uint); &tmp_uint);
if (entry->skb->nf_bridge if (entskb->nf_bridge
&& entry->skb->nf_bridge->physoutdev) { && entskb->nf_bridge->physoutdev) {
tmp_uint = htonl(entry->skb->nf_bridge->physoutdev->ifindex); tmp_uint = htonl(entskb->nf_bridge->physoutdev->ifindex);
NFA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV, NFA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV,
sizeof(tmp_uint), &tmp_uint); sizeof(tmp_uint), &tmp_uint);
} }
...@@ -472,27 +479,27 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -472,27 +479,27 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
#endif #endif
} }
if (entry->skb->nfmark) { if (entskb->nfmark) {
tmp_uint = htonl(entry->skb->nfmark); tmp_uint = htonl(entskb->nfmark);
NFA_PUT(skb, NFQA_MARK, sizeof(u_int32_t), &tmp_uint); NFA_PUT(skb, NFQA_MARK, sizeof(u_int32_t), &tmp_uint);
} }
if (entry->info->indev && entry->skb->dev if (indev && entskb->dev
&& entry->skb->dev->hard_header_parse) { && entskb->dev->hard_header_parse) {
struct nfqnl_msg_packet_hw phw; struct nfqnl_msg_packet_hw phw;
phw.hw_addrlen = phw.hw_addrlen =
entry->skb->dev->hard_header_parse(entry->skb, entskb->dev->hard_header_parse(entskb,
phw.hw_addr); phw.hw_addr);
phw.hw_addrlen = htons(phw.hw_addrlen); phw.hw_addrlen = htons(phw.hw_addrlen);
NFA_PUT(skb, NFQA_HWADDR, sizeof(phw), &phw); NFA_PUT(skb, NFQA_HWADDR, sizeof(phw), &phw);
} }
if (entry->skb->tstamp.off_sec) { if (entskb->tstamp.off_sec) {
struct nfqnl_msg_packet_timestamp ts; struct nfqnl_msg_packet_timestamp ts;
ts.sec = cpu_to_be64(entry->skb->tstamp.off_sec); ts.sec = cpu_to_be64(entskb->tstamp.off_sec);
ts.usec = cpu_to_be64(entry->skb->tstamp.off_usec); ts.usec = cpu_to_be64(entskb->tstamp.off_usec);
NFA_PUT(skb, NFQA_TIMESTAMP, sizeof(ts), &ts); NFA_PUT(skb, NFQA_TIMESTAMP, sizeof(ts), &ts);
} }
...@@ -510,7 +517,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ...@@ -510,7 +517,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
nfa->nfa_type = NFQA_PAYLOAD; nfa->nfa_type = NFQA_PAYLOAD;
nfa->nfa_len = size; nfa->nfa_len = size;
if (skb_copy_bits(entry->skb, 0, NFA_DATA(nfa), data_len)) if (skb_copy_bits(entskb, 0, NFA_DATA(nfa), data_len))
BUG(); BUG();
} }
...@@ -667,12 +674,14 @@ nfqnl_set_mode(struct nfqnl_instance *queue, ...@@ -667,12 +674,14 @@ nfqnl_set_mode(struct nfqnl_instance *queue,
static int static int
dev_cmp(struct nfqnl_queue_entry *entry, unsigned long ifindex) dev_cmp(struct nfqnl_queue_entry *entry, unsigned long ifindex)
{ {
if (entry->info->indev) struct nf_info *entinf = entry->info;
if (entry->info->indev->ifindex == ifindex)
if (entinf->indev)
if (entinf->indev->ifindex == ifindex)
return 1; return 1;
if (entry->info->outdev) if (entinf->outdev)
if (entry->info->outdev->ifindex == ifindex) if (entinf->outdev->ifindex == ifindex)
return 1; return 1;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment