]> git.saurik.com Git - apple/network_cmds.git/blame - rtadvd.tproj/dump.c
network_cmds-176.tar.gz
[apple/network_cmds.git] / rtadvd.tproj / dump.c
CommitLineData
7ba0088d
A
1/* $KAME: dump.c,v 1.16 2001/03/21 17:41:13 jinmei Exp $ */
2
3/*
4 * Copyright (C) 2000 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * $FreeBSD: src/usr.sbin/rtadvd/dump.c,v 1.1.2.2 2001/07/03 11:02:14 ume Exp $
32 */
33#include <sys/types.h>
34#include <sys/socket.h>
35#include <sys/queue.h>
36
37#include <net/if.h>
38#if defined(__FreeBSD__) && __FreeBSD__ >= 3
39#include <net/if_var.h>
40#endif /* __FreeBSD__ >= 3 */
41#include <net/if_dl.h>
42
43#include <netinet/in.h>
44
45/* XXX: the following two are non-standard include files */
46#include <netinet6/in6_var.h>
47#include <netinet6/nd6.h>
48
49#include <arpa/inet.h>
50
51#include <time.h>
52#include <stdio.h>
53#include <stdarg.h>
54#include <syslog.h>
55#include <string.h>
56#include <errno.h>
57
58#include "rtadvd.h"
59#include "timer.h"
60#include "if.h"
61#include "dump.h"
62
63static FILE *fp;
64
65extern struct rainfo *ralist;
66
67static char *ether_str __P((struct sockaddr_dl *));
68static void if_dump __P((void));
69
70#ifdef __FreeBSD__ /* XXX: see PORTABILITY */
71#define LONGLONG "%qu"
72#else
73#define LONGLONG "%llu"
74#endif
75
76static char *rtpref_str[] = {
77 "medium", /* 00 */
78 "high", /* 01 */
79 "rsv", /* 10 */
80 "low" /* 11 */
81};
82
83static char *
84ether_str(sdl)
85 struct sockaddr_dl *sdl;
86{
87 static char ebuf[32];
88 u_char *cp;
89
90 if (sdl->sdl_alen && sdl->sdl_alen > 5) {
91 cp = (u_char *)LLADDR(sdl);
92 sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
93 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
94 }
95 else {
96 sprintf(ebuf, "NONE");
97 }
98
99 return(ebuf);
100}
101
102static void
103if_dump()
104{
105 struct rainfo *rai;
106 struct prefix *pfx;
107 char prefixbuf[INET6_ADDRSTRLEN];
108 int first;
109 struct timeval now;
110
111 gettimeofday(&now, NULL); /* XXX: unused in most cases */
112 for (rai = ralist; rai; rai = rai->next) {
113 fprintf(fp, "%s:\n", rai->ifname);
114
115 fprintf(fp, " Status: %s\n",
116 (iflist[rai->ifindex]->ifm_flags & IFF_UP) ? "UP" :
117 "DOWN");
118
119 /* control information */
120 if (rai->lastsent.tv_sec) {
121 /* note that ctime() appends CR by itself */
122 fprintf(fp, " Last RA sent: %s",
123 ctime((time_t *)&rai->lastsent.tv_sec));
124 }
125 if (rai->timer) {
126 fprintf(fp, " Next RA will be sent: %s",
127 ctime((time_t *)&rai->timer->tm.tv_sec));
128 }
129 else
130 fprintf(fp, " RA timer is stopped");
131 fprintf(fp, " waits: %d, initcount: %d\n",
132 rai->waiting, rai->initcounter);
133
134 /* statistics */
135 fprintf(fp,
136 " statistics: RA(out/in/inconsistent): "
137 LONGLONG "/" LONGLONG "/" LONGLONG ", ",
138 (unsigned long long)rai->raoutput,
139 (unsigned long long)rai->rainput,
140 (unsigned long long)rai->rainconsistent);
141 fprintf(fp, "RS(input): " LONGLONG "\n",
142 (unsigned long long)rai->rsinput);
143
144 /* interface information */
145 if (rai->advlinkopt)
146 fprintf(fp, " Link-layer address: %s\n",
147 ether_str(rai->sdl));
148 fprintf(fp, " MTU: %d\n", rai->phymtu);
149
150 /* Router configuration variables */
151 fprintf(fp,
152 " DefaultLifetime: %d, MaxAdvInterval: %d, "
153 "MinAdvInterval: %d\n",
154 rai->lifetime, rai->maxinterval, rai->mininterval);
155 fprintf(fp, " Flags: %s%s%s, ",
156 rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
157#ifdef MIP6
158 rai->haflg ? "H" :
159#endif
160 "");
161 fprintf(fp, "Preference: %s, ",
162 rtpref_str[(rai->rtpref >> 3) & 0xff]);
163 fprintf(fp, "MTU: %d\n", rai->linkmtu);
164 fprintf(fp, " ReachableTime: %d, RetransTimer: %d, "
165 "CurHopLimit: %d\n", rai->reachabletime,
166 rai->retranstimer, rai->hoplimit);
167#ifdef MIP6
168 fprintf(fp, " HAPreference: %d, HALifetime: %d\n",
169 rai->hapref, rai->hatime);
170#endif
171
172 if (rai->clockskew)
173 fprintf(fp, " Clock skew: %ldsec\n",
174 rai->clockskew);
175 for (first = 1, pfx = rai->prefix.next; pfx != &rai->prefix;
176 pfx = pfx->next) {
177 if (first) {
178 fprintf(fp, " Prefixes:\n");
179 first = 0;
180 }
181 fprintf(fp, " %s/%d(",
182 inet_ntop(AF_INET6, &pfx->prefix,
183 prefixbuf, sizeof(prefixbuf)),
184 pfx->prefixlen);
185 switch(pfx->origin) {
186 case PREFIX_FROM_KERNEL:
187 fprintf(fp, "KERNEL, ");
188 break;
189 case PREFIX_FROM_CONFIG:
190 fprintf(fp, "CONFIG, ");
191 break;
192 case PREFIX_FROM_DYNAMIC:
193 fprintf(fp, "DYNAMIC, ");
194 break;
195 }
196 if (pfx->validlifetime == ND6_INFINITE_LIFETIME)
197 fprintf(fp, "vltime: infinity");
198 else
199 fprintf(fp, "vltime: %ld",
200 (long)pfx->validlifetime);
201 if (pfx->vltimeexpire != 0)
202 fprintf(fp, "(decr,expire %ld), ", (long)
203 pfx->vltimeexpire > now.tv_sec ?
204 pfx->vltimeexpire - now.tv_sec : 0);
205 else
206 fprintf(fp, ", ");
207 if (pfx->preflifetime == ND6_INFINITE_LIFETIME)
208 fprintf(fp, "pltime: infinity");
209 else
210 fprintf(fp, "pltime: %ld",
211 (long)pfx->preflifetime);
212 if (pfx->pltimeexpire != 0)
213 fprintf(fp, "(decr,expire %ld), ", (long)
214 pfx->pltimeexpire > now.tv_sec ?
215 pfx->pltimeexpire - now.tv_sec : 0);
216 else
217 fprintf(fp, ", ");
218 fprintf(fp, "flags: %s%s%s",
219 pfx->onlinkflg ? "L" : "",
220 pfx->autoconfflg ? "A" : "",
221#ifdef MIP6
222 pfx->routeraddr ? "R" :
223#endif
224 "");
225 fprintf(fp, ")\n");
226 }
227 }
228}
229
230void
231rtadvd_dump_file(dumpfile)
232 char *dumpfile;
233{
234 if ((fp = fopen(dumpfile, "w")) == NULL) {
235 syslog(LOG_WARNING, "<%s> open a dump file(%s)",
236 __FUNCTION__, dumpfile);
237 return;
238 }
239
240 if_dump();
241
242 fclose(fp);
243}