lkml.org 
[lkml]   [2010]   [Jan]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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!)


\
 
 \ /
  Last update: 2010-01-12 18:17    [W:0.083 / U:0.400 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site