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