Commit 04a17583 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: tag_sja1105: fix control packets on SJA1110 being received on an imprecise port

On RX, a control packet with SJA1110 will have:
- an in-band control extension (DSA tag) composed of a header and an
  optional trailer (if it is a timestamp frame). We can (and do) deduce
  the source port and switch id from this.
- a VLAN header, which can either be the tag_8021q RX VLAN (pvid) or the
  bridge VLAN. The sja1105_vlan_rcv() function attempts to deduce the
  source port and switch id a second time from this.

The basic idea is that even though we don't need the source port
information from the tag_8021q header if it's a control packet, we do
need to strip that header before we pass it on to the network stack.

The problem is that we call sja1105_vlan_rcv for ports under VLAN-aware
bridges, and that function tells us it couldn't identify a tag_8021q
header, so we need to perform imprecise RX by VID. Well, we don't,
because we already know the source port and switch ID.

This patch drops the return value from sja1105_vlan_rcv and we just look
at the source_port and switch_id values from sja1105_rcv and sja1110_rcv
which were initialized to -1. If they are still -1 it means we need to
perform imprecise RX.

Fixes: 884be12f ("net: dsa: sja1105: add support for imprecise RX")
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bef0746c
...@@ -368,10 +368,11 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb) ...@@ -368,10 +368,11 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb)
return ntohs(eth_hdr(skb)->h_proto) == ETH_P_SJA1110; return ntohs(eth_hdr(skb)->h_proto) == ETH_P_SJA1110;
} }
/* Returns true for imprecise RX and sets the @vid. /* If the VLAN in the packet is a tag_8021q one, set @source_port and
* Returns false for precise RX and sets @source_port and @switch_id. * @switch_id and strip the header. Otherwise set @vid and keep it in the
* packet.
*/ */
static bool sja1105_vlan_rcv(struct sk_buff *skb, int *source_port, static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port,
int *switch_id, u16 *vid) int *switch_id, u16 *vid)
{ {
struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)skb_mac_header(skb); struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
...@@ -382,15 +383,11 @@ static bool sja1105_vlan_rcv(struct sk_buff *skb, int *source_port, ...@@ -382,15 +383,11 @@ static bool sja1105_vlan_rcv(struct sk_buff *skb, int *source_port,
else else
vlan_tci = ntohs(hdr->h_vlan_TCI); vlan_tci = ntohs(hdr->h_vlan_TCI);
if (vid_is_dsa_8021q_rxvlan(vlan_tci & VLAN_VID_MASK)) { if (vid_is_dsa_8021q_rxvlan(vlan_tci & VLAN_VID_MASK))
dsa_8021q_rcv(skb, source_port, switch_id); return dsa_8021q_rcv(skb, source_port, switch_id);
return false;
}
/* Try our best with imprecise RX */ /* Try our best with imprecise RX */
*vid = vlan_tci & VLAN_VID_MASK; *vid = vlan_tci & VLAN_VID_MASK;
return true;
} }
static struct sk_buff *sja1105_rcv(struct sk_buff *skb, static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
...@@ -399,7 +396,6 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, ...@@ -399,7 +396,6 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
{ {
int source_port = -1, switch_id = -1; int source_port = -1, switch_id = -1;
struct sja1105_meta meta = {0}; struct sja1105_meta meta = {0};
bool imprecise_rx = false;
struct ethhdr *hdr; struct ethhdr *hdr;
bool is_link_local; bool is_link_local;
bool is_meta; bool is_meta;
...@@ -413,8 +409,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, ...@@ -413,8 +409,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
if (sja1105_skb_has_tag_8021q(skb)) { if (sja1105_skb_has_tag_8021q(skb)) {
/* Normal traffic path. */ /* Normal traffic path. */
imprecise_rx = sja1105_vlan_rcv(skb, &source_port, &switch_id, sja1105_vlan_rcv(skb, &source_port, &switch_id, &vid);
&vid);
} else if (is_link_local) { } else if (is_link_local) {
/* Management traffic path. Switch embeds the switch ID and /* Management traffic path. Switch embeds the switch ID and
* port ID into bytes of the destination MAC, courtesy of * port ID into bytes of the destination MAC, courtesy of
...@@ -433,7 +428,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, ...@@ -433,7 +428,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
return NULL; return NULL;
} }
if (imprecise_rx) if (source_port == -1 || switch_id == -1)
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
else else
skb->dev = dsa_master_find_slave(netdev, switch_id, source_port); skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
...@@ -550,7 +545,6 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, ...@@ -550,7 +545,6 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
struct packet_type *pt) struct packet_type *pt)
{ {
int source_port = -1, switch_id = -1; int source_port = -1, switch_id = -1;
bool imprecise_rx = false;
u16 vid; u16 vid;
skb->offload_fwd_mark = 1; skb->offload_fwd_mark = 1;
...@@ -564,10 +558,9 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, ...@@ -564,10 +558,9 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
/* Packets with in-band control extensions might still have RX VLANs */ /* Packets with in-band control extensions might still have RX VLANs */
if (likely(sja1105_skb_has_tag_8021q(skb))) if (likely(sja1105_skb_has_tag_8021q(skb)))
imprecise_rx = sja1105_vlan_rcv(skb, &source_port, &switch_id, sja1105_vlan_rcv(skb, &source_port, &switch_id, &vid);
&vid);
if (imprecise_rx) if (source_port == -1 || switch_id == -1)
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
else else
skb->dev = dsa_master_find_slave(netdev, switch_id, source_port); skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment