1 /* $OpenBSD: printconf.c,v 1.7 2022/10/15 13:26:15 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 struct ra_pref64_conf *pref64; 52 char buf[INET6_ADDRSTRLEN]; 53 54 printf("%sdefault router %s\n", indent, yesno(ra_options->dfr)); 55 printf("%shop limit %d\n", indent, ra_options->cur_hl); 56 printf("%smanaged address configuration %s\n", indent, 57 yesno(ra_options->m_flag)); 58 printf("%sother configuration %s\n", indent, yesno(ra_options->o_flag)); 59 printf("%srouter lifetime %d\n", indent, ra_options->router_lifetime); 60 printf("%sreachable time %u\n", indent, ra_options->reachable_time); 61 printf("%sretrans timer %u\n", indent, ra_options->retrans_timer); 62 if (ra_options->mtu > 0) 63 printf("%smtu %u\n", indent, ra_options->mtu); 64 65 if (!SIMPLEQ_EMPTY(&ra_options->ra_rdnss_list) || 66 !SIMPLEQ_EMPTY(&ra_options->ra_dnssl_list)) { 67 printf("%sdns {\n", indent); 68 printf("%s\tlifetime %u\n", indent, ra_options->rdns_lifetime); 69 if (!SIMPLEQ_EMPTY(&ra_options->ra_rdnss_list)) { 70 printf("%s\tnameserver {\n", indent); 71 SIMPLEQ_FOREACH(ra_rdnss, 72 &ra_options->ra_rdnss_list, entry) { 73 inet_ntop(AF_INET6, &ra_rdnss->rdnss, 74 buf, sizeof(buf)); 75 printf("%s\t\t%s\n", indent, buf); 76 } 77 printf("%s\t}\n", indent); 78 } 79 if (!SIMPLEQ_EMPTY(&ra_options->ra_dnssl_list)) { 80 printf("%s\tsearch {\n", indent); 81 SIMPLEQ_FOREACH(ra_dnssl, 82 &ra_options->ra_dnssl_list, entry) 83 printf("%s\t\t%s\n", indent, ra_dnssl->search); 84 printf("%s\t}\n", indent); 85 } 86 printf("%s}\n", indent); 87 } 88 SIMPLEQ_FOREACH(pref64, &ra_options->ra_pref64_list, entry) { 89 printf("%snat64 prefix %s/%d {\n", indent, inet_ntop(AF_INET6, 90 &pref64->prefix, buf, sizeof(buf)), pref64->prefixlen); 91 printf("%s\tlifetime %u\n", indent, pref64->ltime); 92 printf("%s}\n", indent); 93 } 94 95 } 96 97 void 98 print_prefix_options(const char *indent, const struct ra_prefix_conf 99 *ra_prefix_conf) 100 { 101 printf("%svalid lifetime %u\n", indent, ra_prefix_conf->vltime); 102 printf("%spreferred lifetime %u\n", indent, ra_prefix_conf->pltime); 103 printf("%son-link %s\n", indent, yesno(ra_prefix_conf->lflag)); 104 printf("%sautonomous address-configuration %s\n", indent, 105 yesno(ra_prefix_conf->aflag)); 106 } 107 108 void 109 print_config(struct rad_conf *conf) 110 { 111 struct ra_iface_conf *iface; 112 struct ra_prefix_conf *prefix; 113 char buf[INET6_ADDRSTRLEN]; 114 115 print_ra_options("", &conf->ra_options); 116 printf("\n"); 117 118 SIMPLEQ_FOREACH(iface, &conf->ra_iface_list, entry) { 119 printf("interface %s {\n", iface->name); 120 121 print_ra_options("\t", &iface->ra_options); 122 123 if (iface->autoprefix) { 124 printf("\tauto prefix {\n"); 125 print_prefix_options("\t\t", iface->autoprefix); 126 printf("\t}\n"); 127 } else 128 printf("\tno auto prefix\n"); 129 130 SIMPLEQ_FOREACH(prefix, &iface->ra_prefix_list, entry) { 131 printf("\tprefix %s/%d {\n", inet_ntop(AF_INET6, 132 &prefix->prefix, buf, sizeof(buf)), 133 prefix->prefixlen); 134 print_prefix_options("\t\t", prefix); 135 printf("\t}\n"); 136 } 137 138 printf("}\n"); 139 } 140 } 141