1 /* $OpenBSD: printconf.c,v 1.6 2021/01/19 17:38:41 florian Exp $ */ 2 3 /* 4 * Copyright (c) 2018 Florian Obser <florian@openbsd.org> 5 * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include <sys/types.h> 21 #include <sys/queue.h> 22 #include <sys/socket.h> 23 #include <sys/uio.h> 24 25 #include <netinet/in.h> 26 #include <net/if.h> 27 28 #include <arpa/inet.h> 29 30 #include <event.h> 31 #include <imsg.h> 32 #include <stdio.h> 33 34 #include "rad.h" 35 36 const char* yesno(int); 37 void print_ra_options(const char*, const struct ra_options_conf*); 38 void print_prefix_options(const char*, const struct ra_prefix_conf*); 39 40 const char* 41 yesno(int flag) 42 { 43 return flag ? "yes" : "no"; 44 } 45 46 void 47 print_ra_options(const char *indent, const struct ra_options_conf *ra_options) 48 { 49 struct ra_rdnss_conf *ra_rdnss; 50 struct ra_dnssl_conf *ra_dnssl; 51 char buf[INET6_ADDRSTRLEN]; 52 53 printf("%sdefault router %s\n", indent, yesno(ra_options->dfr)); 54 printf("%shop limit %d\n", indent, ra_options->cur_hl); 55 printf("%smanaged address configuration %s\n", indent, 56 yesno(ra_options->m_flag)); 57 printf("%sother configuration %s\n", indent, yesno(ra_options->o_flag)); 58 printf("%srouter lifetime %d\n", indent, ra_options->router_lifetime); 59 printf("%sreachable time %u\n", indent, ra_options->reachable_time); 60 printf("%sretrans timer %u\n", indent, ra_options->retrans_timer); 61 if (ra_options->mtu > 0) 62 printf("%smtu %u\n", indent, ra_options->mtu); 63 64 if (!SIMPLEQ_EMPTY(&ra_options->ra_rdnss_list) || 65 !SIMPLEQ_EMPTY(&ra_options->ra_dnssl_list)) { 66 printf("%sdns {\n", indent); 67 printf("%s\tlifetime %u\n", indent, ra_options->rdns_lifetime); 68 if (!SIMPLEQ_EMPTY(&ra_options->ra_rdnss_list)) { 69 printf("%s\tnameserver {\n", indent); 70 SIMPLEQ_FOREACH(ra_rdnss, 71 &ra_options->ra_rdnss_list, entry) { 72 inet_ntop(AF_INET6, &ra_rdnss->rdnss, 73 buf, sizeof(buf)); 74 printf("%s\t\t%s\n", indent, buf); 75 } 76 printf("%s\t}\n", indent); 77 } 78 if (!SIMPLEQ_EMPTY(&ra_options->ra_dnssl_list)) { 79 printf("%s\tsearch {\n", indent); 80 SIMPLEQ_FOREACH(ra_dnssl, 81 &ra_options->ra_dnssl_list, entry) 82 printf("%s\t\t%s\n", indent, ra_dnssl->search); 83 printf("%s\t}\n", indent); 84 } 85 printf("%s}\n", indent); 86 } 87 } 88 89 void 90 print_prefix_options(const char *indent, const struct ra_prefix_conf 91 *ra_prefix_conf) 92 { 93 printf("%svalid lifetime %u\n", indent, ra_prefix_conf->vltime); 94 printf("%spreferred lifetime %u\n", indent, ra_prefix_conf->pltime); 95 printf("%son-link %s\n", indent, yesno(ra_prefix_conf->lflag)); 96 printf("%sautonomous address-configuration %s\n", indent, 97 yesno(ra_prefix_conf->aflag)); 98 } 99 100 void 101 print_config(struct rad_conf *conf) 102 { 103 struct ra_iface_conf *iface; 104 struct ra_prefix_conf *prefix; 105 char buf[INET6_ADDRSTRLEN]; 106 107 print_ra_options("", &conf->ra_options); 108 printf("\n"); 109 110 SIMPLEQ_FOREACH(iface, &conf->ra_iface_list, entry) { 111 printf("interface %s {\n", iface->name); 112 113 print_ra_options("\t", &iface->ra_options); 114 115 if (iface->autoprefix) { 116 printf("\tauto prefix {\n"); 117 print_prefix_options("\t\t", iface->autoprefix); 118 printf("\t}\n"); 119 } else 120 printf("\tno auto prefix\n"); 121 122 SIMPLEQ_FOREACH(prefix, &iface->ra_prefix_list, entry) { 123 printf("\tprefix %s/%d {\n", inet_ntop(AF_INET6, 124 &prefix->prefix, buf, sizeof(buf)), 125 prefix->prefixlen); 126 print_prefix_options("\t\t", prefix); 127 printf("\t}\n"); 128 } 129 130 printf("}\n"); 131 } 132 } 133