diff options
author | Michael Brown | 2007-01-03 22:13:11 +0100 |
---|---|---|
committer | Michael Brown | 2007-01-03 22:13:11 +0100 |
commit | 94fc68895d8aed4ec4eeb7c7f1e62fb6312afc6d (patch) | |
tree | ab7f7b8cc866e44bbc013a82e867ce138841c8ce /src/net/tcp.c | |
parent | Verify checksums on the RX datapath. (diff) | |
download | ipxe-94fc68895d8aed4ec4eeb7c7f1e62fb6312afc6d.tar.gz ipxe-94fc68895d8aed4ec4eeb7c7f1e62fb6312afc6d.tar.xz ipxe-94fc68895d8aed4ec4eeb7c7f1e62fb6312afc6d.zip |
Improve consistency between TCP and UDP RX datapaths
Diffstat (limited to 'src/net/tcp.c')
-rw-r--r-- | src/net/tcp.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/net/tcp.c b/src/net/tcp.c index d9d427c4..8b56604a 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -600,7 +600,7 @@ static int tcp_rx ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src __unused, struct sockaddr_tcpip *st_dest __unused, uint16_t pshdr_csum ) { - struct tcp_header *tcphdr; + struct tcp_header *tcphdr = pkb->data; struct tcp_connection *conn; unsigned int hlen; uint16_t csum; @@ -611,34 +611,34 @@ static int tcp_rx ( struct pk_buff *pkb, unsigned int flags; void *data; size_t len; - int rc = 0; + int rc; /* Sanity check packet */ if ( pkb_len ( pkb ) < sizeof ( *tcphdr ) ) { DBG ( "TCP packet too short at %d bytes (min %d bytes)\n", pkb_len ( pkb ), sizeof ( *tcphdr ) ); rc = -EINVAL; - goto err; + goto done; } - tcphdr = pkb->data; hlen = ( ( tcphdr->hlen & TCP_MASK_HLEN ) / 16 ) * 4; if ( hlen < sizeof ( *tcphdr ) ) { DBG ( "TCP header too short at %d bytes (min %d bytes)\n", hlen, sizeof ( *tcphdr ) ); rc = -EINVAL; - goto err; + goto done; } if ( hlen > pkb_len ( pkb ) ) { DBG ( "TCP header too long at %d bytes (max %d bytes)\n", hlen, pkb_len ( pkb ) ); rc = -EINVAL; - goto err; + goto done; } csum = tcpip_continue_chksum ( pshdr_csum, pkb->data, pkb_len ( pkb )); if ( csum != 0 ) { DBG ( "TCP checksum incorrect (is %04x including checksum " "field, should be 0000)\n", csum ); - goto err; + rc = -EINVAL; + goto done; } /* Parse parameters from header and strip header */ @@ -663,13 +663,17 @@ static int tcp_rx ( struct pk_buff *pkb, * sending RST */ #warning "Handle non-matched connections" - if ( ! conn ) - goto err; + if ( ! conn ) { + rc = -ENOTCONN; + goto done; + } /* Handle RST, if present */ #warning "Handle RST" - if ( flags & TCP_RST ) - goto err; + if ( flags & TCP_RST ) { + rc = -ECONNRESET; + goto done; + } /* Handle ACK, if present */ if ( flags & TCP_ACK ) @@ -707,7 +711,8 @@ static int tcp_rx ( struct pk_buff *pkb, start_timer ( &conn->timer ); } - err: + rc = 0; + done: /* Free received packet */ free_pkb ( pkb ); return rc; |