summaryrefslogtreecommitdiffstats
path: root/src/net/tcp.c
diff options
context:
space:
mode:
authorMichael Brown2007-01-03 21:48:52 +0100
committerMichael Brown2007-01-03 21:48:52 +0100
commita0525a4ed36a28260d6dee4723bd6a1eb29020be (patch)
tree720037999566f4a80c7873f173938fddf2942d5e /src/net/tcp.c
parentTidy up debug messages (diff)
downloadipxe-a0525a4ed36a28260d6dee4723bd6a1eb29020be.tar.gz
ipxe-a0525a4ed36a28260d6dee4723bd6a1eb29020be.tar.xz
ipxe-a0525a4ed36a28260d6dee4723bd6a1eb29020be.zip
Verify checksums on the RX datapath.
Simplify checksum generation on the TX datapath.
Diffstat (limited to 'src/net/tcp.c')
-rw-r--r--src/net/tcp.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/net/tcp.c b/src/net/tcp.c
index cd625c37..d9d427c4 100644
--- a/src/net/tcp.c
+++ b/src/net/tcp.c
@@ -309,7 +309,7 @@ static int tcp_senddata_conn ( struct tcp_connection *conn, int force_send ) {
DBGC ( conn, "\n" );
/* Transmit packet */
- return tcpip_tx ( pkb, &tcp_protocol, &conn->peer );
+ return tcpip_tx ( pkb, &tcp_protocol, &conn->peer, &tcphdr->csum );
}
/**
@@ -591,14 +591,19 @@ static int tcp_rx_fin ( struct tcp_connection *conn, uint32_t seq ) {
* Process received packet
*
* @v pkb Packet buffer
- * @v partial Partial checksum
- */
+ * @v st_src Partially-filled source address
+ * @v st_dest Partially-filled destination address
+ * @v pshdr_csum Pseudo-header checksum
+ * @ret rc Return status code
+ */
static int tcp_rx ( struct pk_buff *pkb,
struct sockaddr_tcpip *st_src __unused,
- struct sockaddr_tcpip *st_dest __unused ) {
+ struct sockaddr_tcpip *st_dest __unused,
+ uint16_t pshdr_csum ) {
struct tcp_header *tcphdr;
struct tcp_connection *conn;
unsigned int hlen;
+ uint16_t csum;
uint32_t start_seq;
uint32_t seq;
uint32_t ack;
@@ -608,7 +613,7 @@ static int tcp_rx ( struct pk_buff *pkb,
size_t len;
int rc = 0;
- /* Sanity check packet and strip TCP header */
+ /* 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 ) );
@@ -629,9 +634,12 @@ static int tcp_rx ( struct pk_buff *pkb,
rc = -EINVAL;
goto err;
}
-
- /* TODO: Verify checksum */
-#warning "Verify checksum"
+ 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;
+ }
/* Parse parameters from header and strip header */
conn = tcp_demux ( tcphdr->dest );
@@ -845,5 +853,4 @@ struct tcpip_protocol tcp_protocol __tcpip_protocol = {
.name = "TCP",
.rx = tcp_rx,
.tcpip_proto = IP_TCP,
- .csum_offset = 16,
};