Skip to content

Commit f7cf972

Browse files
wkzdavem330
authored andcommitted
net: bridge: disambiguate offload_fwd_mark
Before this change, four related - but distinct - concepts where named offload_fwd_mark: - skb->offload_fwd_mark: Set by the switchdev driver if the underlying hardware has already forwarded this frame to the other ports in the same hardware domain. - nbp->offload_fwd_mark: An idetifier used to group ports that share the same hardware forwarding domain. - br->offload_fwd_mark: Counter used to make sure that unique IDs are used in cases where a bridge contains ports from multiple hardware domains. - skb->cb->offload_fwd_mark: The hardware domain on which the frame ingressed and was forwarded. Introduce the term "hardware forwarding domain" ("hwdom") in the bridge to denote a set of ports with the following property: If an skb with skb->offload_fwd_mark set, is received on a port belonging to hwdom N, that frame has already been forwarded to all other ports in hwdom N. By decoupling the name from "offload_fwd_mark", we can extend the term's definition in the future - e.g. to add constraints that describe expected egress behavior - without overloading the meaning of "offload_fwd_mark". - nbp->offload_fwd_mark thus becomes nbp->hwdom. - br->offload_fwd_mark becomes br->last_hwdom. - skb->cb->offload_fwd_mark becomes skb->cb->src_hwdom. The slight change in naming here mandates a slight change in behavior of the nbp_switchdev_frame_mark() function. Previously, it only set this value in skb->cb for packets with skb->offload_fwd_mark true (ones which were forwarded in hardware). Whereas now we always track the incoming hwdom for all packets coming from a switchdev (even for the packets which weren't forwarded in hardware, such as STP BPDUs, IGMP reports etc). As all uses of skb->cb->offload_fwd_mark were already gated behind checks of skb->offload_fwd_mark, this will not introduce any functional change, but it paves the way for future changes where the ingressing hwdom must be known for frames coming from a switchdev regardless of whether they were forwarded in hardware or not (basically, if the skb comes from a switchdev, skb->cb->src_hwdom now always tracks which one). A typical example where this is relevant: the switchdev has a fixed configuration to trap STP BPDUs, but STP is not running on the bridge and the group_fwd_mask allows them to be forwarded. Say we have this setup: br0 / | \ / | \ swp0 swp1 swp2 A BPDU comes in on swp0 and is trapped to the CPU; the driver does not set skb->offload_fwd_mark. The bridge determines that the frame should be forwarded to swp{1,2}. It is imperative that forward offloading is _not_ allowed in this case, as the source hwdom is already "poisoned". Recording the source hwdom allows this case to be handled properly. v2->v3: added code comments v3->v6: none Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 45035fe commit f7cf972

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

net/bridge/br_if.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
643643
if (err)
644644
goto err5;
645645

646-
err = nbp_switchdev_mark_set(p);
646+
err = nbp_switchdev_hwdom_set(p);
647647
if (err)
648648
goto err6;
649649

net/bridge/br_private.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ struct net_bridge_port {
386386
struct netpoll *np;
387387
#endif
388388
#ifdef CONFIG_NET_SWITCHDEV
389-
int offload_fwd_mark;
389+
/* Identifier used to group ports that share the same switchdev
390+
* hardware domain.
391+
*/
392+
int hwdom;
390393
#endif
391394
u16 group_fwd_mask;
392395
u16 backup_redirected_cnt;
@@ -510,7 +513,10 @@ struct net_bridge {
510513
u32 auto_cnt;
511514

512515
#ifdef CONFIG_NET_SWITCHDEV
513-
int offload_fwd_mark;
516+
/* Counter used to make sure that hardware domains get unique
517+
* identifiers in case a bridge spans multiple switchdev instances.
518+
*/
519+
int last_hwdom;
514520
#endif
515521
struct hlist_head fdb_list;
516522

@@ -540,7 +546,12 @@ struct br_input_skb_cb {
540546
#endif
541547

542548
#ifdef CONFIG_NET_SWITCHDEV
543-
int offload_fwd_mark;
549+
/* The switchdev hardware domain from which this packet was received.
550+
* If skb->offload_fwd_mark was set, then this packet was already
551+
* forwarded by hardware to the other ports in the source hardware
552+
* domain, otherwise it wasn't.
553+
*/
554+
int src_hwdom;
544555
#endif
545556
};
546557

@@ -1829,7 +1840,7 @@ static inline void br_sysfs_delbr(struct net_device *dev) { return; }
18291840

18301841
/* br_switchdev.c */
18311842
#ifdef CONFIG_NET_SWITCHDEV
1832-
int nbp_switchdev_mark_set(struct net_bridge_port *p);
1843+
int nbp_switchdev_hwdom_set(struct net_bridge_port *p);
18331844
void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
18341845
struct sk_buff *skb);
18351846
bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
@@ -1849,7 +1860,7 @@ static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
18491860
skb->offload_fwd_mark = 0;
18501861
}
18511862
#else
1852-
static inline int nbp_switchdev_mark_set(struct net_bridge_port *p)
1863+
static inline int nbp_switchdev_hwdom_set(struct net_bridge_port *p)
18531864
{
18541865
return 0;
18551866
}

net/bridge/br_switchdev.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88

99
#include "br_private.h"
1010

11-
static int br_switchdev_mark_get(struct net_bridge *br, struct net_device *dev)
11+
static int br_switchdev_hwdom_get(struct net_bridge *br, struct net_device *dev)
1212
{
1313
struct net_bridge_port *p;
1414

1515
/* dev is yet to be added to the port list. */
1616
list_for_each_entry(p, &br->port_list, list) {
1717
if (netdev_port_same_parent_id(dev, p->dev))
18-
return p->offload_fwd_mark;
18+
return p->hwdom;
1919
}
2020

21-
return ++br->offload_fwd_mark;
21+
return ++br->last_hwdom;
2222
}
2323

24-
int nbp_switchdev_mark_set(struct net_bridge_port *p)
24+
int nbp_switchdev_hwdom_set(struct net_bridge_port *p)
2525
{
2626
struct netdev_phys_item_id ppid = { };
2727
int err;
@@ -35,23 +35,23 @@ int nbp_switchdev_mark_set(struct net_bridge_port *p)
3535
return err;
3636
}
3737

38-
p->offload_fwd_mark = br_switchdev_mark_get(p->br, p->dev);
38+
p->hwdom = br_switchdev_hwdom_get(p->br, p->dev);
3939

4040
return 0;
4141
}
4242

4343
void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
4444
struct sk_buff *skb)
4545
{
46-
if (skb->offload_fwd_mark && !WARN_ON_ONCE(!p->offload_fwd_mark))
47-
BR_INPUT_SKB_CB(skb)->offload_fwd_mark = p->offload_fwd_mark;
46+
if (p->hwdom)
47+
BR_INPUT_SKB_CB(skb)->src_hwdom = p->hwdom;
4848
}
4949

5050
bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
5151
const struct sk_buff *skb)
5252
{
5353
return !skb->offload_fwd_mark ||
54-
BR_INPUT_SKB_CB(skb)->offload_fwd_mark != p->offload_fwd_mark;
54+
BR_INPUT_SKB_CB(skb)->src_hwdom != p->hwdom;
5555
}
5656

5757
/* Flags that can be offloaded to hardware */

0 commit comments

Comments
 (0)