1 /* $OpenBSD: printconf.c,v 1.26 2016/07/01 23:14:31 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 if (conf->trans_pref == DUAL_STACK_LDPOV4) 48 printf("transport-preference ipv4\n"); 49 else if (conf->trans_pref == DUAL_STACK_LDPOV6) 50 printf("transport-preference ipv6\n"); 51 52 if (conf->flags & F_LDPD_DS_CISCO_INTEROP) 53 printf("ds-cisco-interop yes\n"); 54 else 55 printf("ds-cisco-interop no\n"); 56 } 57 58 static void 59 print_af(int af, struct ldpd_conf *conf, struct ldpd_af_conf *af_conf) 60 { 61 struct iface *iface; 62 struct iface_af *ia; 63 struct tnbr *tnbr; 64 65 printf("\naddress-family %s {\n", af_name(af)); 66 67 if (af_conf->flags & F_LDPD_AF_THELLO_ACCEPT) 68 printf("\ttargeted-hello-accept yes\n"); 69 else 70 printf("\ttargeted-hello-accept no\n"); 71 72 if (af_conf->flags & F_LDPD_AF_EXPNULL) 73 printf("\texplicit-null yes\n"); 74 else 75 printf("\texplicit-null no\n"); 76 77 if (af_conf->flags & F_LDPD_AF_NO_GTSM) 78 printf("\tgtsm-enable no\n"); 79 else 80 printf("\tgtsm-enable yes\n"); 81 82 printf("\tkeepalive %u\n", af_conf->keepalive); 83 printf("\ttransport-address %s\n", log_addr(af, &af_conf->trans_addr)); 84 85 LIST_FOREACH(iface, &conf->iface_list, entry) { 86 ia = iface_af_get(iface, af); 87 if (ia->enabled) 88 print_iface(iface, ia); 89 } 90 91 LIST_FOREACH(tnbr, &conf->tnbr_list, entry) 92 if (tnbr->af == af && tnbr->flags & F_TNBR_CONFIGURED) 93 print_tnbr(tnbr); 94 95 printf("}\n"); 96 } 97 98 static void 99 print_iface(struct iface *iface, struct iface_af *ia) 100 { 101 printf("\tinterface %s {\n", iface->name); 102 printf("\t\tlink-hello-holdtime %u\n", ia->hello_holdtime); 103 printf("\t\tlink-hello-interval %u\n", ia->hello_interval); 104 printf("\t}\n"); 105 } 106 107 static void 108 print_tnbr(struct tnbr *tnbr) 109 { 110 printf("\n\ttargeted-neighbor %s {\n", log_addr(tnbr->af, &tnbr->addr)); 111 printf("\t\ttargeted-hello-holdtime %u\n", tnbr->hello_holdtime); 112 printf("\t\ttargeted-hello-interval %u\n", tnbr->hello_interval); 113 printf("\t}\n"); 114 } 115 116 static void 117 print_nbrp(struct nbr_params *nbrp) 118 { 119 printf("\nneighbor %s {\n", inet_ntoa(nbrp->lsr_id)); 120 121 if (nbrp->flags & F_NBRP_KEEPALIVE) 122 printf("\tkeepalive %u\n", nbrp->keepalive); 123 124 if (nbrp->flags & F_NBRP_GTSM) { 125 if (nbrp->gtsm_enabled) 126 printf("\tgtsm-enable yes\n"); 127 else 128 printf("\tgtsm-enable no\n"); 129 } 130 131 if (nbrp->flags & F_NBRP_GTSM_HOPS) 132 printf("\tgtsm-hops %u\n", nbrp->gtsm_hops); 133 134 if (nbrp->auth.method == AUTH_MD5SIG) 135 printf("\tpassword XXXXXX\n"); 136 137 printf("}\n"); 138 } 139 140 static void 141 print_l2vpn(struct l2vpn *l2vpn) 142 { 143 struct l2vpn_if *lif; 144 struct l2vpn_pw *pw; 145 146 printf("\nl2vpn %s type vpls {\n", l2vpn->name); 147 148 if (l2vpn->pw_type == PW_TYPE_ETHERNET) 149 printf("\tpw-type ethernet\n"); 150 else 151 printf("\tpw-type ethernet-tagged\n"); 152 153 printf("\tmtu %u\n", l2vpn->mtu); 154 if (l2vpn->br_ifindex != 0) 155 printf("\tbridge %s\n", l2vpn->br_ifname); 156 LIST_FOREACH(lif, &l2vpn->if_list, entry) 157 printf("\tinterface %s\n", lif->ifname); 158 LIST_FOREACH(pw, &l2vpn->pw_list, entry) 159 print_pw(pw); 160 161 printf("}\n"); 162 } 163 164 static void 165 print_pw(struct l2vpn_pw *pw) 166 { 167 printf("\tpseudowire %s {\n", pw->ifname); 168 169 printf("\t\tneighbor-id %s\n", inet_ntoa(pw->lsr_id)); 170 printf("\t\tneighbor-addr %s\n", log_addr(pw->af, &pw->addr)); 171 printf("\t\tpw-id %u\n", pw->pwid); 172 173 if (pw->flags & F_PW_STATUSTLV_CONF) 174 printf("\t\tstatus-tlv yes\n"); 175 else 176 printf("\t\tstatus-tlv no\n"); 177 178 if (pw->flags & F_PW_CWORD_CONF) 179 printf("\t\tcontrol-word yes\n"); 180 else 181 printf("\t\tcontrol-word no\n"); 182 183 printf("\t}\n"); 184 } 185 186 void 187 print_config(struct ldpd_conf *conf) 188 { 189 struct nbr_params *nbrp; 190 struct l2vpn *l2vpn; 191 192 print_mainconf(conf); 193 194 if (conf->ipv4.flags & F_LDPD_AF_ENABLED) 195 print_af(AF_INET, conf, &conf->ipv4); 196 if (conf->ipv6.flags & F_LDPD_AF_ENABLED) 197 print_af(AF_INET6, conf, &conf->ipv6); 198 199 LIST_FOREACH(nbrp, &conf->nbrp_list, entry) 200 print_nbrp(nbrp); 201 202 LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry) 203 print_l2vpn(l2vpn); 204 } 205