net/bridge: add drop reasons for bridge forwarding
Subsystems (3)
PATCH 1/1 net/bridge: add drop reasons for bridge forwarding
From: xu xin <[email protected]>
This creates six drop reasons as follows, which will help users know the specific reason why bridge drops the packets when forwarding.
1) SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup port link when the destination port is down.
2) SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT: destination port is the same with originating port when forwarding by a bridge.
3) SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE: the bridge's state is not forwarding.
4) SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port due to vlan filtering.
5) SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port which is offloaded by a hardware switchdev, checked by nbp_switchdev_allowed_egress().
6) SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED: both source port and dest port are in BR_ISOLATED state when bridge forwarding.
--- include/net/dropreason.h | 33 ++++++++++++++++++++++++++++++++ net/bridge/br_forward.c | 49 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 71 insertions(+), 11 deletions(-)
include/net/dropreason.h +33 -0
@@ -78,6 +78,12 @@ FN(IPV6_NDISC_BAD_CODE) \ FN(IPV6_NDISC_BAD_OPTIONS) \ FN(IPV6_NDISC_NS_OTHERHOST) \ + FN(BRIDGE_FWD_NO_BACKUP_PORT) \ + FN(BRIDGE_FWD_SAME_PORT) \ + FN(BRIDGE_NON_FORWARDING_STATE) \ + FN(BRIDGE_NOT_ALLOWED_EGRESS) \ + FN(BRIDGE_SWDEV_NOT_ALLOWED_EGRESS) \ + FN(BRIDGE_BOTH_PORT_ISOLATED) \ FNe(MAX)/**
@@ -338,6 +344,33 @@ enum skb_drop_reason {* for another host. */ SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST , +/** @SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup +* port link when the destination port is down. +*/ +SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT , +/** @SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT: destination port is the same +* with originating port when forwarding by a bridge. +*/ +SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT , +/** @SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE: the bridge's state is +* not forwarding. +*/ +SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE , +/** @SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS: the packet is not allowed +* to go out through the port due to vlan filtering. +*/ +SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS , +/** @SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS: the packet is not +* allowed to go out through the port which is offloaded by a hardware +* switchdev, checked by nbp_switchdev_allowed_egress(). E.g, the source +* switchdev is the same with the switchdev by which the dest port is +* offloaded. +*/ +SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS , +/** @SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED: both source port and dest +* port are in BR_ISOLATED state when bridge forwarding. +*/ +SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED ,/** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason'
net/bridge/br_forward.c +38 -11
93 lines not on this page · raw message
Signature · 1 line
2.15.2
Jakub Kicinski
maintainerQuoted 25 lines · On Thu, 6 Apr 2023 19:30:34 +0800 (CST) [email protected] wrote:
From: xu xin <[email protected]>
This creates six drop reasons as follows, which will help users know the specific reason why bridge drops the packets when forwarding.
1)
SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup port link when the destination port is down.2)
SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT: destination port is the same with originating port when forwarding by a bridge.3)
SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE: the bridge's state is not forwarding.4)
SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port due to vlan filtering.5)
SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port which is offloaded by a hardware switchdev, checked bynbp_switchdev_allowed_egress().6)
SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED: both source port and dest port are inBR_ISOLATEDstate when bridge forwarding.
include/net/dropreason.h enum skb_drop_reason { · line 349
Quoted 6 lines
include/net/dropreason.h +3
-0@@ -338,6 +344,33 @@ enum skb_drop_reason {* for another host. */ SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST, +/** @SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup +* port link when the destination port is down. +*/
That's not valid kdoc. Text can be on the same line as the value only in one-line comments. Otherwise:
/** * @VALUE: bla bla bla * more blas. */
Quoted 27 lines
net/bridge/br_forward.c +19
-4+static inline bool should_deliver (const struct net_bridge_port *p,const struct sk_buff *skb, +enum skb_drop_reason *need_reason) {struct net_bridge_vlan_group *vg; +enum skb_drop_reason reason; vg =nbp_vlan_group_rcu (p); -return ((p->flags &BR_HAIRPIN_MODE ) || skb->dev != p->dev) && - p->state ==BR_STATE_FORWARDING &&br_allowed_egress (vg, skb) && -nbp_switchdev_allowed_egress (p, skb) && - !br_skb_isolated (p, skb); +if (!(p->flags &BR_HAIRPIN_MODE ) && skb->dev == p->dev) { + reason =SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT ; + goto undeliverable; + } +if (p->state !=BR_STATE_FORWARDING ) { + reason =SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE ; + goto undeliverable; + } +if (!br_allowed_egress (vg, skb)) { + reason =SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS ; + goto undeliverable; + } +if (!nbp_switchdev_allowed_egress (p, skb)) { + reason =SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS ; + goto undeliverable; + }
net/bridge/br_forward.c line 53
Quoted 10 lines
net/bridge/br_forward.c +10
-0+if (br_skb_isolated (p, skb)) { + reason =SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED ; + goto undeliverable; + } +return true; + +undeliverable: +if (need_reason) + *need_reason = reason; +return false;
You can return the reason from this function. That's the whole point of SKB_NOT_DROPPED_YET existing and being equal to 0.
Which is not to say that I know whether the reasons are worth adding here. We'll need to hear from bridge experts on that.
Quoted 35 lines · On Thu, 6 Apr 2023 19:30:34 +0800 (CST) [email protected] wrote:
Quoted 25 lines
From: xu xin <[email protected]>
This creates six drop reasons as follows, which will help users know the specific reason why bridge drops the packets when forwarding.
1)
SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup port link when the destination port is down.2)
SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT: destination port is the same with originating port when forwarding by a bridge.3)
SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE: the bridge's state is not forwarding.4)
SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port due to vlan filtering.5)
SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port which is offloaded by a hardware switchdev, checked bynbp_switchdev_allowed_egress().6)
SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED: both source port and dest port are inBR_ISOLATEDstate when bridge forwarding.include/net/dropreason.h enum skb_drop_reason { · line 349
Quoted 6 lines
include/net/dropreason.h +3
-0@@ -338,6 +344,33 @@ enum skb_drop_reason {* for another host. */ SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST, +/** @SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup +* port link when the destination port is down. +*/ That's not valid kdoc. Text can be on the same line as the value only in one-line comments. Otherwise:
Quoted 5 lines
/** * @VALUE: bla bla bla * more blas. */
Ok, I didn't notice that.
Quoted 32 lines
Quoted 32 lines
net/bridge/br_forward.c +24
-4+static inline bool should_deliver (const struct net_bridge_port *p,const struct sk_buff *skb, +enum skb_drop_reason *need_reason) {struct net_bridge_vlan_group *vg; +enum skb_drop_reason reason; vg =nbp_vlan_group_rcu (p); -return ((p->flags &BR_HAIRPIN_MODE ) || skb->dev != p->dev) && - p->state ==BR_STATE_FORWARDING &&br_allowed_egress (vg, skb) && -nbp_switchdev_allowed_egress (p, skb) && - !br_skb_isolated (p, skb); +if (!(p->flags &BR_HAIRPIN_MODE ) && skb->dev == p->dev) { + reason =SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT ; + goto undeliverable; + } +if (p->state !=BR_STATE_FORWARDING ) { + reason =SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE ; + goto undeliverable; + } +if (!br_allowed_egress (vg, skb)) { + reason =SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS ; + goto undeliverable; + } +if (!nbp_switchdev_allowed_egress (p, skb)) { + reason =SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS ; + goto undeliverable; + } +if (br_skb_isolated (p, skb)) { + reason =SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED ; + goto undeliverable; + } +return true;
Quoted 9 lines
net/bridge/br_forward.c line 53
Quoted 5 lines
net/bridge/br_forward.c +5
-0+ +undeliverable: +if (need_reason) + *need_reason = reason; +return false;You can return the reason from this function. That's the whole point of
SKB_NOT_DROPPED_YETexisting and being equal to 0.
If returning the reasons, then the funtion will have to be renamed because 'should_deliever()' is expected to return a non-zero value when it's ok to deliever. I don't want to change the name here, and it's better to keep its name and use the pointer to store the reasons.
Quoted 2 lines
Which is not to say that I know whether the reasons are worth adding here. We'll need to hear from bridge experts on that.
Jakub Kicinski
maintainerQuoted 7 lines · On Wed, 12 Apr 2023 09:33:10 +0800 xu xin wrote:
Quoted 2 lines
You can return the reason from this function. That's the whole point of
SKB_NOT_DROPPED_YETexisting and being equal to 0.If returning the reasons, then the funtion will have to be renamed because '
should_deliever()' is expected to return a non-zero value when it's ok to deliever. I don't want to change the name here, and it's better to keep its name and use the pointer to store the reasons.
Sure. You have to touch all callers, anyway, you can as well adjust the name.
Nikolay Aleksandrov
maintainerQuoted 24 lines · On 06/04/2023 14:30, [email protected] wrote:
From: xu xin <[email protected]>
This creates six drop reasons as follows, which will help users know the specific reason why bridge drops the packets when forwarding.
1)
SKB_DROP_REASON_BRIDGE_FWD_NO_BACKUP_PORT: failed to get a backup port link when the destination port is down.2)
SKB_DROP_REASON_BRIDGE_FWD_SAME_PORT: destination port is the same with originating port when forwarding by a bridge.3)
SKB_DROP_REASON_BRIDGE_NON_FORWARDING_STATE: the bridge's state is not forwarding.4)
SKB_DROP_REASON_BRIDGE_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port due to vlan filtering.5)
SKB_DROP_REASON_BRIDGE_SWDEV_NOT_ALLOWED_EGRESS: the packet is not allowed to go out through the port which is offloaded by a hardware switchdev, checked bynbp_switchdev_allowed_egress().6)
SKB_DROP_REASON_BRIDGE_BOTH_PORT_ISOLATED: both source port and dest port are inBR_ISOLATEDstate when bridge forwarding.
Quoted 9 lines
Signed-off-by xu xin <[email protected]>Reviewed-by Zhang Yunkai <[email protected]>Reviewed-by Yang Yang <[email protected]>Cc Xuexin Jiang <[email protected]>--- include/net/dropreason.h | 33 ++++++++++++++++++++++++++++++++ net/bridge/br_forward.c | 49 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 71 insertions(+), 11 deletions(-)
In addition to Jakub's comments, next time please CC bridge maintainers. I just noticed this patch now.
Thanks,
Nik