xref: /openbsd-src/usr.sbin/ospf6d/printconf.c (revision 09e8f7802c96471b3cc391ddfb8e5f094d267a59)
1 /*	$OpenBSD: printconf.c,v 1.10 2020/01/21 20:38:52 remi Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005 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 "ospf6.h"
28 #include "ospf6d.h"
29 #include "ospfe.h"
30 #include "log.h"
31 
32 void	print_mainconf(struct ospfd_conf *);
33 const char *print_no(u_int16_t);
34 void	print_redistribute(struct ospfd_conf *);
35 void	print_rtlabel(struct ospfd_conf *);
36 void	print_iface(struct iface *);
37 
38 void
print_mainconf(struct ospfd_conf * conf)39 print_mainconf(struct ospfd_conf *conf)
40 {
41 	printf("router-id %s\n", inet_ntoa(conf->rtr_id));
42 
43 	if (conf->flags & OSPFD_FLAG_NO_FIB_UPDATE)
44 		printf("fib-update no\n");
45 	else
46 		printf("fib-update yes\n");
47 
48 	printf("fib-priority %hhu\n", conf->fib_priority);
49 
50 	if (conf->rdomain)
51 		printf("rdomain %d\n", conf->rdomain);
52 
53 	if (conf->flags & OSPFD_FLAG_STUB_ROUTER)
54 		printf("stub router yes\n");
55 
56 	print_redistribute(conf);
57 	print_rtlabel(conf);
58 
59 	printf("spf-delay %u\n", conf->spf_delay);
60 	printf("spf-holdtime %u\n", conf->spf_hold_time);
61 }
62 
63 const char *
print_no(u_int16_t type)64 print_no(u_int16_t type)
65 {
66 	if (type & REDIST_NO)
67 		return ("no ");
68 	else
69 		return ("");
70 }
71 
72 void
print_redistribute(struct ospfd_conf * conf)73 print_redistribute(struct ospfd_conf *conf)
74 {
75 	struct redistribute	*r;
76 
77 	SIMPLEQ_FOREACH(r, &conf->redist_list, entry) {
78 		switch (r->type & ~REDIST_NO) {
79 		case REDIST_STATIC:
80 			printf("%sredistribute static ", print_no(r->type));
81 			break;
82 		case REDIST_CONNECTED:
83 			printf("%sredistribute connected ", print_no(r->type));
84 			break;
85 		case REDIST_LABEL:
86 			printf("%sredistribute rtlabel %s ",
87 			    print_no(r->type), rtlabel_id2name(r->label));
88 			break;
89 		case REDIST_ADDR:
90 			printf("%sredistribute %s/%d ",
91 			    print_no(r->type), log_in6addr(&r->addr),
92 			    r->prefixlen);
93 			break;
94 		case REDIST_DEFAULT:
95 			printf("%sredistribute default ", print_no(r->type));
96 			break;
97 		}
98 		printf("set { metric %d type %d }",
99 		    (r->metric & LSA_METRIC_MASK),
100 		    ((r->metric & LSA_ASEXT_E_FLAG) == 0 ? 1 : 2));
101 		if (r->dependon[0])
102 			printf(" depend on %s", r->dependon);
103 		printf("\n");
104 	}
105 }
106 
107 void
print_rtlabel(struct ospfd_conf * conf)108 print_rtlabel(struct ospfd_conf *conf)
109 {
110 	struct n2id_label	*label;
111 
112 	TAILQ_FOREACH(label, &rt_labels, entry)
113 		if (label->ext_tag)
114 			printf("rtlabel \"%s\" external-tag %u\n",
115 			    label->name, label->ext_tag);
116 }
117 
118 void
print_iface(struct iface * iface)119 print_iface(struct iface *iface)
120 {
121 	printf("\tinterface %s {\n", iface->name);
122 
123 	printf("\t\thello-interval %d\n", iface->hello_interval);
124 	printf("\t\tmetric %d\n", iface->metric);
125 
126 	if (iface->cflags & F_IFACE_PASSIVE)
127 		printf("\t\tpassive\n");
128 	if (*iface->demote_group)
129 		printf("\t\tdemote %s\n", iface->demote_group);
130 	if (iface->dependon[0] != '\0')
131 		printf("\t\tdepend on %s\n", iface->dependon);
132 
133 	printf("\t\tretransmit-interval %d\n", iface->rxmt_interval);
134 	printf("\t\trouter-dead-time %d\n", iface->dead_interval);
135 	printf("\t\trouter-priority %d\n", iface->priority);
136 	printf("\t\ttransmit-delay %d\n", iface->transmit_delay);
137 
138 	if (iface->type == IF_TYPE_POINTOPOINT)
139 		printf("\t\ttype p2p\n");
140 
141 	printf("\t}\n");
142 }
143 
144 void
print_config(struct ospfd_conf * conf)145 print_config(struct ospfd_conf *conf)
146 {
147 	struct area	*area;
148 	struct iface	*iface;
149 
150 	printf("\n");
151 	print_mainconf(conf);
152 	printf("\n");
153 
154 	LIST_FOREACH(area, &conf->area_list, entry) {
155 		printf("area %s {\n", inet_ntoa(area->id));
156 		if (*area->demote_group)
157 			printf("\tdemote %s %d\n", area->demote_group,
158 			area->demote_level);
159 		LIST_FOREACH(iface, &area->iface_list, entry) {
160 			print_iface(iface);
161 		}
162 		printf("}\n\n");
163 	}
164 }
165