[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 31/48] net/eth: Always add VLAN tag
From: |
Akihiko Odaki |
Subject: |
[PATCH v4 31/48] net/eth: Always add VLAN tag |
Date: |
Wed, 26 Apr 2023 19:36:59 +0900 |
It is possible to have another VLAN tag even if the packet is already
tagged.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/net/eth.h | 4 ++--
hw/net/net_tx_pkt.c | 16 +++++++---------
net/eth.c | 22 ++++++----------------
3 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/include/net/eth.h b/include/net/eth.h
index 95ff24d6b8..048e434685 100644
--- a/include/net/eth.h
+++ b/include/net/eth.h
@@ -353,8 +353,8 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt,
size_t iovoff,
uint16_t
eth_get_l3_proto(const struct iovec *l2hdr_iov, int iovcnt, size_t l2hdr_len);
-void eth_setup_vlan_headers(struct eth_header *ehdr, uint16_t vlan_tag,
- uint16_t vlan_ethtype, bool *is_new);
+void eth_setup_vlan_headers(struct eth_header *ehdr, size_t *ehdr_size,
+ uint16_t vlan_tag, uint16_t vlan_ethtype);
uint8_t eth_get_gso_type(uint16_t l3_proto, uint8_t *l3_hdr, uint8_t l4proto);
diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c
index ce6b102391..af8f77a3f0 100644
--- a/hw/net/net_tx_pkt.c
+++ b/hw/net/net_tx_pkt.c
@@ -40,7 +40,10 @@ struct NetTxPkt {
struct iovec *vec;
- uint8_t l2_hdr[ETH_MAX_L2_HDR_LEN];
+ struct {
+ struct eth_header eth;
+ struct vlan_header vlan[3];
+ } l2_hdr;
union {
struct ip_header ip;
struct ip6_header ip6;
@@ -365,18 +368,13 @@ bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool
tso_enable,
void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt,
uint16_t vlan, uint16_t vlan_ethtype)
{
- bool is_new;
assert(pkt);
eth_setup_vlan_headers(pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_base,
- vlan, vlan_ethtype, &is_new);
+ &pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_len,
+ vlan, vlan_ethtype);
- /* update l2hdrlen */
- if (is_new) {
- pkt->hdr_len += sizeof(struct vlan_header);
- pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_len +=
- sizeof(struct vlan_header);
- }
+ pkt->hdr_len += sizeof(struct vlan_header);
}
bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, void *base, size_t len)
diff --git a/net/eth.c b/net/eth.c
index f7ffbda600..5307978486 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -21,26 +21,16 @@
#include "net/checksum.h"
#include "net/tap.h"
-void eth_setup_vlan_headers(struct eth_header *ehdr, uint16_t vlan_tag,
- uint16_t vlan_ethtype, bool *is_new)
+void eth_setup_vlan_headers(struct eth_header *ehdr, size_t *ehdr_size,
+ uint16_t vlan_tag, uint16_t vlan_ethtype)
{
struct vlan_header *vhdr = PKT_GET_VLAN_HDR(ehdr);
- switch (be16_to_cpu(ehdr->h_proto)) {
- case ETH_P_VLAN:
- case ETH_P_DVLAN:
- /* vlan hdr exists */
- *is_new = false;
- break;
-
- default:
- /* No VLAN header, put a new one */
- vhdr->h_proto = ehdr->h_proto;
- ehdr->h_proto = cpu_to_be16(vlan_ethtype);
- *is_new = true;
- break;
- }
+ memmove(vhdr + 1, vhdr, *ehdr_size - ETH_HLEN);
vhdr->h_tci = cpu_to_be16(vlan_tag);
+ vhdr->h_proto = ehdr->h_proto;
+ ehdr->h_proto = cpu_to_be16(vlan_ethtype);
+ *ehdr_size += sizeof(*vhdr);
}
uint8_t
--
2.40.0
- [PATCH v4 21/48] igb: Read DCMD.VLE of the first Tx descriptor, (continued)
- [PATCH v4 21/48] igb: Read DCMD.VLE of the first Tx descriptor, Akihiko Odaki, 2023/04/26
- [PATCH v4 22/48] e1000e: Reset packet state after emptying Tx queue, Akihiko Odaki, 2023/04/26
- [PATCH v4 23/48] vmxnet3: Reset packet state after emptying Tx queue, Akihiko Odaki, 2023/04/26
- [PATCH v4 25/48] igb: Share common VF constants, Akihiko Odaki, 2023/04/26
- [PATCH v4 24/48] igb: Add more definitions for Tx descriptor, Akihiko Odaki, 2023/04/26
- [PATCH v4 26/48] igb: Fix igb_mac_reg_init coding style alignment, Akihiko Odaki, 2023/04/26
- [PATCH v4 27/48] igb: Clear EICR bits for delayed MSI-X interrupts, Akihiko Odaki, 2023/04/26
- [PATCH v4 28/48] e1000e: Rename a variable in e1000e_receive_internal(), Akihiko Odaki, 2023/04/26
- [PATCH v4 29/48] igb: Rename a variable in igb_receive_internal(), Akihiko Odaki, 2023/04/26
- [PATCH v4 30/48] net/eth: Use void pointers, Akihiko Odaki, 2023/04/26
- [PATCH v4 31/48] net/eth: Always add VLAN tag,
Akihiko Odaki <=
- [PATCH v4 32/48] hw/net/net_rx_pkt: Enforce alignment for eth_header, Akihiko Odaki, 2023/04/26
- [PATCH v4 33/48] tests/qtest/libqos/igb: Set GPIE.Multiple_MSIX, Akihiko Odaki, 2023/04/26
- [PATCH v4 34/48] igb: Implement MSI-X single vector mode, Akihiko Odaki, 2023/04/26
- [PATCH v4 35/48] igb: Use UDP for RSS hash, Akihiko Odaki, 2023/04/26
- [PATCH v4 36/48] igb: Implement Rx SCTP CSO, Akihiko Odaki, 2023/04/26
- [PATCH v4 37/48] igb: Implement Tx SCTP CSO, Akihiko Odaki, 2023/04/26
- [PATCH v4 38/48] igb: Strip the second VLAN tag for extended VLAN, Akihiko Odaki, 2023/04/26
- [PATCH v4 39/48] igb: Filter with the second VLAN tag for extended VLAN, Akihiko Odaki, 2023/04/26
- [PATCH v4 40/48] igb: Implement igb-specific oversize check, Akihiko Odaki, 2023/04/26
- [PATCH v4 41/48] igb: Implement Rx PTP2 timestamp, Akihiko Odaki, 2023/04/26