aboutsummaryrefslogtreecommitdiff
path: root/net/eth.c
diff options
context:
space:
mode:
authorBin Meng <bmeng.cn@gmail.com>2021-03-17 14:26:27 +0800
committerJason Wang <jasowang@redhat.com>2021-03-22 17:34:31 +0800
commitaf774513f7d646badfdb5b686650254f7f08af6b (patch)
tree42cbc1d3a53f55415bb40da770b15bd7a40ba584 /net/eth.c
parentbdee969c0e65d4d509932b1d70e3a3b2ffbff6d5 (diff)
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>
Diffstat (limited to 'net/eth.c')
-rw-r--r--net/eth.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/net/eth.c b/net/eth.c
index 1e0821c5f8..f913e4396f 100644
--- a/net/eth.c
+++ b/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;
+}