xref: /openbsd-src/regress/sys/net/rtable/delete/main.c (revision 2e154ce3af7dcd2254242b98d7360799269be731)
1*2e154ce3Sclaudio /*	$OpenBSD: main.c,v 1.7 2021/04/13 08:21:12 claudio Exp $ */
2996673c0Smpi 
3996673c0Smpi /*
4996673c0Smpi  * Copyright (c) 2015 Martin Pieuchot
5996673c0Smpi  *
6996673c0Smpi  * Permission to use, copy, modify, and distribute this software for any
7996673c0Smpi  * purpose with or without fee is hereby granted, provided that the above
8996673c0Smpi  * copyright notice and this permission notice appear in all copies.
9996673c0Smpi  *
10996673c0Smpi  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11996673c0Smpi  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12996673c0Smpi  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13996673c0Smpi  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14996673c0Smpi  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15996673c0Smpi  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16996673c0Smpi  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17996673c0Smpi  */
18996673c0Smpi 
198ceda520Smpi #include "srp_compat.h"
208ceda520Smpi 
21996673c0Smpi #include <sys/socket.h>
22996673c0Smpi #include <net/route.h>
23*2e154ce3Sclaudio #include <net/rtable.h>
24*2e154ce3Sclaudio #include <net/art.h>
25996673c0Smpi 
26*2e154ce3Sclaudio #include <assert.h>
27996673c0Smpi #include <err.h>
28996673c0Smpi #include <stdio.h>
29996673c0Smpi #include <stdlib.h>
30996673c0Smpi 
31996673c0Smpi #include "util.h"
32996673c0Smpi 
33e3275b66Smpi extern void  *rtable_get(unsigned int, sa_family_t);
34e3275b66Smpi 
35996673c0Smpi __dead void
usage(void)36996673c0Smpi usage(void)
37996673c0Smpi {
38996673c0Smpi 	extern const char *__progname;
39996673c0Smpi 	fprintf(stderr, "Usage: %s <file>\n", __progname);
40996673c0Smpi 	exit(1);
41996673c0Smpi }
42996673c0Smpi 
43996673c0Smpi int
main(int argc,char * argv[])44996673c0Smpi main(int argc, char *argv[])
45996673c0Smpi {
46996673c0Smpi 	char *filename;
47996673c0Smpi 
48996673c0Smpi 	if (argc != 2)
49996673c0Smpi 		usage();
50996673c0Smpi 
51996673c0Smpi 	filename = argv[1];
52996673c0Smpi 
53996673c0Smpi 	rtable_init();
54996673c0Smpi 
55996673c0Smpi 	do_from_file(0, AF_INET6, filename, route_insert);
56996673c0Smpi 
573924ad6bSvisa 	rtable_walk(0, AF_INET6, NULL, rtentry_delete, NULL);
58996673c0Smpi 
593924ad6bSvisa 	rtable_walk(0, AF_INET6, NULL, rtentry_dump, NULL);
60e3275b66Smpi 
61e3275b66Smpi 	struct art_root *ar;
62e3275b66Smpi 	ar = rtable_get(0, AF_INET6);
63e3275b66Smpi 	assert(ar != NULL);
647df47212Smpi 	assert(ar->ar_root.ref == NULL);
65e3275b66Smpi 
66996673c0Smpi 	return (0);
67996673c0Smpi }
68