Skip to content

Commit

Permalink
net: check the existence of peer before trying to pad
Browse files Browse the repository at this point in the history
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: 969e50b ("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>
  • Loading branch information
jasowang authored and pm215 committed Apr 23, 2021
1 parent b1cffef commit bc38e31
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/net/net.h
Expand Up @@ -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
2 changes: 1 addition & 1 deletion net/slirp.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/tap-win32.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/tap.c
Expand Up @@ -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;
Expand Down

0 comments on commit bc38e31

Please sign in to comment.