Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63354C77B7C for ; Wed, 24 May 2023 21:19:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D38B28467A; Wed, 24 May 2023 23:19:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kWELgXbs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 40D258467E; Wed, 24 May 2023 23:19:28 +0200 (CEST) Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 740AF84661 for ; Wed, 24 May 2023 23:19:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=paul.liu@linaro.org Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-255bd112757so224876a91.1 for ; Wed, 24 May 2023 14:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684963163; x=1687555163; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2MSYUneBKMNDZgueZCWeT+lsGno5naUHO7foOAqmbII=; b=kWELgXbsBA2HjemxS4WfiZ/bpXmICGrQGaL2962fyvgJSoVjIAxkiiwa3BDrnIeNqu ezn2qxlqwvlf8HVJV3UbVX88cQwh4m4ftWXtPViEtSigvSIn3myybsG6fmdTcAIB56QN ux+fnFjePmRVY7lrxZs9Z9FxC7ozfSMXAJAVQjHcxRd8DghI80CZSyM/NUuuikGU1Qfr S4X0Nk+RAdQKAG36BmQH6A/PdMWQMTrmfY/sPOkfW/XfCnerYz/gmeucIBj7VM9Kuu7f x96cYuQnT6+KyBKlPZPk6aecL9qQs/6E+Py+KJNrzSfYXQjc0IJfJtdvwmUwGeXWrgVO gX7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684963163; x=1687555163; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2MSYUneBKMNDZgueZCWeT+lsGno5naUHO7foOAqmbII=; b=B2Hhn5clD+R4VSTJulImh9cDtrqxSUZNssZkwq6ThfB3O6HlUX4qbfszLgMBaSerm6 pELdeEGg94oS0qxicW5EW5rbcl4biLcHfn8xzatqFC8I2V5+w2lyjEzDCSaNjuP8OnzW AucoCb8qt96m9JUfdr2IBropH2Pw8NlHIDLJuD+Ko2b3w8dXL4gmteyvyBMlalp+x7oQ h8KXstO9ZTXJxNy9Fj0KE5DCDzZSpd6gYre12muAHsFFWrmnSBx8TdOZvdqGFnzo1qsN rONfO2FTc0jGbFW/1rZYkUGDEri4DhgBEadGnwtYApxKeed9m54BPbpiDJOVYJMv2GrF a5sQ== X-Gm-Message-State: AC+VfDzgT9hoF3M4lTnSGGF4zlwQMwnRX7AgLkjkDaSgAKwD0rkFefHt bMXugn/dquqEsf4k5dCuBsENZw== X-Google-Smtp-Source: ACHHUZ4dKEPLnPgzdzv7Z9gNZW2PdTXy4+y6hb3xD5wY6OUd35X7pcxRalXI1t5RHw0lfEvTm2FrSQ== X-Received: by 2002:a17:90a:6e4f:b0:24e:14a4:9b92 with SMTP id s15-20020a17090a6e4f00b0024e14a49b92mr755500pjm.5.1684963162606; Wed, 24 May 2023 14:19:22 -0700 (PDT) Received: from [192.168.66.10] ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id bs5-20020a632805000000b0051eff0a70d7sm8150566pgb.94.2023.05.24.14.19.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 14:19:22 -0700 (PDT) Message-ID: Date: Thu, 25 May 2023 05:19:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v2 1/6] net: split IP_TCP header into separate IP/IP6 and TCP headers To: Dmitrii Merkurev , u-boot@lists.denx.de Cc: rammuthiah@google.com, rfried.dev@gmail.com, Simon Glass References: <20230510165959.2228978-1-dimorinny@google.com> Content-Language: en-US From: "Ying-Chun Liu (PaulLiu)" In-Reply-To: <20230510165959.2228978-1-dimorinny@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Reviewed-by: Ying-Chun Liu (PaulLiu) On 2023/5/11 00:59, Dmitrii Merkurev wrote: > This allows us to reuse TCP logic between IP and IP6 stack. > > Signed-off-by: Dmitrii Merkurev > Cc: Ying-Chun Liu (PaulLiu) > Cc: Simon Glass > Сс: Joe Hershberger > Сс: Ramon Fried > --- > include/net/tcp.h | 54 ++++++++++++++++-------------------- > net/tcp.c | 70 +++++++++++++++++++++++------------------------ > test/cmd/wget.c | 48 ++++++++++++++++++-------------- > 3 files changed, 85 insertions(+), 87 deletions(-) > > diff --git a/include/net/tcp.h b/include/net/tcp.h > index c29d4ce24a..93ed728dfe 100644 > --- a/include/net/tcp.h > +++ b/include/net/tcp.h > @@ -5,20 +5,16 @@ > * Copyright 2017 Duncan Hare, All rights reserved. > */ > > +#ifndef __TCP_H__ > +#define __TCP_H__ > + > #define TCP_ACTIVITY 127 /* Number of packets received */ > /* before console progress mark */ > + > +#define GET_TCP_HDR_LEN_IN_BYTES(x) ((x) >> 2) > + > /** > - * struct ip_tcp_hdr - IP and TCP header > - * @ip_hl_v: header length and version > - * @ip_tos: type of service > - * @ip_len: total length > - * @ip_id: identification > - * @ip_off: fragment offset field > - * @ip_ttl: time to live > - * @ip_p: protocol > - * @ip_sum: checksum > - * @ip_src: Source IP address > - * @ip_dst: Destination IP address > + * struct tcp_hdr - TCP header > * @tcp_src: TCP source port > * @tcp_dst: TCP destination port > * @tcp_seq: TCP sequence number > @@ -28,18 +24,8 @@ > * @tcp_win: TCP windows size > * @tcp_xsum: Checksum > * @tcp_ugr: Pointer to urgent data > - */ > -struct ip_tcp_hdr { > - u8 ip_hl_v; > - u8 ip_tos; > - u16 ip_len; > - u16 ip_id; > - u16 ip_off; > - u8 ip_ttl; > - u8 ip_p; > - u16 ip_sum; > - struct in_addr ip_src; > - struct in_addr ip_dst; > +*/ > +struct tcp_hdr { > u16 tcp_src; > u16 tcp_dst; > u32 tcp_seq; > @@ -51,8 +37,8 @@ struct ip_tcp_hdr { > u16 tcp_ugr; > } __packed; > > -#define IP_TCP_HDR_SIZE (sizeof(struct ip_tcp_hdr)) > -#define TCP_HDR_SIZE (IP_TCP_HDR_SIZE - IP_HDR_SIZE) > +#define TCP_HDR_SIZE (sizeof(struct tcp_hdr)) > +#define IP_TCP_HDR_SIZE (IP_HDR_SIZE + TCP_HDR_SIZE) > > #define TCP_DATA 0x00 /* Data Packet - internal use only */ > #define TCP_FIN 0x01 /* Finish flag */ > @@ -178,7 +164,8 @@ struct tcp_t_opt { > > /** > * struct ip_tcp_hdr_o - IP + TCP header + TCP options > - * @hdr: IP + TCP header > + * @ip_hdr: IP + TCP header > + * @tcp_hdr: TCP header > * @mss: TCP MSS Option > * @scale: TCP Windows Scale Option > * @sack_p: TCP Sack-Permitted Option > @@ -186,7 +173,8 @@ struct tcp_t_opt { > * @end: end of options > */ > struct ip_tcp_hdr_o { > - struct ip_tcp_hdr hdr; > + struct ip_hdr ip_hdr; > + struct tcp_hdr tcp_hdr; > struct tcp_mss mss; > struct tcp_scale scale; > struct tcp_sack_p sack_p; > @@ -198,15 +186,17 @@ struct ip_tcp_hdr_o { > > /** > * struct ip_tcp_hdr_s - IP + TCP header + TCP options > - * @hdr: IP + TCP header > + * @ip_hdr: IP + TCP header > + * @tcp_hdr: TCP header > * @t_opt: TCP Timestamp Option > * @sack_v: TCP SACK Option > * @end: end of options > */ > struct ip_tcp_hdr_s { > - struct ip_tcp_hdr hdr; > - struct tcp_t_opt t_opt; > - struct tcp_sack_v sack_v; > + struct ip_hdr ip_hdr; > + struct tcp_hdr tcp_hdr; > + struct tcp_t_opt t_opt; > + struct tcp_sack_v sack_v; > u8 end; > } __packed; > > @@ -303,3 +293,5 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int len); > > u16 tcp_set_pseudo_header(uchar *pkt, struct in_addr src, struct in_addr dest, > int tcp_len, int pkt_len); > + > +#endif // __TCP_H__ > diff --git a/net/tcp.c b/net/tcp.c > index a713e1dd60..10ce799814 100644 > --- a/net/tcp.c > +++ b/net/tcp.c > @@ -155,7 +155,7 @@ u16 tcp_set_pseudo_header(uchar *pkt, struct in_addr src, struct in_addr dest, > */ > int net_set_ack_options(union tcp_build_pkt *b) > { > - b->sack.hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE)); > + b->sack.tcp_hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE)); > > b->sack.t_opt.kind = TCP_O_TS; > b->sack.t_opt.len = TCP_OPT_LEN_A; > @@ -187,12 +187,12 @@ int net_set_ack_options(union tcp_build_pkt *b) > b->sack.sack_v.hill[3].r = TCP_O_NOP; > } > > - b->sack.hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(ROUND_TCPHDR_LEN(TCP_HDR_SIZE + > + b->sack.tcp_hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(ROUND_TCPHDR_LEN(TCP_HDR_SIZE + > TCP_TSOPT_SIZE + > tcp_lost.len)); > } else { > b->sack.sack_v.kind = 0; > - b->sack.hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(ROUND_TCPHDR_LEN(TCP_HDR_SIZE + > + b->sack.tcp_hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(ROUND_TCPHDR_LEN(TCP_HDR_SIZE + > TCP_TSOPT_SIZE)); > } > > @@ -201,7 +201,7 @@ int net_set_ack_options(union tcp_build_pkt *b) > * TCP header to add to the total packet length > */ > > - return GET_TCP_HDR_LEN_IN_BYTES(b->sack.hdr.tcp_hlen); > + return GET_TCP_HDR_LEN_IN_BYTES(b->sack.tcp_hdr.tcp_hlen); > } > > /** > @@ -213,7 +213,7 @@ void net_set_syn_options(union tcp_build_pkt *b) > if (IS_ENABLED(CONFIG_PROT_TCP_SACK)) > tcp_lost.len = 0; > > - b->ip.hdr.tcp_hlen = 0xa0; > + b->ip.tcp_hdr.tcp_hlen = 0xa0; > > b->ip.mss.kind = TCP_O_MSS; > b->ip.mss.len = TCP_OPT_LEN_4; > @@ -249,9 +249,9 @@ int tcp_set_tcp_header(uchar *pkt, int dport, int sport, int payload_len, > * Header: 5 32 bit words. 4 bits TCP header Length, > * 4 bits reserved options > */ > - b->ip.hdr.tcp_flags = action; > + b->ip.tcp_hdr.tcp_flags = action; > pkt_hdr_len = IP_TCP_HDR_SIZE; > - b->ip.hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE)); > + b->ip.tcp_hdr.tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE)); > > switch (action) { > case TCP_SYN: > @@ -274,7 +274,7 @@ int tcp_set_tcp_header(uchar *pkt, int dport, int sport, int payload_len, > case TCP_SYN | TCP_ACK: > case TCP_ACK: > pkt_hdr_len = IP_HDR_SIZE + net_set_ack_options(b); > - b->ip.hdr.tcp_flags = action; > + b->ip.tcp_hdr.tcp_flags = action; > debug_cond(DEBUG_DEV_PKT, > "TCP Hdr:ACK (%pI4, %pI4, s=%u, a=%u, A=%x)\n", > &net_server_ip, &net_ip, tcp_seq_num, tcp_ack_num, > @@ -308,7 +308,7 @@ int tcp_set_tcp_header(uchar *pkt, int dport, int sport, int payload_len, > fallthrough; > default: > pkt_hdr_len = IP_HDR_SIZE + net_set_ack_options(b); > - b->ip.hdr.tcp_flags = action | TCP_PUSH | TCP_ACK; > + b->ip.tcp_hdr.tcp_flags = action | TCP_PUSH | TCP_ACK; > debug_cond(DEBUG_DEV_PKT, > "TCP Hdr:dft (%pI4, %pI4, s=%u, a=%u, A=%x)\n", > &net_server_ip, &net_ip, > @@ -320,10 +320,10 @@ int tcp_set_tcp_header(uchar *pkt, int dport, int sport, int payload_len, > > tcp_ack_edge = tcp_ack_num; > /* TCP Header */ > - b->ip.hdr.tcp_ack = htonl(tcp_ack_edge); > - b->ip.hdr.tcp_src = htons(sport); > - b->ip.hdr.tcp_dst = htons(dport); > - b->ip.hdr.tcp_seq = htonl(tcp_seq_num); > + b->ip.tcp_hdr.tcp_ack = htonl(tcp_ack_edge); > + b->ip.tcp_hdr.tcp_src = htons(sport); > + b->ip.tcp_hdr.tcp_dst = htons(dport); > + b->ip.tcp_hdr.tcp_seq = htonl(tcp_seq_num); > > /* > * TCP window size - TCP header variable tcp_win. > @@ -340,13 +340,13 @@ int tcp_set_tcp_header(uchar *pkt, int dport, int sport, int payload_len, > * it is, then the u-boot tftp or nfs kernel netboot should be > * considered. > */ > - b->ip.hdr.tcp_win = htons(PKTBUFSRX * TCP_MSS >> TCP_SCALE); > + b->ip.tcp_hdr.tcp_win = htons(PKTBUFSRX * TCP_MSS >> TCP_SCALE); > > - b->ip.hdr.tcp_xsum = 0; > - b->ip.hdr.tcp_ugr = 0; > + b->ip.tcp_hdr.tcp_xsum = 0; > + b->ip.tcp_hdr.tcp_ugr = 0; > > - b->ip.hdr.tcp_xsum = tcp_set_pseudo_header(pkt, net_ip, net_server_ip, > - tcp_len, pkt_len); > + b->ip.tcp_hdr.tcp_xsum = tcp_set_pseudo_header(pkt, net_ip, net_server_ip, > + tcp_len, pkt_len); > > net_set_ip_header((uchar *)&b->ip, net_server_ip, net_ip, > pkt_len, IPPROTO_TCP); > @@ -638,7 +638,7 @@ static u8 tcp_state_machine(u8 tcp_flags, u32 tcp_seq_num, int payload_len) > void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > { > int tcp_len = pkt_len - IP_HDR_SIZE; > - u16 tcp_rx_xsum = b->ip.hdr.ip_sum; > + u16 tcp_rx_xsum = b->ip.ip_hdr.ip_sum; > u8 tcp_action = TCP_DATA; > u32 tcp_seq_num, tcp_ack_num; > int tcp_hdr_len, payload_len; > @@ -646,11 +646,11 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > /* Verify IP header */ > debug_cond(DEBUG_DEV_PKT, > "TCP RX in RX Sum (to=%pI4, from=%pI4, len=%d)\n", > - &b->ip.hdr.ip_src, &b->ip.hdr.ip_dst, pkt_len); > + &b->ip.ip_hdr.ip_src, &b->ip.ip_hdr.ip_dst, pkt_len); > > - b->ip.hdr.ip_src = net_server_ip; > - b->ip.hdr.ip_dst = net_ip; > - b->ip.hdr.ip_sum = 0; > + b->ip.ip_hdr.ip_src = net_server_ip; > + b->ip.ip_hdr.ip_dst = net_ip; > + b->ip.ip_hdr.ip_sum = 0; > if (tcp_rx_xsum != compute_ip_checksum(b, IP_HDR_SIZE)) { > debug_cond(DEBUG_DEV_PKT, > "TCP RX IP xSum Error (%pI4, =%pI4, len=%d)\n", > @@ -659,10 +659,10 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > } > > /* Build pseudo header and verify TCP header */ > - tcp_rx_xsum = b->ip.hdr.tcp_xsum; > - b->ip.hdr.tcp_xsum = 0; > - if (tcp_rx_xsum != tcp_set_pseudo_header((uchar *)b, b->ip.hdr.ip_src, > - b->ip.hdr.ip_dst, tcp_len, > + tcp_rx_xsum = b->ip.tcp_hdr.tcp_xsum; > + b->ip.tcp_hdr.tcp_xsum = 0; > + if (tcp_rx_xsum != tcp_set_pseudo_header((uchar *)b, b->ip.ip_hdr.ip_src, > + b->ip.ip_hdr.ip_dst, tcp_len, > pkt_len)) { > debug_cond(DEBUG_DEV_PKT, > "TCP RX TCP xSum Error (%pI4, %pI4, len=%d)\n", > @@ -670,7 +670,7 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > return; > } > > - tcp_hdr_len = GET_TCP_HDR_LEN_IN_BYTES(b->ip.hdr.tcp_hlen); > + tcp_hdr_len = GET_TCP_HDR_LEN_IN_BYTES(b->ip.tcp_hdr.tcp_hlen); > payload_len = tcp_len - tcp_hdr_len; > > if (tcp_hdr_len > TCP_HDR_SIZE) > @@ -680,11 +680,11 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > * Incoming sequence and ack numbers are server's view of the numbers. > * The app must swap the numbers when responding. > */ > - tcp_seq_num = ntohl(b->ip.hdr.tcp_seq); > - tcp_ack_num = ntohl(b->ip.hdr.tcp_ack); > + tcp_seq_num = ntohl(b->ip.tcp_hdr.tcp_seq); > + tcp_ack_num = ntohl(b->ip.tcp_hdr.tcp_ack); > > /* Packets are not ordered. Send to app as received. */ > - tcp_action = tcp_state_machine(b->ip.hdr.tcp_flags, > + tcp_action = tcp_state_machine(b->ip.tcp_hdr.tcp_flags, > tcp_seq_num, payload_len); > > tcp_activity_count++; > @@ -698,8 +698,8 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > "TCP Notify (action=%x, Seq=%u,Ack=%u,Pay%d)\n", > tcp_action, tcp_seq_num, tcp_ack_num, payload_len); > > - (*tcp_packet_handler) ((uchar *)b + pkt_len - payload_len, b->ip.hdr.tcp_dst, > - b->ip.hdr.ip_src, b->ip.hdr.tcp_src, tcp_seq_num, > + (*tcp_packet_handler) ((uchar *)b + pkt_len - payload_len, b->ip.tcp_hdr.tcp_dst, > + b->ip.ip_hdr.ip_src, b->ip.tcp_hdr.tcp_src, tcp_seq_num, > tcp_ack_num, tcp_action, payload_len); > > } else if (tcp_action != TCP_DATA) { > @@ -711,8 +711,8 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len) > * Warning: Incoming Ack & Seq sequence numbers are transposed > * here to outgoing Seq & Ack sequence numbers > */ > - net_send_tcp_packet(0, ntohs(b->ip.hdr.tcp_src), > - ntohs(b->ip.hdr.tcp_dst), > + net_send_tcp_packet(0, ntohs(b->ip.tcp_hdr.tcp_src), > + ntohs(b->ip.tcp_hdr.tcp_dst), > (tcp_action & (~TCP_PUSH)), > tcp_ack_num, tcp_ack_edge); > } > diff --git a/test/cmd/wget.c b/test/cmd/wget.c > index ed83fc94a5..e2c11d3e76 100644 > --- a/test/cmd/wget.c > +++ b/test/cmd/wget.c > @@ -52,9 +52,11 @@ static int sb_syn_handler(struct udevice *dev, void *packet, > { > struct eth_sandbox_priv *priv = dev_get_priv(dev); > struct ethernet_hdr *eth = packet; > - struct ip_tcp_hdr *tcp = packet + ETHER_HDR_SIZE; > + struct ip_hdr *ip = packet + ETHER_HDR_SIZE; > + struct tcp_hdr *tcp = (void *)ip + IP_HDR_SIZE; > struct ethernet_hdr *eth_send; > - struct ip_tcp_hdr *tcp_send; > + struct ip_hdr *ip_send; > + struct tcp_hdr *tcp_send; > > /* Don't allow the buffer to overrun */ > if (priv->recv_packets >= PKTBUFSRX) > @@ -64,7 +66,8 @@ static int sb_syn_handler(struct udevice *dev, void *packet, > memcpy(eth_send->et_dest, eth->et_src, ARP_HLEN); > memcpy(eth_send->et_src, priv->fake_host_hwaddr, ARP_HLEN); > eth_send->et_protlen = htons(PROT_IP); > - tcp_send = (void *)eth_send + ETHER_HDR_SIZE; > + ip_send = (void *)eth_send + ETHER_HDR_SIZE; > + tcp_send = (void *)ip_send + IP_HDR_SIZE; > tcp_send->tcp_src = tcp->tcp_dst; > tcp_send->tcp_dst = tcp->tcp_src; > tcp_send->tcp_seq = htonl(0); > @@ -74,14 +77,14 @@ static int sb_syn_handler(struct udevice *dev, void *packet, > tcp_send->tcp_win = htons(PKTBUFSRX * TCP_MSS >> TCP_SCALE); > tcp_send->tcp_xsum = 0; > tcp_send->tcp_ugr = 0; > - tcp_send->tcp_xsum = tcp_set_pseudo_header((uchar *)tcp_send, > - tcp->ip_src, > - tcp->ip_dst, > + tcp_send->tcp_xsum = tcp_set_pseudo_header((uchar *)ip_send, > + ip->ip_src, > + ip->ip_dst, > TCP_HDR_SIZE, > IP_TCP_HDR_SIZE); > - net_set_ip_header((uchar *)tcp_send, > - tcp->ip_src, > - tcp->ip_dst, > + net_set_ip_header((uchar *)ip_send, > + ip->ip_src, > + ip->ip_dst, > IP_TCP_HDR_SIZE, > IPPROTO_TCP); > > @@ -97,9 +100,11 @@ static int sb_ack_handler(struct udevice *dev, void *packet, > { > struct eth_sandbox_priv *priv = dev_get_priv(dev); > struct ethernet_hdr *eth = packet; > - struct ip_tcp_hdr *tcp = packet + ETHER_HDR_SIZE; > + struct ip_hdr *ip = packet + ETHER_HDR_SIZE; > + struct tcp_hdr *tcp = (void *)ip + IP_HDR_SIZE; > struct ethernet_hdr *eth_send; > - struct ip_tcp_hdr *tcp_send; > + struct ip_hdr *ip_send; > + struct tcp_hdr *tcp_send; > void *data; > int pkt_len; > int payload_len = 0; > @@ -115,10 +120,11 @@ static int sb_ack_handler(struct udevice *dev, void *packet, > memcpy(eth_send->et_dest, eth->et_src, ARP_HLEN); > memcpy(eth_send->et_src, priv->fake_host_hwaddr, ARP_HLEN); > eth_send->et_protlen = htons(PROT_IP); > - tcp_send = (void *)eth_send + ETHER_HDR_SIZE; > + ip_send = (void *)eth_send + ETHER_HDR_SIZE; > + tcp_send = (void *)ip_send + IP_HDR_SIZE; > + data = (void *)tcp_send + TCP_HDR_SIZE; > tcp_send->tcp_src = tcp->tcp_dst; > tcp_send->tcp_dst = tcp->tcp_src; > - data = (void *)tcp_send + IP_TCP_HDR_SIZE; > > if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1) { > tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack)); > @@ -138,14 +144,14 @@ static int sb_ack_handler(struct udevice *dev, void *packet, > tcp_send->tcp_xsum = 0; > tcp_send->tcp_ugr = 0; > pkt_len = IP_TCP_HDR_SIZE + payload_len; > - tcp_send->tcp_xsum = tcp_set_pseudo_header((uchar *)tcp_send, > - tcp->ip_src, > - tcp->ip_dst, > + tcp_send->tcp_xsum = tcp_set_pseudo_header((uchar *)ip_send, > + ip->ip_src, > + ip->ip_dst, > pkt_len - IP_HDR_SIZE, > pkt_len); > - net_set_ip_header((uchar *)tcp_send, > - tcp->ip_src, > - tcp->ip_dst, > + net_set_ip_header((uchar *)ip_send, > + ip->ip_src, > + ip->ip_dst, > pkt_len, > IPPROTO_TCP); > > @@ -163,14 +169,14 @@ static int sb_http_handler(struct udevice *dev, void *packet, > { > struct ethernet_hdr *eth = packet; > struct ip_hdr *ip; > - struct ip_tcp_hdr *tcp; > + struct tcp_hdr *tcp; > > if (ntohs(eth->et_protlen) == PROT_ARP) { > return sb_arp_handler(dev, packet, len); > } else if (ntohs(eth->et_protlen) == PROT_IP) { > ip = packet + ETHER_HDR_SIZE; > if (ip->ip_p == IPPROTO_TCP) { > - tcp = packet + ETHER_HDR_SIZE; > + tcp = packet + ETHER_HDR_SIZE + IP_HDR_SIZE; > if (tcp->tcp_flags == TCP_SYN) > return sb_syn_handler(dev, packet, len); > else if (tcp->tcp_flags & TCP_ACK && !(tcp->tcp_flags & TCP_SYN))