1*09e8f780Sremi /* $OpenBSD: printconf.c,v 1.10 2020/01/21 20:38:52 remi Exp $ */
2a1a4e97bSnorby
3a1a4e97bSnorby /*
4a1a4e97bSnorby * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
5a1a4e97bSnorby *
6a1a4e97bSnorby * Permission to use, copy, modify, and distribute this software for any
7a1a4e97bSnorby * purpose with or without fee is hereby granted, provided that the above
8a1a4e97bSnorby * copyright notice and this permission notice appear in all copies.
9a1a4e97bSnorby *
10a1a4e97bSnorby * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11a1a4e97bSnorby * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12a1a4e97bSnorby * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13a1a4e97bSnorby * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14a1a4e97bSnorby * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15a1a4e97bSnorby * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16a1a4e97bSnorby * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17a1a4e97bSnorby */
18a1a4e97bSnorby
19a1a4e97bSnorby #include <sys/queue.h>
20a1a4e97bSnorby #include <sys/types.h>
21a1a4e97bSnorby #include <sys/socket.h>
22a1a4e97bSnorby #include <netinet/in.h>
23a1a4e97bSnorby #include <arpa/inet.h>
24a1a4e97bSnorby
25a1a4e97bSnorby #include <stdio.h>
26a1a4e97bSnorby
27a1a4e97bSnorby #include "ospf6.h"
28a1a4e97bSnorby #include "ospf6d.h"
29a1a4e97bSnorby #include "ospfe.h"
30f8efa005Sclaudio #include "log.h"
31a1a4e97bSnorby
32a1a4e97bSnorby void print_mainconf(struct ospfd_conf *);
33a1a4e97bSnorby const char *print_no(u_int16_t);
34a1a4e97bSnorby void print_redistribute(struct ospfd_conf *);
35a1a4e97bSnorby void print_rtlabel(struct ospfd_conf *);
36a1a4e97bSnorby void print_iface(struct iface *);
37a1a4e97bSnorby
38a1a4e97bSnorby void
print_mainconf(struct ospfd_conf * conf)39a1a4e97bSnorby print_mainconf(struct ospfd_conf *conf)
40a1a4e97bSnorby {
41a1a4e97bSnorby printf("router-id %s\n", inet_ntoa(conf->rtr_id));
42a1a4e97bSnorby
43a1a4e97bSnorby if (conf->flags & OSPFD_FLAG_NO_FIB_UPDATE)
44a1a4e97bSnorby printf("fib-update no\n");
45a1a4e97bSnorby else
46a1a4e97bSnorby printf("fib-update yes\n");
47a1a4e97bSnorby
48d1e43ac2Sremi printf("fib-priority %hhu\n", conf->fib_priority);
49d1e43ac2Sremi
505d393f89Sremi if (conf->rdomain)
515d393f89Sremi printf("rdomain %d\n", conf->rdomain);
525d393f89Sremi
53a1a4e97bSnorby if (conf->flags & OSPFD_FLAG_STUB_ROUTER)
54a1a4e97bSnorby printf("stub router yes\n");
55a1a4e97bSnorby
56a1a4e97bSnorby print_redistribute(conf);
57a1a4e97bSnorby print_rtlabel(conf);
58a1a4e97bSnorby
59a1a4e97bSnorby printf("spf-delay %u\n", conf->spf_delay);
60a1a4e97bSnorby printf("spf-holdtime %u\n", conf->spf_hold_time);
61a1a4e97bSnorby }
62a1a4e97bSnorby
63a1a4e97bSnorby const char *
print_no(u_int16_t type)64a1a4e97bSnorby print_no(u_int16_t type)
65a1a4e97bSnorby {
66a1a4e97bSnorby if (type & REDIST_NO)
67a1a4e97bSnorby return ("no ");
68a1a4e97bSnorby else
69a1a4e97bSnorby return ("");
70a1a4e97bSnorby }
71a1a4e97bSnorby
72a1a4e97bSnorby void
print_redistribute(struct ospfd_conf * conf)73a1a4e97bSnorby print_redistribute(struct ospfd_conf *conf)
74a1a4e97bSnorby {
75a1a4e97bSnorby struct redistribute *r;
76a1a4e97bSnorby
77a1a4e97bSnorby SIMPLEQ_FOREACH(r, &conf->redist_list, entry) {
78a1a4e97bSnorby switch (r->type & ~REDIST_NO) {
79a1a4e97bSnorby case REDIST_STATIC:
802f702e70Sjca printf("%sredistribute static ", print_no(r->type));
81a1a4e97bSnorby break;
82a1a4e97bSnorby case REDIST_CONNECTED:
832f702e70Sjca printf("%sredistribute connected ", print_no(r->type));
84a1a4e97bSnorby break;
85a1a4e97bSnorby case REDIST_LABEL:
862f702e70Sjca printf("%sredistribute rtlabel %s ",
87a1a4e97bSnorby print_no(r->type), rtlabel_id2name(r->label));
88a1a4e97bSnorby break;
89a1a4e97bSnorby case REDIST_ADDR:
902f702e70Sjca printf("%sredistribute %s/%d ",
91f8efa005Sclaudio print_no(r->type), log_in6addr(&r->addr),
92f8efa005Sclaudio r->prefixlen);
93a1a4e97bSnorby break;
9493c5cf97Sbluhm case REDIST_DEFAULT:
952f702e70Sjca printf("%sredistribute default ", print_no(r->type));
9693c5cf97Sbluhm break;
97a1a4e97bSnorby }
98a66c91f2Sremi printf("set { metric %d type %d }",
992f702e70Sjca (r->metric & LSA_METRIC_MASK),
1002f702e70Sjca ((r->metric & LSA_ASEXT_E_FLAG) == 0 ? 1 : 2));
101a66c91f2Sremi if (r->dependon[0])
102a66c91f2Sremi printf(" depend on %s", r->dependon);
103a66c91f2Sremi printf("\n");
104a1a4e97bSnorby }
105a1a4e97bSnorby }
106a1a4e97bSnorby
107a1a4e97bSnorby void
print_rtlabel(struct ospfd_conf * conf)108a1a4e97bSnorby print_rtlabel(struct ospfd_conf *conf)
109a1a4e97bSnorby {
110a1a4e97bSnorby struct n2id_label *label;
111a1a4e97bSnorby
112a1a4e97bSnorby TAILQ_FOREACH(label, &rt_labels, entry)
113a1a4e97bSnorby if (label->ext_tag)
114a1a4e97bSnorby printf("rtlabel \"%s\" external-tag %u\n",
115a1a4e97bSnorby label->name, label->ext_tag);
116a1a4e97bSnorby }
117a1a4e97bSnorby
118a1a4e97bSnorby void
print_iface(struct iface * iface)119a1a4e97bSnorby print_iface(struct iface *iface)
120a1a4e97bSnorby {
121a1a4e97bSnorby printf("\tinterface %s {\n", iface->name);
122a1a4e97bSnorby
123a1a4e97bSnorby printf("\t\thello-interval %d\n", iface->hello_interval);
124a1a4e97bSnorby printf("\t\tmetric %d\n", iface->metric);
125a1a4e97bSnorby
1266c9e7a5bSclaudio if (iface->cflags & F_IFACE_PASSIVE)
127a1a4e97bSnorby printf("\t\tpassive\n");
128a1a4e97bSnorby if (*iface->demote_group)
129a1a4e97bSnorby printf("\t\tdemote %s\n", iface->demote_group);
130a66c91f2Sremi if (iface->dependon[0] != '\0')
131a66c91f2Sremi printf("\t\tdepend on %s\n", iface->dependon);
132a1a4e97bSnorby
133a1a4e97bSnorby printf("\t\tretransmit-interval %d\n", iface->rxmt_interval);
134a1a4e97bSnorby printf("\t\trouter-dead-time %d\n", iface->dead_interval);
135a1a4e97bSnorby printf("\t\trouter-priority %d\n", iface->priority);
136a1a4e97bSnorby printf("\t\ttransmit-delay %d\n", iface->transmit_delay);
137a1a4e97bSnorby
138*09e8f780Sremi if (iface->type == IF_TYPE_POINTOPOINT)
139b0cdd6d0Sremi printf("\t\ttype p2p\n");
140b0cdd6d0Sremi
141a1a4e97bSnorby printf("\t}\n");
142a1a4e97bSnorby }
143a1a4e97bSnorby
144a1a4e97bSnorby void
print_config(struct ospfd_conf * conf)145a1a4e97bSnorby print_config(struct ospfd_conf *conf)
146a1a4e97bSnorby {
147a1a4e97bSnorby struct area *area;
148a1a4e97bSnorby struct iface *iface;
149a1a4e97bSnorby
150a1a4e97bSnorby printf("\n");
151a1a4e97bSnorby print_mainconf(conf);
152a1a4e97bSnorby printf("\n");
153a1a4e97bSnorby
154a1a4e97bSnorby LIST_FOREACH(area, &conf->area_list, entry) {
155a1a4e97bSnorby printf("area %s {\n", inet_ntoa(area->id));
156a1a4e97bSnorby if (*area->demote_group)
157a1a4e97bSnorby printf("\tdemote %s %d\n", area->demote_group,
158a1a4e97bSnorby area->demote_level);
159a1a4e97bSnorby LIST_FOREACH(iface, &area->iface_list, entry) {
160a1a4e97bSnorby print_iface(iface);
161a1a4e97bSnorby }
162a1a4e97bSnorby printf("}\n\n");
163a1a4e97bSnorby }
164a1a4e97bSnorby }
165