Skip to content

Commit c1ae02d

Browse files
vladimirolteanPaolo Abeni
authored andcommitted
net: dsa: tag_sja1105: always prefer source port information from INCL_SRCPT
Currently the sja1105 tagging protocol prefers using the source port information from the VLAN header if that is available, falling back to the INCL_SRCPT option if it isn't. The VLAN header is available for all frames except for META frames initiated by the switch (containing RX timestamps), and thus, the "if (is_link_local)" branch is practically dead. The tag_8021q source port identification has become more loose ("imprecise") and will report a plausible rather than exact bridge port, when under a bridge (be it VLAN-aware or VLAN-unaware). But link-local traffic always needs to know the precise source port. With incorrect source port reporting, for example PTP traffic over 2 bridged ports will all be seen on sockets opened on the first such port, which is incorrect. Now that the tagging protocol has been changed to make link-local frames always contain source port information, we can reverse the order of the checks so that we always give precedence to that information (which is always precise) in lieu of the tag_8021q VID which is only precise for a standalone port. Fixes: d7f9787 ("net: dsa: tag_8021q: add support for imprecise RX based on the VBID") Fixes: 91495f2 ("net: dsa: tag_8021q: replace the SVL bridging with VLAN-unaware IVL bridging") Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent b4638af commit c1ae02d

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

net/dsa/tag_sja1105.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
545545
is_link_local = sja1105_is_link_local(skb);
546546
is_meta = sja1105_is_meta_frame(skb);
547547

548-
if (sja1105_skb_has_tag_8021q(skb)) {
549-
/* Normal traffic path. */
550-
sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid);
551-
} else if (is_link_local) {
548+
if (is_link_local) {
552549
/* Management traffic path. Switch embeds the switch ID and
553550
* port ID into bytes of the destination MAC, courtesy of
554551
* the incl_srcpt options.
@@ -562,16 +559,39 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
562559
sja1105_meta_unpack(skb, &meta);
563560
source_port = meta.source_port;
564561
switch_id = meta.switch_id;
565-
} else {
562+
}
563+
564+
/* Normal data plane traffic and link-local frames are tagged with
565+
* a tag_8021q VLAN which we have to strip
566+
*/
567+
if (sja1105_skb_has_tag_8021q(skb)) {
568+
int tmp_source_port = -1, tmp_switch_id = -1;
569+
570+
sja1105_vlan_rcv(skb, &tmp_source_port, &tmp_switch_id, &vbid,
571+
&vid);
572+
/* Preserve the source information from the INCL_SRCPT option,
573+
* if available. This allows us to not overwrite a valid source
574+
* port and switch ID with zeroes when receiving link-local
575+
* frames from a VLAN-unaware bridged port (non-zero vbid) or a
576+
* VLAN-aware bridged port (non-zero vid).
577+
*/
578+
if (source_port == -1)
579+
source_port = tmp_source_port;
580+
if (switch_id == -1)
581+
switch_id = tmp_switch_id;
582+
} else if (source_port == -1 && switch_id == -1) {
583+
/* Packets with no source information have no chance of
584+
* getting accepted, drop them straight away.
585+
*/
566586
return NULL;
567587
}
568588

569-
if (vbid >= 1)
589+
if (source_port != -1 && switch_id != -1)
590+
skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
591+
else if (vbid >= 1)
570592
skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid);
571-
else if (source_port == -1 || switch_id == -1)
572-
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
573593
else
574-
skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
594+
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
575595
if (!skb->dev) {
576596
netdev_warn(netdev, "Couldn't decode source port\n");
577597
return NULL;

0 commit comments

Comments
 (0)