aboutsummaryrefslogtreecommitdiff
path: root/include/net
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 /include/net
parentbdee969c0e65d4d509932b1d70e3a3b2ffbff6d5 (diff)
downloadqemu-af774513f7d646badfdb5b686650254f7f08af6b.zip
qemu-af774513f7d646badfdb5b686650254f7f08af6b.tar.gz
qemu-af774513f7d646badfdb5b686650254f7f08af6b.tar.bz2
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 'include/net')
-rw-r--r--include/net/eth.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/net/eth.h b/include/net/eth.h
index 0671be6..7767ae8 100644
--- a/include/net/eth.h
+++ b/include/net/eth.h
@@ -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