1 |
|
|
/* $OpenBSD: printconf.c,v 1.5 2016/12/24 14:58:55 jca 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 |
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 |
|
|
if (conf->flags & OSPFD_FLAG_STUB_ROUTER) |
49 |
|
|
printf("stub router yes\n"); |
50 |
|
|
|
51 |
|
|
print_redistribute(conf); |
52 |
|
|
print_rtlabel(conf); |
53 |
|
|
|
54 |
|
|
printf("spf-delay %u\n", conf->spf_delay); |
55 |
|
|
printf("spf-holdtime %u\n", conf->spf_hold_time); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
const char * |
59 |
|
|
print_no(u_int16_t type) |
60 |
|
|
{ |
61 |
|
|
if (type & REDIST_NO) |
62 |
|
|
return ("no "); |
63 |
|
|
else |
64 |
|
|
return (""); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
void |
68 |
|
|
print_redistribute(struct ospfd_conf *conf) |
69 |
|
|
{ |
70 |
|
|
struct redistribute *r; |
71 |
|
|
|
72 |
|
|
SIMPLEQ_FOREACH(r, &conf->redist_list, entry) { |
73 |
|
|
switch (r->type & ~REDIST_NO) { |
74 |
|
|
case REDIST_STATIC: |
75 |
|
|
printf("%sredistribute static ", print_no(r->type)); |
76 |
|
|
break; |
77 |
|
|
case REDIST_CONNECTED: |
78 |
|
|
printf("%sredistribute connected ", print_no(r->type)); |
79 |
|
|
break; |
80 |
|
|
case REDIST_LABEL: |
81 |
|
|
printf("%sredistribute rtlabel %s ", |
82 |
|
|
print_no(r->type), rtlabel_id2name(r->label)); |
83 |
|
|
break; |
84 |
|
|
case REDIST_ADDR: |
85 |
|
|
printf("%sredistribute %s/%d ", |
86 |
|
|
print_no(r->type), log_in6addr(&r->addr), |
87 |
|
|
r->prefixlen); |
88 |
|
|
break; |
89 |
|
|
case REDIST_DEFAULT: |
90 |
|
|
printf("%sredistribute default ", print_no(r->type)); |
91 |
|
|
break; |
92 |
|
|
} |
93 |
|
|
printf("set { metric %d type %d }\n", |
94 |
|
|
(r->metric & LSA_METRIC_MASK), |
95 |
|
|
((r->metric & LSA_ASEXT_E_FLAG) == 0 ? 1 : 2)); |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void |
100 |
|
|
print_rtlabel(struct ospfd_conf *conf) |
101 |
|
|
{ |
102 |
|
|
struct n2id_label *label; |
103 |
|
|
|
104 |
|
|
TAILQ_FOREACH(label, &rt_labels, entry) |
105 |
|
|
if (label->ext_tag) |
106 |
|
|
printf("rtlabel \"%s\" external-tag %u\n", |
107 |
|
|
label->name, label->ext_tag); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
void |
111 |
|
|
print_iface(struct iface *iface) |
112 |
|
|
{ |
113 |
|
|
printf("\tinterface %s {\n", iface->name); |
114 |
|
|
|
115 |
|
|
printf("\t\thello-interval %d\n", iface->hello_interval); |
116 |
|
|
printf("\t\tmetric %d\n", iface->metric); |
117 |
|
|
|
118 |
|
|
if (iface->cflags & F_IFACE_PASSIVE) |
119 |
|
|
printf("\t\tpassive\n"); |
120 |
|
|
if (*iface->demote_group) |
121 |
|
|
printf("\t\tdemote %s\n", iface->demote_group); |
122 |
|
|
|
123 |
|
|
printf("\t\tretransmit-interval %d\n", iface->rxmt_interval); |
124 |
|
|
printf("\t\trouter-dead-time %d\n", iface->dead_interval); |
125 |
|
|
printf("\t\trouter-priority %d\n", iface->priority); |
126 |
|
|
printf("\t\ttransmit-delay %d\n", iface->transmit_delay); |
127 |
|
|
|
128 |
|
|
printf("\t}\n"); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
void |
132 |
|
|
print_config(struct ospfd_conf *conf) |
133 |
|
|
{ |
134 |
|
|
struct area *area; |
135 |
|
|
struct iface *iface; |
136 |
|
|
|
137 |
|
|
printf("\n"); |
138 |
|
|
print_mainconf(conf); |
139 |
|
|
printf("\n"); |
140 |
|
|
|
141 |
|
|
LIST_FOREACH(area, &conf->area_list, entry) { |
142 |
|
|
printf("area %s {\n", inet_ntoa(area->id)); |
143 |
|
|
if (*area->demote_group) |
144 |
|
|
printf("\tdemote %s %d\n", area->demote_group, |
145 |
|
|
area->demote_level); |
146 |
|
|
LIST_FOREACH(iface, &area->iface_list, entry) { |
147 |
|
|
print_iface(iface); |
148 |
|
|
} |
149 |
|
|
printf("}\n\n"); |
150 |
|
|
} |
151 |
|
|
} |