* [PATCH] Reduce number of pointer dereferences in IPv6 netfilter LOG module function dump_packet()
@ 2010-11-14 21:47 Jesper Juhl
2010-11-15 0:50 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2010-11-14 21:47 UTC (permalink / raw)
To: Netfilter Core Team
Cc: Jan Rekorajski, David S. Miller, netfilter-devel, netfilter,
netdev, linux-kernel
By adding two pointer variables to
net/ipv6/netfilter/ip6t_LOG.c::dump_packet() we can save 19 bytes of .text
and many pointer dereferences.
before:
text data bss dec hex filename
6258 600 3088 9946 26da net/ipv6/netfilter/ip6t_LOG.o
after:
text data bss dec hex filename
6239 600 3088 9927 26c7 net/ipv6/netfilter/ip6t_LOG.o
Please Cc me on replies.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
ip6t_LOG.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
index 09c8889..51d10a5 100644
--- a/net/ipv6/netfilter/ip6t_LOG.c
+++ b/net/ipv6/netfilter/ip6t_LOG.c
@@ -46,6 +46,8 @@ static void dump_packet(struct sbuff *m,
unsigned int ptr;
unsigned int hdrlen = 0;
unsigned int logflags;
+ struct sock *sk;
+ struct socket *sk_socket;
if (info->type == NF_LOG_TYPE_LOG)
logflags = info->u.log.logflags;
@@ -358,13 +360,15 @@ static void dump_packet(struct sbuff *m,
}
/* Max length: 15 "UID=4294967295 " */
- if ((logflags & IP6T_LOG_UID) && recurse && 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;
+ if ((logflags & IP6T_LOG_UID) && recurse && 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 " */
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Reduce number of pointer dereferences in IPv6 netfilter LOG module function dump_packet()
2010-11-14 21:47 [PATCH] Reduce number of pointer dereferences in IPv6 netfilter LOG module function dump_packet() Jesper Juhl
@ 2010-11-15 0:50 ` Eric Dumazet
2010-11-15 21:49 ` Jesper Juhl
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2010-11-15 0:50 UTC (permalink / raw)
To: Jesper Juhl
Cc: Netfilter Core Team, Jan Rekorajski, David S. Miller,
netfilter-devel, netfilter, netdev, linux-kernel
Le dimanche 14 novembre 2010 à 22:47 +0100, Jesper Juhl a écrit :
> By adding two pointer variables to
> net/ipv6/netfilter/ip6t_LOG.c::dump_packet() we can save 19 bytes of .text
> and many pointer dereferences.
>
> before:
> text data bss dec hex filename
> 6258 600 3088 9946 26da net/ipv6/netfilter/ip6t_LOG.o
>
> after:
> text data bss dec hex filename
> 6239 600 3088 9927 26c7 net/ipv6/netfilter/ip6t_LOG.o
>
>
> Please Cc me on replies.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
> ip6t_LOG.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
> index 09c8889..51d10a5 100644
> --- a/net/ipv6/netfilter/ip6t_LOG.c
> +++ b/net/ipv6/netfilter/ip6t_LOG.c
> @@ -46,6 +46,8 @@ static void dump_packet(struct sbuff *m,
> unsigned int ptr;
> unsigned int hdrlen = 0;
> unsigned int logflags;
> + struct sock *sk;
> + struct socket *sk_socket;
>
> if (info->type == NF_LOG_TYPE_LOG)
> logflags = info->u.log.logflags;
> @@ -358,13 +360,15 @@ static void dump_packet(struct sbuff *m,
> }
>
> /* Max length: 15 "UID=4294967295 " */
> - if ((logflags & IP6T_LOG_UID) && recurse && 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;
> + if ((logflags & IP6T_LOG_UID) && recurse && 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 " */
>
>
>
Same comment than previous patch, you add a NULL dereference.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Reduce number of pointer dereferences in IPv6 netfilter LOG module function dump_packet()
2010-11-15 0:50 ` Eric Dumazet
@ 2010-11-15 21:49 ` Jesper Juhl
2010-11-15 21:50 ` Jesper Juhl
0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2010-11-15 21:49 UTC (permalink / raw)
To: Eric Dumazet
Cc: Netfilter Core Team, Jan Rekorajski, David S. Miller,
netfilter-devel, netfilter, netdev, linux-kernel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2613 bytes --]
On Mon, 15 Nov 2010, Eric Dumazet wrote:
> Le dimanche 14 novembre 2010 à 22:47 +0100, Jesper Juhl a écrit :
> > By adding two pointer variables to
> > net/ipv6/netfilter/ip6t_LOG.c::dump_packet() we can save 19 bytes of .text
> > and many pointer dereferences.
> >
> > before:
> > text data bss dec hex filename
> > 6258 600 3088 9946 26da net/ipv6/netfilter/ip6t_LOG.o
> >
> > after:
> > text data bss dec hex filename
> > 6239 600 3088 9927 26c7 net/ipv6/netfilter/ip6t_LOG.o
> >
> >
> > Please Cc me on replies.
> >
> >
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> > ---
> > ip6t_LOG.c | 16 ++++++++++------
> > 1 file changed, 10 insertions(+), 6 deletions(-)
> >
> > diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
> > index 09c8889..51d10a5 100644
> > --- a/net/ipv6/netfilter/ip6t_LOG.c
> > +++ b/net/ipv6/netfilter/ip6t_LOG.c
[...]
>
> Same comment than previous patch, you add a NULL dereference.
>
Hopefully this is beter (same as change done to the other (ipv4) patch).
Fewer pointer derefs and smaller .text size for
net/ipv4/netfilter/ipt_LOG.c::dump_packet()
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
ip6t_LOG.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
index 09c8889..de15b14 100644
--- a/net/ipv6/netfilter/ip6t_LOG.c
+++ b/net/ipv6/netfilter/ip6t_LOG.c
@@ -46,6 +46,7 @@ static void dump_packet(struct sbuff *m,
unsigned int ptr;
unsigned int hdrlen = 0;
unsigned int logflags;
+ struct sock *sk;
if (info->type == NF_LOG_TYPE_LOG)
logflags = info->u.log.logflags;
@@ -359,12 +360,13 @@ static void dump_packet(struct sbuff *m,
/* Max length: 15 "UID=4294967295 " */
if ((logflags & IP6T_LOG_UID) && recurse && skb->sk) {
- read_lock_bh(&skb->sk->sk_callback_lock);
- if (skb->sk->sk_socket && skb->sk->sk_socket->file)
+ sk = skb->sk;
+ read_lock_bh(&sk->sk_callback_lock);
+ if (sk->sk_socket && sk->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->sk_socket->file->f_cred->fsuid,
+ sk->sk_socket->file->f_cred->fsgid);
+ read_unlock_bh(&sk->sk_callback_lock);
}
/* Max length: 16 "MARK=0xFFFFFFFF " */
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Reduce number of pointer dereferences in IPv6 netfilter LOG module function dump_packet()
2010-11-15 21:49 ` Jesper Juhl
@ 2010-11-15 21:50 ` Jesper Juhl
0 siblings, 0 replies; 4+ messages in thread
From: Jesper Juhl @ 2010-11-15 21:50 UTC (permalink / raw)
To: Eric Dumazet
Cc: Netfilter Core Team, Jan Rekorajski, David S. Miller,
netfilter-devel, netfilter, netdev, linux-kernel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1630 bytes --]
On Mon, 15 Nov 2010, Jesper Juhl wrote:
> On Mon, 15 Nov 2010, Eric Dumazet wrote:
>
> > Le dimanche 14 novembre 2010 à 22:47 +0100, Jesper Juhl a écrit :
> > > By adding two pointer variables to
> > > net/ipv6/netfilter/ip6t_LOG.c::dump_packet() we can save 19 bytes of .text
> > > and many pointer dereferences.
> > >
> > > before:
> > > text data bss dec hex filename
> > > 6258 600 3088 9946 26da net/ipv6/netfilter/ip6t_LOG.o
> > >
> > > after:
> > > text data bss dec hex filename
> > > 6239 600 3088 9927 26c7 net/ipv6/netfilter/ip6t_LOG.o
> > >
> > >
> > > Please Cc me on replies.
> > >
> > >
> > > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> > > ---
> > > ip6t_LOG.c | 16 ++++++++++------
> > > 1 file changed, 10 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
> > > index 09c8889..51d10a5 100644
> > > --- a/net/ipv6/netfilter/ip6t_LOG.c
> > > +++ b/net/ipv6/netfilter/ip6t_LOG.c
> [...]
> >
> > Same comment than previous patch, you add a NULL dereference.
> >
> Hopefully this is beter (same as change done to the other (ipv4) patch).
>
>
>
> Fewer pointer derefs and smaller .text size for
> net/ipv4/netfilter/ipt_LOG.c::dump_packet()
>
I'm an idiot, that should of course read
"net/ipv6/netfilter/ip6t_LOG.c::dump_packet()"
That'll teach me not to cut'n'paste descriptions :-(
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-11-15 21:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-14 21:47 [PATCH] Reduce number of pointer dereferences in IPv6 netfilter LOG module function dump_packet() Jesper Juhl
2010-11-15 0:50 ` Eric Dumazet
2010-11-15 21:49 ` Jesper Juhl
2010-11-15 21:50 ` Jesper Juhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox