net: Pad short frames for network backends
v5 cover net: Pad short frames for network backends
The minimum Ethernet frame length is 60 bytes. For short frames with smaller length like ARP packets (only 42 bytes), on a real world NIC it can choose either padding its length to the minimum required 60 bytes, or sending it out directly to the wire. Such behavior can be hardcoded or controled by a register bit. Similarly on the receive path, NICs can choose either dropping such short frames directly or handing them over to software to handle.
On the other hand, for the network backends like SLiRP/TAP, they don't expose a way to control the short frame behavior. As of today they just send/receive data from/to the other end connected to them, which means any sized packet is acceptable. So they can send and receive short frames without any problem. It is observed that ARP packets sent from SLiRP/TAP are 42 bytes, and SLiRP/TAP just send these ARP packets to the other end which might be a NIC model that does not allow short frames to pass through.
To provide better compatibility, for packets sent from QEMU network backends like SLiRP/TAP, we change to pad short frames before sending it out to the other end, if the other end does not forbid it via the nc->do_not_pad flag. This ensures a backend as an Ethernet sender does not violate the spec. But with this change, the behavior of dropping short frames from SLiRP/TAP interfaces in the NIC model cannot be emulated because it always receives a packet that is spec complaint. The capability of sending short frames from NIC models is still supported and short frames can still pass through SLiRP/TAP.
This series should be able to fix the issue as reported with some NIC models before, that ARP requests get dropped, preventing the guest from becoming visible on the network. It was workarounded in these NIC models on the receive path, that when a short frame is received, it is padded up to 60 bytes.
Changes in v5:
- minor update on commit message
- update the eth_pad_short_frame() comment
Changes in v4:
- change 'ethernet' to 'Ethernet'
- do not inline the helper
- check the padded buffer size to avoid buffer overflow
- squash slirp/tap commits into one
Changes in v3:
- use 'without' instead of 'sans'
- add a helper to pad short frames
- add a comment to 'do_not_pad'
- use the pad_short_frame() helper
Bin Meng (12):
net: eth: Add a helper to pad a short Ethernet frame
net: Add a 'do_not_pad" to NetClientState
net: Pad short frames to minimum size before sending from SLiRP/TAP hw/net: virtio-net: Initialize nc->do_not_pad to true hw/net: e1000: Remove the logic of padding short frames in the receive
path
hw/net: vmxnet3: Remove the logic of padding short frames in the
receive path
hw/net: i82596: Remove the logic of padding short frames in the
receive path
hw/net: ne2000: Remove the logic of padding short frames in the
receive path
hw/net: pcnet: Remove the logic of padding short frames in the receive
path
hw/net: rtl8139: Remove the logic of padding short frames in the
receive path
hw/net: sungem: Remove the logic of padding short frames in the
receive path
hw/net: sunhme: Remove the logic of padding short frames in the
receive path
hw/net/e1000.c | 11 +---------- hw/net/i82596.c | 18 ------------------ hw/net/ne2000.c | 12 ------------ hw/net/pcnet.c | 9 --------- hw/net/rtl8139.c | 12 ------------ hw/net/sungem.c | 14 -------------- hw/net/sunhme.c | 11 ----------- hw/net/virtio-net.c | 4 ++++ hw/net/vmxnet3.c | 10 ---------- include/net/eth.h | 17 +++++++++++++++++ include/net/net.h | 1 + net/eth.c | 17 +++++++++++++++++ net/slirp.c | 10 ++++++++++ net/tap-win32.c | 10 ++++++++++ net/tap.c | 10 ++++++++++ 15 files changed, 70 insertions(+), 96 deletions(-)
Signature · 1 line
2.17.1
PATCH v5 1/12 net: eth: Add a helper to pad a short Ethernet frame
Add a helper to pad a short Ethernet frame to the minimum required length, which can be used by backends' code.
---
Changes in v5:
- minor update on commit message
- update the eth_pad_short_frame() comment
Changes in v4:
- change 'ethernet' to 'Ethernet'
- do not inline the helper
- check the padded buffer size to avoid buffer overflow
Changes in v3:
- use 'without' instead of 'sans'
- add a helper to pad short frames
include/net/eth.h | 17 +++++++++++++++++ net/eth.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+)
include/net/eth.h +17 -0
@@ -31,6 +31,7 @@#define ETH_ALEN 6#define ETH_HLEN 14 +#define ETH_ZLEN 60/* Min. octets in frame without FCS */ struct eth_header {uint8_t h_dest[ETH_ALEN ];/* destination eth addr */
@@ -422,4 +423,20 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags, size_t ip6hdr_off, eth_ip6_hdr_info *info); +/** +* eth_pad_short_frame - pad a short frame to the minimum Ethernet frame length +* +* If the Ethernet frame size is shorter than 60 bytes, it will be padded to +* 60 bytes at the address @padded_pkt. +* +* @padded_pkt: buffer address to hold the padded frame +* @padded_buflen: pointer holding length of @padded_pkt. If the frame is +* padded, the length will be updated to the padded one. +* @pkt: address to hold the original Ethernet frame +* @pkt_size: size of the original Ethernet frame +* @return true if the frame is padded, otherwise false +*/ +bool eth_pad_short_frame (uint8_t *padded_pkt,size_t *padded_buflen, +const void *pkt,size_t pkt_size); +#endif
net/eth.c +17 -0
@@ -548,3 +548,20 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags, info->l4proto = ext_hdr.ip6r_nxt;return true; } + +bool eth_pad_short_frame (uint8_t *padded_pkt,size_t *padded_buflen, +const void *pkt,size_t pkt_size) +{ +assert (padded_buflen && *padded_buflen >=ETH_ZLEN ); + +if (pkt_size >=ETH_ZLEN ) { +return false; + } + +/* pad to minimum Ethernet frame length */ +memcpy (padded_pkt, pkt, pkt_size); +memset (&padded_pkt[pkt_size],0 ,ETH_ZLEN - pkt_size); + *padded_buflen =ETH_ZLEN ; + +return true; +}
Signature · 1 line
2.17.1
PATCH v5 2/12 net: Add a 'do_not_pad" to NetClientState
In reply to Bin MengThis adds a flag in NetClientState, so that a net client can tell its peer that the packets do not need to be padded to the minimum size of an Ethernet frame (60 bytes) before sending to it.
---
(no changes since v3)
Changes in v3:
- add a comment to 'do_not_pad'
include/net/net.h | 1 + 1 file changed, 1 insertion(+)
include/net/net.h +1 -0
@@ -103,6 +103,7 @@ struct NetClientState {int vring_enable;int vnet_hdr_len;bool is_netdev; +bool do_not_pad;/* do not pad to the minimum ethernet frame length */ QTAILQ_HEAD(, NetFilterState) filters; };
Signature · 1 line
2.17.1
PATCH v5 3/12 net: Pad short frames to minimum size before sending from SLiRP/TAP
In reply to Bin MengThe minimum Ethernet frame length is 60 bytes. For short frames with smaller length like ARP packets (only 42 bytes), on a real world NIC it can choose either padding its length to the minimum required 60 bytes, or sending it out directly to the wire. Such behavior can be hardcoded or controled by a register bit. Similarly on the receive path, NICs can choose either dropping such short frames directly or handing them over to software to handle.
On the other hand, for the network backends like SLiRP/TAP, they don't expose a way to control the short frame behavior. As of today they just send/receive data from/to the other end connected to them, which means any sized packet is acceptable. So they can send and receive short frames without any problem. It is observed that ARP packets sent from SLiRP/TAP are 42 bytes, and SLiRP/TAP just send these ARP packets to the other end which might be a NIC model that does not allow short frames to pass through.
To provide better compatibility, for packets sent from QEMU network backends like SLiRP/TAP, we change to pad short frames before sending it out to the other end, if the other end does not forbid it via the nc->do_not_pad flag. This ensures a backend as an Ethernet sender does not violate the spec. But with this change, the behavior of dropping short frames from SLiRP/TAP interfaces in the NIC model cannot be emulated because it always receives a packet that is spec complaint. The capability of sending short frames from NIC models is still supported and short frames can still pass through SLiRP/TAP.
This commit should be able to fix the issue as reported with some NIC models before, that ARP requests get dropped, preventing the guest from becoming visible on the network. It was workarounded in these NIC models on the receive path, that when a short frame is received, it is padded up to 60 bytes.
The following 2 commits seem to be the one to workaround this issue in e1000 and vmxenet3 before, and should probably be reverted.
commit 78aeb23eded2 ("e1000: Pad short frames to minimum size (60 bytes)") commit 40a87c6c9b11 ("vmxnet3: Pad short frames to minimum size (60 bytes)")
---
(no changes since v4)
Changes in v4:
- squash slirp/tap commits into one
Changes in v3:
- use the pad_short_frame() helper
net/slirp.c | 10 ++++++++++ net/tap-win32.c | 10 ++++++++++ net/tap.c | 10 ++++++++++ 3 files changed, 30 insertions(+)
net/slirp.c +10 -0
@@ -31,6 +31,7 @@#include <pwd.h> #include <sys/wait.h> #endif +#include "net/eth.h" #include "net/net.h" #include "clients.h" #include "hub.h"
@@ -115,6 +116,15 @@ static ssize_t net_slirp_send_packet(const void *pkt, size_t pkt_len, void *opaque) {SlirpState *s = opaque; +uint8_t min_pkt[ETH_ZLEN ]; +size_t min_pktsz =sizeof (min_pkt); + +if (!s->nc.peer->do_not_pad) { +if (eth_pad_short_frame (min_pkt, &min_pktsz, pkt, pkt_len)) { + pkt = min_pkt; + pkt_len = min_pktsz; + } + }return qemu_send_packet (&s->nc, pkt, pkt_len); }
net/tap-win32.c +10 -0
@@ -31,6 +31,7 @@#include "qemu-common.h" #include "clients.h" /* net_init_tap */ +#include "net/eth.h" #include "net/net.h" #include "net/tap.h" /* tap_has_ufo, ... */ #include "qemu/error-report.h"
@@ -688,9 +689,18 @@ static void tap_win32_send(void *opaque)uint8_t *buf;int max_size =4096 ;int size; +uint8_t min_pkt[ETH_ZLEN ]; +size_t min_pktsz =sizeof (min_pkt); size =tap_win32_read (s->handle, &buf, max_size);if (size >0 ) { +if (!s->nc.peer->do_not_pad) { +if (eth_pad_short_frame (min_pkt, &min_pktsz, buf, size)) { + buf = min_pkt; + size = min_pktsz; + } + } +qemu_send_packet (&s->nc, buf, size);tap_win32_free_buffer (s->handle, buf); }
net/tap.c +10 -0
@@ -32,6 +32,7 @@#include <sys/socket.h> #include <net/if.h> +#include "net/eth.h" #include "net/net.h" #include "clients.h" #include "monitor/monitor.h"
@@ -189,6 +190,8 @@ static void tap_send(void *opaque)while (true) {uint8_t *buf = s->buf; +uint8_t min_pkt[ETH_ZLEN ]; +size_t min_pktsz =sizeof (min_pkt); size =tap_read_packet (s->fd, s->buf,sizeof (s->buf));if (size <=0 ) {
@@ -200,6 +203,13 @@ static void tap_send(void *opaque) size -= s->host_vnet_hdr_len; } +if (!s->nc.peer->do_not_pad) { +if (eth_pad_short_frame (min_pkt, &min_pktsz, buf, size)) { + buf = min_pkt; + size = min_pktsz; + } + } + size =qemu_send_packet_async (&s->nc, buf, size, tap_send_completed);if (size ==0 ) {tap_read_poll (s, false);
Signature · 1 line
2.17.1
PATCH v5 4/12 hw/net: virtio-net: Initialize nc->do_not_pad to true
In reply to Bin MengFor virtio-net, there is no need to pad the Ethernet frame size to 60 bytes before sending to it.
---
(no changes since v1)
hw/net/virtio-net.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/net/virtio-net.c +4 -0
@@ -3314,6 +3314,10 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) object_get_typename(OBJECT(dev)), dev->id, n); } +for (i =0 ; i < n->max_queues; i++) { + n->nic->ncs[i].do_not_pad = true; + } +peer_test_vnet_hdr (n);if (peer_has_vnet_hdr (n)) {for (i =0 ; i < n->max_queues; i++) {
Signature · 1 line
2.17.1
PATCH v5 5/12 hw/net: e1000: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
This actually reverts commit 78aeb23eded2d0b765bf9145c71f80025b568acd.
---
(no changes since v1)
hw/net/e1000.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
hw/net/e1000.c +1 -10
@@ -886,7 +886,6 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)uint16_t vlan_special =0 ;uint8_t vlan_status =0 ;uint8_t min_buf[MIN_BUF_SIZE ]; -struct iovec min_iov;uint8_t *filter_buf = iov->iov_base;size_t size =iov_size (iov, iovcnt);size_t iov_ofs =0 ;
@@ -902,15 +901,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)return 0 ; } -/* Pad to minimum Ethernet frame length */ -if (size <sizeof (min_buf)) { -iov_to_buf (iov, iovcnt,0 , min_buf, size); -memset (&min_buf[size],0 ,sizeof (min_buf) - size); - min_iov.iov_base = filter_buf = min_buf; - min_iov.iov_len = size =sizeof (min_buf); - iovcnt =1 ; - iov = &min_iov; - }else if (iov->iov_len <MAXIMUM_ETHERNET_HDR_LEN ) { +if (iov->iov_len <MAXIMUM_ETHERNET_HDR_LEN ) {/* This is very unlikely, but may happen. */ iov_to_buf (iov, iovcnt,0 , min_buf,MAXIMUM_ETHERNET_HDR_LEN ); filter_buf = min_buf;
Signature · 1 line
2.17.1
PATCH v5 6/12 hw/net: vmxnet3: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
This actually reverts commit 40a87c6c9b11ef9c14e0301f76abf0eb2582f08e.
---
(no changes since v1)
hw/net/vmxnet3.c | 10 ---------- 1 file changed, 10 deletions(-)
hw/net/vmxnet3.c +0 -10
@@ -39,7 +39,6 @@#define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1#define VMXNET3_MSIX_BAR_SIZE 0x2000 -#define MIN_BUF_SIZE 60/* Compatibility flags for migration */ #define VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS_BIT 0
@@ -1951,7 +1950,6 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size) {VMXNET3State *s =qemu_get_nic_opaque (nc);size_t bytes_indicated; -uint8_t min_buf[MIN_BUF_SIZE ];if (!vmxnet3_can_receive (nc)) {VMW_PKPRN ("Cannot receive now" );
@@ -1964,14 +1962,6 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size) size -=sizeof (struct virtio_net_hdr ); } -/* Pad to minimum Ethernet frame length */ -if (size <sizeof (min_buf)) { -memcpy (min_buf, buf, size); -memset (&min_buf[size],0 ,sizeof (min_buf) - size); - buf = min_buf; - size =sizeof (min_buf); - } -net_rx_pkt_set_packet_type (s->rx_pkt,get_eth_packet_type (PKT_GET_ETH_HDR (buf)));
Signature · 1 line
2.17.1
PATCH v5 7/12 hw/net: i82596: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
---
(no changes since v1)
hw/net/i82596.c | 18 ------------------ 1 file changed, 18 deletions(-)
hw/net/i82596.c +0 -18
@@ -73,10 +73,6 @@ enum commands {#define I596_EOF 0x8000#define SIZE_MASK 0x3fff -#define ETHER_TYPE_LEN 2 -#define VLAN_TCI_LEN 2 -#define VLAN_HLEN (ETHER_TYPE_LEN + VLAN_TCI_LEN) -/* various flags in the chip config registers */ #define I596_PREFETCH (s->config[0] & 0x80)#define I596_PROMISC (s->config[8] & 0x01)
@@ -489,8 +485,6 @@ bool i82596_can_receive(NetClientState *nc)return true; } -#define MIN_BUF_SIZE 60 -ssize_t i82596_receive (NetClientState *nc,const uint8_t *buf,size_t sz) {I82596State *s =qemu_get_nic_opaque (nc);
@@ -501,7 +495,6 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_t *buf, size_t sz)size_t bufsz = sz;/* length of data in buf */ uint32_t crc;uint8_t *crc_ptr; -uint8_t buf1[MIN_BUF_SIZE +VLAN_HLEN ];static const uint8_t broadcast_macaddr[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff };
@@ -584,17 +577,6 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_t *buf, size_t sz) } } -/* if too small buffer, then expand it */ -if (len <MIN_BUF_SIZE +VLAN_HLEN ) { -memcpy (buf1, buf, len); -memset (buf1 + len,0 ,MIN_BUF_SIZE +VLAN_HLEN - len); - buf = buf1; -if (len <MIN_BUF_SIZE ) { - len =MIN_BUF_SIZE ; - } - bufsz = len; - } -/* Calculate the ethernet checksum (4 bytes) */ len +=4 ; crc =cpu_to_be32 (crc32 (~0 , buf, sz));
Signature · 1 line
2.17.1
PATCH v5 8/12 hw/net: ne2000: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
---
(no changes since v1)
hw/net/ne2000.c | 12 ------------ 1 file changed, 12 deletions(-)
hw/net/ne2000.c +0 -12
@@ -167,15 +167,12 @@ static int ne2000_buffer_full(NE2000State *s)return 0 ; } -#define MIN_BUF_SIZE 60 -ssize_t ne2000_receive (NetClientState *nc,const uint8_t *buf,size_t size_) {NE2000State *s =qemu_get_nic_opaque (nc);size_t size = size_;uint8_t *p;unsigned int total_len, next, avail, len, index, mcast_idx; -uint8_t buf1[60 ];static const uint8_t broadcast_macaddr[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff };
@@ -213,15 +210,6 @@ ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_) } } - -/* if too small buffer, then expand it */ -if (size <MIN_BUF_SIZE ) { -memcpy (buf1, buf, size); -memset (buf1 + size,0 ,MIN_BUF_SIZE - size); - buf = buf1; - size =MIN_BUF_SIZE ; - } - index = s->curpag <<8 ;if (index >=NE2000_PMEM_END ) { index = s->start;
Signature · 1 line
2.17.1
PATCH v5 9/12 hw/net: pcnet: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
---
(no changes since v1)
hw/net/pcnet.c | 9 --------- 1 file changed, 9 deletions(-)
hw/net/pcnet.c +0 -9
@@ -987,7 +987,6 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_) {PCNetState *s =qemu_get_nic_opaque (nc);int is_padr =0 , is_bcast =0 , is_ladr =0 ; -uint8_t buf1[60 ];int remaining;int crc_err =0 ;size_t size = size_;
@@ -1000,14 +999,6 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_)printf ("pcnet_receive size=%zu\n" , size);#endif -/* if too small buffer, then expand it */ -if (size <MIN_BUF_SIZE ) { -memcpy (buf1, buf, size); -memset (buf1 + size,0 ,MIN_BUF_SIZE - size); - buf = buf1; - size =MIN_BUF_SIZE ; - } -if (CSR_PROM (s) || (is_padr=padr_match (s, buf, size)) || (is_bcast=padr_bcast(s, buf, size))
Signature · 1 line
2.17.1
PATCH v5 10/12 hw/net: rtl8139: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
---
(no changes since v1)
hw/net/rtl8139.c | 12 ------------ 1 file changed, 12 deletions(-)
hw/net/rtl8139.c +0 -12
@@ -827,7 +827,6 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_tuint32_t packet_header =0 ; -uint8_t buf1[MIN_BUF_SIZE +VLAN_HLEN ];static const uint8_t broadcast_macaddr[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff };
@@ -939,17 +938,6 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t } } -/* if too small buffer, then expand it -* Include some tailroom in case a vlan tag is later removed. */ -if (size <MIN_BUF_SIZE +VLAN_HLEN ) { -memcpy (buf1, buf, size); -memset (buf1 + size,0 ,MIN_BUF_SIZE +VLAN_HLEN - size); - buf = buf1; -if (size <MIN_BUF_SIZE ) { - size =MIN_BUF_SIZE ; - } - } -if (rtl8139_cp_receiver_enabled (s)) {if (!rtl8139_cp_rx_valid (s)) {
Signature · 1 line
2.17.1
PATCH v5 11/12 hw/net: sungem: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
---
(no changes since v1)
hw/net/sungem.c | 14 -------------- 1 file changed, 14 deletions(-)
hw/net/sungem.c +0 -14
@@ -550,7 +550,6 @@ static ssize_t sungem_receive(NetClientState *nc, const uint8_t *buf,PCIDevice *d =PCI_DEVICE (s);uint32_t mac_crc, done, kick, max_fsize;uint32_t fcs_size, ints, rxdma_cfg, rxmac_cfg, csum, coff; -uint8_t smallbuf[60 ];struct gem_rxd desc;uint64_t dbase, baddr;unsigned int rx_cond;
@@ -584,19 +583,6 @@ static ssize_t sungem_receive(NetClientState *nc, const uint8_t *buf,return size; } -/* We don't drop too small frames since we get them in qemu, we pad -* them instead. We should probably use the min frame size register -* but I don't want to use a variable size staging buffer and I -* know both MacOS and Linux use the default 64 anyway. We use 60 -* here to account for the non-existent FCS. -*/ -if (size <60 ) { -memcpy (smallbuf, buf, size); -memset (&smallbuf[size],0 ,60 - size); - buf = smallbuf; - size =60 ; - } -/* Get MAC crc */ mac_crc =net_crc32_le (buf,ETH_ALEN );
Signature · 1 line
2.17.1
PATCH v5 12/12 hw/net: sunhme: Remove the logic of padding short frames in the receive path
In reply to Bin MengNow that we have implemented unified short frames padding in the QEMU networking codes, remove the same logic in the NIC codes.
---
(no changes since v1)
hw/net/sunhme.c | 11 ----------- 1 file changed, 11 deletions(-)
hw/net/sunhme.c +0 -11
@@ -714,8 +714,6 @@ static inline void sunhme_set_rx_ring_nr(SunHMEState *s, int i) s->erxregs[HME_ERXI_RING >>2 ] = ring; } -#define MIN_BUF_SIZE 60 -static ssize_t sunhme_receive (NetClientState *nc,const uint8_t *buf,size_t size) {
@@ -724,7 +722,6 @@ static ssize_t sunhme_receive(NetClientState *nc, const uint8_t *buf,dma_addr_t rb, addr;uint32_t intstatus, status, buffer, buffersize, sum;uint16_t csum; -uint8_t buf1[60 ];int nr, cr, len, rxoffset, csum_offset;trace_sunhme_rx_incoming (size);
@@ -775,14 +772,6 @@ static ssize_t sunhme_receive(NetClientState *nc, const uint8_t *buf,trace_sunhme_rx_filter_accept (); -/* If too small buffer, then expand it */ -if (size <MIN_BUF_SIZE ) { -memcpy (buf1, buf, size); -memset (buf1 + size,0 ,MIN_BUF_SIZE - size); - buf = buf1; - size =MIN_BUF_SIZE ; - } - rb = s->erxregs[HME_ERXI_RING >>2 ] &HME_ERXI_RING_ADDR ; nr =sunhme_get_rx_ring_count (s); cr =sunhme_get_rx_ring_nr (s);
Signature · 1 line
2.17.1
Quoted 34 lines · Bin Meng
The minimum Ethernet frame length is 60 bytes. For short frames with smaller length like ARP packets (only 42 bytes), on a real world NIC it can choose either padding its length to the minimum required 60 bytes, or sending it out directly to the wire. Such behavior can be hardcoded or controled by a register bit. Similarly on the receive path, NICs can choose either dropping such short frames directly or handing them over to software to handle.
On the other hand, for the network backends like SLiRP/TAP, they don't expose a way to control the short frame behavior. As of today they just send/receive data from/to the other end connected to them, which means any sized packet is acceptable. So they can send and receive short frames without any problem. It is observed that ARP packets sent from SLiRP/TAP are 42 bytes, and SLiRP/TAP just send these ARP packets to the other end which might be a NIC model that does not allow short frames to pass through.
To provide better compatibility, for packets sent from QEMU network backends like SLiRP/TAP, we change to pad short frames before sending it out to the other end, if the other end does not forbid it via the
nc->do_not_padflag. This ensures a backend as an Ethernet sender does not violate the spec. But with this change, the behavior of dropping short frames from SLiRP/TAP interfaces in the NIC model cannot be emulated because it always receives a packet that is spec complaint. The capability of sending short frames from NIC models is still supported and short frames can still pass through SLiRP/TAP.This series should be able to fix the issue as reported with some NIC models before, that ARP requests get dropped, preventing the guest from becoming visible on the network. It was workarounded in these NIC models on the receive path, that when a short frame is received, it is padded up to 60 bytes.
Quoted 4 lines
Changes in v5:
- minor update on commit message
- update theeth_pad_short_frame()comment
Ping?
Quoted 71 lines · Bin Meng
The minimum Ethernet frame length is 60 bytes. For short frames with smaller length like ARP packets (only 42 bytes), on a real world NIC it can choose either padding its length to the minimum required 60 bytes, or sending it out directly to the wire. Such behavior can be hardcoded or controled by a register bit. Similarly on the receive path, NICs can choose either dropping such short frames directly or handing them over to software to handle.
On the other hand, for the network backends like SLiRP/TAP, they don't expose a way to control the short frame behavior. As of today they just send/receive data from/to the other end connected to them, which means any sized packet is acceptable. So they can send and receive short frames without any problem. It is observed that ARP packets sent from SLiRP/TAP are 42 bytes, and SLiRP/TAP just send these ARP packets to the other end which might be a NIC model that does not allow short frames to pass through.
To provide better compatibility, for packets sent from QEMU network backends like SLiRP/TAP, we change to pad short frames before sending it out to the other end, if the other end does not forbid it via the
nc->do_not_padflag. This ensures a backend as an Ethernet sender does not violate the spec. But with this change, the behavior of dropping short frames from SLiRP/TAP interfaces in the NIC model cannot be emulated because it always receives a packet that is spec complaint. The capability of sending short frames from NIC models is still supported and short frames can still pass through SLiRP/TAP.This series should be able to fix the issue as reported with some NIC models before, that ARP requests get dropped, preventing the guest from becoming visible on the network. It was workarounded in these NIC models on the receive path, that when a short frame is received, it is padded up to 60 bytes.
Changes in v5:
- minor update on commit message
- update theeth_pad_short_frame()commentChanges in v4:
- change 'ethernet' to 'Ethernet'
- do not inline the helper
- check the padded buffer size to avoid buffer overflow
- squash slirp/tap commits into oneChanges in v3:
- use 'without' instead of 'sans'
- add a helper to pad short frames
- add a comment to 'do_not_pad'
- use thepad_short_frame()helperBin Meng (12):
net: eth: Add a helper to pad a short Ethernet frame
net: Add a 'do_not_pad" to NetClientState
net: Pad short frames to minimum size before sending from SLiRP/TAP hw/net: virtio-net: Initializenc->do_not_padto true hw/net: e1000: Remove the logic of padding short frames in the receive
path
hw/net: vmxnet3: Remove the logic of padding short frames in the
receive path
hw/net: i82596: Remove the logic of padding short frames in the
receive path
hw/net: ne2000: Remove the logic of padding short frames in the
receive path
hw/net: pcnet: Remove the logic of padding short frames in the receive
path
hw/net: rtl8139: Remove the logic of padding short frames in the
receive path
hw/net: sungem: Remove the logic of padding short frames in the
receive path
hw/net: sunhme: Remove the logic of padding short frames in the
receive path
Quoted 16 lines
hw/net/e1000.c | 11 +---------- hw/net/i82596.c | 18 ------------------ hw/net/ne2000.c | 12 ------------ hw/net/pcnet.c | 9 --------- hw/net/rtl8139.c | 12 ------------ hw/net/sungem.c | 14 -------------- hw/net/sunhme.c | 11 ----------- hw/net/virtio-net.c | 4 ++++ hw/net/vmxnet3.c | 10 ---------- include/net/eth.h | 17 +++++++++++++++++ include/net/net.h | 1 + net/eth.c | 17 +++++++++++++++++ net/slirp.c | 10 ++++++++++ net/tap-win32.c | 10 ++++++++++ net/tap.c | 10 ++++++++++ 15 files changed, 70 insertions(+), 96 deletions(-)
I've queued patch 1-4 for 6.0 and the reset for 6.1.
Thanks
Quoted 1 line
Hi Jason,
Quoted 92 lines · Jason Wang
Quoted 71 lines · Bin Meng
The minimum Ethernet frame length is 60 bytes. For short frames with smaller length like ARP packets (only 42 bytes), on a real world NIC it can choose either padding its length to the minimum required 60 bytes, or sending it out directly to the wire. Such behavior can be hardcoded or controled by a register bit. Similarly on the receive path, NICs can choose either dropping such short frames directly or handing them over to software to handle.
On the other hand, for the network backends like SLiRP/TAP, they don't expose a way to control the short frame behavior. As of today they just send/receive data from/to the other end connected to them, which means any sized packet is acceptable. So they can send and receive short frames without any problem. It is observed that ARP packets sent from SLiRP/TAP are 42 bytes, and SLiRP/TAP just send these ARP packets to the other end which might be a NIC model that does not allow short frames to pass through.
To provide better compatibility, for packets sent from QEMU network backends like SLiRP/TAP, we change to pad short frames before sending it out to the other end, if the other end does not forbid it via the
nc->do_not_padflag. This ensures a backend as an Ethernet sender does not violate the spec. But with this change, the behavior of dropping short frames from SLiRP/TAP interfaces in the NIC model cannot be emulated because it always receives a packet that is spec complaint. The capability of sending short frames from NIC models is still supported and short frames can still pass through SLiRP/TAP.This series should be able to fix the issue as reported with some NIC models before, that ARP requests get dropped, preventing the guest from becoming visible on the network. It was workarounded in these NIC models on the receive path, that when a short frame is received, it is padded up to 60 bytes.
Changes in v5:
- minor update on commit message
- update theeth_pad_short_frame()commentChanges in v4:
- change 'ethernet' to 'Ethernet'
- do not inline the helper
- check the padded buffer size to avoid buffer overflow
- squash slirp/tap commits into oneChanges in v3:
- use 'without' instead of 'sans'
- add a helper to pad short frames
- add a comment to 'do_not_pad'
- use thepad_short_frame()helperBin Meng (12):
net: eth: Add a helper to pad a short Ethernet frame
net: Add a 'do_not_pad" to NetClientState
net: Pad short frames to minimum size before sending from SLiRP/TAP hw/net: virtio-net: Initializenc->do_not_padto true hw/net: e1000: Remove the logic of padding short frames in the receive
path
hw/net: vmxnet3: Remove the logic of padding short frames in the
receive path
hw/net: i82596: Remove the logic of padding short frames in the
receive path
hw/net: ne2000: Remove the logic of padding short frames in the
receive path
hw/net: pcnet: Remove the logic of padding short frames in the receive
path
hw/net: rtl8139: Remove the logic of padding short frames in the
receive path
hw/net: sungem: Remove the logic of padding short frames in the
receive path
hw/net: sunhme: Remove the logic of padding short frames in the
receive pathQuoted 16 lines
hw/net/e1000.c | 11 +---------- hw/net/i82596.c | 18 ------------------ hw/net/ne2000.c | 12 ------------ hw/net/pcnet.c | 9 --------- hw/net/rtl8139.c | 12 ------------ hw/net/sungem.c | 14 -------------- hw/net/sunhme.c | 11 ----------- hw/net/virtio-net.c | 4 ++++ hw/net/vmxnet3.c | 10 ---------- include/net/eth.h | 17 +++++++++++++++++ include/net/net.h | 1 + net/eth.c | 17 +++++++++++++++++ net/slirp.c | 10 ++++++++++ net/tap-win32.c | 10 ++++++++++ net/tap.c | 10 ++++++++++ 15 files changed, 70 insertions(+), 96 deletions(-)
Quoted 1 line
I've queued patch 1-4 for 6.0 and the reset for 6.1.
It seems the reset has not been applied for 6.1?
Regards,
Bin