mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
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. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
bdee969c0e
commit
af774513f7
2 changed files with 34 additions and 0 deletions
17
net/eth.c
17
net/eth.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue