mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 22:02:02 +00:00
net: vlan: introduce skb_vlan_eth_hdr()
[ Upstream commit1f5020acb3
] Similar to skb_eth_hdr() introduced in commit96cc4b6958
("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> Stable-dep-of:9fc95fe95c
("net: fec: correct queue selection") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
fe779dbb42
commit
3c4dcfbff1
12 changed files with 24 additions and 20 deletions
|
@ -1924,8 +1924,7 @@ u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
|
||||||
|
|
||||||
/* Skip VLAN tag if present */
|
/* Skip VLAN tag if present */
|
||||||
if (ether_type == ETH_P_8021Q) {
|
if (ether_type == ETH_P_8021Q) {
|
||||||
struct vlan_ethhdr *vhdr =
|
struct vlan_ethhdr *vhdr = skb_vlan_eth_hdr(skb);
|
||||||
(struct vlan_ethhdr *)skb->data;
|
|
||||||
|
|
||||||
ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
|
ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1125,7 +1125,7 @@ static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter,
|
||||||
struct be_wrb_params
|
struct be_wrb_params
|
||||||
*wrb_params)
|
*wrb_params)
|
||||||
{
|
{
|
||||||
struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
|
struct vlan_ethhdr *veh = skb_vlan_eth_hdr(skb);
|
||||||
unsigned int eth_hdr_len;
|
unsigned int eth_hdr_len;
|
||||||
struct iphdr *ip;
|
struct iphdr *ip;
|
||||||
|
|
||||||
|
|
|
@ -1512,7 +1512,7 @@ static int hns3_handle_vtags(struct hns3_enet_ring *tx_ring,
|
||||||
if (unlikely(rc < 0))
|
if (unlikely(rc < 0))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
vhdr = (struct vlan_ethhdr *)skb->data;
|
vhdr = skb_vlan_eth_hdr(skb);
|
||||||
vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority << VLAN_PRIO_SHIFT)
|
vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority << VLAN_PRIO_SHIFT)
|
||||||
& VLAN_PRIO_MASK);
|
& VLAN_PRIO_MASK);
|
||||||
|
|
||||||
|
|
|
@ -2975,7 +2975,7 @@ static inline int i40e_tx_prepare_vlan_flags(struct sk_buff *skb,
|
||||||
rc = skb_cow_head(skb, 0);
|
rc = skb_cow_head(skb, 0);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc;
|
return rc;
|
||||||
vhdr = (struct vlan_ethhdr *)skb->data;
|
vhdr = skb_vlan_eth_hdr(skb);
|
||||||
vhdr->h_vlan_TCI = htons(tx_flags >>
|
vhdr->h_vlan_TCI = htons(tx_flags >>
|
||||||
I40E_TX_FLAGS_VLAN_SHIFT);
|
I40E_TX_FLAGS_VLAN_SHIFT);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8696,7 +8696,7 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
|
||||||
|
|
||||||
if (skb_cow_head(skb, 0))
|
if (skb_cow_head(skb, 0))
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
vhdr = (struct vlan_ethhdr *)skb->data;
|
vhdr = skb_vlan_eth_hdr(skb);
|
||||||
vhdr->h_vlan_TCI = htons(tx_flags >>
|
vhdr->h_vlan_TCI = htons(tx_flags >>
|
||||||
IXGBE_TX_FLAGS_VLAN_SHIFT);
|
IXGBE_TX_FLAGS_VLAN_SHIFT);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1861,7 +1861,7 @@ netxen_tso_check(struct net_device *netdev,
|
||||||
|
|
||||||
if (protocol == cpu_to_be16(ETH_P_8021Q)) {
|
if (protocol == cpu_to_be16(ETH_P_8021Q)) {
|
||||||
|
|
||||||
vh = (struct vlan_ethhdr *)skb->data;
|
vh = skb_vlan_eth_hdr(skb);
|
||||||
protocol = vh->h_vlan_encapsulated_proto;
|
protocol = vh->h_vlan_encapsulated_proto;
|
||||||
flags = FLAGS_VLAN_TAGGED;
|
flags = FLAGS_VLAN_TAGGED;
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,7 @@ static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
|
||||||
|
|
||||||
if (adapter->flags & QLCNIC_VLAN_FILTERING) {
|
if (adapter->flags & QLCNIC_VLAN_FILTERING) {
|
||||||
if (protocol == ETH_P_8021Q) {
|
if (protocol == ETH_P_8021Q) {
|
||||||
vh = (struct vlan_ethhdr *)skb->data;
|
vh = skb_vlan_eth_hdr(skb);
|
||||||
vlan_id = ntohs(vh->h_vlan_TCI);
|
vlan_id = ntohs(vh->h_vlan_TCI);
|
||||||
} else if (skb_vlan_tag_present(skb)) {
|
} else if (skb_vlan_tag_present(skb)) {
|
||||||
vlan_id = skb_vlan_tag_get(skb);
|
vlan_id = skb_vlan_tag_get(skb);
|
||||||
|
@ -467,7 +467,7 @@ static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
|
||||||
u32 producer = tx_ring->producer;
|
u32 producer = tx_ring->producer;
|
||||||
|
|
||||||
if (protocol == ETH_P_8021Q) {
|
if (protocol == ETH_P_8021Q) {
|
||||||
vh = (struct vlan_ethhdr *)skb->data;
|
vh = skb_vlan_eth_hdr(skb);
|
||||||
flags = QLCNIC_FLAGS_VLAN_TAGGED;
|
flags = QLCNIC_FLAGS_VLAN_TAGGED;
|
||||||
vlan_tci = ntohs(vh->h_vlan_TCI);
|
vlan_tci = ntohs(vh->h_vlan_TCI);
|
||||||
protocol = ntohs(vh->h_vlan_encapsulated_proto);
|
protocol = ntohs(vh->h_vlan_encapsulated_proto);
|
||||||
|
|
|
@ -147,7 +147,7 @@ static __be16 efx_tso_check_protocol(struct sk_buff *skb)
|
||||||
EFX_WARN_ON_ONCE_PARANOID(((struct ethhdr *)skb->data)->h_proto !=
|
EFX_WARN_ON_ONCE_PARANOID(((struct ethhdr *)skb->data)->h_proto !=
|
||||||
protocol);
|
protocol);
|
||||||
if (protocol == htons(ETH_P_8021Q)) {
|
if (protocol == htons(ETH_P_8021Q)) {
|
||||||
struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
|
struct vlan_ethhdr *veh = skb_vlan_eth_hdr(skb);
|
||||||
|
|
||||||
protocol = veh->h_vlan_encapsulated_proto;
|
protocol = veh->h_vlan_encapsulated_proto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4494,13 +4494,10 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||||
|
|
||||||
static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
|
static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct vlan_ethhdr *veth;
|
struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb);
|
||||||
__be16 vlan_proto;
|
__be16 vlan_proto = veth->h_vlan_proto;
|
||||||
u16 vlanid;
|
u16 vlanid;
|
||||||
|
|
||||||
veth = (struct vlan_ethhdr *)skb->data;
|
|
||||||
vlan_proto = veth->h_vlan_proto;
|
|
||||||
|
|
||||||
if ((vlan_proto == htons(ETH_P_8021Q) &&
|
if ((vlan_proto == htons(ETH_P_8021Q) &&
|
||||||
dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
|
dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
|
||||||
(vlan_proto == htons(ETH_P_8021AD) &&
|
(vlan_proto == htons(ETH_P_8021AD) &&
|
||||||
|
|
|
@ -350,7 +350,7 @@ static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb)
|
||||||
/* Get ethernet protocol */
|
/* Get ethernet protocol */
|
||||||
eth = (struct ethhdr *)skb->data;
|
eth = (struct ethhdr *)skb->data;
|
||||||
if (ntohs(eth->h_proto) == ETH_P_8021Q) {
|
if (ntohs(eth->h_proto) == ETH_P_8021Q) {
|
||||||
vlan_eth = (struct vlan_ethhdr *)skb->data;
|
vlan_eth = skb_vlan_eth_hdr(skb);
|
||||||
mac_proto = ntohs(vlan_eth->h_vlan_encapsulated_proto);
|
mac_proto = ntohs(vlan_eth->h_vlan_encapsulated_proto);
|
||||||
network_data = skb->data + VLAN_ETH_HLEN;
|
network_data = skb->data + VLAN_ETH_HLEN;
|
||||||
nic_type |= NIC_TYPE_F_VLAN;
|
nic_type |= NIC_TYPE_F_VLAN;
|
||||||
|
@ -436,7 +436,7 @@ static netdev_tx_t gdm_lte_tx(struct sk_buff *skb, struct net_device *dev)
|
||||||
* driver based on the NIC mac
|
* driver based on the NIC mac
|
||||||
*/
|
*/
|
||||||
if (nic_type & NIC_TYPE_F_VLAN) {
|
if (nic_type & NIC_TYPE_F_VLAN) {
|
||||||
struct vlan_ethhdr *vlan_eth = (struct vlan_ethhdr *)skb->data;
|
struct vlan_ethhdr *vlan_eth = skb_vlan_eth_hdr(skb);
|
||||||
|
|
||||||
nic->vlan_id = ntohs(vlan_eth->h_vlan_TCI) & VLAN_VID_MASK;
|
nic->vlan_id = ntohs(vlan_eth->h_vlan_TCI) & VLAN_VID_MASK;
|
||||||
data_buf = skb->data + (VLAN_ETH_HLEN - ETH_HLEN);
|
data_buf = skb->data + (VLAN_ETH_HLEN - ETH_HLEN);
|
||||||
|
|
|
@ -60,6 +60,14 @@ static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
|
||||||
return (struct vlan_ethhdr *)skb_mac_header(skb);
|
return (struct vlan_ethhdr *)skb_mac_header(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Prefer this version in TX path, instead of
|
||||||
|
* skb_reset_mac_header() + vlan_eth_hdr()
|
||||||
|
*/
|
||||||
|
static inline struct vlan_ethhdr *skb_vlan_eth_hdr(const struct sk_buff *skb)
|
||||||
|
{
|
||||||
|
return (struct vlan_ethhdr *)skb->data;
|
||||||
|
}
|
||||||
|
|
||||||
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
|
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
|
||||||
#define VLAN_PRIO_SHIFT 13
|
#define VLAN_PRIO_SHIFT 13
|
||||||
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
|
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
|
||||||
|
@ -526,7 +534,7 @@ static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb,
|
||||||
*/
|
*/
|
||||||
static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
|
static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
|
||||||
{
|
{
|
||||||
struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;
|
struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb);
|
||||||
|
|
||||||
if (!eth_type_vlan(veth->h_vlan_proto))
|
if (!eth_type_vlan(veth->h_vlan_proto))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -727,7 +735,7 @@ static inline bool skb_vlan_tagged_multi(struct sk_buff *skb)
|
||||||
if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
|
if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
veh = (struct vlan_ethhdr *)skb->data;
|
veh = skb_vlan_eth_hdr(skb);
|
||||||
protocol = veh->h_vlan_encapsulated_proto;
|
protocol = veh->h_vlan_encapsulated_proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,7 @@ void batadv_interface_rx(struct net_device *soft_iface,
|
||||||
if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
|
if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
|
||||||
goto dropped;
|
goto dropped;
|
||||||
|
|
||||||
vhdr = (struct vlan_ethhdr *)skb->data;
|
vhdr = skb_vlan_eth_hdr(skb);
|
||||||
|
|
||||||
/* drop batman-in-batman packets to prevent loops */
|
/* drop batman-in-batman packets to prevent loops */
|
||||||
if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
|
if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
|
||||||
|
|
Loading…
Reference in a new issue