hw/net: Added basic IPv6 fragmentation. Fixed IPv6 payload length. Fixed CSO for IPv6.
PATCH 1/1 hw/net: Added basic IPv6 fragmentation. Fixed IPv6 payload length. Fixed CSO for IPv6.
From: Andrew Melnychenko <[email protected]>
Overall, there was an issue that big frames of IPv6 doesn't sent. With network backend with 'virtual header' - there was an issue in 'plen' field. Overall, during TSO, 'plen' would be changed, but with 'vheader' this field should be set to the size of the payload itself instead of '0'.
For software offload - there is added basic IPv6 fragmentation. Also fixed checksum offload for IPv6.
The basic IPv6 fragmentation - adding 'frag' extension to the packet, overall shares some logic with IPv4. It works, but there are still issues with a combination of extensions - in the future, it would require refactoring work to implement workflow with IPv6 and extension. e1000e driver doesn't set the 'plen' field for IPv6 for big packets if TSO is enabled. "Jumbo option" isn't added yet, until qemu supports packets greater than 64K.
--- hw/net/net_tx_pkt.c | 53 ++++++++++++++++++++++++--- hw/net/net_tx_pkt.h | 7 ++++ include/net/eth.h | 15 ++++++-- net/eth.c | 89 ++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 150 insertions(+), 14 deletions(-)
hw/net/net_tx_pkt.c +47 -6
@@ -468,8 +468,8 @@ static void net_tx_pkt_do_sw_csum(struct NetTxPkt *pkt)/* num of iovec without vhdr */ uint32_t iov_len = pkt->payload_frags +NET_TX_PKT_PL_START_FRAG -1 ;uint16_t csl; -struct ip_header *iphdr;size_t csum_offset = pkt->virt_hdr.csum_start + pkt->virt_hdr.csum_offset; +uint16_t l3_proto =eth_get_l3_proto (iov,1 , iov->iov_len);/* Put zero to checksum field */ iov_from_buf (iov, iov_len, csum_offset, &csum,sizeof csum);
@@ -477,9 +477,17 @@ static void net_tx_pkt_do_sw_csum(struct NetTxPkt *pkt)/* Calculate L4 TCP/UDP checksum */ csl = pkt->payload_len; + csum_cntr =0 ;/* add pseudo header to csum */ - iphdr = pkt->vec[NET_TX_PKT_L3HDR_FRAG ].iov_base; - csum_cntr =eth_calc_ip4_pseudo_hdr_csum (iphdr, csl, &cso); +if (l3_proto ==ETH_P_IP ) { + csum_cntr =eth_calc_ip4_pseudo_hdr_csum ( + pkt->vec[NET_TX_PKT_L3HDR_FRAG ].iov_base, + csl, &cso); + }else if (l3_proto ==ETH_P_IPV6 ) { + csum_cntr =eth_calc_ip6_pseudo_hdr_csum ( + pkt->vec[NET_TX_PKT_L3HDR_FRAG ].iov_base, + csl, pkt->l4proto, &cso); + }/* data checksum */ csum_cntr +=
@@ -580,10 +588,11 @@ static bool net_tx_pkt_do_sw_fragmentation(struct NetTxPkt *pkt, more_frags = (fragment_offset + fragment_len < pkt->payload_len); -eth_setup_ip4_fragmentation (l2_iov_base, l2_iov_len, l3_iov_base, - l3_iov_len, fragment_len, fragment_offset, more_frags); +eth_setup_ip_fragmentation (l2_iov_base, l2_iov_len, l3_iov_base, + &l3_iov_len,ETH_MAX_IP_DGRAM_LEN , + fragment_len, fragment_offset, more_frags); -eth_fix_ip4_checksum (l3_iov_base, l3_iov_len); + fragment[NET_TX_PKT_FRAGMENT_L3_HDR_POS ].iov_len = l3_iov_len;net_tx_pkt_sendv (pkt, nc, fragment, dst_idx);
@@ -617,6 +626,7 @@ bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc)if (pkt->has_virt_hdr || pkt->virt_hdr.gso_type ==VIRTIO_NET_HDR_GSO_NONE ) { +net_tx_pkt_fix_ip6_payload_len (pkt);net_tx_pkt_sendv (pkt, nc, pkt->vec, pkt->payload_frags +NET_TX_PKT_PL_START_FRAG );return true;
@@ -635,3 +645,34 @@ bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc)return res; } + +void net_tx_pkt_fix_ip6_payload_len (struct NetTxPkt *pkt) +{ +/* +* If ipv6 payload length field is 0 - then there should be Hop-by-Hop +* option for packets greater than 65,535. +* For packets with payload less than 65,535: fix 'plen' field. +* For now, qemu drops every packet with size greater 64K +* (see net_tx_pkt_send()) so, there is no reason to add jumbo option to ip6 +* hop-by-hop extension if it's missed +*/ + +struct iovec *l2 = &pkt->vec[NET_TX_PKT_L2HDR_FRAG ]; +if (eth_get_l3_proto (l2,1 , l2->iov_len) ==ETH_P_IPV6 ) { +struct ip6_header *ip6 = (struct ip6_header *) pkt->l3_hdr; +/* +* TODO: if qemu would support >64K packets - add jumbo option check +* something like that: +* 'if (ip6->ip6_plen == 0 && !has_jumbo_option(ip6)) {' +*/ +if (ip6->ip6_plen ==0 ) { +if (pkt->payload_len <=ETH_MAX_IP_DGRAM_LEN ) { + ip6->ip6_plen =htons (pkt->payload_len); + } +/* +* TODO: if qemu would support >64K packets +* add jumbo option for packets greater then 65,535 bytes +*/ + } + } +}
hw/net/net_tx_pkt.h +7 -0
@@ -187,4 +187,11 @@ bool net_tx_pkt_parse(struct NetTxPkt *pkt);*/ bool net_tx_pkt_has_fragments (struct NetTxPkt *pkt); +/** +* Fix IPv6 'plen' field. +* +* @pkt packet +*/ +void net_tx_pkt_fix_ip6_payload_len (struct NetTxPkt *pkt); +#endif
include/net/eth.h +12 -3
@@ -139,6 +139,14 @@ struct ip6_ext_hdr_routing {uint8_t rsvd[4 ]; }; +struct ip6_ext_hdr_fragment { +uint8_t nxt; +uint8_t res0; +uint16_t off; +uint32_t id; +}; + +struct ip6_option_hdr {#define IP6_OPT_PAD1 (0x00)#define IP6_OPT_HOME (0xC9)
@@ -186,6 +194,7 @@ struct tcp_hdr {#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt#define ip6_ecn_acc ip6_ctlun.ip6_un3.ip6_un3_ecn +#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen#define PKT_GET_ETH_HDR (p) \ ((struct eth_header *)(p))
@@ -398,9 +407,9 @@ void eth_get_protocols(const struct iovec *iov, int iovcnt, eth_ip4_hdr_info *ip4hdr_info, eth_l4_hdr_info *l4hdr_info); -void eth_setup_ip4_fragmentation (const void *l2hdr,size_t l2hdr_len, -void *l3hdr,size_t l3hdr_len, -size_t l3payload_len, +void eth_setup_ip_fragmentation (const void *l2hdr,size_t l2hdr_len, +void *l3hdr,size_t *l3hdr_len, +size_t l3hdr_max_len,size_t l3payload_len,size_t frag_offset,bool more_frags);void
net/eth.c +84 -5
108 lines not on this page · raw message
Signature · 1 line
2.24.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===
CC hw/pci/pci_host.o
CC hw/pci/pcie_aer.o
CC hw/pci/pcie.o
/tmp/qemu-test/src/hw/net/net_tx_pkt.c:486:16: error: variable 'cso' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
} else if (l3_proto == ETH_P_IPV6) {
^~~~~~~~~~~~~~~~~~~~~~
/tmp/qemu-test/src/hw/net/net_tx_pkt.c:494:75: note: uninitialized use occurs here
---
^
= 01 error generated.
make: *** [/tmp/qemu-test/src/rules.mak:69: hw/net/net_tx_pkt.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=e154d651c56545a88917b911771f2f22', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=x86_64-softmmu', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-g2q7crd4/src/docker-src.2020-05-06-21.14.48.1453:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-debug']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=e154d651c56545a88917b911771f2f22
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-g2q7crd4/src'
make: *** [docker-run-test-debug@fedora] Error 2
real 4m5.832s
user 0m8.624s
The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]