Skip to content

Commit 6bc506b

Browse files
idoschdavem330
authored andcommitted
bridge: switchdev: Add forward mark support for stacked devices
switchdev_port_fwd_mark_set() is used to set the 'offload_fwd_mark' of port netdevs so that packets being flooded by the device won't be flooded twice. It works by assigning a unique identifier (the ifindex of the first bridge port) to bridge ports sharing the same parent ID. This prevents packets from being flooded twice by the same switch, but will flood packets through bridge ports belonging to a different switch. This method is problematic when stacked devices are taken into account, such as VLANs. In such cases, a physical port netdev can have upper devices being members in two different bridges, thus requiring two different 'offload_fwd_mark's to be configured on the port netdev, which is impossible. The main problem is that packet and netdev marking is performed at the physical netdev level, whereas flooding occurs between bridge ports, which are not necessarily port netdevs. Instead, packet and netdev marking should really be done in the bridge driver with the switch driver only telling it which packets it already forwarded. The bridge driver will mark such packets using the mark assigned to the ingress bridge port and will prevent the packet from being forwarded through any bridge port sharing the same mark (i.e. having the same parent ID). Remove the current switchdev 'offload_fwd_mark' implementation and instead implement the proposed method. In addition, make rocker - the sole user of the mark - use the proposed method. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5c326ab commit 6bc506b

14 files changed

Lines changed: 117 additions & 132 deletions

File tree

‎Documentation/networking/switchdev.txt‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,10 @@ be sent to the port netdev for processing by the bridge driver. The
283283
bridge should not reflood the packet to the same ports the device flooded,
284284
otherwise there will be duplicate packets on the wire.
285285

286-
To avoid duplicate packets, the device/driver should mark a packet as already
287-
forwarded using skb->offload_fwd_mark. The same mark is set on the device
288-
ports in the domain using dev->offload_fwd_mark. If the skb->offload_fwd_mark
289-
is non-zero and matches the forwarding egress port's dev->skb_mark, the kernel
290-
will drop the skb right before transmit on the egress port, with the
291-
understanding that the device already forwarded the packet on same egress port.
292-
The driver can use switchdev_port_fwd_mark_set() to set a globally unique mark
293-
for port's dev->offload_fwd_mark, based on the port's parent ID (switch ID) and
294-
a group ifindex.
286+
To avoid duplicate packets, the switch driver should mark a packet as already
287+
forwarded by setting the skb->offload_fwd_mark bit. The bridge driver will mark
288+
the skb using the ingress bridge port's mark and prevent it from being forwarded
289+
through any bridge port with the same mark.
295290

296291
It is possible for the switch device to not handle flooding and push the
297292
packets up to the bridge driver for flooding. This is not ideal as the number

‎drivers/net/ethernet/rocker/rocker_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ static int rocker_port_rx_proc(const struct rocker *rocker,
24122412
skb->protocol = eth_type_trans(skb, rocker_port->dev);
24132413

24142414
if (rx_flags & ROCKER_RX_FLAGS_FWD_OFFLOAD)
2415-
skb->offload_fwd_mark = rocker_port->dev->offload_fwd_mark;
2415+
skb->offload_fwd_mark = 1;
24162416

24172417
rocker_port->dev->stats.rx_packets++;
24182418
rocker_port->dev->stats.rx_bytes += skb->len;

‎drivers/net/ethernet/rocker/rocker_ofdpa.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,6 @@ static int ofdpa_port_init(struct rocker_port *rocker_port)
25582558
struct ofdpa_port *ofdpa_port = rocker_port->wpriv;
25592559
int err;
25602560

2561-
switchdev_port_fwd_mark_set(ofdpa_port->dev, NULL, false);
25622561
rocker_port_set_learning(rocker_port,
25632562
!!(ofdpa_port->brport_flags & BR_LEARNING));
25642563

@@ -2817,7 +2816,6 @@ static int ofdpa_port_bridge_join(struct ofdpa_port *ofdpa_port,
28172816
ofdpa_port_internal_vlan_id_get(ofdpa_port, bridge->ifindex);
28182817

28192818
ofdpa_port->bridge_dev = bridge;
2820-
switchdev_port_fwd_mark_set(ofdpa_port->dev, bridge, true);
28212819

28222820
return ofdpa_port_vlan_add(ofdpa_port, NULL, OFDPA_UNTAGGED_VID, 0);
28232821
}
@@ -2836,8 +2834,6 @@ static int ofdpa_port_bridge_leave(struct ofdpa_port *ofdpa_port)
28362834
ofdpa_port_internal_vlan_id_get(ofdpa_port,
28372835
ofdpa_port->dev->ifindex);
28382836

2839-
switchdev_port_fwd_mark_set(ofdpa_port->dev, ofdpa_port->bridge_dev,
2840-
false);
28412837
ofdpa_port->bridge_dev = NULL;
28422838

28432839
err = ofdpa_port_vlan_add(ofdpa_port, NULL, OFDPA_UNTAGGED_VID, 0);

‎include/linux/netdevice.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,6 @@ enum netdev_priv_flags {
15621562
*
15631563
* @xps_maps: XXX: need comments on this one
15641564
*
1565-
* @offload_fwd_mark: Offload device fwding mark
1566-
*
15671565
* @watchdog_timeo: Represents the timeout that is used by
15681566
* the watchdog (see dev_watchdog())
15691567
* @watchdog_timer: List of timers
@@ -1814,9 +1812,6 @@ struct net_device {
18141812
#ifdef CONFIG_NET_CLS_ACT
18151813
struct tcf_proto __rcu *egress_cl_list;
18161814
#endif
1817-
#ifdef CONFIG_NET_SWITCHDEV
1818-
u32 offload_fwd_mark;
1819-
#endif
18201815

18211816
/* These may be needed for future network-power-down code. */
18221817
struct timer_list watchdog_timer;

‎include/linux/skbuff.h‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,
612612
* @no_fcs: Request NIC to treat last 4 bytes as Ethernet FCS
613613
* @napi_id: id of the NAPI struct this skb came from
614614
* @secmark: security marking
615-
* @offload_fwd_mark: fwding offload mark
616615
* @mark: Generic packet mark
617616
* @vlan_proto: vlan encapsulation protocol
618617
* @vlan_tci: vlan tag control information
@@ -730,7 +729,10 @@ struct sk_buff {
730729
__u8 ipvs_property:1;
731730
__u8 inner_protocol_type:1;
732731
__u8 remcsum_offload:1;
733-
/* 3 or 5 bit hole */
732+
#ifdef CONFIG_NET_SWITCHDEV
733+
__u8 offload_fwd_mark:1;
734+
#endif
735+
/* 2, 4 or 5 bit hole */
734736

735737
#ifdef CONFIG_NET_SCHED
736738
__u16 tc_index; /* traffic control index */
@@ -757,14 +759,9 @@ struct sk_buff {
757759
unsigned int sender_cpu;
758760
};
759761
#endif
760-
union {
761762
#ifdef CONFIG_NETWORK_SECMARK
762-
__u32 secmark;
763+
__u32 secmark;
763764
#endif
764-
#ifdef CONFIG_NET_SWITCHDEV
765-
__u32 offload_fwd_mark;
766-
#endif
767-
};
768765

769766
union {
770767
__u32 mark;

‎include/net/switchdev.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,6 @@ static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
347347
return idx;
348348
}
349349

350-
static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
351-
struct net_device *group_dev,
352-
bool joining)
353-
{
354-
}
355-
356350
static inline bool switchdev_port_same_parent_id(struct net_device *a,
357351
struct net_device *b)
358352
{

‎net/bridge/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o
2020

2121
bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o
2222

23+
bridge-$(CONFIG_NET_SWITCHDEV) += br_switchdev.o
24+
2325
obj-$(CONFIG_NETFILTER) += netfilter/

‎net/bridge/br_forward.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static inline int should_deliver(const struct net_bridge_port *p,
2929

3030
vg = nbp_vlan_group_rcu(p);
3131
return ((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) &&
32-
br_allowed_egress(vg, skb) && p->state == BR_STATE_FORWARDING;
32+
br_allowed_egress(vg, skb) && p->state == BR_STATE_FORWARDING &&
33+
nbp_switchdev_allowed_egress(p, skb);
3334
}
3435

3536
int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)

‎net/bridge/br_if.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
545545
if (err)
546546
goto err5;
547547

548+
err = nbp_switchdev_mark_set(p);
549+
if (err)
550+
goto err6;
551+
548552
dev_disable_lro(dev);
549553

550554
list_add_rcu(&p->list, &br->port_list);
@@ -566,7 +570,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
566570
err = nbp_vlan_init(p);
567571
if (err) {
568572
netdev_err(dev, "failed to initialize vlan filtering on this port\n");
569-
goto err6;
573+
goto err7;
570574
}
571575

572576
spin_lock_bh(&br->lock);
@@ -589,12 +593,12 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
589593

590594
return 0;
591595

592-
err6:
596+
err7:
593597
list_del_rcu(&p->list);
594598
br_fdb_delete_by_port(br, p, 0, 1);
595599
nbp_update_port_count(br);
600+
err6:
596601
netdev_upper_dev_unlink(dev, br->dev);
597-
598602
err5:
599603
dev->priv_flags &= ~IFF_BRIDGE_PORT;
600604
netdev_rx_handler_unregister(dev);

‎net/bridge/br_input.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb
145145
if (!br_allowed_ingress(p->br, nbp_vlan_group_rcu(p), skb, &vid))
146146
goto out;
147147

148+
nbp_switchdev_frame_mark(p, skb);
149+
148150
/* insert into forwarding database after filtering to avoid spoofing */
149151
br = p->br;
150152
if (p->flags & BR_LEARNING)

0 commit comments

Comments
 (0)