1*7ee91690Sdlg /* $OpenBSD: printconf.c,v 1.28 2019/01/23 02:02:04 dlg Exp $ */
2ab0c2486Smichele
3ab0c2486Smichele /*
45dc9330aSrenato * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
55dc9330aSrenato * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
6ab0c2486Smichele * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
7ab0c2486Smichele *
8ab0c2486Smichele * Permission to use, copy, modify, and distribute this software for any
9ab0c2486Smichele * purpose with or without fee is hereby granted, provided that the above
10ab0c2486Smichele * copyright notice and this permission notice appear in all copies.
11ab0c2486Smichele *
12ab0c2486Smichele * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13ab0c2486Smichele * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14ab0c2486Smichele * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15ab0c2486Smichele * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16ab0c2486Smichele * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17ab0c2486Smichele * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18ab0c2486Smichele * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19ab0c2486Smichele */
20ab0c2486Smichele
21ab0c2486Smichele #include <sys/types.h>
22*7ee91690Sdlg #include <sys/socket.h>
23ab0c2486Smichele #include <arpa/inet.h>
24ab0c2486Smichele #include <stdio.h>
25*7ee91690Sdlg #include <netdb.h>
26*7ee91690Sdlg #include <err.h>
27ab0c2486Smichele
28ab0c2486Smichele #include "ldpd.h"
29ab0c2486Smichele #include "ldpe.h"
30a8c39dc0Srenato #include "log.h"
31ab0c2486Smichele
32c28a25a1Srenato static void print_mainconf(struct ldpd_conf *);
33c28a25a1Srenato static void print_af(int, struct ldpd_conf *, struct ldpd_af_conf *);
34c28a25a1Srenato static void print_iface(struct iface *, struct iface_af *);
35c28a25a1Srenato static void print_tnbr(struct tnbr *);
36c28a25a1Srenato static void print_nbrp(struct nbr_params *);
37c28a25a1Srenato static void print_l2vpn(struct l2vpn *);
38c28a25a1Srenato static void print_pw(struct l2vpn_pw *);
39ab0c2486Smichele
40c28a25a1Srenato static void
print_mainconf(struct ldpd_conf * conf)41ab0c2486Smichele print_mainconf(struct ldpd_conf *conf)
42ab0c2486Smichele {
43de27550dSrenato printf("router-id %s\n", inet_ntoa(conf->rtr_id));
44ab0c2486Smichele
453de94509Srenato if (conf->flags & F_LDPD_NO_FIB_UPDATE)
466a647450Sclaudio printf("fib-update no\n");
476a647450Sclaudio else
486a647450Sclaudio printf("fib-update yes\n");
496a647450Sclaudio
508622bd53Srenato printf("rdomain %u\n", conf->rdomain);
51a8c39dc0Srenato if (conf->trans_pref == DUAL_STACK_LDPOV4)
52a8c39dc0Srenato printf("transport-preference ipv4\n");
53a8c39dc0Srenato else if (conf->trans_pref == DUAL_STACK_LDPOV6)
54a8c39dc0Srenato printf("transport-preference ipv6\n");
5583dcf737Sclaudio
56a8c39dc0Srenato if (conf->flags & F_LDPD_DS_CISCO_INTEROP)
57a8c39dc0Srenato printf("ds-cisco-interop yes\n");
583de94509Srenato else
59a8c39dc0Srenato printf("ds-cisco-interop no\n");
60ab0c2486Smichele }
61ab0c2486Smichele
62c28a25a1Srenato static void
print_af(int af,struct ldpd_conf * conf,struct ldpd_af_conf * af_conf)63a8c39dc0Srenato print_af(int af, struct ldpd_conf *conf, struct ldpd_af_conf *af_conf)
64ab0c2486Smichele {
65a8c39dc0Srenato struct iface *iface;
66a8c39dc0Srenato struct iface_af *ia;
67a8c39dc0Srenato struct tnbr *tnbr;
68a8c39dc0Srenato
69a8c39dc0Srenato printf("\naddress-family %s {\n", af_name(af));
70a8c39dc0Srenato
71a8c39dc0Srenato if (af_conf->flags & F_LDPD_AF_THELLO_ACCEPT)
72a8c39dc0Srenato printf("\ttargeted-hello-accept yes\n");
73a8c39dc0Srenato else
74a8c39dc0Srenato printf("\ttargeted-hello-accept no\n");
75a8c39dc0Srenato
76a8c39dc0Srenato if (af_conf->flags & F_LDPD_AF_EXPNULL)
77a8c39dc0Srenato printf("\texplicit-null yes\n");
78a8c39dc0Srenato else
79a8c39dc0Srenato printf("\texplicit-null no\n");
80a8c39dc0Srenato
815ff72af8Srenato if (af_conf->flags & F_LDPD_AF_NO_GTSM)
825ff72af8Srenato printf("\tgtsm-enable no\n");
835ff72af8Srenato else
845ff72af8Srenato printf("\tgtsm-enable yes\n");
855ff72af8Srenato
86a8c39dc0Srenato printf("\tkeepalive %u\n", af_conf->keepalive);
87a8c39dc0Srenato printf("\ttransport-address %s\n", log_addr(af, &af_conf->trans_addr));
88a8c39dc0Srenato
89a8c39dc0Srenato LIST_FOREACH(iface, &conf->iface_list, entry) {
90a8c39dc0Srenato ia = iface_af_get(iface, af);
91a8c39dc0Srenato if (ia->enabled)
92a8c39dc0Srenato print_iface(iface, ia);
93a8c39dc0Srenato }
94a8c39dc0Srenato
95a8c39dc0Srenato LIST_FOREACH(tnbr, &conf->tnbr_list, entry)
96a8c39dc0Srenato if (tnbr->af == af && tnbr->flags & F_TNBR_CONFIGURED)
97a8c39dc0Srenato print_tnbr(tnbr);
98a8c39dc0Srenato
9983dcf737Sclaudio printf("}\n");
10083dcf737Sclaudio }
10183dcf737Sclaudio
102c28a25a1Srenato static void
print_iface(struct iface * iface,struct iface_af * ia)103a8c39dc0Srenato print_iface(struct iface *iface, struct iface_af *ia)
104a8c39dc0Srenato {
105a8c39dc0Srenato printf("\tinterface %s {\n", iface->name);
106a8c39dc0Srenato printf("\t\tlink-hello-holdtime %u\n", ia->hello_holdtime);
107a8c39dc0Srenato printf("\t\tlink-hello-interval %u\n", ia->hello_interval);
108a8c39dc0Srenato printf("\t}\n");
109a8c39dc0Srenato }
110a8c39dc0Srenato
111c28a25a1Srenato static void
print_tnbr(struct tnbr * tnbr)11283dcf737Sclaudio print_tnbr(struct tnbr *tnbr)
11383dcf737Sclaudio {
114a8c39dc0Srenato printf("\n\ttargeted-neighbor %s {\n", log_addr(tnbr->af, &tnbr->addr));
115a8c39dc0Srenato printf("\t\ttargeted-hello-holdtime %u\n", tnbr->hello_holdtime);
116a8c39dc0Srenato printf("\t\ttargeted-hello-interval %u\n", tnbr->hello_interval);
117a8c39dc0Srenato printf("\t}\n");
118ab0c2486Smichele }
119ab0c2486Smichele
120c28a25a1Srenato static void
print_nbrp(struct nbr_params * nbrp)121627846caSrenato print_nbrp(struct nbr_params *nbrp)
122627846caSrenato {
1231ce5acabSrenato printf("\nneighbor %s {\n", inet_ntoa(nbrp->lsr_id));
12419fce358Srenato
1253d39db89Srenato if (nbrp->flags & F_NBRP_KEEPALIVE)
1263d39db89Srenato printf("\tkeepalive %u\n", nbrp->keepalive);
12719fce358Srenato
1285ff72af8Srenato if (nbrp->flags & F_NBRP_GTSM) {
1295ff72af8Srenato if (nbrp->gtsm_enabled)
1305ff72af8Srenato printf("\tgtsm-enable yes\n");
1315ff72af8Srenato else
1325ff72af8Srenato printf("\tgtsm-enable no\n");
1335ff72af8Srenato }
1345ff72af8Srenato
1355ff72af8Srenato if (nbrp->flags & F_NBRP_GTSM_HOPS)
1365ff72af8Srenato printf("\tgtsm-hops %u\n", nbrp->gtsm_hops);
1375ff72af8Srenato
138627846caSrenato printf("}\n");
139627846caSrenato }
140627846caSrenato
141c28a25a1Srenato static void
print_l2vpn(struct l2vpn * l2vpn)1426399cec1Srenato print_l2vpn(struct l2vpn *l2vpn)
1436399cec1Srenato {
1446399cec1Srenato struct l2vpn_if *lif;
1456399cec1Srenato struct l2vpn_pw *pw;
1466399cec1Srenato
147de27550dSrenato printf("\nl2vpn %s type vpls {\n", l2vpn->name);
14819fce358Srenato
1496399cec1Srenato if (l2vpn->pw_type == PW_TYPE_ETHERNET)
1506399cec1Srenato printf("\tpw-type ethernet\n");
1516399cec1Srenato else
1526399cec1Srenato printf("\tpw-type ethernet-tagged\n");
15319fce358Srenato
1546399cec1Srenato printf("\tmtu %u\n", l2vpn->mtu);
1556399cec1Srenato if (l2vpn->br_ifindex != 0)
1566399cec1Srenato printf("\tbridge %s\n", l2vpn->br_ifname);
1576399cec1Srenato LIST_FOREACH(lif, &l2vpn->if_list, entry)
1586399cec1Srenato printf("\tinterface %s\n", lif->ifname);
1596399cec1Srenato LIST_FOREACH(pw, &l2vpn->pw_list, entry)
1606399cec1Srenato print_pw(pw);
16119fce358Srenato
1626399cec1Srenato printf("}\n");
1636399cec1Srenato }
1646399cec1Srenato
165c28a25a1Srenato static void
print_pw(struct l2vpn_pw * pw)16633f6ccfeSrenato print_pw(struct l2vpn_pw *pw)
16733f6ccfeSrenato {
16833f6ccfeSrenato printf("\tpseudowire %s {\n", pw->ifname);
169a8c39dc0Srenato
170a8c39dc0Srenato printf("\t\tneighbor-id %s\n", inet_ntoa(pw->lsr_id));
171a8c39dc0Srenato printf("\t\tneighbor-addr %s\n", log_addr(pw->af, &pw->addr));
17233f6ccfeSrenato printf("\t\tpw-id %u\n", pw->pwid);
17319fce358Srenato
17433f6ccfeSrenato if (pw->flags & F_PW_STATUSTLV_CONF)
17533f6ccfeSrenato printf("\t\tstatus-tlv yes\n");
17633f6ccfeSrenato else
17733f6ccfeSrenato printf("\t\tstatus-tlv no\n");
17819fce358Srenato
1792d825b92Srenato if (pw->flags & F_PW_CWORD_CONF)
18033f6ccfeSrenato printf("\t\tcontrol-word yes\n");
18133f6ccfeSrenato else
18233f6ccfeSrenato printf("\t\tcontrol-word no\n");
18319fce358Srenato
18433f6ccfeSrenato printf("\t}\n");
18533f6ccfeSrenato }
18633f6ccfeSrenato
187*7ee91690Sdlg static void
print_auth(struct ldpd_conf * conf)188*7ee91690Sdlg print_auth(struct ldpd_conf *conf)
189*7ee91690Sdlg {
190*7ee91690Sdlg struct ldp_auth *auth;
191*7ee91690Sdlg
192*7ee91690Sdlg printf("\n");
193*7ee91690Sdlg
194*7ee91690Sdlg LIST_FOREACH(auth, &conf->auth_list, entry) {
195*7ee91690Sdlg if (auth->md5key_len)
196*7ee91690Sdlg printf("tcp md5sig key XXX");
197*7ee91690Sdlg else
198*7ee91690Sdlg printf("no tcp md5sig");
199*7ee91690Sdlg if (auth->idlen) {
200*7ee91690Sdlg char hbuf[NI_MAXHOST];
201*7ee91690Sdlg
202*7ee91690Sdlg if (inet_net_ntop(AF_INET, &auth->id, auth->idlen,
203*7ee91690Sdlg hbuf, sizeof(hbuf)) == NULL)
204*7ee91690Sdlg err(1, "inet_net_ntop");
205*7ee91690Sdlg
206*7ee91690Sdlg printf(" %s", hbuf);
207*7ee91690Sdlg }
208*7ee91690Sdlg printf("\n");
209*7ee91690Sdlg }
210*7ee91690Sdlg }
211*7ee91690Sdlg
21233f6ccfeSrenato void
print_config(struct ldpd_conf * conf)213ab0c2486Smichele print_config(struct ldpd_conf *conf)
214ab0c2486Smichele {
215627846caSrenato struct nbr_params *nbrp;
2166399cec1Srenato struct l2vpn *l2vpn;
217ab0c2486Smichele
218ab0c2486Smichele print_mainconf(conf);
219ab0c2486Smichele
220*7ee91690Sdlg if (!LIST_EMPTY(&conf->auth_list))
221*7ee91690Sdlg print_auth(conf);
222*7ee91690Sdlg
223a8c39dc0Srenato if (conf->ipv4.flags & F_LDPD_AF_ENABLED)
224a8c39dc0Srenato print_af(AF_INET, conf, &conf->ipv4);
225a8c39dc0Srenato if (conf->ipv6.flags & F_LDPD_AF_ENABLED)
226a8c39dc0Srenato print_af(AF_INET6, conf, &conf->ipv6);
227de27550dSrenato
228627846caSrenato LIST_FOREACH(nbrp, &conf->nbrp_list, entry)
229627846caSrenato print_nbrp(nbrp);
230de27550dSrenato
2316399cec1Srenato LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry)
2326399cec1Srenato print_l2vpn(l2vpn);
233ab0c2486Smichele }
234