GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/ldpd/printconf.c Lines: 0 84 0.0 %
Date: 2017-11-07 Branches: 0 54 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: printconf.c,v 1.27 2017/03/03 23:36:06 renato Exp $ */
2
3
/*
4
 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5
 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
6
 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
7
 *
8
 * Permission to use, copy, modify, and distribute this software for any
9
 * purpose with or without fee is hereby granted, provided that the above
10
 * copyright notice and this permission notice appear in all copies.
11
 *
12
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
 */
20
21
#include <sys/types.h>
22
#include <arpa/inet.h>
23
#include <stdio.h>
24
25
#include "ldpd.h"
26
#include "ldpe.h"
27
#include "log.h"
28
29
static void	print_mainconf(struct ldpd_conf *);
30
static void	print_af(int, struct ldpd_conf *, struct ldpd_af_conf *);
31
static void	print_iface(struct iface *, struct iface_af *);
32
static void	print_tnbr(struct tnbr *);
33
static void	print_nbrp(struct nbr_params *);
34
static void	print_l2vpn(struct l2vpn *);
35
static void	print_pw(struct l2vpn_pw *);
36
37
static void
38
print_mainconf(struct ldpd_conf *conf)
39
{
40
	printf("router-id %s\n", inet_ntoa(conf->rtr_id));
41
42
	if (conf->flags & F_LDPD_NO_FIB_UPDATE)
43
		printf("fib-update no\n");
44
	else
45
		printf("fib-update yes\n");
46
47
	printf("rdomain %u\n", conf->rdomain);
48
	if (conf->trans_pref == DUAL_STACK_LDPOV4)
49
		printf("transport-preference ipv4\n");
50
	else if (conf->trans_pref == DUAL_STACK_LDPOV6)
51
		printf("transport-preference ipv6\n");
52
53
	if (conf->flags & F_LDPD_DS_CISCO_INTEROP)
54
		printf("ds-cisco-interop yes\n");
55
	else
56
		printf("ds-cisco-interop no\n");
57
}
58
59
static void
60
print_af(int af, struct ldpd_conf *conf, struct ldpd_af_conf *af_conf)
61
{
62
	struct iface		*iface;
63
	struct iface_af		*ia;
64
	struct tnbr		*tnbr;
65
66
	printf("\naddress-family %s {\n", af_name(af));
67
68
	if (af_conf->flags & F_LDPD_AF_THELLO_ACCEPT)
69
		printf("\ttargeted-hello-accept yes\n");
70
	else
71
		printf("\ttargeted-hello-accept no\n");
72
73
	if (af_conf->flags & F_LDPD_AF_EXPNULL)
74
		printf("\texplicit-null yes\n");
75
	else
76
		printf("\texplicit-null no\n");
77
78
	if (af_conf->flags & F_LDPD_AF_NO_GTSM)
79
		printf("\tgtsm-enable no\n");
80
	else
81
		printf("\tgtsm-enable yes\n");
82
83
	printf("\tkeepalive %u\n", af_conf->keepalive);
84
	printf("\ttransport-address %s\n", log_addr(af, &af_conf->trans_addr));
85
86
	LIST_FOREACH(iface, &conf->iface_list, entry) {
87
		ia = iface_af_get(iface, af);
88
		if (ia->enabled)
89
			print_iface(iface, ia);
90
	}
91
92
	LIST_FOREACH(tnbr, &conf->tnbr_list, entry)
93
		if (tnbr->af == af && tnbr->flags & F_TNBR_CONFIGURED)
94
			print_tnbr(tnbr);
95
96
	printf("}\n");
97
}
98
99
static void
100
print_iface(struct iface *iface, struct iface_af *ia)
101
{
102
	printf("\tinterface %s {\n", iface->name);
103
	printf("\t\tlink-hello-holdtime %u\n", ia->hello_holdtime);
104
	printf("\t\tlink-hello-interval %u\n", ia->hello_interval);
105
	printf("\t}\n");
106
}
107
108
static void
109
print_tnbr(struct tnbr *tnbr)
110
{
111
	printf("\n\ttargeted-neighbor %s {\n", log_addr(tnbr->af, &tnbr->addr));
112
	printf("\t\ttargeted-hello-holdtime %u\n", tnbr->hello_holdtime);
113
	printf("\t\ttargeted-hello-interval %u\n", tnbr->hello_interval);
114
	printf("\t}\n");
115
}
116
117
static void
118
print_nbrp(struct nbr_params *nbrp)
119
{
120
	printf("\nneighbor %s {\n", inet_ntoa(nbrp->lsr_id));
121
122
	if (nbrp->flags & F_NBRP_KEEPALIVE)
123
		printf("\tkeepalive %u\n", nbrp->keepalive);
124
125
	if (nbrp->flags & F_NBRP_GTSM) {
126
		if (nbrp->gtsm_enabled)
127
			printf("\tgtsm-enable yes\n");
128
		else
129
			printf("\tgtsm-enable no\n");
130
	}
131
132
	if (nbrp->flags & F_NBRP_GTSM_HOPS)
133
		printf("\tgtsm-hops %u\n", nbrp->gtsm_hops);
134
135
	if (nbrp->auth.method == AUTH_MD5SIG)
136
		printf("\tpassword XXXXXX\n");
137
138
	printf("}\n");
139
}
140
141
static void
142
print_l2vpn(struct l2vpn *l2vpn)
143
{
144
	struct l2vpn_if	*lif;
145
	struct l2vpn_pw	*pw;
146
147
	printf("\nl2vpn %s type vpls {\n", l2vpn->name);
148
149
	if (l2vpn->pw_type == PW_TYPE_ETHERNET)
150
		printf("\tpw-type ethernet\n");
151
	else
152
		printf("\tpw-type ethernet-tagged\n");
153
154
	printf("\tmtu %u\n", l2vpn->mtu);
155
	if (l2vpn->br_ifindex != 0)
156
		printf("\tbridge %s\n", l2vpn->br_ifname);
157
	LIST_FOREACH(lif, &l2vpn->if_list, entry)
158
		printf("\tinterface %s\n", lif->ifname);
159
	LIST_FOREACH(pw, &l2vpn->pw_list, entry)
160
		print_pw(pw);
161
162
	printf("}\n");
163
}
164
165
static void
166
print_pw(struct l2vpn_pw *pw)
167
{
168
	printf("\tpseudowire %s {\n", pw->ifname);
169
170
	printf("\t\tneighbor-id %s\n", inet_ntoa(pw->lsr_id));
171
	printf("\t\tneighbor-addr %s\n", log_addr(pw->af, &pw->addr));
172
	printf("\t\tpw-id %u\n", pw->pwid);
173
174
	if (pw->flags & F_PW_STATUSTLV_CONF)
175
		printf("\t\tstatus-tlv yes\n");
176
	else
177
		printf("\t\tstatus-tlv no\n");
178
179
	if (pw->flags & F_PW_CWORD_CONF)
180
		printf("\t\tcontrol-word yes\n");
181
	else
182
		printf("\t\tcontrol-word no\n");
183
184
	printf("\t}\n");
185
}
186
187
void
188
print_config(struct ldpd_conf *conf)
189
{
190
	struct nbr_params	*nbrp;
191
	struct l2vpn		*l2vpn;
192
193
	print_mainconf(conf);
194
195
	if (conf->ipv4.flags & F_LDPD_AF_ENABLED)
196
		print_af(AF_INET, conf, &conf->ipv4);
197
	if (conf->ipv6.flags & F_LDPD_AF_ENABLED)
198
		print_af(AF_INET6, conf, &conf->ipv6);
199
200
	LIST_FOREACH(nbrp, &conf->nbrp_list, entry)
201
		print_nbrp(nbrp);
202
203
	LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry)
204
		print_l2vpn(l2vpn);
205
}