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

Line Branch Exec Source
1
/*	$OpenBSD: printconf.c,v 1.6 2009/07/31 16:04:34 michele 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
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
	print_redistribute(conf);
45
46
	if (conf->options & OPT_SPLIT_HORIZON)
47
		printf("split-horizon simple\n");
48
	else if (conf->options & OPT_SPLIT_POISONED)
49
		printf("split-horizon poisoned\n");
50
	else
51
		printf("split-horizon none\n");
52
53
	if (conf->options & OPT_TRIGGERED_UPDATES)
54
		printf("triggered-updates yes\n");
55
	else
56
		printf("triggered-updates no\n");
57
}
58
59
const char *
60
print_no(u_int16_t type)
61
{
62
	if (type & REDIST_NO)
63
		return ("no ");
64
	else
65
		return ("");
66
}
67
68
void
69
print_redistribute(struct ripd_conf *conf)
70
{
71
	struct redistribute	*r;
72
73
	SIMPLEQ_FOREACH(r, &conf->redist_list, entry) {
74
		switch (r->type & ~REDIST_NO) {
75
		case REDIST_STATIC:
76
			printf("%sredistribute static\n", print_no(r->type));
77
			break;
78
		case REDIST_CONNECTED:
79
			printf("%sredistribute connected\n", print_no(r->type));
80
			break;
81
		case REDIST_LABEL:
82
			printf("%sredistribute rtlabel %s\n",
83
			    print_no(r->type), rtlabel_id2name(r->label));
84
			break;
85
		case REDIST_DEFAULT:
86
			printf("redistribute default\n");
87
			break;
88
		case REDIST_ADDR:
89
			printf("%ssredistribute %s/%d\n",
90
			    print_no(r->type), inet_ntoa(r->addr),
91
			    mask2prefixlen(r->mask.s_addr));
92
			break;
93
		}
94
	}
95
}
96
97
void
98
print_iface(struct iface *iface)
99
{
100
	struct auth_md	*m;
101
102
	printf("interface %s {\n", iface->name);
103
104
	if (iface->passive)
105
		printf("\tpassive\n");
106
107
	printf("\tcost %d\n", iface->cost);
108
109
	printf("\tauth-type %s\n", if_auth_name(iface->auth_type));
110
	switch (iface->auth_type) {
111
	case AUTH_NONE:
112
		break;
113
	case AUTH_SIMPLE:
114
		printf("\tauth-key XXXXXX\n");
115
		break;
116
	case AUTH_CRYPT:
117
		printf("\tauth-md-keyid %d\n", iface->auth_keyid);
118
		TAILQ_FOREACH(m, &iface->auth_md_list, entry)
119
			printf("\tauth-md %d XXXXXX\n", m->keyid);
120
		break;
121
	default:
122
		printf("\tunknown auth type!\n");
123
		break;
124
	}
125
126
	printf("}\n\n");
127
}
128
129
void
130
print_config(struct ripd_conf *conf)
131
{
132
	struct iface	*iface;
133
134
	print_mainconf(conf);
135
	printf("\n");
136
137
	LIST_FOREACH(iface, &conf->iface_list, entry) {
138
		print_iface(iface);
139
	}
140
}