public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jesper Juhl <jj@chaosbits.net>
Cc: Netfilter Core Team <coreteam@netfilter.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	netfilter@vger.kernel.org, netfilter-devel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [PATCH] Reduce number of pointer dereferences in IPv4 netfilter LOG module function dump_packet()
Date: Mon, 15 Nov 2010 01:49:40 +0100	[thread overview]
Message-ID: <1289782180.2743.166.camel@edumazet-laptop> (raw)
In-Reply-To: <alpine.LNX.2.00.1011142212310.1253@swampdragon.chaosbits.net>

Le dimanche 14 novembre 2010 à 22:35 +0100, Jesper Juhl a écrit :
> By adding two pointer variables to 
> net/ipv4/netfilter/ipt_LOG.c::dump_packet() we can save 16 bytes of .text 
> and 9 pointer dereferences.
> 
> before this patch we did 20 pointer dereferences and had this object file 
> size:
>    text    data     bss     dec     hex filename
>    6233     600    3080    9913    26b9 net/ipv4/netfilter/ipt_LOG.o
> 
> after this patch we do just 11 pointer dereferences and have this object 
> file size:
>    text    data     bss     dec     hex filename
>    6217     600    3080    9897    26a9 net/ipv4/netfilter/ipt_LOG.o
> 
> 
> Please Cc me on replies.
> 
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  ipt_LOG.c |   16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/net/ipv4/netfilter/ipt_LOG.c b/net/ipv4/netfilter/ipt_LOG.c
> index 72ffc8f..02a92de 100644
> --- a/net/ipv4/netfilter/ipt_LOG.c
> +++ b/net/ipv4/netfilter/ipt_LOG.c
> @@ -39,6 +39,8 @@ static void dump_packet(struct sbuff *m,
>  	struct iphdr _iph;
>  	const struct iphdr *ih;
>  	unsigned int logflags;
> +	struct sock *sk;
> +	struct socket *sk_socket;
>  
>  	if (info->type == NF_LOG_TYPE_LOG)
>  		logflags = info->u.log.logflags;
> @@ -335,13 +337,15 @@ static void dump_packet(struct sbuff *m,
>  	}
>  
>  	/* Max length: 15 "UID=4294967295 " */
> -	if ((logflags & IPT_LOG_UID) && !iphoff && skb->sk) {
> -		read_lock_bh(&skb->sk->sk_callback_lock);
> -		if (skb->sk->sk_socket && skb->sk->sk_socket->file)
> +	sk = skb->sk;
> +	sk_socket = sk->sk_socket;

Really ? sk can be NULL, so you add a NULL dereference.

> +	if ((logflags & IPT_LOG_UID) && !iphoff && sk) {
> +		read_lock_bh(&sk->sk_callback_lock);
> +		if (sk_socket && sk_socket->file)
>  			sb_add(m, "UID=%u GID=%u ",
> -				skb->sk->sk_socket->file->f_cred->fsuid,
> -				skb->sk->sk_socket->file->f_cred->fsgid);
> -		read_unlock_bh(&skb->sk->sk_callback_lock);
> +				sk_socket->file->f_cred->fsuid,
> +				sk_socket->file->f_cred->fsgid);
> +		read_unlock_bh(&sk->sk_callback_lock);
>  	}
>  
>  	/* Max length: 16 "MARK=0xFFFFFFFF " */
> 
> 
> 

Most of these "dereferences" are compiler optimized.

You added a bug in your patch, and make ipt_LOG slower if rule is not
asking for IPT_LOG_UID

  reply	other threads:[~2010-11-15  0:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-14 21:35 [PATCH] Reduce number of pointer dereferences in IPv4 netfilter LOG module function dump_packet() Jesper Juhl
2010-11-15  0:49 ` Eric Dumazet [this message]
2010-11-15 21:48   ` Jesper Juhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289782180.2743.166.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=netfilter@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox