1 /* $OpenBSD: printconf.c,v 1.13 2009/01/07 21:16:36 claudio 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 %u\n", conf->spf_delay); 59 printf("spf-holdtime %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\thello-interval %d\n", iface->hello_interval); 119 printf("\t\tmetric %d\n", iface->metric); 120 121 if (iface->passive) 122 printf("\t\tpassive\n"); 123 if (*iface->demote_group) 124 printf("\t\tdemote %s\n", iface->demote_group); 125 126 printf("\t\tretransmit-interval %d\n", iface->rxmt_interval); 127 printf("\t\trouter-dead-time %d\n", iface->dead_interval); 128 printf("\t\trouter-priority %d\n", iface->priority); 129 printf("\t\ttransmit-delay %d\n", iface->transmit_delay); 130 131 printf("\t\tauth-type %s\n", if_auth_name(iface->auth_type)); 132 switch (iface->auth_type) { 133 case AUTH_TYPE_NONE: 134 break; 135 case AUTH_TYPE_SIMPLE: 136 printf("\t\tauth-key XXXXXX\n"); 137 break; 138 case AUTH_TYPE_CRYPT: 139 printf("\t\tauth-md-keyid %d\n", iface->auth_keyid); 140 TAILQ_FOREACH(md, &iface->auth_md_list, entry) 141 printf("\t\tauth-md %d XXXXXX\n", md->keyid); 142 break; 143 default: 144 printf("\t\tunknown auth type!\n"); 145 break; 146 } 147 148 printf("\t}\n"); 149 } 150 151 void 152 print_config(struct ospfd_conf *conf) 153 { 154 struct area *area; 155 struct iface *iface; 156 157 printf("\n"); 158 print_mainconf(conf); 159 printf("\n"); 160 161 LIST_FOREACH(area, &conf->area_list, entry) { 162 printf("area %s {\n", inet_ntoa(area->id)); 163 if (area->stub) { 164 printf("\tstub"); 165 if (SIMPLEQ_EMPTY(&area->redist_list)) 166 printf("\n"); 167 else { 168 printf(" "); 169 print_redistribute(&area->redist_list); 170 } 171 } 172 if (*area->demote_group) 173 printf("\tdemote %s %d\n", area->demote_group, 174 area->demote_level); 175 LIST_FOREACH(iface, &area->iface_list, entry) { 176 print_iface(iface); 177 } 178 printf("}\n\n"); 179 } 180 } 181