diff mbox series

[v6,net] stmmac: strip all VLAN tag types when kernel 802.1Q support is selected

Message ID cb89c947-21cf-b5da-9cff-940e904105c3@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series [v6,net] stmmac: strip all VLAN tag types when kernel 802.1Q support is selected | expand

Commit Message

Elad Nachman June 8, 2018, 9:19 a.m. UTC
stmmac reception handler calls stmmac_rx_vlan() to strip the vlan before 
calling napi_gro_receive().

The function assumes VLAN tagged frames are always tagged with 
802.1Q protocol, and assigns ETH_P_8021Q to the skb by hard-coding
the parameter on call to __vlan_hwaccel_put_tag() .

This causes packets not to be passed to the VLAN slave if it was created 
with 802.1AD protocol
(ip link add link eth0 eth0.100 type vlan proto 802.1ad id 100).

This fix passes the protocol from the VLAN header into 
__vlan_hwaccel_put_tag() instead of using the hard-coded value of
ETH_P_8021Q.

NETIF_F_HW_VLAN_CTAG_RX check was removed and instead the strip action 
is dependent upon a preprocessor define which is defined when 802.1Q 
support is selected in the kernel config. 

NETIF_F_HW_VLAN_STAG_RX feature was added to be in line with the driver 
actual abilities.

Signed-off-by: Elad Nachman <eladn@gilat.com>


---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Comments

David Miller June 10, 2018, 7:29 p.m. UTC | #1
From: Elad Nachman <eladv6@gmail.com>
Date: Fri, 8 Jun 2018 12:19:29 +0300

> stmmac reception handler calls stmmac_rx_vlan() to strip the vlan before 
> calling napi_gro_receive().
> 
> The function assumes VLAN tagged frames are always tagged with 
> 802.1Q protocol, and assigns ETH_P_8021Q to the skb by hard-coding
> the parameter on call to __vlan_hwaccel_put_tag() .
> 
> This causes packets not to be passed to the VLAN slave if it was created 
> with 802.1AD protocol
> (ip link add link eth0 eth0.100 type vlan proto 802.1ad id 100).
> 
> This fix passes the protocol from the VLAN header into 
> __vlan_hwaccel_put_tag() instead of using the hard-coded value of
> ETH_P_8021Q.
> 
> NETIF_F_HW_VLAN_CTAG_RX check was removed and instead the strip action 
> is dependent upon a preprocessor define which is defined when 802.1Q 
> support is selected in the kernel config. 
> 
> NETIF_F_HW_VLAN_STAG_RX feature was added to be in line with the driver 
> actual abilities.
> 
> Signed-off-by: Elad Nachman <eladn@gilat.com>

You can't remove the NETIF_F_* checks.

If the user doesn't have VLAN offloading enabled, the VLAN tags should
be left in the packet as-is.

It can't be controlled by a CPP check.
Toshiaki Makita June 11, 2018, 12:50 a.m. UTC | #2
On 2018/06/11 4:29, David Miller wrote:
> From: Elad Nachman <eladv6@gmail.com>
> Date: Fri, 8 Jun 2018 12:19:29 +0300
> 
>> stmmac reception handler calls stmmac_rx_vlan() to strip the vlan before 
>> calling napi_gro_receive().
>>
>> The function assumes VLAN tagged frames are always tagged with 
>> 802.1Q protocol, and assigns ETH_P_8021Q to the skb by hard-coding
>> the parameter on call to __vlan_hwaccel_put_tag() .
>>
>> This causes packets not to be passed to the VLAN slave if it was created 
>> with 802.1AD protocol
>> (ip link add link eth0 eth0.100 type vlan proto 802.1ad id 100).
>>
>> This fix passes the protocol from the VLAN header into 
>> __vlan_hwaccel_put_tag() instead of using the hard-coded value of
>> ETH_P_8021Q.
>>
>> NETIF_F_HW_VLAN_CTAG_RX check was removed and instead the strip action 
>> is dependent upon a preprocessor define which is defined when 802.1Q 
>> support is selected in the kernel config. 
>>
>> NETIF_F_HW_VLAN_STAG_RX feature was added to be in line with the driver 
>> actual abilities.
>>
>> Signed-off-by: Elad Nachman <eladn@gilat.com>
> 
> You can't remove the NETIF_F_* checks.
> 
> If the user doesn't have VLAN offloading enabled, the VLAN tags should
> be left in the packet as-is.
> 
> It can't be controlled by a CPP check.

David, NETIF_F_HW_VALN_*_RX is not user-controllable in this driver
because hw_features does not include them.

But this can break when those features are added to hw_features so if
David does not like this situation I think we need the condition anyway.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b65e2d1..707917d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3293,18 +3293,20 @@  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)
 {
-	struct ethhdr *ehdr;
+#ifdef STMMAC_VLAN_TAG_USED
+	struct vlan_ethhdr *veth;
+	__be16 vlan_proto;
 	u16 vlanid;
 
-	if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) ==
-	    NETIF_F_HW_VLAN_CTAG_RX &&
-	    !__vlan_get_tag(skb, &vlanid)) {
+	if (!__vlan_get_tag(skb, &vlanid)) {
 		/* pop the vlan tag */
-		ehdr = (struct ethhdr *)skb->data;
-		memmove(skb->data + VLAN_HLEN, ehdr, ETH_ALEN * 2);
+		veth = (struct vlan_ethhdr *)skb->data;
+		vlan_proto = veth->h_vlan_proto;
+		memmove(skb->data + VLAN_HLEN, veth, ETH_ALEN * 2);
 		skb_pull(skb, VLAN_HLEN);
-		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
+		__vlan_hwaccel_put_tag(skb, vlan_proto, vlanid);
 	}
+#endif
 }
 
 
@@ -4344,7 +4346,7 @@  int stmmac_dvr_probe(struct device *device,
 	ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
 #ifdef STMMAC_VLAN_TAG_USED
 	/* Both mac100 and gmac support receive VLAN tag detection */
-	ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
+	ndev->features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX;
 #endif
 	priv->msg_enable = netif_msg_init(debug, default_msg_level);