Skip to content

Commit 1f5020a

Browse files
vladimirolteandavem330
authored andcommitted
net: vlan: introduce skb_vlan_eth_hdr()
Similar to skb_eth_hdr() introduced in commit 96cc4b6 ("macvlan: do not assume mac_header is set in macvlan_broadcast()"), let's introduce a skb_vlan_eth_hdr() helper which can be used in TX-only code paths to get to the VLAN header based on skb->data rather than based on the skb_mac_header(skb). We also consolidate the drivers that dereference skb->data to go through this helper. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f90615a commit 1f5020a

12 files changed

Lines changed: 24 additions & 20 deletions

File tree

drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,8 +1935,7 @@ u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
19351935

19361936
/* Skip VLAN tag if present */
19371937
if (ether_type == ETH_P_8021Q) {
1938-
struct vlan_ethhdr *vhdr =
1939-
(struct vlan_ethhdr *)skb->data;
1938+
struct vlan_ethhdr *vhdr = skb_vlan_eth_hdr(skb);
19401939

19411940
ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
19421941
}

drivers/net/ethernet/emulex/benet/be_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter,
11241124
struct be_wrb_params
11251125
*wrb_params)
11261126
{
1127-
struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
1127+
struct vlan_ethhdr *veh = skb_vlan_eth_hdr(skb);
11281128
unsigned int eth_hdr_len;
11291129
struct iphdr *ip;
11301130

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ static int hns3_handle_vtags(struct hns3_enet_ring *tx_ring,
15321532
if (unlikely(rc < 0))
15331533
return rc;
15341534

1535-
vhdr = (struct vlan_ethhdr *)skb->data;
1535+
vhdr = skb_vlan_eth_hdr(skb);
15361536
vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority << VLAN_PRIO_SHIFT)
15371537
& VLAN_PRIO_MASK);
15381538

drivers/net/ethernet/intel/i40e/i40e_txrx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3063,7 +3063,7 @@ static inline int i40e_tx_prepare_vlan_flags(struct sk_buff *skb,
30633063
rc = skb_cow_head(skb, 0);
30643064
if (rc < 0)
30653065
return rc;
3066-
vhdr = (struct vlan_ethhdr *)skb->data;
3066+
vhdr = skb_vlan_eth_hdr(skb);
30673067
vhdr->h_vlan_TCI = htons(tx_flags >>
30683068
I40E_TX_FLAGS_VLAN_SHIFT);
30693069
} else {

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8798,7 +8798,7 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
87988798

87998799
if (skb_cow_head(skb, 0))
88008800
goto out_drop;
8801-
vhdr = (struct vlan_ethhdr *)skb->data;
8801+
vhdr = skb_vlan_eth_hdr(skb);
88028802
vhdr->h_vlan_TCI = htons(tx_flags >>
88038803
IXGBE_TX_FLAGS_VLAN_SHIFT);
88048804
} else {

drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ netxen_tso_check(struct net_device *netdev,
18541854

18551855
if (protocol == cpu_to_be16(ETH_P_8021Q)) {
18561856

1857-
vh = (struct vlan_ethhdr *)skb->data;
1857+
vh = skb_vlan_eth_hdr(skb);
18581858
protocol = vh->h_vlan_encapsulated_proto;
18591859
flags = FLAGS_VLAN_TAGGED;
18601860

drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
318318

319319
if (adapter->flags & QLCNIC_VLAN_FILTERING) {
320320
if (protocol == ETH_P_8021Q) {
321-
vh = (struct vlan_ethhdr *)skb->data;
321+
vh = skb_vlan_eth_hdr(skb);
322322
vlan_id = ntohs(vh->h_vlan_TCI);
323323
} else if (skb_vlan_tag_present(skb)) {
324324
vlan_id = skb_vlan_tag_get(skb);
@@ -468,7 +468,7 @@ static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
468468
u32 producer = tx_ring->producer;
469469

470470
if (protocol == ETH_P_8021Q) {
471-
vh = (struct vlan_ethhdr *)skb->data;
471+
vh = skb_vlan_eth_hdr(skb);
472472
flags = QLCNIC_FLAGS_VLAN_TAGGED;
473473
vlan_tci = ntohs(vh->h_vlan_TCI);
474474
protocol = ntohs(vh->h_vlan_encapsulated_proto);

drivers/net/ethernet/sfc/tx_tso.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static __be16 efx_tso_check_protocol(struct sk_buff *skb)
147147
EFX_WARN_ON_ONCE_PARANOID(((struct ethhdr *)skb->data)->h_proto !=
148148
protocol);
149149
if (protocol == htons(ETH_P_8021Q)) {
150-
struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
150+
struct vlan_ethhdr *veh = skb_vlan_eth_hdr(skb);
151151

152152
protocol = veh->h_vlan_encapsulated_proto;
153153
}

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4569,13 +4569,10 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
45694569

45704570
static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
45714571
{
4572-
struct vlan_ethhdr *veth;
4573-
__be16 vlan_proto;
4572+
struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb);
4573+
__be16 vlan_proto = veth->h_vlan_proto;
45744574
u16 vlanid;
45754575

4576-
veth = (struct vlan_ethhdr *)skb->data;
4577-
vlan_proto = veth->h_vlan_proto;
4578-
45794576
if ((vlan_proto == htons(ETH_P_8021Q) &&
45804577
dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
45814578
(vlan_proto == htons(ETH_P_8021AD) &&

drivers/staging/gdm724x/gdm_lte.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb)
349349
/* Get ethernet protocol */
350350
eth = (struct ethhdr *)skb->data;
351351
if (ntohs(eth->h_proto) == ETH_P_8021Q) {
352-
vlan_eth = (struct vlan_ethhdr *)skb->data;
352+
vlan_eth = skb_vlan_eth_hdr(skb);
353353
mac_proto = ntohs(vlan_eth->h_vlan_encapsulated_proto);
354354
network_data = skb->data + VLAN_ETH_HLEN;
355355
nic_type |= NIC_TYPE_F_VLAN;
@@ -435,7 +435,7 @@ static netdev_tx_t gdm_lte_tx(struct sk_buff *skb, struct net_device *dev)
435435
* driver based on the NIC mac
436436
*/
437437
if (nic_type & NIC_TYPE_F_VLAN) {
438-
struct vlan_ethhdr *vlan_eth = (struct vlan_ethhdr *)skb->data;
438+
struct vlan_ethhdr *vlan_eth = skb_vlan_eth_hdr(skb);
439439

440440
nic->vlan_id = ntohs(vlan_eth->h_vlan_TCI) & VLAN_VID_MASK;
441441
data_buf = skb->data + (VLAN_ETH_HLEN - ETH_HLEN);

0 commit comments

Comments
 (0)