2 /* $KAME: dump.c,v 1.32 2003/05/19 09:46:50 keiichi Exp $ */
5 * Copyright (C) 2000 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/queue.h>
37 #include <net/if_var.h>
38 #include <net/if_dl.h>
40 #include <netinet/in.h>
42 /* XXX: the following two are non-standard include files */
43 #include <netinet6/in6_var.h>
44 #include <netinet6/nd6.h>
46 #include <arpa/inet.h>
62 extern struct rainfo *ralist;
64 static char *ether_str __P((struct sockaddr_dl *));
65 static void if_dump __P((void));
67 static char *rtpref_str[] = {
76 struct sockaddr_dl *sdl;
81 if (sdl->sdl_alen && sdl->sdl_alen > 5) {
82 cp = (u_char *)LLADDR(sdl);
83 snprintf(hbuf, sizeof(hbuf), "%x:%x:%x:%x:%x:%x",
84 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
86 snprintf(hbuf, sizeof(hbuf), "NONE");
99 char prefixbuf[INET6_ADDRSTRLEN];
103 gettimeofday(&now, NULL); /* XXX: unused in most cases */
104 for (rai = ralist; rai; rai = rai->next) {
105 fprintf(fp, "%s:\n", rai->ifname);
107 fprintf(fp, " Status: %s\n",
108 (iflist[rai->ifindex]->ifm_flags & IFF_UP) ? "UP" :
111 /* control information */
112 if (rai->lastsent.tv_sec) {
113 /* note that ctime() appends CR by itself */
114 fprintf(fp, " Last RA sent: %s",
115 ctime((time_t *)&rai->lastsent.tv_sec));
118 fprintf(fp, " Next RA will be sent: %s",
119 ctime((time_t *)&rai->timer->tm.tv_sec));
122 fprintf(fp, " RA timer is stopped");
123 fprintf(fp, " waits: %d, initcount: %d\n",
124 rai->waiting, rai->initcounter);
127 fprintf(fp, " statistics: RA(out/in/inconsistent): "
129 (unsigned long long)rai->raoutput,
130 (unsigned long long)rai->rainput,
131 (unsigned long long)rai->rainconsistent);
132 fprintf(fp, "RS(input): %llu\n",
133 (unsigned long long)rai->rsinput);
135 /* interface information */
137 fprintf(fp, " Link-layer address: %s\n",
138 ether_str(rai->sdl));
139 fprintf(fp, " MTU: %d\n", rai->phymtu);
141 /* Router configuration variables */
142 fprintf(fp, " DefaultLifetime: %d, MaxAdvInterval: %d, "
143 "MinAdvInterval: %d\n", rai->lifetime, rai->maxinterval,
145 fprintf(fp, " Flags: %s%s%s, ",
146 rai->managedflg ? "M" : "", rai->otherflg ? "O" : "", "");
147 fprintf(fp, "Preference: %s, ",
148 rtpref_str[(rai->rtpref >> 3) & 0xff]);
149 fprintf(fp, "MTU: %d\n", rai->linkmtu);
150 fprintf(fp, " ReachableTime: %d, RetransTimer: %d, "
151 "CurHopLimit: %d\n", rai->reachabletime,
152 rai->retranstimer, rai->hoplimit);
154 fprintf(fp, " Clock skew: %ldsec\n",
156 for (first = 1, pfx = rai->prefix.next; pfx != &rai->prefix;
159 fprintf(fp, " Prefixes:\n");
162 fprintf(fp, " %s/%d(",
163 inet_ntop(AF_INET6, &pfx->prefix, prefixbuf,
164 sizeof(prefixbuf)), pfx->prefixlen);
165 switch (pfx->origin) {
166 case PREFIX_FROM_KERNEL:
167 fprintf(fp, "KERNEL, ");
169 case PREFIX_FROM_CONFIG:
170 fprintf(fp, "CONFIG, ");
172 case PREFIX_FROM_DYNAMIC:
173 fprintf(fp, "DYNAMIC, ");
176 if (pfx->validlifetime == ND6_INFINITE_LIFETIME)
177 fprintf(fp, "vltime: infinity");
179 fprintf(fp, "vltime: %ld",
180 (long)pfx->validlifetime);
181 if (pfx->vltimeexpire != 0)
182 fprintf(fp, "(decr,expire %ld), ", (long)
183 pfx->vltimeexpire > now.tv_sec ?
184 pfx->vltimeexpire - now.tv_sec : 0);
187 if (pfx->preflifetime == ND6_INFINITE_LIFETIME)
188 fprintf(fp, "pltime: infinity");
190 fprintf(fp, "pltime: %ld",
191 (long)pfx->preflifetime);
192 if (pfx->pltimeexpire != 0)
193 fprintf(fp, "(decr,expire %ld), ", (long)
194 pfx->pltimeexpire > now.tv_sec ?
195 pfx->pltimeexpire - now.tv_sec : 0);
198 fprintf(fp, "flags: %s%s%s",
199 pfx->onlinkflg ? "L" : "",
200 pfx->autoconfflg ? "A" : "",
203 struct timeval *rest;
205 rest = rtadvd_timer_rest(pfx->timer);
206 if (rest) { /* XXX: what if not? */
207 fprintf(fp, ", expire in: %ld",
214 for (first = 1, rti = rai->route.next; rti != &rai->route;
217 fprintf(fp, " Route Information:\n");
220 fprintf(fp, " %s/%d (",
221 inet_ntop(AF_INET6, &rti->prefix,
222 prefixbuf, sizeof(prefixbuf)),
224 fprintf(fp, "preference: %s, ",
225 rtpref_str[0xff & (rti->rtpref >> 3)]);
226 if (rti->ltime == ND6_INFINITE_LIFETIME)
227 fprintf(fp, "lifetime: infinity");
229 fprintf(fp, "lifetime: %ld", (long)rti->ltime);
237 rtadvd_dump_file(dumpfile)
240 syslog(LOG_DEBUG, "<%s> dump current status to %s", __func__,
243 if ((fp = fopen(dumpfile, "w")) == NULL) {
244 syslog(LOG_WARNING, "<%s> open a dump file(%s)",