1 |
|
|
/* $OpenBSD: printconf.c,v 1.6 2016/09/02 16:44:33 renato Exp $ */ |
2 |
|
|
|
3 |
|
|
/* |
4 |
|
|
* Copyright (c) 2015 Renato Westphal <renato@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/types.h> |
20 |
|
|
|
21 |
|
|
#include <arpa/inet.h> |
22 |
|
|
#include <stdio.h> |
23 |
|
|
|
24 |
|
|
#include "eigrpd.h" |
25 |
|
|
#include "log.h" |
26 |
|
|
|
27 |
|
|
static void print_mainconf(struct eigrpd_conf *); |
28 |
|
|
static const char *print_no(uint16_t); |
29 |
|
|
static void print_redist_metric(struct redist_metric *); |
30 |
|
|
static void print_redistribute(struct eigrp *); |
31 |
|
|
static void print_iface(struct eigrp_iface *); |
32 |
|
|
static void print_as(struct eigrp *); |
33 |
|
|
static void print_af(struct eigrpd_conf *, int); |
34 |
|
|
|
35 |
|
|
static void |
36 |
|
|
print_mainconf(struct eigrpd_conf *conf) |
37 |
|
|
{ |
38 |
|
|
printf("router-id %s\n", inet_ntoa(conf->rtr_id)); |
39 |
|
|
|
40 |
|
|
if (conf->flags & EIGRPD_FLAG_NO_FIB_UPDATE) |
41 |
|
|
printf("fib-update no\n"); |
42 |
|
|
else |
43 |
|
|
printf("fib-update yes\n"); |
44 |
|
|
|
45 |
|
|
printf("rdomain %u\n", conf->rdomain); |
46 |
|
|
printf("fib-priority-internal %u\n", conf->fib_priority_internal); |
47 |
|
|
printf("fib-priority-external %u\n", conf->fib_priority_external); |
48 |
|
|
printf("fib-priority-summary %u\n", conf->fib_priority_summary); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
static const char * |
52 |
|
|
print_no(uint16_t type) |
53 |
|
|
{ |
54 |
|
|
if (type & REDIST_NO) |
55 |
|
|
return ("no "); |
56 |
|
|
else |
57 |
|
|
return (""); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
static void |
61 |
|
|
print_redist_metric(struct redist_metric *metric) |
62 |
|
|
{ |
63 |
|
|
printf(" %u %u %u %u %u", metric->bandwidth, metric->delay, |
64 |
|
|
metric->reliability, metric->load, metric->mtu); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
static void |
68 |
|
|
print_redistribute(struct eigrp *eigrp) |
69 |
|
|
{ |
70 |
|
|
struct redistribute *r; |
71 |
|
|
|
72 |
|
|
if (eigrp->dflt_metric) { |
73 |
|
|
printf("\t\tdefault-metric"); |
74 |
|
|
print_redist_metric(eigrp->dflt_metric); |
75 |
|
|
printf("\n"); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
SIMPLEQ_FOREACH(r, &eigrp->redist_list, entry) { |
79 |
|
|
switch (r->type & ~REDIST_NO) { |
80 |
|
|
case REDIST_STATIC: |
81 |
|
|
printf("\t\t%sredistribute static", print_no(r->type)); |
82 |
|
|
break; |
83 |
|
|
case REDIST_RIP: |
84 |
|
|
printf("\t\t%sredistribute rip", print_no(r->type)); |
85 |
|
|
break; |
86 |
|
|
case REDIST_OSPF: |
87 |
|
|
printf("\t\t%sredistribute ospf", print_no(r->type)); |
88 |
|
|
break; |
89 |
|
|
case REDIST_CONNECTED: |
90 |
|
|
printf("\t\t%sredistribute connected", |
91 |
|
|
print_no(r->type)); |
92 |
|
|
break; |
93 |
|
|
case REDIST_DEFAULT: |
94 |
|
|
printf("\t\t%sredistribute default", print_no(r->type)); |
95 |
|
|
break; |
96 |
|
|
case REDIST_ADDR: |
97 |
|
|
printf("\t\t%sredistribute %s/%u", |
98 |
|
|
print_no(r->type), log_addr(r->af, &r->addr), |
99 |
|
|
r->prefixlen); |
100 |
|
|
break; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
if (r->metric) { |
104 |
|
|
printf(" metric"); |
105 |
|
|
print_redist_metric(r->metric); |
106 |
|
|
} |
107 |
|
|
printf("\n"); |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
static void |
112 |
|
|
print_iface(struct eigrp_iface *ei) |
113 |
|
|
{ |
114 |
|
|
struct summary_addr *summary; |
115 |
|
|
|
116 |
|
|
printf("\t\tinterface %s {\n", ei->iface->name); |
117 |
|
|
printf("\t\t\thello-interval %u\n", ei->hello_interval); |
118 |
|
|
printf("\t\t\tholdtime %u\n", ei->hello_holdtime); |
119 |
|
|
printf("\t\t\tdelay %u\n", ei->delay); |
120 |
|
|
printf("\t\t\tbandwidth %u\n", ei->bandwidth); |
121 |
|
|
printf("\t\t\tsplit-horizon %s\n", (ei->splithorizon) ? "yes" : "no"); |
122 |
|
|
if (ei->passive) |
123 |
|
|
printf("\t\t\tpassive\n"); |
124 |
|
|
TAILQ_FOREACH(summary, &ei->summary_list, entry) |
125 |
|
|
printf("\t\t\tsummary-address %s/%u\n", log_addr(ei->eigrp->af, |
126 |
|
|
&summary->prefix), summary->prefixlen); |
127 |
|
|
printf("\t\t}\n"); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
static void |
131 |
|
|
print_as(struct eigrp *eigrp) |
132 |
|
|
{ |
133 |
|
|
struct eigrp_iface *ei; |
134 |
|
|
|
135 |
|
|
printf("\tautonomous-system %u {\n", eigrp->as); |
136 |
|
|
printf("\t\tk-values %u %u %u %u %u %u\n", eigrp->kvalues[0], |
137 |
|
|
eigrp->kvalues[1], eigrp->kvalues[2], eigrp->kvalues[3], |
138 |
|
|
eigrp->kvalues[4], eigrp->kvalues[5]); |
139 |
|
|
printf("\t\tactive-timeout %u\n", eigrp->active_timeout); |
140 |
|
|
printf("\t\tmaximum-hops %u\n", eigrp->maximum_hops); |
141 |
|
|
printf("\t\tmaximum-paths %u\n", eigrp->maximum_paths); |
142 |
|
|
printf("\t\tvariance %u\n", eigrp->variance); |
143 |
|
|
print_redistribute(eigrp); |
144 |
|
|
printf("\n"); |
145 |
|
|
TAILQ_FOREACH(ei, &eigrp->ei_list, e_entry) |
146 |
|
|
print_iface(ei); |
147 |
|
|
printf("\t}\n"); |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
static void |
151 |
|
|
print_af(struct eigrpd_conf *conf, int af) |
152 |
|
|
{ |
153 |
|
|
struct eigrp *eigrp; |
154 |
|
|
|
155 |
|
|
printf("address-family %s {\n", af_name(af)); |
156 |
|
|
TAILQ_FOREACH(eigrp, &conf->instances, entry) |
157 |
|
|
if (eigrp->af == af) |
158 |
|
|
print_as(eigrp); |
159 |
|
|
printf("}\n\n"); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
void |
163 |
|
|
print_config(struct eigrpd_conf *conf) |
164 |
|
|
{ |
165 |
|
|
printf("\n"); |
166 |
|
|
print_mainconf(conf); |
167 |
|
|
printf("\n"); |
168 |
|
|
|
169 |
|
|
print_af(conf, AF_INET); |
170 |
|
|
print_af(conf, AF_INET6); |
171 |
|
|
} |