xref: /openbsd-src/usr.sbin/ldpd/printconf.c (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*	$OpenBSD: printconf.c,v 1.7 2013/06/04 02:25:28 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
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 <sys/queue.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24 
25 #include <stdio.h>
26 
27 #include "ldp.h"
28 #include "ldpd.h"
29 #include "ldpe.h"
30 
31 void	print_mainconf(struct ldpd_conf *);
32 void	print_iface(struct iface *);
33 void	print_tnbr(struct tnbr *tnbr);
34 
35 void
36 print_mainconf(struct ldpd_conf *conf)
37 {
38 	printf("router-id %s\n\n", inet_ntoa(conf->rtr_id));
39 
40 	if (conf->flags & LDPD_FLAG_NO_FIB_UPDATE)
41 		printf("fib-update no\n");
42 	else
43 		printf("fib-update yes\n");
44 
45 	if (conf->mode & MODE_DIST_INDEPENDENT)
46 		printf("distribution independent\n");
47 	else
48 		printf("distribution ordered\n");
49 
50 	if (conf->mode & MODE_RET_LIBERAL)
51 		printf("retention liberal\n");
52 	else
53 		printf("retention conservative\n");
54 
55 	if (conf->mode & MODE_ADV_ONDEMAND)
56 		printf("advertisement ondemand\n");
57 	else
58 		printf("advertisement unsolicited\n");
59 
60 	if (conf->flags & LDPD_FLAG_TH_ACCEPT)
61 		printf("targeted-hello-accept yes\n");
62 	else
63 		printf("targeted-hello-accept no\n");
64 
65 	printf("keepalive %u\n", conf->keepalive);
66 }
67 
68 void
69 print_iface(struct iface *iface)
70 {
71 	printf("\ninterface %s {\n", iface->name);
72 	printf("\tlink-hello-holdtime %u\n", iface->hello_holdtime);
73 	printf("\tlink-hello-interval %u\n", iface->hello_interval);
74 	printf("}\n");
75 }
76 
77 void
78 print_tnbr(struct tnbr *tnbr)
79 {
80 	printf("\ntargeted-neighbor %s {\n", inet_ntoa(tnbr->addr));
81 	printf("\ttargeted-hello-holdtime %u\n", tnbr->hello_holdtime);
82 	printf("\ttargeted-hello-interval %u\n", tnbr->hello_interval);
83 	printf("}\n");
84 }
85 
86 void
87 print_config(struct ldpd_conf *conf)
88 {
89 	struct iface	*iface;
90 	struct tnbr	*tnbr;
91 
92 	print_mainconf(conf);
93 	printf("\n");
94 
95 	LIST_FOREACH(iface, &conf->iface_list, entry)
96 		print_iface(iface);
97 	printf("\n");
98 	LIST_FOREACH(tnbr, &conf->tnbr_list, entry)
99 		print_tnbr(tnbr);
100 }
101