net: hsr: Fix PRP duplicate detection
Subsystems (3)
PATCH v5 1/2 net: hsr: Fix PRP duplicate detection
Add PRP specific function for handling duplicate packets. This is needed because of potential L2 802.1p prioritization done by network switches.
The L2 prioritization can re-order the PRP packets from a node causing the existing implementation to discard the frame(s) that have been received 'late' because the sequence number is before the previous received packet. This can happen if the node is sending multiple frames back-to-back with different priority.
---
Changes in v3:
- Fixed indentation
- Renamed local variables
Changes in v4:
- Fix indentation issues missed in previous version
Thanks to Paolo and Simon for reviewing!
net/hsr/hsr_device.c | 2 + net/hsr/hsr_forward.c | 4 +- net/hsr/hsr_framereg.c | 95 ++++++++++++++++++++++++++++++++++++++++-- net/hsr/hsr_framereg.h | 8 +++- net/hsr/hsr_main.h | 2 + 5 files changed, 104 insertions(+), 7 deletions(-)
net/hsr/hsr_device.c +2 -0
@@ -616,6 +616,7 @@ static struct hsr_proto_ops hsr_ops = { .drop_frame = hsr_drop_frame, .fill_frame_info = hsr_fill_frame_info, .invalid_dan_ingress_frame = hsr_invalid_dan_ingress_frame, + .register_frame_out = hsr_register_frame_out, };static struct hsr_proto_ops prp_ops = {
@@ -626,6 +627,7 @@ static struct hsr_proto_ops prp_ops = { .fill_frame_info = prp_fill_frame_info, .handle_san_frame = prp_handle_san_frame, .update_san_info = prp_update_san_info, + .register_frame_out = prp_register_frame_out, };void hsr_dev_setup (struct net_device *dev)
net/hsr/hsr_forward.c +2 -2
@@ -536,8 +536,8 @@ static void hsr_forward_do(struct hsr_frame_info *frame)* Also for SAN, this shouldn't be done. */ if (!frame->is_from_san && -hsr_register_frame_out (port, frame->node_src, - frame->sequence_nr)) + hsr->proto_ops->register_frame_out && + hsr->proto_ops->register_frame_out (port, frame))continue ; if (frame->is_supervision && port->type == HSR_PT_MASTER &&
net/hsr/hsr_framereg.c +92 -3
121 lines not on this page · raw message
net/hsr/hsr_framereg.h +6 -2
@@ -44,8 +44,7 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,void hsr_register_frame_in (struct hsr_node *node,struct hsr_port *port,u16 sequence_nr); -int hsr_register_frame_out (struct hsr_port *port,struct hsr_node *node, -u16 sequence_nr); +int hsr_register_frame_out (struct hsr_port *port,struct hsr_frame_info *frame);void hsr_prune_nodes (struct timer_list *t);void hsr_prune_proxy_nodes (struct timer_list *t);
@@ -73,6 +72,8 @@ void prp_update_san_info(struct hsr_node *node, bool is_sup);bool hsr_is_node_in_db (struct list_head *node_db,const unsigned char addr[ETH_ALEN ]); +int prp_register_frame_out (struct hsr_port *port,struct hsr_frame_info *frame); +struct hsr_node {struct list_head mac_list;/* Protect R/W access to seq_out */
@@ -89,6 +90,9 @@ struct hsr_node {bool san_b;u16 seq_out[HSR_PT_PORTS ];bool removed; +/* PRP specific duplicate handling */ +u16 seq_expected[HSR_PT_PORTS ]; +u16 seq_start[HSR_PT_PORTS ];struct rcu_head rcu_head; };
net/hsr/hsr_main.h +2 -0
@@ -175,6 +175,8 @@ struct hsr_proto_ops { struct hsr_frame_info *frame);bool (*invalid_dan_ingress_frame)(__be16 protocol);void (*update_san_info)(struct hsr_node *node,bool is_sup); +int (*register_frame_out)(struct hsr_port *port, +struct hsr_frame_info *frame); };struct hsr_self_node {
Signature · 1 line
2.43.0
PATCH v5 2/2 net: hsr: Add KUnit test for PRP
Add unit tests for the PRP duplicate detection
---
Changes in v2:
- Changed KUnit tests to compile as built-in only Changes in v3:
- Changed the KUnit tests to compile as a module Changes in v4:
- Use IS_MODULE for checking if the unit test is compiled as a loadable module
Changes in v5:
- Use correct define in IS_MODULE()
Thanks to Paolo and Simon for reviewing!
net/hsr/Kconfig | 18 +++ net/hsr/Makefile | 2 + net/hsr/hsr_framereg.c | 4 + net/hsr/prp_dup_discard_test.c | 212 +++++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 net/hsr/prp_dup_discard_test.c
net/hsr/Kconfig +18 -0
@@ -38,3 +38,21 @@ config HSR relying on this code in a safety critical system! If unsure, say N. + +if HSR + +config PRP_DUP_DISCARD_KUNIT_TEST + tristate "PRP duplicate discard KUnit tests" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Covers the PRP duplicate discard algorithm. + Only useful for kernel devs running KUnit test harness and are not + for inclusion into a production build. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + +endif
net/hsr/Makefile +2 -0
@@ -8,3 +8,5 @@ obj-$(CONFIG_HSR) += hsr.o hsr-y := hsr_main.o hsr_framereg.o hsr_device.o \ hsr_netlink.o hsr_slave.o hsr_forward.o hsr-$(CONFIG_DEBUG_FS) += hsr_debugfs.o + +obj-$(CONFIG_PRP_DUP_DISCARD_KUNIT_TEST) += prp_dup_discard_test.o
net/hsr/hsr_framereg.c +4 -0
@@ -588,6 +588,10 @@ int prp_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame)return 0 ; } +#if IS_MODULE (CONFIG_PRP_DUP_DISCARD_KUNIT_TEST ) +EXPORT_SYMBOL (prp_register_frame_out); +#endif +static struct hsr_port *get_late_port (struct hsr_priv *hsr,struct hsr_node *node) {
net/hsr/prp_dup_discard_test.c new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.43.0
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 12 lines · On Fri, 7 Mar 2025 18:16:59 +0200 you wrote:
Add PRP specific function for handling duplicate packets. This is needed because of potential L2 802.1p prioritization done by network switches.
The L2 prioritization can re-order the PRP packets from a node causing the existing implementation to discard the frame(s) that have been received 'late' because the sequence number is before the previous received packet. This can happen if the node is sending multiple frames back-to-back with different priority.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v5,1/2] net: hsr: Fix PRP duplicate detection
https://git.kernel.org/netdev/net-next/c/05fd00e5e7b1 - [net-next,v5,2/2] net: hsr: Add KUnit test for PRP https://git.kernel.org/netdev/net-next/c/814dbf4b6c95
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html