Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
#	$NetBSD: t_ra.sh,v 1.32.6.1 2019/10/23 19:33:07 martin Exp $
#
# Copyright (c) 2015 Internet Initiative Japan Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

RUMPSRV=unix://r1
RUMPSRV1_2=unix://r12
RUMPCLI=unix://r2
RUMPSRV3=unix://r3
RUMPSRV4=unix://r4
IP6SRV=fc00:1::1
IP6SRV1_2=fc00:1::2
IP6SRV_PREFIX=fc00:1:
IP6CLI=fc00:2::2
IP6SRV3=fc00:3::1
IP6SRV3_PREFIX=fc00:3:
IP6SRV4=fc00:4::1
IP6SRV4_PREFIX=fc00:4:
PIDFILE=./rump.rtadvd.pid
PIDFILE1_2=./rump.rtadvd.pid12
PIDFILE3=./rump.rtadvd.pid3
PIDFILE4=./rump.rtadvd.pid4
CONFIG=./rtadvd.conf
DEBUG=${DEBUG:-false}

RUMP_PROGS="rump_server rump.rtadvd rump.ndp rump.ifconfig rump.netstat"

init_server()
{

	export RUMP_SERVER=$1
	atf_check -s exit:0 -o match:'0.->.1' \
		rump.sysctl -w net.inet6.ip6.forwarding=1
	export LD_PRELOAD=/usr/lib/librumphijack.so
	atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd
	unset LD_PRELOAD
	unset RUMP_SERVER
}

setup_shmif0()
{
	local sock=$1
	local IP6ADDR=$2

	rump_server_add_iface $sock shmif0 bus1

	export RUMP_SERVER=$sock
	atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6ADDR}
	atf_check -s exit:0 rump.ifconfig shmif0 up
	atf_check -s exit:0 rump.ifconfig -w 10

	$DEBUG && rump.ifconfig
}

kill_rtadvd()
{
	local pid=$(cat "$1")

	test -n "$pid" && {
		case "$pid" in
		*[!0-9]*)	return 1;;
		esac
		test "$pid" -gt 1 && kill -s KILL "${pid}"
	}
	rm -f "$1"
}

terminate_rtadvd()
{
	local pidfile=$1
	local n=5

	if ! [ -f "$pidfile" ]; then
		return
	fi

	local pid=$(cat "$pidfile")

	test -n "${pid}" && kill -s TERM "${pid}"

	# Note, rtadvd cannot remove its own pidfile, it chroots after
	# creating it (and if it chroot'd first, we would not be able to
	# control where it puts the thing, and so it would be useless.)
	# However, it does truncate it... so watch for that.
	while [ -s "$pidfile" ]; do
		n=$((n - 1))
		if [ "$n" = 0 ]; then
			kill_rtadvd "$pidfile"
			return
		fi
		sleep 0.2
	done
	# and finally complete the cleanup that rtadvd did not do.
	rm -f "$pidfile"
}

create_rtadvdconfig()
{
	cat << _EOF > ${CONFIG}
shmif0:\\
	:mtu#1300:maxinterval#4:mininterval#3:
_EOF
}

create_rtadvdconfig_rltime()
{
	cat << _EOF > ${CONFIG}
shmif0:\\
	:mtu#1300:maxinterval#4:mininterval#3:rltime#$1:
_EOF
	$DEBUG && cat ${CONFIG}
}

create_rtadvdconfig_vltime()
{
	cat << _EOF > ${CONFIG}
shmif0:\\
	:mtu#1300:maxinterval#4:mininterval#3:addr="$1":vltime#$2:
_EOF
	$DEBUG && cat ${CONFIG}
}

RA_count()
{
	RUMP_SERVER="$1" rump.netstat -p icmp6 | sed -n '
		$ {
			s/^.*$/0/p
			q
		}
		/router advertisement:/!d
		s/.*router advertisement: *//
		s/[ 	]*$//
		s/^$/0/
		p
		q
	'
}

await_RA()
{
	local N=$(RA_count "$1")
	while [ "$(RA_count "$1")" -le "$N" ]; do
		sleep 0.2
	done
}

start_rtadvd()
{
	local RUMP_SERVER="$1"
	export RUMP_SERVER

	atf_check -s exit:0 -e ignore \
	    rump.rtadvd -D -c ${CONFIG} -p "$2" shmif0

	# don't wait for the pid file to appear and get a pid in it.
	# we look for receiving RAs instead, must more reliable
	# extra delay here increases possibility of RA arriving before
	# we start looking (which means we then wait for the next .. boring!)
}

check_entries()
{
	local RUMP_SERVER="$1"
	local srv=$2
	local addr_prefix=$3
	local mac_srv= ll_srv=
	export RUMP_SERVER

	ll_srv=$(get_linklocal_addr "$srv" shmif0)
	mac_srv=$(get_macaddr "$srv" shmif0)

	$DEBUG && dump_entries
	atf_check -s exit:0 -o match:if=shmif0 rump.ndp -r
	atf_check -s exit:0 -o match:advertised  \
	    -o match:"${ll_srv}%shmif0 \(reachable\)" \
		rump.ndp -p
	atf_check -s exit:0 -o match:linkmtu=1300 rump.ndp -n -i shmif0
	atf_check -s exit:0 \
	    -o match:"$ll_srv%shmif0 +$mac_srv +shmif0 +$ONEDAYISH S R" \
	    -o not-match:"$addr_prefix"  \
		    rump.ndp -n -a
	atf_check -s exit:0 \
	    -o match:"$addr_prefix.+<(TENTATIVE,)?AUTOCONF>" \
	    rump.ifconfig shmif0 inet6
}

dump_entries()
{
	local marker="+-+-+-+-+-+-+-+-+"

	printf '%s %s\n' "$marker" 'ndp -n -a'
	rump.ndp -n -a
	printf '%s %s\n' "$marker" 'ndp -p'
	rump.ndp -p
	printf '%s %s\n' "$marker" 'ndp -r'
	rump.ndp -r
	printf '%s\n' "$marker"
}

atf_test_case ra_basic cleanup
ra_basic_head()
{

	atf_set "descr" "Tests for basic functions of router advaertisement(RA)"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_basic_body()
{

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	init_server $RUMPSRV

	setup_shmif0 ${RUMPCLI} ${IP6CLI}
	export RUMP_SERVER=${RUMPCLI}
	$DEBUG && rump.ndp -n -a
	atf_check -s exit:0 -o match:'= 0' \
		rump.sysctl net.inet6.ip6.accept_rtadv
	unset RUMP_SERVER

	create_rtadvdconfig
	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	export RUMP_SERVER=${RUMPCLI}
	atf_check -s exit:0 -o empty rump.ndp -r
	atf_check -s exit:0 -o not-match:advertised rump.ndp -p
	atf_check -s exit:0 -o match:linkmtu=0 rump.ndp -n -i shmif0
	atf_check -s exit:0 -o not-match:'S R' -o not-match:fc00:1: \
		rump.ndp -n -a
	atf_check -s exit:0 -o not-match:fc00:1: rump.ifconfig shmif0 inet6
	unset RUMP_SERVER

	terminate_rtadvd $PIDFILE

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0 -> 1' \
		rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	terminate_rtadvd $PIDFILE

	rump_server_destroy_ifaces
}

ra_basic_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_test_case ra_flush_prefix_entries cleanup
ra_flush_prefix_entries_head()
{

	atf_set "descr" "Tests for flushing prefixes (ndp -P)"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_flush_prefix_entries_body()
{

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV

	create_rtadvdconfig

	export RUMP_SERVER=${RUMPCLI}
	atf_check -s exit:0 -o match:'0 -> 1' \
		rump.sysctl -w net.inet6.ip6.accept_rtadv=1
	unset RUMP_SERVER

	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	export RUMP_SERVER=${RUMPCLI}

	# Terminate rtadvd to prevent new RA messages from coming
	terminate_rtadvd $PIDFILE

	# Flush all the entries in the prefix list
	atf_check -s exit:0 rump.ndp -P

	$DEBUG && dump_entries
	atf_check -s exit:0 -o match:if=shmif0 rump.ndp -r
	atf_check -s exit:0 -o empty rump.ndp -p
	atf_check -s exit:0 -o match:linkmtu=1300 rump.ndp -n -i shmif0
	atf_check -s exit:0 -o match:"$ONEDAYISH S R" -o not-match:fc00:1: \
		rump.ndp -n -a
	atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6
	unset RUMP_SERVER

	rump_server_destroy_ifaces
}

ra_flush_prefix_entries_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_test_case ra_flush_defrouter_entries cleanup
ra_flush_defrouter_entries_head()
{

	atf_set "descr" "Tests for flushing default routers (ndp -R)"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_flush_defrouter_entries_body()
{

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV

	create_rtadvdconfig

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0 -> 1' \
		rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	export RUMP_SERVER=${RUMPCLI}

	# Terminate rtadvd to prevent new RA messages from coming
	terminate_rtadvd $PIDFILE

	# Flush all the entries in the default router list
	atf_check -s exit:0 rump.ndp -R

	$DEBUG && dump_entries
	atf_check -s exit:0 -o empty rump.ndp -r
	atf_check -s exit:0 -o match:'No advertising router' rump.ndp -p
	atf_check -s exit:0 -o match:linkmtu=1300 rump.ndp -n -i shmif0
	atf_check -s exit:0 -o not-match:fc00:1: rump.ndp -n -a
	atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6
	unset RUMP_SERVER

	rump_server_destroy_ifaces
}

ra_flush_defrouter_entries_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_test_case ra_delete_address cleanup
ra_delete_address_head()
{

	atf_set "descr" "Tests for deleting auto-configured address"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_delete_address_body()
{

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV

	create_rtadvdconfig

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0 -> 1' \
		rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	export RUMP_SERVER=${RUMPCLI}
	$DEBUG && rump.ifconfig shmif0
	atf_check -s exit:0 rump.ifconfig shmif0 inet6 \
	    $(rump.ifconfig shmif0 | awk '/AUTOCONF/ {print $2}') delete
	unset RUMP_SERVER

	terminate_rtadvd $PIDFILE

	rump_server_destroy_ifaces
}

ra_delete_address_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_test_case ra_multiple_routers cleanup
ra_multiple_routers_head()
{

	atf_set "descr" "Tests for multiple routers"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_multiple_routers_body()
{
	local n=

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_fs_start $RUMPSRV3 netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPSRV3} ${IP6SRV3}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV
	init_server $RUMPSRV3

	create_rtadvdconfig

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0 -> 1' \
		rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	start_rtadvd $RUMPSRV3 $PIDFILE3
	await_RA "${RUMPCLI}"
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX
	check_entries $RUMPCLI $RUMPSRV3 $IP6SRV3_PREFIX

	# Two prefixes are advertised by differnt two routers
	n=$(RUMP_SERVER=$RUMPCLI rump.ndp -p | grep 'advertised by' | wc -l)
	atf_check_equal $n 2

	terminate_rtadvd $PIDFILE
	terminate_rtadvd $PIDFILE3

	rump_server_destroy_ifaces
}

ra_multiple_routers_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	terminate_rtadvd $PIDFILE3
	cleanup
}

atf_test_case ra_multiple_routers_single_prefix cleanup
ra_multiple_routers_single_prefix_head()
{

	atf_set "descr" "Tests for multiple routers with a single prefix"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_multiple_routers_single_prefix_body()
{
	local n=

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_fs_start $RUMPSRV1_2 netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPSRV1_2} ${IP6SRV1_2}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV
	init_server $RUMPSRV1_2

	create_rtadvdconfig

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0 -> 1' \
		rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	start_rtadvd $RUMPSRV1_2 $PIDFILE1_2
	await_RA "${RUMPCLI}"
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX
	check_entries $RUMPCLI $RUMPSRV1_2 $IP6SRV_PREFIX

	export RUMP_SERVER=$RUMPCLI
	# One prefix is advertised by differnt two routers
	n=$(rump.ndp -p |grep 'advertised by' |wc -l)
	atf_check_equal $n 1
	unset RUMP_SERVER

	terminate_rtadvd $PIDFILE
	terminate_rtadvd $PIDFILE1_2

	rump_server_destroy_ifaces
}

ra_multiple_routers_single_prefix_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	terminate_rtadvd $PIDFILE1_2
	cleanup
}

atf_test_case ra_multiple_routers_maxifprefixes cleanup
ra_multiple_routers_maxifprefixes_head()
{

	atf_set "descr" "Tests for exceeding the number of maximum prefixes"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_multiple_routers_maxifprefixes_body()
{
	local n=

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_fs_start $RUMPSRV3 netinet6
	rump_server_fs_start $RUMPSRV4 netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPSRV3} ${IP6SRV3}
	setup_shmif0 ${RUMPSRV4} ${IP6SRV4}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV
	init_server $RUMPSRV3
	init_server $RUMPSRV4

	create_rtadvdconfig

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0.->.1' \
	    rump.sysctl -w net.inet6.ip6.accept_rtadv=1
	# Limit the maximum number of prefix entries to 2
	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'16 -> 2' \
	    rump.sysctl -w net.inet6.ip6.maxifprefixes=2

	start_rtadvd $RUMPSRV $PIDFILE
	start_rtadvd $RUMPSRV3 $PIDFILE3
	await_RA "${RUMPCLI}"
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX
	check_entries $RUMPCLI $RUMPSRV3 $IP6SRV3_PREFIX

	start_rtadvd $RUMPSRV4 $PIDFILE4
	await_RA "${RUMPCLI}"

	$DEBUG && RUMP_SERVER="${RUMPCLI}" dump_entries
	# There should remain two prefixes
	n=$(RUMP_SERVER=${RUMPCLI} rump.ndp -p | grep 'advertised by' | wc -l)
	atf_check_equal $n 2
	# TODO check other conditions

	terminate_rtadvd $PIDFILE
	terminate_rtadvd $PIDFILE3
	terminate_rtadvd $PIDFILE4

	rump_server_destroy_ifaces
}

ra_multiple_routers_maxifprefixes_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	terminate_rtadvd $PIDFILE3
	terminate_rtadvd $PIDFILE4
	cleanup
}

atf_test_case ra_temporary_address cleanup
ra_temporary_address_head()
{

	atf_set "descr" "Tests for IPv6 temporary address"
	atf_set "require.progs" "${RUMP_PROGS}"
}

check_echo_request_pkt()
{
	local pkt="$2 > $3: .+ echo request"

	extract_new_packets $1 > ./out
	$DEBUG && echo "$pkt"
	$DEBUG && cat ./out
	atf_check -s exit:0 -o match:"$pkt" cat ./out
}

ra_temporary_address_body()
{
	local ip_auto= ip_temp=

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 $RUMPSRV $IP6SRV
	init_server $RUMPSRV
	setup_shmif0 $RUMPCLI $IP6CLI

	RUMP_SERVER=$RUMPCLI atf_check -s exit:0 -o match:'0 -> 1' \
	    rump.sysctl -w net.inet6.ip6.accept_rtadv=1
	RUMP_SERVER=$RUMPCLI atf_check -s exit:0 -o match:'0 -> 1' \
	    rump.sysctl -w net.inet6.ip6.use_tempaddr=1

	create_rtadvdconfig
	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	export RUMP_SERVER=$RUMPCLI

	# Check temporary address
	atf_check -s exit:0 \
	    -o match:"$IP6SRV_PREFIX.+<(TENTATIVE,)?AUTOCONF,TEMPORARY>" \
	    rump.ifconfig shmif0 inet6

	#
	# Testing net.inet6.ip6.prefer_tempaddr
	#
	atf_check -s exit:0 rump.ifconfig -w 10
	$DEBUG && rump.ifconfig shmif0
	ip_auto=$(rump.ifconfig shmif0 |
	    awk '/<AUTOCONF>/ {sub(/\/[0-9]*/, ""); print $2;}')
	ip_temp=$(rump.ifconfig shmif0 |
	    awk '/<AUTOCONF,TEMPORARY>/ {sub(/\/[0-9]*/, ""); print $2;}')
	$DEBUG && echo "AUTO=$ip_auto TEMP=$ip_temp"

	# Ignore old packets
	extract_new_packets bus1 > /dev/null

	atf_check -s exit:0 -o ignore rump.ping6 -n -X 2 -c 1 $IP6SRV
	# autoconf (non-temporal) address should be used as the source address
	check_echo_request_pkt bus1 $ip_auto $IP6SRV

	# Enable net.inet6.ip6.prefer_tempaddr
	atf_check -s exit:0 -o match:'0 -> 1' \
	    rump.sysctl -w net.inet6.ip6.prefer_tempaddr=1

	atf_check -s exit:0 -o ignore rump.ping6 -n -X 2 -c 1 $IP6SRV
	# autoconf, temporal address should be used as the source address
	check_echo_request_pkt bus1 $ip_temp $IP6SRV

	#
	# Testing the validation of net.inet6.ip6.temppltime
	#
	# XXX should move to a better place
	atf_check -s not-exit:0 -e match:'Invalid argument' \
	    rump.sysctl -w net.inet6.ip6.temppltime=$((600 + 5))
	atf_check -s exit:0 -o match:'86400 -> 606' \
	    rump.sysctl -w net.inet6.ip6.temppltime=$((600 + 5 + 1))

	unset RUMP_SERVER

	terminate_rtadvd $PIDFILE

	rump_server_destroy_ifaces
}

ra_temporary_address_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_test_case ra_defrouter_expiration cleanup
ra_defrouter_expiration_head()
{

	atf_set "descr" "Tests for default router expiration"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_defrouter_expiration_body()
{
	local expire_time=5

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV

	create_rtadvdconfig_rltime $expire_time

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0.->.1' \
	    rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	export RUMP_SERVER=${RUMPCLI}

	# Terminate rtadvd to prevent new RA messages from coming
	terminate_rtadvd $PIDFILE

	# Wait until the default routers and prefix entries are expired
	# XXX need to work out a better way ... this is a race.
	# XXX fortunately this race usually ends with the winner we want
	# XXX (long odds on - not worth placing a bet...)
	sleep $expire_time

	$DEBUG && dump_entries

	# Give nd6_timer a chance to sweep default routers and prefix entries
	# XXX Ugh again.
	sleep 2

	$DEBUG && dump_entries
	atf_check -s exit:0 -o not-match:if=shmif0 rump.ndp -r
	atf_check -s exit:0 -o match:'No advertising router' rump.ndp -p
	atf_check -s exit:0 -o match:linkmtu=1300 rump.ndp -n -i shmif0
	atf_check -s exit:0 -o not-match:fc00:1: rump.ndp -n -a
	atf_check -s exit:0 -o match:fc00:1: rump.ifconfig shmif0 inet6
	unset RUMP_SERVER

	rump_server_destroy_ifaces
}

ra_defrouter_expiration_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_test_case ra_prefix_expiration cleanup
ra_prefix_expiration_head()
{

	atf_set "descr" "Tests for prefix expiration"
	atf_set "require.progs" "${RUMP_PROGS}"
}

ra_prefix_expiration_body()
{
	local expire_time=5

	rump_server_fs_start $RUMPSRV netinet6
	rump_server_start $RUMPCLI netinet6

	setup_shmif0 ${RUMPSRV} ${IP6SRV}
	setup_shmif0 ${RUMPCLI} ${IP6CLI}

	init_server $RUMPSRV

	create_rtadvdconfig_vltime "${IP6SRV_PREFIX}:" $expire_time

	RUMP_SERVER=${RUMPCLI} atf_check -s exit:0 -o match:'0 -> 1' \
	    rump.sysctl -w net.inet6.ip6.accept_rtadv=1

	start_rtadvd $RUMPSRV $PIDFILE
	await_RA "${RUMPCLI}"

	check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX

	export RUMP_SERVER=${RUMPCLI}

	# Terminate rtadvd to prevent new RA messages from coming
	terminate_rtadvd $PIDFILE

	# Wait until the default routers and prefix entries are expired
	# XXX need the same better way here too...
	sleep $expire_time

	$DEBUG && dump_entries

	# Give nd6_timer a chance to sweep default routers and prefix entries
	# XXX and here
	sleep 2

	$DEBUG && dump_entries
	atf_check -s exit:0 -o match:if=shmif0 rump.ndp -r
	atf_check -s exit:0 -o empty rump.ndp -p
	atf_check -s exit:0 -o match:linkmtu=1300 rump.ndp -n -i shmif0
	atf_check -s exit:0 -o match:"$ONEDAYISH S R" -o not-match:fc00:1: \
		rump.ndp -n -a
	atf_check -s exit:0 -o not-match:fc00:1: rump.ifconfig shmif0 inet6
	unset RUMP_SERVER

	rump_server_destroy_ifaces
}

ra_prefix_expiration_cleanup()
{

	$DEBUG && dump
	terminate_rtadvd $PIDFILE
	cleanup
}

atf_init_test_cases()
{

	atf_add_test_case ra_basic
	atf_add_test_case ra_flush_prefix_entries
	atf_add_test_case ra_flush_defrouter_entries
	atf_add_test_case ra_delete_address
	atf_add_test_case ra_multiple_routers
	atf_add_test_case ra_multiple_routers_single_prefix
	atf_add_test_case ra_multiple_routers_maxifprefixes
	atf_add_test_case ra_temporary_address
	atf_add_test_case ra_defrouter_expiration
	atf_add_test_case ra_prefix_expiration
}