Skip to content

Commit

Permalink
tcp: remove redundant checks
Browse files Browse the repository at this point in the history
tcp_v4_rcv() checks the following before calling tcp_v4_do_rcv():

if (th->doff < sizeof(struct tcphdr) / 4)
    goto bad_packet;
if (!pskb_may_pull(skb, th->doff * 4))
    goto discard_it;

So following check in tcp_v4_do_rcv() is redundant
and "goto csum_err;" is wrong anyway.

if (skb->len < tcp_hdrlen(skb) || ...)
	goto csum_err;

A second check can be removed after no_tcp_socket label for same reason.

Same tests can be removed in tcp_v6_do_rcv()

Note : short tcp frames are not properly accounted in tcpInErrs MIB,
because pskb_may_pull() failure simply drops incoming skb, we might
fix this in a separate patch.

Signed-off-by: Eric Dumazet  <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Jun 4, 2015
1 parent 37c8e2b commit 12e25e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0;
}

if (skb->len < tcp_hdrlen(skb) || tcp_checksum_complete(skb))
if (tcp_checksum_complete(skb))
goto csum_err;

if (sk->sk_state == TCP_LISTEN) {
Expand Down Expand Up @@ -1647,7 +1647,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
goto discard_it;

if (skb->len < (th->doff << 2) || tcp_checksum_complete(skb)) {
if (tcp_checksum_complete(skb)) {
csum_error:
TCP_INC_STATS_BH(net, TCP_MIB_CSUMERRORS);
bad_packet:
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/tcp_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0;
}

if (skb->len < tcp_hdrlen(skb) || tcp_checksum_complete(skb))
if (tcp_checksum_complete(skb))
goto csum_err;

if (sk->sk_state == TCP_LISTEN) {
Expand Down Expand Up @@ -1442,7 +1442,7 @@ static int tcp_v6_rcv(struct sk_buff *skb)

tcp_v6_fill_cb(skb, hdr, th);

if (skb->len < (th->doff<<2) || tcp_checksum_complete(skb)) {
if (tcp_checksum_complete(skb)) {
csum_error:
TCP_INC_STATS_BH(net, TCP_MIB_CSUMERRORS);
bad_packet:
Expand Down

0 comments on commit 12e25e1

Please sign in to comment.