1 /* $OpenBSD: printconf.c,v 1.4 2010/08/22 21:15:25 bluhm 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 "ospf6.h" 28 #include "ospf6d.h" 29 #include "ospfe.h" 30 #include "log.h" 31 32 void print_mainconf(struct ospfd_conf *); 33 const char *print_no(u_int16_t); 34 void print_redistribute(struct ospfd_conf *); 35 void print_rtlabel(struct ospfd_conf *); 36 void print_iface(struct iface *); 37 38 void 39 print_mainconf(struct ospfd_conf *conf) 40 { 41 printf("router-id %s\n", inet_ntoa(conf->rtr_id)); 42 43 if (conf->flags & OSPFD_FLAG_NO_FIB_UPDATE) 44 printf("fib-update no\n"); 45 else 46 printf("fib-update yes\n"); 47 48 if (conf->flags & OSPFD_FLAG_STUB_ROUTER) 49 printf("stub router yes\n"); 50 51 print_redistribute(conf); 52 print_rtlabel(conf); 53 54 printf("spf-delay %u\n", conf->spf_delay); 55 printf("spf-holdtime %u\n", conf->spf_hold_time); 56 } 57 58 const char * 59 print_no(u_int16_t type) 60 { 61 if (type & REDIST_NO) 62 return ("no "); 63 else 64 return (""); 65 } 66 67 void 68 print_redistribute(struct ospfd_conf *conf) 69 { 70 struct redistribute *r; 71 72 SIMPLEQ_FOREACH(r, &conf->redist_list, entry) { 73 switch (r->type & ~REDIST_NO) { 74 case REDIST_STATIC: 75 printf("%sredistribute static\n", print_no(r->type)); 76 break; 77 case REDIST_CONNECTED: 78 printf("%sredistribute connected\n", print_no(r->type)); 79 break; 80 case REDIST_LABEL: 81 printf("%sredistribute rtlabel %s\n", 82 print_no(r->type), rtlabel_id2name(r->label)); 83 break; 84 case REDIST_ADDR: 85 printf("%sredistribute %s/%d\n", 86 print_no(r->type), log_in6addr(&r->addr), 87 r->prefixlen); 88 break; 89 case REDIST_DEFAULT: 90 printf("%sredistribute default\n", print_no(r->type)); 91 break; 92 } 93 } 94 } 95 96 void 97 print_rtlabel(struct ospfd_conf *conf) 98 { 99 struct n2id_label *label; 100 101 TAILQ_FOREACH(label, &rt_labels, entry) 102 if (label->ext_tag) 103 printf("rtlabel \"%s\" external-tag %u\n", 104 label->name, label->ext_tag); 105 } 106 107 void 108 print_iface(struct iface *iface) 109 { 110 printf("\tinterface %s {\n", iface->name); 111 112 printf("\t\thello-interval %d\n", iface->hello_interval); 113 printf("\t\tmetric %d\n", iface->metric); 114 115 if (iface->cflags & F_IFACE_PASSIVE) 116 printf("\t\tpassive\n"); 117 if (*iface->demote_group) 118 printf("\t\tdemote %s\n", iface->demote_group); 119 120 printf("\t\tretransmit-interval %d\n", iface->rxmt_interval); 121 printf("\t\trouter-dead-time %d\n", iface->dead_interval); 122 printf("\t\trouter-priority %d\n", iface->priority); 123 printf("\t\ttransmit-delay %d\n", iface->transmit_delay); 124 125 printf("\t}\n"); 126 } 127 128 void 129 print_config(struct ospfd_conf *conf) 130 { 131 struct area *area; 132 struct iface *iface; 133 134 printf("\n"); 135 print_mainconf(conf); 136 printf("\n"); 137 138 LIST_FOREACH(area, &conf->area_list, entry) { 139 printf("area %s {\n", inet_ntoa(area->id)); 140 if (*area->demote_group) 141 printf("\tdemote %s %d\n", area->demote_group, 142 area->demote_level); 143 LIST_FOREACH(iface, &area->iface_list, entry) { 144 print_iface(iface); 145 } 146 printf("}\n\n"); 147 } 148 } 149