GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/ospfd/printconf.c Lines: 0 82 0.0 %
Date: 2017-11-07 Branches: 0 42 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: printconf.c,v 1.17 2016/11/19 12:46:46 sthen 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 msec %u\n", conf->spf_delay);
59
	printf("spf-holdtime msec %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 ", print_no(r->type));
80
			break;
81
		case REDIST_CONNECTED:
82
			printf("%sredistribute connected ", print_no(r->type));
83
			break;
84
		case REDIST_LABEL:
85
			printf("%sredistribute rtlabel %s ",
86
			    print_no(r->type), rtlabel_id2name(r->label));
87
			break;
88
		case REDIST_ADDR:
89
			printf("%sredistribute %s/%d ",
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 ", print_no(r->type));
95
			break;
96
		}
97
		printf("set { metric %d type %d }\n",
98
		    (r->metric & LSA_METRIC_MASK),
99
		    ((r->metric & LSA_ASEXT_E_FLAG) == 0 ? 1 : 2));
100
	}
101
}
102
103
void
104
print_rtlabel(struct ospfd_conf *conf)
105
{
106
	struct n2id_label	*label;
107
108
	TAILQ_FOREACH(label, &rt_labels, entry)
109
		if (label->ext_tag)
110
			printf("rtlabel \"%s\" external-tag %u\n",
111
			    label->name, label->ext_tag);
112
}
113
114
void
115
print_iface(struct iface *iface)
116
{
117
	struct auth_md	*md;
118
119
	printf("\tinterface %s:%s {\n", iface->name, inet_ntoa(iface->addr));
120
121
	printf("\t\tmetric %d\n", iface->metric);
122
123
	if (*iface->demote_group)
124
		printf("\t\tdemote %s\n", iface->demote_group);
125
	if (iface->passive)
126
		printf("\t\tpassive\n");
127
	else {
128
		printf("\t\tretransmit-interval %d\n", iface->rxmt_interval);
129
		if (iface->dead_interval == FAST_RTR_DEAD_TIME) {
130
			printf("\t\trouter-dead-time minimal\n");
131
			printf("\t\tfast-hello-interval msec %u\n",
132
			    iface->fast_hello_interval);
133
		} else {
134
			printf("\t\trouter-dead-time %d\n",
135
			    iface->dead_interval);
136
			printf("\t\thello-interval %d\n",
137
			    iface->hello_interval);
138
		}
139
		printf("\t\trouter-priority %d\n", iface->priority);
140
		printf("\t\ttransmit-delay %d\n", iface->transmit_delay);
141
142
		printf("\t\tauth-type %s\n", if_auth_name(iface->auth_type));
143
		switch (iface->auth_type) {
144
		case AUTH_TYPE_NONE:
145
			break;
146
		case AUTH_TYPE_SIMPLE:
147
			printf("\t\tauth-key XXXXXX\n");
148
			break;
149
		case AUTH_TYPE_CRYPT:
150
			printf("\t\tauth-md-keyid %d\n", iface->auth_keyid);
151
			TAILQ_FOREACH(md, &iface->auth_md_list, entry)
152
				printf("\t\tauth-md %d XXXXXX\n", md->keyid);
153
			break;
154
		default:
155
			printf("\t\tunknown auth type!\n");
156
			break;
157
		}
158
	}
159
160
	printf("\t}\n");
161
}
162
163
void
164
print_config(struct ospfd_conf *conf)
165
{
166
	struct area	*area;
167
	struct iface	*iface;
168
169
	printf("\n");
170
	print_mainconf(conf);
171
	printf("\n");
172
173
	LIST_FOREACH(area, &conf->area_list, entry) {
174
		printf("area %s {\n", inet_ntoa(area->id));
175
		if (area->stub) {
176
			printf("\tstub");
177
			if (SIMPLEQ_EMPTY(&area->redist_list))
178
				printf("\n");
179
			else {
180
				printf(" ");
181
				print_redistribute(&area->redist_list);
182
			}
183
		}
184
		if (*area->demote_group)
185
			printf("\tdemote %s %d\n", area->demote_group,
186
			area->demote_level);
187
		LIST_FOREACH(iface, &area->iface_list, entry) {
188
			print_iface(iface);
189
		}
190
		printf("}\n\n");
191
	}
192
}