Commit cb307c2d authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'net-dsa-Improve-dsa_untag_bridge_pvid'

Florian Fainelli says:

====================
net: dsa: Improve dsa_untag_bridge_pvid()

This patch series is based on the recent discussions with Vladimir:

https://lore.kernel.org/netdev/20201001030623.343535-1-f.fainelli@gmail.com/



the simplest way forward was to call dsa_untag_bridge_pvid() after
eth_type_trans() has been set which guarantees that skb->protocol is set
to a correct value and this allows us to utilize
__vlan_find_dev_deep_rcu() properly without playing or using the bridge
master as a net_device reference.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c16bcd70 3a68844d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2603,6 +2603,7 @@ struct b53_device *b53_switch_alloc(struct device *base,
	dev->ops = ops;
	ds->ops = &b53_switch_ops;
	ds->configure_vlan_while_not_filtering = true;
	ds->untag_bridge_pvid = true;
	dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
	mutex_init(&dev->reg_mutex);
	mutex_init(&dev->stats_mutex);
+8 −0
Original line number Diff line number Diff line
@@ -308,6 +308,14 @@ struct dsa_switch {
	 */
	bool			configure_vlan_while_not_filtering;

	/* If the switch driver always programs the CPU port as egress tagged
	 * despite the VLAN configuration indicating otherwise, then setting
	 * @untag_bridge_pvid will force the DSA receive path to pop the bridge's
	 * default_pvid VLAN tagged frames to offer a consistent behavior
	 * between a vlan_filtering=0 and vlan_filtering=1 bridge device.
	 */
	bool			untag_bridge_pvid;

	/* In case vlan_filtering_is_global is set, the VLAN awareness state
	 * should be retrieved from here and not from the per-port settings.
	 */
+9 −0
Original line number Diff line number Diff line
@@ -225,6 +225,15 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
	skb->pkt_type = PACKET_HOST;
	skb->protocol = eth_type_trans(skb, skb->dev);

	if (unlikely(cpu_dp->ds->untag_bridge_pvid)) {
		nskb = dsa_untag_bridge_pvid(skb);
		if (!nskb) {
			kfree_skb(skb);
			return 0;
		}
		skb = nskb;
	}

	s = this_cpu_ptr(p->stats64);
	u64_stats_update_begin(&s->syncp);
	s->rx_packets++;
+4 −10
Original line number Diff line number Diff line
@@ -201,11 +201,9 @@ dsa_slave_to_master(const struct net_device *dev)
static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
{
	struct dsa_port *dp = dsa_slave_to_port(skb->dev);
	struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
	struct net_device *br = dp->bridge_dev;
	struct net_device *dev = skb->dev;
	struct net_device *upper_dev;
	struct list_head *iter;
	u16 vid, pvid, proto;
	int err;

@@ -217,7 +215,7 @@ static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
		return skb;

	/* Move VLAN tag from data to hwaccel */
	if (!skb_vlan_tag_present(skb) && hdr->h_vlan_proto == htons(proto)) {
	if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) {
		skb = skb_vlan_untag(skb);
		if (!skb)
			return NULL;
@@ -247,13 +245,9 @@ static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
	 * supports because vlan_filtering is 0. In that case, we should
	 * definitely keep the tag, to make sure it keeps working.
	 */
	netdev_for_each_upper_dev_rcu(dev, upper_dev, iter) {
		if (!is_vlan_dev(upper_dev))
			continue;

		if (vid == vlan_dev_vlan_id(upper_dev))
	upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid);
	if (upper_dev)
		return skb;
	}

	__vlan_hwaccel_clear_tag(skb);

+2 −13
Original line number Diff line number Diff line
@@ -152,11 +152,6 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
	/* Remove Broadcom tag and update checksum */
	skb_pull_rcsum(skb, BRCM_TAG_LEN);

	/* Set the MAC header to where it should point for
	 * dsa_untag_bridge_pvid() to parse the correct VLAN header.
	 */
	skb_set_mac_header(skb, -ETH_HLEN);

	skb->offload_fwd_mark = 1;

	return skb;
@@ -187,7 +182,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
		nskb->data - ETH_HLEN - BRCM_TAG_LEN,
		2 * ETH_ALEN);

	return dsa_untag_bridge_pvid(nskb);
	return nskb;
}

static const struct dsa_device_ops brcm_netdev_ops = {
@@ -214,14 +209,8 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
					    struct net_device *dev,
					    struct packet_type *pt)
{
	struct sk_buff *nskb;

	/* tag is prepended to the packet */
	nskb = brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
	if (!nskb)
		return nskb;

	return dsa_untag_bridge_pvid(nskb);
	return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
}

static const struct dsa_device_ops brcm_prepend_netdev_ops = {