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

Line Branch Exec Source
1
/*	$OpenBSD: logmsg.c,v 1.1 2016/09/02 17:59:58 benno Exp $ */
2
3
/*
4
 * Copyright (c) 2003, 2004 Henning Brauer <henning@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 <errno.h>
20
#include <stdarg.h>
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <string.h>
24
#include <syslog.h>
25
#include <unistd.h>
26
#include <arpa/inet.h>
27
#include <netdb.h>
28
29
#include "eigrpd.h"
30
#include "rde.h"
31
#include "log.h"
32
33
#define NUM_LOGS	4
34
const char *
35
log_sockaddr(void *vp)
36
{
37
	static char	 buf[NUM_LOGS][NI_MAXHOST];
38
	static int	 round = 0;
39
	struct sockaddr	*sa = vp;
40
41
	round = (round + 1) % NUM_LOGS;
42
43
	if (getnameinfo(sa, sa->sa_len, buf[round], NI_MAXHOST, NULL, 0,
44
	    NI_NUMERICHOST))
45
		return ("(unknown)");
46
	else
47
		return (buf[round]);
48
}
49
50
const char *
51
log_in6addr(const struct in6_addr *addr)
52
{
53
	struct sockaddr_in6	sa_in6;
54
55
	memset(&sa_in6, 0, sizeof(sa_in6));
56
	sa_in6.sin6_len = sizeof(sa_in6);
57
	sa_in6.sin6_family = AF_INET6;
58
	sa_in6.sin6_addr = *addr;
59
60
	recoverscope(&sa_in6);
61
62
	return (log_sockaddr(&sa_in6));
63
}
64
65
const char *
66
log_in6addr_scope(const struct in6_addr *addr, unsigned int ifindex)
67
{
68
	struct sockaddr_in6	sa_in6;
69
70
	memset(&sa_in6, 0, sizeof(sa_in6));
71
	sa_in6.sin6_len = sizeof(sa_in6);
72
	sa_in6.sin6_family = AF_INET6;
73
	sa_in6.sin6_addr = *addr;
74
75
	addscope(&sa_in6, ifindex);
76
77
	return (log_sockaddr(&sa_in6));
78
}
79
80
const char *
81
log_addr(int af, union eigrpd_addr *addr)
82
{
83
	static char	 buf[NUM_LOGS][INET6_ADDRSTRLEN];
84
	static int	 round = 0;
85
86
	switch (af) {
87
	case AF_INET:
88
		round = (round + 1) % NUM_LOGS;
89
		if (inet_ntop(AF_INET, &addr->v4, buf[round],
90
		    sizeof(buf[round])) == NULL)
91
			return ("???");
92
		return (buf[round]);
93
	case AF_INET6:
94
		return (log_in6addr(&addr->v6));
95
	default:
96
		break;
97
	}
98
99
	return ("???");
100
}
101
102
const char *
103
log_prefix(struct rt_node *rn)
104
{
105
	static char	buf[64];
106
107
	if (snprintf(buf, sizeof(buf), "%s/%u", log_addr(rn->eigrp->af,
108
	    &rn->prefix), rn->prefixlen) == -1)
109
		return ("???");
110
111
	return (buf);
112
}
113
114
const char *
115
log_route_origin(int af, struct rde_nbr *nbr)
116
{
117
	if (nbr->flags & F_RDE_NBR_SELF) {
118
		if (nbr->flags & F_RDE_NBR_REDIST)
119
			return ("redistribute");
120
		if (nbr->flags & F_RDE_NBR_SUMMARY)
121
			return ("summary");
122
		else
123
			return ("connected");
124
	}
125
126
	return (log_addr(af, &nbr->addr));
127
}
128
129
const char *
130
opcode_name(uint8_t opcode)
131
{
132
	switch (opcode) {
133
	case EIGRP_OPC_UPDATE:
134
		return ("UPDATE");
135
	case EIGRP_OPC_REQUEST:
136
		return ("REQUEST");
137
	case EIGRP_OPC_QUERY:
138
		return ("QUERY");
139
	case EIGRP_OPC_REPLY:
140
		return ("REPLY");
141
	case EIGRP_OPC_HELLO:
142
		return ("HELLO");
143
	case EIGRP_OPC_PROBE:
144
		return ("PROBE");
145
	case EIGRP_OPC_SIAQUERY:
146
		return ("SIAQUERY");
147
	case EIGRP_OPC_SIAREPLY:
148
		return ("SIAREPLY");
149
	default:
150
		return ("UNKNOWN");
151
	}
152
}
153
154
const char *
155
af_name(int af)
156
{
157
	switch (af) {
158
	case AF_INET:
159
		return ("ipv4");
160
	case AF_INET6:
161
		return ("ipv6");
162
	default:
163
		return ("UNKNOWN");
164
	}
165
}
166
167
const char *
168
if_type_name(enum iface_type type)
169
{
170
	switch (type) {
171
	case IF_TYPE_POINTOPOINT:
172
		return ("POINTOPOINT");
173
	case IF_TYPE_BROADCAST:
174
		return ("BROADCAST");
175
	default:
176
		return ("UNKNOWN");
177
	}
178
}
179
180
const char *
181
dual_state_name(int state)
182
{
183
	switch (state) {
184
	case DUAL_STA_PASSIVE:
185
		return ("PASSIVE");
186
	case DUAL_STA_ACTIVE0:
187
		return ("ACTIVE(Oij=0)");
188
	case DUAL_STA_ACTIVE1:
189
		return ("ACTIVE(Oij=1)");
190
	case DUAL_STA_ACTIVE2:
191
		return ("ACTIVE(Oij=2)");
192
	case DUAL_STA_ACTIVE3:
193
		return ("ACTIVE(Oij=3)");
194
	default:
195
		return ("UNKNOWN");
196
	}
197
}
198
199
const char *
200
ext_proto_name(int proto)
201
{
202
	switch (proto) {
203
	case EIGRP_EXT_PROTO_IGRP:
204
		return ("IGRP");
205
	case EIGRP_EXT_PROTO_EIGRP:
206
		return ("EIGRP");
207
	case EIGRP_EXT_PROTO_STATIC:
208
		return ("Static");
209
	case EIGRP_EXT_PROTO_RIP:
210
		return ("RIP");
211
	case EIGRP_EXT_PROTO_HELLO:
212
		return ("HELLO");
213
	case EIGRP_EXT_PROTO_OSPF:
214
		return ("OSPF");
215
	case EIGRP_EXT_PROTO_ISIS:
216
		return ("ISIS");
217
	case EIGRP_EXT_PROTO_EGP:
218
		return ("EGP");
219
	case EIGRP_EXT_PROTO_BGP:
220
		return ("BGP");
221
	case EIGRP_EXT_PROTO_IDRP:
222
		return ("IDRP");
223
	case EIGRP_EXT_PROTO_CONN:
224
		return ("Connected");
225
	default:
226
		return ("UNKNOWN");
227
	}
228
}