Skip to content

Commit d124cf5

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user()
A new tagging protocol implementation based on tag_8021q is on the horizon, and it appears that it also has to open-code the complicated logic of finding a source port based on a VLAN header. Create a single dsa_tag_8021q_find_user() and make sja1105 call it. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: Pawel Dembicki <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 823e5cc commit d124cf5

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

net/dsa/tag_8021q.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
468468
}
469469
EXPORT_SYMBOL_GPL(dsa_8021q_xmit);
470470

471-
struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
472-
int vbid)
471+
static struct net_device *
472+
dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid)
473473
{
474474
struct dsa_port *cpu_dp = conduit->dsa_ptr;
475475
struct dsa_switch_tree *dst = cpu_dp->dst;
@@ -495,7 +495,20 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
495495

496496
return NULL;
497497
}
498-
EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid);
498+
499+
struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit,
500+
int source_port, int switch_id,
501+
int vid, int vbid)
502+
{
503+
/* Always prefer precise source port information, if available */
504+
if (source_port != -1 && switch_id != -1)
505+
return dsa_conduit_find_user(conduit, switch_id, source_port);
506+
else if (vbid >= 1)
507+
return dsa_tag_8021q_find_port_by_vbid(conduit, vbid);
508+
509+
return dsa_find_designated_bridge_port_by_vid(conduit, vid);
510+
}
511+
EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_user);
499512

500513
/**
501514
* dsa_8021q_rcv - Decode source information from tag_8021q header

net/dsa/tag_8021q.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
1616
void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
1717
int *vbid, int *vid);
1818

19-
struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
20-
int vbid);
19+
struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit,
20+
int source_port, int switch_id,
21+
int vid, int vbid);
2122

2223
int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
2324
struct dsa_notifier_tag_8021q_vlan_info *info);

net/dsa/tag_sja1105.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,8 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
509509
*/
510510
return NULL;
511511

512-
if (source_port != -1 && switch_id != -1)
513-
skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port);
514-
else if (vbid >= 1)
515-
skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid);
516-
else
517-
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
512+
skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id,
513+
vid, vbid);
518514
if (!skb->dev) {
519515
netdev_warn(netdev, "Couldn't decode source port\n");
520516
return NULL;
@@ -652,12 +648,9 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
652648
if (likely(sja1105_skb_has_tag_8021q(skb)))
653649
dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid);
654650

655-
if (source_port != -1 && switch_id != -1)
656-
skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port);
657-
else if (vbid >= 1)
658-
skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid);
659-
else
660-
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
651+
skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id,
652+
vid, vbid);
653+
661654
if (!skb->dev) {
662655
netdev_warn(netdev, "Couldn't decode source port\n");
663656
return NULL;

0 commit comments

Comments
 (0)