Skip to content

Commit af21b94

Browse files
committed
Merge branch 'hsr-supervisor-frames'
Sebastian Andrzej Siewior says: ==================== net: hsr: Properly parse HSRv1 supervisor frames. this is a follow-up to https://lore.kernel.org/all/20230825153111.228768-1-lukma@denx.de/ replacing https://lore.kernel.org/all/20230914124731.1654059-1-lukma@denx.de/ by grabing/ adding tags and reposting with a commit message plus a missing __packed to a struct (#2) plus extending the testsuite to sover HSRv1 which is what broke here (#3-#5). HSRv0 is (was) not affected. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 6af2897 + b0e9c3b commit af21b94

File tree

3 files changed

+146
-126
lines changed

3 files changed

+146
-126
lines changed

net/hsr/hsr_framereg.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
288288

289289
/* And leave the HSR tag. */
290290
if (ethhdr->h_proto == htons(ETH_P_HSR)) {
291-
pull_size = sizeof(struct ethhdr);
291+
pull_size = sizeof(struct hsr_tag);
292292
skb_pull(skb, pull_size);
293293
total_pull_size += pull_size;
294294
}
295295

296296
/* And leave the HSR sup tag. */
297-
pull_size = sizeof(struct hsr_tag);
297+
pull_size = sizeof(struct hsr_sup_tag);
298298
skb_pull(skb, pull_size);
299299
total_pull_size += pull_size;
300300

net/hsr/hsr_main.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct hsr_vlan_ethhdr {
8383
struct hsr_sup_tlv {
8484
u8 HSR_TLV_type;
8585
u8 HSR_TLV_length;
86-
};
86+
} __packed;
8787

8888
/* HSR/PRP Supervision Frame data types.
8989
* Field names as defined in the IEC:2010 standard for HSR.

tools/testing/selftests/net/hsr/hsr_ping.sh

+143-123
Original file line numberDiff line numberDiff line change
@@ -41,61 +41,6 @@ cleanup()
4141
done
4242
}
4343

44-
ip -Version > /dev/null 2>&1
45-
if [ $? -ne 0 ];then
46-
echo "SKIP: Could not run test without ip tool"
47-
exit $ksft_skip
48-
fi
49-
50-
trap cleanup EXIT
51-
52-
for i in "$ns1" "$ns2" "$ns3" ;do
53-
ip netns add $i || exit $ksft_skip
54-
ip -net $i link set lo up
55-
done
56-
57-
echo "INFO: preparing interfaces."
58-
# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
59-
#
60-
# ns1eth1 ----- ns2eth1
61-
# hsr1 hsr2
62-
# ns1eth2 ns2eth2
63-
# | |
64-
# ns3eth1 ns3eth2
65-
# \ /
66-
# hsr3
67-
#
68-
# Interfaces
69-
ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
70-
ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
71-
ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
72-
73-
# HSRv0.
74-
ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version 0 proto 0
75-
ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 supervision 45 version 0 proto 0
76-
ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 slave2 ns3eth2 supervision 45 version 0 proto 0
77-
78-
# IP for HSR
79-
ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
80-
ip -net "$ns1" addr add dead:beef:1::1/64 dev hsr1 nodad
81-
ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
82-
ip -net "$ns2" addr add dead:beef:1::2/64 dev hsr2 nodad
83-
ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
84-
ip -net "$ns3" addr add dead:beef:1::3/64 dev hsr3 nodad
85-
86-
# All Links up
87-
ip -net "$ns1" link set ns1eth1 up
88-
ip -net "$ns1" link set ns1eth2 up
89-
ip -net "$ns1" link set hsr1 up
90-
91-
ip -net "$ns2" link set ns2eth1 up
92-
ip -net "$ns2" link set ns2eth2 up
93-
ip -net "$ns2" link set hsr2 up
94-
95-
ip -net "$ns3" link set ns3eth1 up
96-
ip -net "$ns3" link set ns3eth2 up
97-
ip -net "$ns3" link set hsr3 up
98-
9944
# $1: IP address
10045
is_v6()
10146
{
@@ -164,93 +109,168 @@ stop_if_error()
164109
fi
165110
}
166111

167-
168-
echo "INFO: Initial validation ping."
169-
# Each node has to be able each one.
170-
do_ping "$ns1" 100.64.0.2
171-
do_ping "$ns2" 100.64.0.1
172-
do_ping "$ns3" 100.64.0.1
173-
stop_if_error "Initial validation failed."
174-
175-
do_ping "$ns1" 100.64.0.3
176-
do_ping "$ns2" 100.64.0.3
177-
do_ping "$ns3" 100.64.0.2
178-
179-
do_ping "$ns1" dead:beef:1::2
180-
do_ping "$ns1" dead:beef:1::3
181-
do_ping "$ns2" dead:beef:1::1
182-
do_ping "$ns2" dead:beef:1::2
183-
do_ping "$ns3" dead:beef:1::1
184-
do_ping "$ns3" dead:beef:1::2
185-
186-
stop_if_error "Initial validation failed."
112+
do_complete_ping_test()
113+
{
114+
echo "INFO: Initial validation ping."
115+
# Each node has to be able each one.
116+
do_ping "$ns1" 100.64.0.2
117+
do_ping "$ns2" 100.64.0.1
118+
do_ping "$ns3" 100.64.0.1
119+
stop_if_error "Initial validation failed."
120+
121+
do_ping "$ns1" 100.64.0.3
122+
do_ping "$ns2" 100.64.0.3
123+
do_ping "$ns3" 100.64.0.2
124+
125+
do_ping "$ns1" dead:beef:1::2
126+
do_ping "$ns1" dead:beef:1::3
127+
do_ping "$ns2" dead:beef:1::1
128+
do_ping "$ns2" dead:beef:1::2
129+
do_ping "$ns3" dead:beef:1::1
130+
do_ping "$ns3" dead:beef:1::2
131+
132+
stop_if_error "Initial validation failed."
187133

188134
# Wait until supervisor all supervision frames have been processed and the node
189135
# entries have been merged. Otherwise duplicate frames will be observed which is
190136
# valid at this stage.
191-
WAIT=5
192-
while [ ${WAIT} -gt 0 ]
193-
do
194-
grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
195-
if [ $? -ne 0 ]
196-
then
197-
break
198-
fi
199-
sleep 1
200-
let WAIT = WAIT - 1
201-
done
137+
WAIT=5
138+
while [ ${WAIT} -gt 0 ]
139+
do
140+
grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
141+
if [ $? -ne 0 ]
142+
then
143+
break
144+
fi
145+
sleep 1
146+
let "WAIT = WAIT - 1"
147+
done
202148

203149
# Just a safety delay in case the above check didn't handle it.
204-
sleep 1
150+
sleep 1
151+
152+
echo "INFO: Longer ping test."
153+
do_ping_long "$ns1" 100.64.0.2
154+
do_ping_long "$ns1" dead:beef:1::2
155+
do_ping_long "$ns1" 100.64.0.3
156+
do_ping_long "$ns1" dead:beef:1::3
205157

206-
echo "INFO: Longer ping test."
207-
do_ping_long "$ns1" 100.64.0.2
208-
do_ping_long "$ns1" dead:beef:1::2
209-
do_ping_long "$ns1" 100.64.0.3
210-
do_ping_long "$ns1" dead:beef:1::3
158+
stop_if_error "Longer ping test failed."
211159

212-
stop_if_error "Longer ping test failed."
160+
do_ping_long "$ns2" 100.64.0.1
161+
do_ping_long "$ns2" dead:beef:1::1
162+
do_ping_long "$ns2" 100.64.0.3
163+
do_ping_long "$ns2" dead:beef:1::2
164+
stop_if_error "Longer ping test failed."
213165

214-
do_ping_long "$ns2" 100.64.0.1
215-
do_ping_long "$ns2" dead:beef:1::1
216-
do_ping_long "$ns2" 100.64.0.3
217-
do_ping_long "$ns2" dead:beef:1::2
218-
stop_if_error "Longer ping test failed."
166+
do_ping_long "$ns3" 100.64.0.1
167+
do_ping_long "$ns3" dead:beef:1::1
168+
do_ping_long "$ns3" 100.64.0.2
169+
do_ping_long "$ns3" dead:beef:1::2
170+
stop_if_error "Longer ping test failed."
219171

220-
do_ping_long "$ns3" 100.64.0.1
221-
do_ping_long "$ns3" dead:beef:1::1
222-
do_ping_long "$ns3" 100.64.0.2
223-
do_ping_long "$ns3" dead:beef:1::2
224-
stop_if_error "Longer ping test failed."
172+
echo "INFO: Cutting one link."
173+
do_ping_long "$ns1" 100.64.0.3 &
225174

226-
echo "INFO: Cutting one link."
227-
do_ping_long "$ns1" 100.64.0.3 &
175+
sleep 3
176+
ip -net "$ns3" link set ns3eth1 down
177+
wait
228178

229-
sleep 3
230-
ip -net "$ns3" link set ns3eth1 down
231-
wait
179+
ip -net "$ns3" link set ns3eth1 up
232180

233-
ip -net "$ns3" link set ns3eth1 up
181+
stop_if_error "Failed with one link down."
234182

235-
stop_if_error "Failed with one link down."
183+
echo "INFO: Delay the link and drop a few packages."
184+
tc -net "$ns3" qdisc add dev ns3eth1 root netem delay 50ms
185+
tc -net "$ns2" qdisc add dev ns2eth1 root netem delay 5ms loss 25%
236186

237-
echo "INFO: Delay the link and drop a few packages."
238-
tc -net "$ns3" qdisc add dev ns3eth1 root netem delay 50ms
239-
tc -net "$ns2" qdisc add dev ns2eth1 root netem delay 5ms loss 25%
187+
do_ping_long "$ns1" 100.64.0.2
188+
do_ping_long "$ns1" 100.64.0.3
240189

241-
do_ping_long "$ns1" 100.64.0.2
242-
do_ping_long "$ns1" 100.64.0.3
190+
stop_if_error "Failed with delay and packetloss."
243191

244-
stop_if_error "Failed with delay and packetloss."
192+
do_ping_long "$ns2" 100.64.0.1
193+
do_ping_long "$ns2" 100.64.0.3
245194

246-
do_ping_long "$ns2" 100.64.0.1
247-
do_ping_long "$ns2" 100.64.0.3
195+
stop_if_error "Failed with delay and packetloss."
248196

249-
stop_if_error "Failed with delay and packetloss."
197+
do_ping_long "$ns3" 100.64.0.1
198+
do_ping_long "$ns3" 100.64.0.2
199+
stop_if_error "Failed with delay and packetloss."
200+
201+
echo "INFO: All good."
202+
}
203+
204+
setup_hsr_interfaces()
205+
{
206+
local HSRv="$1"
207+
208+
echo "INFO: preparing interfaces for HSRv${HSRv}."
209+
# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
210+
#
211+
# ns1eth1 ----- ns2eth1
212+
# hsr1 hsr2
213+
# ns1eth2 ns2eth2
214+
# | |
215+
# ns3eth1 ns3eth2
216+
# \ /
217+
# hsr3
218+
#
219+
# Interfaces
220+
ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
221+
ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
222+
ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
223+
224+
# HSRv0/1
225+
ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version $HSRv proto 0
226+
ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 supervision 45 version $HSRv proto 0
227+
ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 slave2 ns3eth2 supervision 45 version $HSRv proto 0
228+
229+
# IP for HSR
230+
ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
231+
ip -net "$ns1" addr add dead:beef:1::1/64 dev hsr1 nodad
232+
ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
233+
ip -net "$ns2" addr add dead:beef:1::2/64 dev hsr2 nodad
234+
ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
235+
ip -net "$ns3" addr add dead:beef:1::3/64 dev hsr3 nodad
236+
237+
# All Links up
238+
ip -net "$ns1" link set ns1eth1 up
239+
ip -net "$ns1" link set ns1eth2 up
240+
ip -net "$ns1" link set hsr1 up
241+
242+
ip -net "$ns2" link set ns2eth1 up
243+
ip -net "$ns2" link set ns2eth2 up
244+
ip -net "$ns2" link set hsr2 up
245+
246+
ip -net "$ns3" link set ns3eth1 up
247+
ip -net "$ns3" link set ns3eth2 up
248+
ip -net "$ns3" link set hsr3 up
249+
}
250+
251+
ip -Version > /dev/null 2>&1
252+
if [ $? -ne 0 ];then
253+
echo "SKIP: Could not run test without ip tool"
254+
exit $ksft_skip
255+
fi
256+
257+
trap cleanup EXIT
258+
259+
for i in "$ns1" "$ns2" "$ns3" ;do
260+
ip netns add $i || exit $ksft_skip
261+
ip -net $i link set lo up
262+
done
263+
264+
setup_hsr_interfaces 0
265+
do_complete_ping_test
266+
cleanup
267+
268+
for i in "$ns1" "$ns2" "$ns3" ;do
269+
ip netns add $i || exit $ksft_skip
270+
ip -net $i link set lo up
271+
done
250272

251-
do_ping_long "$ns3" 100.64.0.1
252-
do_ping_long "$ns3" 100.64.0.2
253-
stop_if_error "Failed with delay and packetloss."
273+
setup_hsr_interfaces 1
274+
do_complete_ping_test
254275

255-
echo "INFO: All good."
256276
exit $ret

0 commit comments

Comments
 (0)