1 /* $KAME: dump.c,v 1.16 2001/03/21 17:41:13 jinmei Exp $ */
4 * Copyright (C) 2000 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * $FreeBSD: src/usr.sbin/rtadvd/dump.c,v 1.1.2.3 2002/06/29 18:59:53 ume Exp $
32 * $DragonFly: src/usr.sbin/rtadvd/dump.c,v 1.6 2005/12/05 00:56:37 swildner Exp $
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <sys/queue.h>
39 #if defined(__DragonFly__)
40 #include <net/if_var.h>
41 #endif /* __DragonFly__ */
42 #include <net/if_dl.h>
44 #include <netinet/in.h>
46 /* XXX: the following two are non-standard include files */
47 #include <netinet6/in6_var.h>
48 #include <netinet6/nd6.h>
50 #include <arpa/inet.h>
66 extern struct rainfo
*ralist
;
68 static char *ether_str(struct sockaddr_dl
*);
69 static void if_dump(void);
71 #ifdef __DragonFly__ /* XXX: see PORTABILITY */
72 #define LONGLONG "%qu"
74 #define LONGLONG "%llu"
77 static char *rtpref_str
[] = {
85 ether_str(struct sockaddr_dl
*sdl
)
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]);
96 sprintf(ebuf
, "NONE");
107 char prefixbuf
[INET6_ADDRSTRLEN
];
111 gettimeofday(&now
, NULL
); /* XXX: unused in most cases */
112 for (rai
= ralist
; rai
; rai
= rai
->next
) {
113 fprintf(fp
, "%s:\n", rai
->ifname
);
115 fprintf(fp
, " Status: %s\n",
116 (iflist
[rai
->ifindex
]->ifm_flags
& IFF_UP
) ? "UP" :
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
));
126 fprintf(fp
, " Next RA will be sent: %s",
127 ctime((time_t *)&rai
->timer
->tm
.tv_sec
));
130 fprintf(fp
, " RA timer is stopped");
131 fprintf(fp
, " waits: %d, initcount: %d\n",
132 rai
->waiting
, rai
->initcounter
);
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
);
144 /* interface information */
146 fprintf(fp
, " Link-layer address: %s\n",
147 ether_str(rai
->sdl
));
148 fprintf(fp
, " MTU: %d\n", rai
->phymtu
);
150 /* Router configuration variables */
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" : "",
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
);
168 fprintf(fp
, " HAPreference: %d, HALifetime: %d\n",
169 rai
->hapref
, rai
->hatime
);
173 fprintf(fp
, " Clock skew: %ldsec\n",
175 for (first
= 1, pfx
= rai
->prefix
.next
; pfx
!= &rai
->prefix
;
178 fprintf(fp
, " Prefixes:\n");
181 fprintf(fp
, " %s/%d(",
182 inet_ntop(AF_INET6
, &pfx
->prefix
,
183 prefixbuf
, sizeof(prefixbuf
)),
185 switch(pfx
->origin
) {
186 case PREFIX_FROM_KERNEL
:
187 fprintf(fp
, "KERNEL, ");
189 case PREFIX_FROM_CONFIG
:
190 fprintf(fp
, "CONFIG, ");
192 case PREFIX_FROM_DYNAMIC
:
193 fprintf(fp
, "DYNAMIC, ");
196 if (pfx
->validlifetime
== ND6_INFINITE_LIFETIME
)
197 fprintf(fp
, "vltime: infinity");
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);
207 if (pfx
->preflifetime
== ND6_INFINITE_LIFETIME
)
208 fprintf(fp
, "pltime: infinity");
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);
218 fprintf(fp
, "flags: %s%s%s",
219 pfx
->onlinkflg
? "L" : "",
220 pfx
->autoconfflg
? "A" : "",
222 pfx
->routeraddr
? "R" :
226 struct timeval
*rest
;
228 rest
= rtadvd_timer_rest(pfx
->timer
);
229 if (rest
) { /* XXX: what if not? */
230 fprintf(fp
, ", expire in: %ld",
240 rtadvd_dump_file(char *dumpfile
)
242 if ((fp
= fopen(dumpfile
, "w")) == NULL
) {
243 syslog(LOG_WARNING
, "<%s> open a dump file(%s)",