xref: /openbsd/regress/sys/net/rtable/delete/main.c (revision 2e154ce3)
1 /*	$OpenBSD: main.c,v 1.7 2021/04/13 08:21:12 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2015 Martin Pieuchot
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include "srp_compat.h"
20 
21 #include <sys/socket.h>
22 #include <net/route.h>
23 #include <net/rtable.h>
24 #include <net/art.h>
25 
26 #include <assert.h>
27 #include <err.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 #include "util.h"
32 
33 extern void  *rtable_get(unsigned int, sa_family_t);
34 
35 __dead void
usage(void)36 usage(void)
37 {
38 	extern const char *__progname;
39 	fprintf(stderr, "Usage: %s <file>\n", __progname);
40 	exit(1);
41 }
42 
43 int
main(int argc,char * argv[])44 main(int argc, char *argv[])
45 {
46 	char *filename;
47 
48 	if (argc != 2)
49 		usage();
50 
51 	filename = argv[1];
52 
53 	rtable_init();
54 
55 	do_from_file(0, AF_INET6, filename, route_insert);
56 
57 	rtable_walk(0, AF_INET6, NULL, rtentry_delete, NULL);
58 
59 	rtable_walk(0, AF_INET6, NULL, rtentry_dump, NULL);
60 
61 	struct art_root *ar;
62 	ar = rtable_get(0, AF_INET6);
63 	assert(ar != NULL);
64 	assert(ar->ar_root.ref == NULL);
65 
66 	return (0);
67 }
68