1 /* $OpenBSD: printconf.c,v 1.15 2010/02/16 08:39:05 dlg 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 "ospf.h" 28 #include "ospfd.h" 29 #include "ospfe.h" 30 31 void print_mainconf(struct ospfd_conf *); 32 const char *print_no(u_int16_t); 33 void print_redistribute(struct redist_list *); 34 void print_rtlabel(struct ospfd_conf *); 35 void print_iface(struct iface *); 36 37 void 38 print_mainconf(struct ospfd_conf *conf) 39 { 40 printf("router-id %s\n", inet_ntoa(conf->rtr_id)); 41 42 if (conf->flags & OSPFD_FLAG_NO_FIB_UPDATE) 43 printf("fib-update no\n"); 44 else 45 printf("fib-update yes\n"); 46 47 if (conf->rfc1583compat) 48 printf("rfc1583compat yes\n"); 49 else 50 printf("rfc1583compat no\n"); 51 52 if (conf->flags & OSPFD_FLAG_STUB_ROUTER) 53 printf("stub router yes\n"); 54 55 print_redistribute(&conf->redist_list); 56 print_rtlabel(conf); 57 58 printf("spf-delay msec %u\n", conf->spf_delay); 59 printf("spf-holdtime msec %u\n", conf->spf_hold_time); 60 } 61 62 const char * 63 print_no(u_int16_t type) 64 { 65 if (type & REDIST_NO) 66 return ("no "); 67 else 68 return (""); 69 } 70 71 void 72 print_redistribute(struct redist_list *rlh) 73 { 74 struct redistribute *r; 75 76 SIMPLEQ_FOREACH(r, rlh, entry) { 77 switch (r->type & ~REDIST_NO) { 78 case REDIST_STATIC: 79 printf("%sredistribute static\n", print_no(r->type)); 80 break; 81 case REDIST_CONNECTED: 82 printf("%sredistribute connected\n", print_no(r->type)); 83 break; 84 case REDIST_LABEL: 85 printf("%sredistribute rtlabel %s\n", 86 print_no(r->type), rtlabel_id2name(r->label)); 87 break; 88 case REDIST_ADDR: 89 printf("%sredistribute %s/%d\n", 90 print_no(r->type), inet_ntoa(r->addr), 91 mask2prefixlen(r->mask.s_addr)); 92 break; 93 case REDIST_DEFAULT: 94 printf("%sredistribute default\n", print_no(r->type)); 95 break; 96 } 97 } 98 } 99 100 void 101 print_rtlabel(struct ospfd_conf *conf) 102 { 103 struct n2id_label *label; 104 105 TAILQ_FOREACH(label, &rt_labels, entry) 106 if (label->ext_tag) 107 printf("rtlabel \"%s\" external-tag %u\n", 108 label->name, label->ext_tag); 109 } 110 111 void 112 print_iface(struct iface *iface) 113 { 114 struct auth_md *md; 115 116 printf("\tinterface %s:%s {\n", iface->name, inet_ntoa(iface->addr)); 117 118 printf("\t\tmetric %d\n", iface->metric); 119 120 if (iface->passive) 121 printf("\t\tpassive\n"); 122 if (*iface->demote_group) 123 printf("\t\tdemote %s\n", iface->demote_group); 124 125 printf("\t\tretransmit-interval %d\n", iface->rxmt_interval); 126 if (iface->dead_interval == FAST_RTR_DEAD_TIME) { 127 printf("\t\trouter-dead-time minimal\n"); 128 printf("\t\tfast-hello-interval msec %u\n", 129 iface->fast_hello_interval); 130 } else { 131 printf("\t\trouter-dead-time %d\n", iface->dead_interval); 132 printf("\t\thello-interval %d\n", iface->hello_interval); 133 } 134 printf("\t\trouter-priority %d\n", iface->priority); 135 printf("\t\ttransmit-delay %d\n", iface->transmit_delay); 136 137 printf("\t\tauth-type %s\n", if_auth_name(iface->auth_type)); 138 switch (iface->auth_type) { 139 case AUTH_TYPE_NONE: 140 break; 141 case AUTH_TYPE_SIMPLE: 142 printf("\t\tauth-key XXXXXX\n"); 143 break; 144 case AUTH_TYPE_CRYPT: 145 printf("\t\tauth-md-keyid %d\n", iface->auth_keyid); 146 TAILQ_FOREACH(md, &iface->auth_md_list, entry) 147 printf("\t\tauth-md %d XXXXXX\n", md->keyid); 148 break; 149 default: 150 printf("\t\tunknown auth type!\n"); 151 break; 152 } 153 154 printf("\t}\n"); 155 } 156 157 void 158 print_config(struct ospfd_conf *conf) 159 { 160 struct area *area; 161 struct iface *iface; 162 163 printf("\n"); 164 print_mainconf(conf); 165 printf("\n"); 166 167 LIST_FOREACH(area, &conf->area_list, entry) { 168 printf("area %s {\n", inet_ntoa(area->id)); 169 if (area->stub) { 170 printf("\tstub"); 171 if (SIMPLEQ_EMPTY(&area->redist_list)) 172 printf("\n"); 173 else { 174 printf(" "); 175 print_redistribute(&area->redist_list); 176 } 177 } 178 if (*area->demote_group) 179 printf("\tdemote %s %d\n", area->demote_group, 180 area->demote_level); 181 LIST_FOREACH(iface, &area->iface_list, entry) { 182 print_iface(iface); 183 } 184 printf("}\n\n"); 185 } 186 } 187