|
|
9ae3a8 |
From fc8f8c54749bfeb7a4320875dc2bfd3565cf5ebe Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Date: Fri, 31 Jul 2015 15:59:43 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 08/13] rtl8139: drop tautologous if (ip) {...} statement
|
|
|
9ae3a8 |
(CVE-2015-5165)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1438358388-10575-3-git-send-email-stefanha@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 67238
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1.z qemu-kvm EMBARGOED PATCH 2/7] rtl8139: drop tautologous if (ip) {...} statement (CVE-2015-5165)
|
|
|
9ae3a8 |
Bugzilla: 1248766
|
|
|
9ae3a8 |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
The previous patch stopped using the ip pointer as an indicator that the
|
|
|
9ae3a8 |
IP header is present. When we reach the if (ip) {...} statement we know
|
|
|
9ae3a8 |
ip is always non-NULL.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Remove the if statement to reduce nesting.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/net/rtl8139.c | 305 +++++++++++++++++++++++++++----------------------------
|
|
|
9ae3a8 |
1 file changed, 151 insertions(+), 154 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
|
|
|
9ae3a8 |
index e3b594f..ab32714 100644
|
|
|
9ae3a8 |
--- a/hw/net/rtl8139.c
|
|
|
9ae3a8 |
+++ b/hw/net/rtl8139.c
|
|
|
9ae3a8 |
@@ -2176,198 +2176,195 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
|
|
|
9ae3a8 |
ip_protocol = ip->ip_p;
|
|
|
9ae3a8 |
ip_data_len = be16_to_cpu(ip->ip_len) - hlen;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (ip)
|
|
|
9ae3a8 |
+ if (txdw0 & CP_TX_IPCS)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- if (txdw0 & CP_TX_IPCS)
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode need IP checksum\n");
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode need IP checksum\n");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (hlen<sizeof(ip_header) || hlen>eth_payload_len) {/* min header length */
|
|
|
9ae3a8 |
- /* bad packet header len */
|
|
|
9ae3a8 |
- /* or packet too short */
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- else
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- ip->ip_sum = 0;
|
|
|
9ae3a8 |
- ip->ip_sum = ip_checksum(ip, hlen);
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode IP header len=%d checksum=%04x\n",
|
|
|
9ae3a8 |
- hlen, ip->ip_sum);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ if (hlen<sizeof(ip_header) || hlen>eth_payload_len) {/* min header length */
|
|
|
9ae3a8 |
+ /* bad packet header len */
|
|
|
9ae3a8 |
+ /* or packet too short */
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if ((txdw0 & CP_TX_LGSEN) && ip_protocol == IP_PROTO_TCP)
|
|
|
9ae3a8 |
+ else
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- int large_send_mss = (txdw0 >> 16) & CP_TC_LGSEN_MSS_MASK;
|
|
|
9ae3a8 |
+ ip->ip_sum = 0;
|
|
|
9ae3a8 |
+ ip->ip_sum = ip_checksum(ip, hlen);
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode IP header len=%d checksum=%04x\n",
|
|
|
9ae3a8 |
+ hlen, ip->ip_sum);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode offloaded task TSO MTU=%d IP data %d "
|
|
|
9ae3a8 |
- "frame data %d specified MSS=%d\n", ETH_MTU,
|
|
|
9ae3a8 |
- ip_data_len, saved_size - ETH_HLEN, large_send_mss);
|
|
|
9ae3a8 |
+ if ((txdw0 & CP_TX_LGSEN) && ip_protocol == IP_PROTO_TCP)
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ int large_send_mss = (txdw0 >> 16) & CP_TC_LGSEN_MSS_MASK;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- int tcp_send_offset = 0;
|
|
|
9ae3a8 |
- int send_count = 0;
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode offloaded task TSO MTU=%d IP data %d "
|
|
|
9ae3a8 |
+ "frame data %d specified MSS=%d\n", ETH_MTU,
|
|
|
9ae3a8 |
+ ip_data_len, saved_size - ETH_HLEN, large_send_mss);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* maximum IP header length is 60 bytes */
|
|
|
9ae3a8 |
- uint8_t saved_ip_header[60];
|
|
|
9ae3a8 |
+ int tcp_send_offset = 0;
|
|
|
9ae3a8 |
+ int send_count = 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* save IP header template; data area is used in tcp checksum calculation */
|
|
|
9ae3a8 |
- memcpy(saved_ip_header, eth_payload_data, hlen);
|
|
|
9ae3a8 |
+ /* maximum IP header length is 60 bytes */
|
|
|
9ae3a8 |
+ uint8_t saved_ip_header[60];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* a placeholder for checksum calculation routine in tcp case */
|
|
|
9ae3a8 |
- uint8_t *data_to_checksum = eth_payload_data + hlen - 12;
|
|
|
9ae3a8 |
- // size_t data_to_checksum_len = eth_payload_len - hlen + 12;
|
|
|
9ae3a8 |
+ /* save IP header template; data area is used in tcp checksum calculation */
|
|
|
9ae3a8 |
+ memcpy(saved_ip_header, eth_payload_data, hlen);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* pointer to TCP header */
|
|
|
9ae3a8 |
- tcp_header *p_tcp_hdr = (tcp_header*)(eth_payload_data + hlen);
|
|
|
9ae3a8 |
+ /* a placeholder for checksum calculation routine in tcp case */
|
|
|
9ae3a8 |
+ uint8_t *data_to_checksum = eth_payload_data + hlen - 12;
|
|
|
9ae3a8 |
+ // size_t data_to_checksum_len = eth_payload_len - hlen + 12;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- int tcp_hlen = TCP_HEADER_DATA_OFFSET(p_tcp_hdr);
|
|
|
9ae3a8 |
+ /* pointer to TCP header */
|
|
|
9ae3a8 |
+ tcp_header *p_tcp_hdr = (tcp_header*)(eth_payload_data + hlen);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* ETH_MTU = ip header len + tcp header len + payload */
|
|
|
9ae3a8 |
- int tcp_data_len = ip_data_len - tcp_hlen;
|
|
|
9ae3a8 |
- int tcp_chunk_size = ETH_MTU - hlen - tcp_hlen;
|
|
|
9ae3a8 |
+ int tcp_hlen = TCP_HEADER_DATA_OFFSET(p_tcp_hdr);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TSO IP data len %d TCP hlen %d TCP "
|
|
|
9ae3a8 |
- "data len %d TCP chunk size %d\n", ip_data_len,
|
|
|
9ae3a8 |
- tcp_hlen, tcp_data_len, tcp_chunk_size);
|
|
|
9ae3a8 |
+ /* ETH_MTU = ip header len + tcp header len + payload */
|
|
|
9ae3a8 |
+ int tcp_data_len = ip_data_len - tcp_hlen;
|
|
|
9ae3a8 |
+ int tcp_chunk_size = ETH_MTU - hlen - tcp_hlen;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* note the cycle below overwrites IP header data,
|
|
|
9ae3a8 |
- but restores it from saved_ip_header before sending packet */
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TSO IP data len %d TCP hlen %d TCP "
|
|
|
9ae3a8 |
+ "data len %d TCP chunk size %d\n", ip_data_len,
|
|
|
9ae3a8 |
+ tcp_hlen, tcp_data_len, tcp_chunk_size);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- int is_last_frame = 0;
|
|
|
9ae3a8 |
+ /* note the cycle below overwrites IP header data,
|
|
|
9ae3a8 |
+ but restores it from saved_ip_header before sending packet */
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- for (tcp_send_offset = 0; tcp_send_offset < tcp_data_len; tcp_send_offset += tcp_chunk_size)
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- uint16_t chunk_size = tcp_chunk_size;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* check if this is the last frame */
|
|
|
9ae3a8 |
- if (tcp_send_offset + tcp_chunk_size >= tcp_data_len)
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- is_last_frame = 1;
|
|
|
9ae3a8 |
- chunk_size = tcp_data_len - tcp_send_offset;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TSO TCP seqno %08x\n",
|
|
|
9ae3a8 |
- be32_to_cpu(p_tcp_hdr->th_seq));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* add 4 TCP pseudoheader fields */
|
|
|
9ae3a8 |
- /* copy IP source and destination fields */
|
|
|
9ae3a8 |
- memcpy(data_to_checksum, saved_ip_header + 12, 8);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TSO calculating TCP checksum for "
|
|
|
9ae3a8 |
- "packet with %d bytes data\n", tcp_hlen +
|
|
|
9ae3a8 |
- chunk_size);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (tcp_send_offset)
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- memcpy((uint8_t*)p_tcp_hdr + tcp_hlen, (uint8_t*)p_tcp_hdr + tcp_hlen + tcp_send_offset, chunk_size);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* keep PUSH and FIN flags only for the last frame */
|
|
|
9ae3a8 |
- if (!is_last_frame)
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- TCP_HEADER_CLEAR_FLAGS(p_tcp_hdr, TCP_FLAG_PUSH|TCP_FLAG_FIN);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* recalculate TCP checksum */
|
|
|
9ae3a8 |
- ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header *)data_to_checksum;
|
|
|
9ae3a8 |
- p_tcpip_hdr->zeros = 0;
|
|
|
9ae3a8 |
- p_tcpip_hdr->ip_proto = IP_PROTO_TCP;
|
|
|
9ae3a8 |
- p_tcpip_hdr->ip_payload = cpu_to_be16(tcp_hlen + chunk_size);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- p_tcp_hdr->th_sum = 0;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- int tcp_checksum = ip_checksum(data_to_checksum, tcp_hlen + chunk_size + 12);
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TSO TCP checksum %04x\n",
|
|
|
9ae3a8 |
- tcp_checksum);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- p_tcp_hdr->th_sum = tcp_checksum;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* restore IP header */
|
|
|
9ae3a8 |
- memcpy(eth_payload_data, saved_ip_header, hlen);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* set IP data length and recalculate IP checksum */
|
|
|
9ae3a8 |
- ip->ip_len = cpu_to_be16(hlen + tcp_hlen + chunk_size);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* increment IP id for subsequent frames */
|
|
|
9ae3a8 |
- ip->ip_id = cpu_to_be16(tcp_send_offset/tcp_chunk_size + be16_to_cpu(ip->ip_id));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ip->ip_sum = 0;
|
|
|
9ae3a8 |
- ip->ip_sum = ip_checksum(eth_payload_data, hlen);
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TSO IP header len=%d "
|
|
|
9ae3a8 |
- "checksum=%04x\n", hlen, ip->ip_sum);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- int tso_send_size = ETH_HLEN + hlen + tcp_hlen + chunk_size;
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TSO transferring packet size "
|
|
|
9ae3a8 |
- "%d\n", tso_send_size);
|
|
|
9ae3a8 |
- rtl8139_transfer_frame(s, saved_buffer, tso_send_size,
|
|
|
9ae3a8 |
- 0, (uint8_t *) dot1q_buffer);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* add transferred count to TCP sequence number */
|
|
|
9ae3a8 |
- p_tcp_hdr->th_seq = cpu_to_be32(chunk_size + be32_to_cpu(p_tcp_hdr->th_seq));
|
|
|
9ae3a8 |
- ++send_count;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ int is_last_frame = 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* Stop sending this frame */
|
|
|
9ae3a8 |
- saved_size = 0;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- else if (txdw0 & (CP_TX_TCPCS|CP_TX_UDPCS))
|
|
|
9ae3a8 |
+ for (tcp_send_offset = 0; tcp_send_offset < tcp_data_len; tcp_send_offset += tcp_chunk_size)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode need TCP or UDP checksum\n");
|
|
|
9ae3a8 |
+ uint16_t chunk_size = tcp_chunk_size;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* maximum IP header length is 60 bytes */
|
|
|
9ae3a8 |
- uint8_t saved_ip_header[60];
|
|
|
9ae3a8 |
- memcpy(saved_ip_header, eth_payload_data, hlen);
|
|
|
9ae3a8 |
+ /* check if this is the last frame */
|
|
|
9ae3a8 |
+ if (tcp_send_offset + tcp_chunk_size >= tcp_data_len)
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ is_last_frame = 1;
|
|
|
9ae3a8 |
+ chunk_size = tcp_data_len - tcp_send_offset;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- uint8_t *data_to_checksum = eth_payload_data + hlen - 12;
|
|
|
9ae3a8 |
- // size_t data_to_checksum_len = eth_payload_len - hlen + 12;
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TSO TCP seqno %08x\n",
|
|
|
9ae3a8 |
+ be32_to_cpu(p_tcp_hdr->th_seq));
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* add 4 TCP pseudoheader fields */
|
|
|
9ae3a8 |
/* copy IP source and destination fields */
|
|
|
9ae3a8 |
memcpy(data_to_checksum, saved_ip_header + 12, 8);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if ((txdw0 & CP_TX_TCPCS) && ip_protocol == IP_PROTO_TCP)
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TSO calculating TCP checksum for "
|
|
|
9ae3a8 |
+ "packet with %d bytes data\n", tcp_hlen +
|
|
|
9ae3a8 |
+ chunk_size);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (tcp_send_offset)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode calculating TCP checksum for "
|
|
|
9ae3a8 |
- "packet with %d bytes data\n", ip_data_len);
|
|
|
9ae3a8 |
+ memcpy((uint8_t*)p_tcp_hdr + tcp_hlen, (uint8_t*)p_tcp_hdr + tcp_hlen + tcp_send_offset, chunk_size);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header *)data_to_checksum;
|
|
|
9ae3a8 |
- p_tcpip_hdr->zeros = 0;
|
|
|
9ae3a8 |
- p_tcpip_hdr->ip_proto = IP_PROTO_TCP;
|
|
|
9ae3a8 |
- p_tcpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
|
|
|
9ae3a8 |
+ /* keep PUSH and FIN flags only for the last frame */
|
|
|
9ae3a8 |
+ if (!is_last_frame)
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ TCP_HEADER_CLEAR_FLAGS(p_tcp_hdr, TCP_FLAG_PUSH|TCP_FLAG_FIN);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- tcp_header* p_tcp_hdr = (tcp_header *) (data_to_checksum+12);
|
|
|
9ae3a8 |
+ /* recalculate TCP checksum */
|
|
|
9ae3a8 |
+ ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header *)data_to_checksum;
|
|
|
9ae3a8 |
+ p_tcpip_hdr->zeros = 0;
|
|
|
9ae3a8 |
+ p_tcpip_hdr->ip_proto = IP_PROTO_TCP;
|
|
|
9ae3a8 |
+ p_tcpip_hdr->ip_payload = cpu_to_be16(tcp_hlen + chunk_size);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- p_tcp_hdr->th_sum = 0;
|
|
|
9ae3a8 |
+ p_tcp_hdr->th_sum = 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- int tcp_checksum = ip_checksum(data_to_checksum, ip_data_len + 12);
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode TCP checksum %04x\n",
|
|
|
9ae3a8 |
- tcp_checksum);
|
|
|
9ae3a8 |
+ int tcp_checksum = ip_checksum(data_to_checksum, tcp_hlen + chunk_size + 12);
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TSO TCP checksum %04x\n",
|
|
|
9ae3a8 |
+ tcp_checksum);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- p_tcp_hdr->th_sum = tcp_checksum;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- else if ((txdw0 & CP_TX_UDPCS) && ip_protocol == IP_PROTO_UDP)
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode calculating UDP checksum for "
|
|
|
9ae3a8 |
- "packet with %d bytes data\n", ip_data_len);
|
|
|
9ae3a8 |
+ p_tcp_hdr->th_sum = tcp_checksum;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ip_pseudo_header *p_udpip_hdr = (ip_pseudo_header *)data_to_checksum;
|
|
|
9ae3a8 |
- p_udpip_hdr->zeros = 0;
|
|
|
9ae3a8 |
- p_udpip_hdr->ip_proto = IP_PROTO_UDP;
|
|
|
9ae3a8 |
- p_udpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
|
|
|
9ae3a8 |
+ /* restore IP header */
|
|
|
9ae3a8 |
+ memcpy(eth_payload_data, saved_ip_header, hlen);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- udp_header *p_udp_hdr = (udp_header *) (data_to_checksum+12);
|
|
|
9ae3a8 |
+ /* set IP data length and recalculate IP checksum */
|
|
|
9ae3a8 |
+ ip->ip_len = cpu_to_be16(hlen + tcp_hlen + chunk_size);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- p_udp_hdr->uh_sum = 0;
|
|
|
9ae3a8 |
+ /* increment IP id for subsequent frames */
|
|
|
9ae3a8 |
+ ip->ip_id = cpu_to_be16(tcp_send_offset/tcp_chunk_size + be16_to_cpu(ip->ip_id));
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- int udp_checksum = ip_checksum(data_to_checksum, ip_data_len + 12);
|
|
|
9ae3a8 |
- DPRINTF("+++ C+ mode UDP checksum %04x\n",
|
|
|
9ae3a8 |
- udp_checksum);
|
|
|
9ae3a8 |
+ ip->ip_sum = 0;
|
|
|
9ae3a8 |
+ ip->ip_sum = ip_checksum(eth_payload_data, hlen);
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TSO IP header len=%d "
|
|
|
9ae3a8 |
+ "checksum=%04x\n", hlen, ip->ip_sum);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- p_udp_hdr->uh_sum = udp_checksum;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ int tso_send_size = ETH_HLEN + hlen + tcp_hlen + chunk_size;
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TSO transferring packet size "
|
|
|
9ae3a8 |
+ "%d\n", tso_send_size);
|
|
|
9ae3a8 |
+ rtl8139_transfer_frame(s, saved_buffer, tso_send_size,
|
|
|
9ae3a8 |
+ 0, (uint8_t *) dot1q_buffer);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* restore IP header */
|
|
|
9ae3a8 |
- memcpy(eth_payload_data, saved_ip_header, hlen);
|
|
|
9ae3a8 |
+ /* add transferred count to TCP sequence number */
|
|
|
9ae3a8 |
+ p_tcp_hdr->th_seq = cpu_to_be32(chunk_size + be32_to_cpu(p_tcp_hdr->th_seq));
|
|
|
9ae3a8 |
+ ++send_count;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Stop sending this frame */
|
|
|
9ae3a8 |
+ saved_size = 0;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ else if (txdw0 & (CP_TX_TCPCS|CP_TX_UDPCS))
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode need TCP or UDP checksum\n");
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* maximum IP header length is 60 bytes */
|
|
|
9ae3a8 |
+ uint8_t saved_ip_header[60];
|
|
|
9ae3a8 |
+ memcpy(saved_ip_header, eth_payload_data, hlen);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ uint8_t *data_to_checksum = eth_payload_data + hlen - 12;
|
|
|
9ae3a8 |
+ // size_t data_to_checksum_len = eth_payload_len - hlen + 12;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* add 4 TCP pseudoheader fields */
|
|
|
9ae3a8 |
+ /* copy IP source and destination fields */
|
|
|
9ae3a8 |
+ memcpy(data_to_checksum, saved_ip_header + 12, 8);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if ((txdw0 & CP_TX_TCPCS) && ip_protocol == IP_PROTO_TCP)
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode calculating TCP checksum for "
|
|
|
9ae3a8 |
+ "packet with %d bytes data\n", ip_data_len);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header *)data_to_checksum;
|
|
|
9ae3a8 |
+ p_tcpip_hdr->zeros = 0;
|
|
|
9ae3a8 |
+ p_tcpip_hdr->ip_proto = IP_PROTO_TCP;
|
|
|
9ae3a8 |
+ p_tcpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ tcp_header* p_tcp_hdr = (tcp_header *) (data_to_checksum+12);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ p_tcp_hdr->th_sum = 0;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ int tcp_checksum = ip_checksum(data_to_checksum, ip_data_len + 12);
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode TCP checksum %04x\n",
|
|
|
9ae3a8 |
+ tcp_checksum);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ p_tcp_hdr->th_sum = tcp_checksum;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ else if ((txdw0 & CP_TX_UDPCS) && ip_protocol == IP_PROTO_UDP)
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode calculating UDP checksum for "
|
|
|
9ae3a8 |
+ "packet with %d bytes data\n", ip_data_len);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ip_pseudo_header *p_udpip_hdr = (ip_pseudo_header *)data_to_checksum;
|
|
|
9ae3a8 |
+ p_udpip_hdr->zeros = 0;
|
|
|
9ae3a8 |
+ p_udpip_hdr->ip_proto = IP_PROTO_UDP;
|
|
|
9ae3a8 |
+ p_udpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ udp_header *p_udp_hdr = (udp_header *) (data_to_checksum+12);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ p_udp_hdr->uh_sum = 0;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ int udp_checksum = ip_checksum(data_to_checksum, ip_data_len + 12);
|
|
|
9ae3a8 |
+ DPRINTF("+++ C+ mode UDP checksum %04x\n",
|
|
|
9ae3a8 |
+ udp_checksum);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ p_udp_hdr->uh_sum = udp_checksum;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* restore IP header */
|
|
|
9ae3a8 |
+ memcpy(eth_payload_data, saved_ip_header, hlen);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|