1 /* $OpenBSD: printconf.c,v 1.16 2013/03/06 15:43:23 sthen 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->demote_group) 121 printf("\t\tdemote %s\n", iface->demote_group); 122 if (iface->passive) 123 printf("\t\tpassive\n"); 124 else { 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", 132 iface->dead_interval); 133 printf("\t\thello-interval %d\n", 134 iface->hello_interval); 135 } 136 printf("\t\trouter-priority %d\n", iface->priority); 137 printf("\t\ttransmit-delay %d\n", iface->transmit_delay); 138 139 printf("\t\tauth-type %s\n", if_auth_name(iface->auth_type)); 140 switch (iface->auth_type) { 141 case AUTH_TYPE_NONE: 142 break; 143 case AUTH_TYPE_SIMPLE: 144 printf("\t\tauth-key XXXXXX\n"); 145 break; 146 case AUTH_TYPE_CRYPT: 147 printf("\t\tauth-md-keyid %d\n", iface->auth_keyid); 148 TAILQ_FOREACH(md, &iface->auth_md_list, entry) 149 printf("\t\tauth-md %d XXXXXX\n", md->keyid); 150 break; 151 default: 152 printf("\t\tunknown auth type!\n"); 153 break; 154 } 155 } 156 157 printf("\t}\n"); 158 } 159 160 void 161 print_config(struct ospfd_conf *conf) 162 { 163 struct area *area; 164 struct iface *iface; 165 166 printf("\n"); 167 print_mainconf(conf); 168 printf("\n"); 169 170 LIST_FOREACH(area, &conf->area_list, entry) { 171 printf("area %s {\n", inet_ntoa(area->id)); 172 if (area->stub) { 173 printf("\tstub"); 174 if (SIMPLEQ_EMPTY(&area->redist_list)) 175 printf("\n"); 176 else { 177 printf(" "); 178 print_redistribute(&area->redist_list); 179 } 180 } 181 if (*area->demote_group) 182 printf("\tdemote %s %d\n", area->demote_group, 183 area->demote_level); 184 LIST_FOREACH(iface, &area->iface_list, entry) { 185 print_iface(iface); 186 } 187 printf("}\n\n"); 188 } 189 } 190