]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
net: check the existence of peer before trying to pad
authorJason Wang <jasowang@redhat.com>
Fri, 23 Apr 2021 03:18:03 +0000 (11:18 +0800)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 23 Apr 2021 10:11:28 +0000 (11:11 +0100)
There could be case that peer is NULL. This can happen when during
network device hot-add where net device needs to be added first. So
the patch check the existence of peer before trying to do the pad.

Fixes: 969e50b61a285 ("net: Pad short frames to minimum size before sending from SLiRP/TAP")
Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Stefan Weil <sw@weilnetz.de>
Message-id: 20210423031803.1479-1-jasowang@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
include/net/net.h
net/slirp.c
net/tap-win32.c
net/tap.c

index eff24519d23ccd4eefc8589188bca05fcd50b299..1ef536d771212d2eaceabab92e51b895465fb8ee 100644 (file)
@@ -241,4 +241,9 @@ uint32_t net_crc32_le(const uint8_t *p, int len);
     .offset     = vmstate_offset_macaddr(_state, _field),            \
 }
 
+static inline bool net_peer_needs_padding(NetClientState *nc)
+{
+  return nc->peer && !nc->peer->do_not_pad;
+}
+
 #endif
index a01a0fccd37a7a9253f03fcd5cd4c1620c21bf65..7a4e96db5c264418ec159b922f8ecf99fb5d6c97 100644 (file)
@@ -119,7 +119,7 @@ static ssize_t net_slirp_send_packet(const void *pkt, size_t pkt_len,
     uint8_t min_pkt[ETH_ZLEN];
     size_t min_pktsz = sizeof(min_pkt);
 
-    if (!s->nc.peer->do_not_pad) {
+    if (net_peer_needs_padding(&s->nc)) {
         if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pkt_len)) {
             pkt = min_pkt;
             pkt_len = min_pktsz;
index 897bd18e32e05ef2e8e1c62130846f9c33f2ec4d..6096972f5d4707eac2ffe5e9cb762945c218479e 100644 (file)
@@ -696,7 +696,7 @@ static void tap_win32_send(void *opaque)
     if (size > 0) {
         orig_buf = buf;
 
-        if (!s->nc.peer->do_not_pad) {
+        if (net_peer_needs_padding(&s->nc)) {
             if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
                 buf = min_pkt;
                 size = min_pktsz;
index dd42ac61347eb6dd2172bc4cc5cb08de517876cc..bae895e2874677f588b4fc592227446ff50680e1 100644 (file)
--- a/net/tap.c
+++ b/net/tap.c
@@ -203,7 +203,7 @@ static void tap_send(void *opaque)
             size -= s->host_vnet_hdr_len;
         }
 
-        if (!s->nc.peer->do_not_pad) {
+        if (net_peer_needs_padding(&s->nc)) {
             if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
                 buf = min_pkt;
                 size = min_pktsz;