[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4B4CADE9.3090302@gmail.com>
Date: Tue, 12 Jan 2010 12:14:17 -0500
From: William Allen Simpson <william.allen.simpson@...il.com>
To: Eric Dumazet <eric.dumazet@...il.com>
CC: Linux Kernel Developers <linux-kernel@...r.kernel.org>,
Linux Kernel Network Developers <netdev@...r.kernel.org>,
Ilpo Järvinen <ilpo.jarvinen@...sinki.fi>,
Andi Kleen <andi@...stfloor.org>
Subject: Re: [PATCH] tcp: harmonize tcp_vx_rcv header length assumptions
Eric Dumazet wrote:
> 2) This part :
>
> - th = tcp_hdr(skb);
> -
> - if (th->doff < sizeof(struct tcphdr)/4)
> + /* Check bad doff, compare doff directly to constant value */
> + tcp_header_len = tcp_hdr(skb)->doff;
> + if (tcp_header_len < (sizeof(struct tcphdr) / 4))
> goto bad_packet;
> - if (!pskb_may_pull(skb, th->doff*4))
> +
> + /* Check too short header and options */
> + tcp_header_len *= 4;
> + if (!pskb_may_pull(skb, tcp_header_len))
> goto discard_it;
>
>
> could be : (no need for 4 multiplies/divides)
>
> tcp_header_len = tcp_header_len_th(tcp_hdr(skb));
> if (tcp_header_len < sizeof(struct tcphdr))
> goto bad_packet;
> /* Check too short header and options */
> if (!pskb_may_pull(skb, tcp_header_len))
> goto discard_it;
>
Actually, tcp_header_len_th() has a multiply by 4 in it, too.
My code exactly parallels the existing code. That is slightly faster
for bad packets, as it does the raw comparison first, saving the
multiply by 4 until it has passed that test.
My change just saves a store (and maybe a register load) over the
existing code. This is supposed to be "fast path" after all....
Also adds comments that explain what we're doing. As I mentioned
earlier in the thread:
... back on Nov 10th, Ilpo brought to my attention --
*hidden* inside the pskb_may_pull() -- the tcp header length is range
checked for being too short (skb->len < th->doff * 4).
Anytime I find the code isn't obvious to me, I figure the next person
will benefit from some more comments....
(Of course, this patch also fixes existing comments that are not true!)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists