xref: /openbsd-src/usr.sbin/ripd/printconf.c (revision 5fa7d4c4bb8be553b3325d2016e39ea5e49ba913)
1 /*	$OpenBSD: printconf.c,v 1.8 2019/05/12 11:27:08 denis Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005, 2006 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 "rip.h"
28 #include "ripd.h"
29 #include "ripe.h"
30 
31 void	print_mainconf(struct ripd_conf *);
32 const char *print_no(u_int16_t);
33 void	print_redistribute(struct ripd_conf *);
34 void	print_iface(struct iface *);
35 
36 void
print_mainconf(struct ripd_conf * conf)37 print_mainconf(struct ripd_conf *conf)
38 {
39 	if (conf->flags & RIPD_FLAG_NO_FIB_UPDATE)
40 		printf("fib-update no\n");
41 	else
42 		printf("fib-update yes\n");
43 
44 	printf("fib-priority %hhu\n", conf->fib_priority);
45 
46 	print_redistribute(conf);
47 
48 	if (conf->options & OPT_SPLIT_HORIZON)
49 		printf("split-horizon simple\n");
50 	else if (conf->options & OPT_SPLIT_POISONED)
51 		printf("split-horizon poisoned\n");
52 	else
53 		printf("split-horizon none\n");
54 
55 	if (conf->options & OPT_TRIGGERED_UPDATES)
56 		printf("triggered-updates yes\n");
57 	else
58 		printf("triggered-updates no\n");
59 }
60 
61 const char *
print_no(u_int16_t type)62 print_no(u_int16_t type)
63 {
64 	if (type & REDIST_NO)
65 		return ("no ");
66 	else
67 		return ("");
68 }
69 
70 void
print_redistribute(struct ripd_conf * conf)71 print_redistribute(struct ripd_conf *conf)
72 {
73 	struct redistribute	*r;
74 
75 	SIMPLEQ_FOREACH(r, &conf->redist_list, entry) {
76 		switch (r->type & ~REDIST_NO) {
77 		case REDIST_STATIC:
78 			printf("%sredistribute static\n", print_no(r->type));
79 			break;
80 		case REDIST_CONNECTED:
81 			printf("%sredistribute connected\n", print_no(r->type));
82 			break;
83 		case REDIST_LABEL:
84 			printf("%sredistribute rtlabel %s\n",
85 			    print_no(r->type), rtlabel_id2name(r->label));
86 			break;
87 		case REDIST_DEFAULT:
88 			printf("redistribute default\n");
89 			break;
90 		case REDIST_ADDR:
91 			printf("%sredistribute %s/%d\n",
92 			    print_no(r->type), inet_ntoa(r->addr),
93 			    mask2prefixlen(r->mask.s_addr));
94 			break;
95 		}
96 	}
97 }
98 
99 void
print_iface(struct iface * iface)100 print_iface(struct iface *iface)
101 {
102 	struct auth_md	*m;
103 
104 	printf("interface %s {\n", iface->name);
105 
106 	if (iface->passive)
107 		printf("\tpassive\n");
108 
109 	printf("\tcost %d\n", iface->cost);
110 
111 	printf("\tauth-type %s\n", if_auth_name(iface->auth_type));
112 	switch (iface->auth_type) {
113 	case AUTH_NONE:
114 		break;
115 	case AUTH_SIMPLE:
116 		printf("\tauth-key XXXXXX\n");
117 		break;
118 	case AUTH_CRYPT:
119 		printf("\tauth-md-keyid %d\n", iface->auth_keyid);
120 		TAILQ_FOREACH(m, &iface->auth_md_list, entry)
121 			printf("\tauth-md %d XXXXXX\n", m->keyid);
122 		break;
123 	default:
124 		printf("\tunknown auth type!\n");
125 		break;
126 	}
127 
128 	printf("}\n\n");
129 }
130 
131 void
print_config(struct ripd_conf * conf)132 print_config(struct ripd_conf *conf)
133 {
134 	struct iface	*iface;
135 
136 	print_mainconf(conf);
137 	printf("\n");
138 
139 	LIST_FOREACH(iface, &conf->iface_list, entry) {
140 		print_iface(iface);
141 	}
142 }
143