2 * modified by Jun-ichiro itojun Itoh <itojun@itojun.org>, 1997
5 * in6_debug.c -- Insipired by Craig Metz's Net/2 in6_debug.c, but
6 * not quite as heavyweight (initially, anyway).
8 * The idea is to have globals here, and dump netinet6/ data structures.
10 * Copyright 1995 by Dan McDonald, Bao Phan, and Randall Atkinson,
11 * All Rights Reserved.
12 * All Rights under this copyright have been assigned to NRL.
15 /*----------------------------------------------------------------------
16 # @(#)COPYRIGHT 1.1a (NRL) 17 August 1995
20 All of the documentation and software included in this software
21 distribution from the US Naval Research Laboratory (NRL) are
22 copyrighted by their respective developers.
24 This software and documentation were developed at NRL by various
25 people. Those developers have each copyrighted the portions that they
26 developed at NRL and have assigned All Rights for those portions to
27 NRL. Outside the USA, NRL also has copyright on the software
28 developed at NRL. The affected files all contain specific copyright
29 notices and those notices must be retained in any derived work.
33 NRL grants permission for redistribution and use in source and binary
34 forms, with or without modification, of the software and documentation
35 created at NRL provided that the following conditions are met:
37 1. Redistributions of source code must retain the above copyright
38 notice, this list of conditions and the following disclaimer.
39 2. Redistributions in binary form must reproduce the above copyright
40 notice, this list of conditions and the following disclaimer in the
41 documentation and/or other materials provided with the distribution.
42 3. All advertising materials mentioning features or use of this software
43 must display the following acknowledgement:
45 This product includes software developed at the Information
46 Technology Division, US Naval Research Laboratory.
48 4. Neither the name of the NRL nor the names of its contributors
49 may be used to endorse or promote products derived from this software
50 without specific prior written permission.
52 THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
53 IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
54 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
55 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
56 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
57 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
58 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
59 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
60 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
61 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
62 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 The views and conclusions contained in the software and documentation
65 are those of the authors and should not be interpreted as representing
66 official policies, either expressed or implied, of the US Naval
67 Research Laboratory (NRL).
69 ----------------------------------------------------------------------*/
77 #ifdef KEY_DEBUG /*wraps the whole code*/
79 /*#include <netkey/osdep_44bsd.h>*/
81 #include <sys/types.h>
82 #include <sys/param.h>
83 #include <sys/socket.h>
85 #include <sys/systm.h>
88 #include <net/if_dl.h>
89 #include <net/route.h>
91 #include <netinet/in.h>
93 #include <netinet/in_systm.h>
94 #include <netinet/ip.h>
95 #include <netinet/in_pcb.h>
98 #include <netinet6/in6.h>
99 #include <netinet6/in6_var.h>
100 #include <netinet6/ip6.h>
101 #include <netinet6/ip6_var.h>
102 #include <netinet6/icmp6.h>
103 #include <netinet6/in6_pcb.h>
106 #include "in6_types.h"
114 #include <netkey/key.h>
115 #include <netkey/key_debug.h>
116 #endif /* KEY_DEBUG */
118 #include <netsec/ipsec.h>
119 #endif /* IPSEC_DEBUG */
122 #include <netinet6/in6_debug.h>
129 /* The following should be sysctl-tweakable. */
131 unsigned int in6_debug_level = IDL_FINISHED + 1; /* 0 is no debugging */
134 * Functions and macros.
137 void in6_debug_init()
139 /* For now, nothing. */
142 /*----------------------------------------------------------------------
143 * dump_* dumps various data structures. These should be called within
144 * the context of a DDO() macro. They assume address and port fields
145 * are in network order.
146 ----------------------------------------------------------------------*/
149 /*----------------------------------------------------------------------
150 * Dump an IPv6 address. Don't compress 0's out because of debugging.
151 ----------------------------------------------------------------------*/
152 void dump_in6_addr(in6_addr)
153 struct in6_addr *in6_addr;
155 u_short *shorts = (u_short *)in6_addr;
159 printf("Dereference a NULL in6_addr? I don't think so.\n");
163 printf("(conv. for printing) ");
165 printf("%4x:",htons(shorts[i++]));
166 printf("%4x\n",htons(shorts[7]));
170 /*----------------------------------------------------------------------
171 * Dump and IPv4 address in x.x.x.x form.
172 ----------------------------------------------------------------------*/
173 void dump_in_addr(in_addr)
174 struct in_addr *in_addr;
176 u_char *chars = (u_char *)in_addr;
180 printf("Dereference a NULL in_addr? I don't think so.\n");
185 printf("%d.",chars[i++]);
186 printf("%d\n",chars[3]);
190 /*----------------------------------------------------------------------
191 * Dump an IPv6 socket address.
192 ----------------------------------------------------------------------*/
193 void dump_sockaddr_in6(sin6)
194 struct sockaddr_in6 *sin6;
197 printf("Dereference a NULL sockaddr_in6? I don't think so.\n");
201 printf("sin6_len = %d, sin6_family = %d, sin6_port = %d (0x%x)\n",
202 sin6->sin6_len,sin6->sin6_family, htons(sin6->sin6_port),
203 htons(sin6->sin6_port));
204 printf("sin6_flowinfo = 0x%x\n",sin6->sin6_flowinfo);
205 printf("sin6_addr = ");
206 dump_in6_addr(&sin6->sin6_addr);
210 /*----------------------------------------------------------------------
211 * Dump an IPv4 socket address.
212 ----------------------------------------------------------------------*/
213 void dump_sockaddr_in(sin)
214 struct sockaddr_in *sin;
219 printf("Dereference a NULL sockaddr_in? I don't think so.\n");
224 printf("sin_len = %d, ", sin->sin_len);
226 printf("sin_family = %d, sin_port (conv.) = %d (0x%x)\n",
227 sin->sin_family, htons(sin->sin_port),
228 htons(sin->sin_port));
229 printf("sin_addr = ");
230 dump_in_addr(&sin->sin_addr);
231 printf("sin_zero == ");
233 printf("0x%2x ",sin->sin_zero[i]);
237 /*----------------------------------------------------------------------
238 * Dump a generic socket address. Use if no family-specific routine is
240 ----------------------------------------------------------------------*/
241 void dump_sockaddr(sa)
245 printf("Dereference a NULL sockaddr? I don't think so.\n");
250 printf("sa_len = %d, ", sa->sa_len);
252 printf("sa_family = %d", sa->sa_family);
254 printf(", remaining bytes are:\n");
257 for (i = 0; i <sa->sa_len - 2; i++)
258 printf("0x%2x ",(unsigned char)sa->sa_data[i]);
264 /*----------------------------------------------------------------------
265 * Dump a link-layer socket address. (Not that there are user-level link
266 * layer sockets, but there are plenty of link-layer addresses in the kernel.)
267 ----------------------------------------------------------------------*/
268 void dump_sockaddr_dl(sdl)
269 struct sockaddr_dl *sdl;
274 printf("Dereference a NULL sockaddr_dl? I don't think so.\n");
278 printf("sdl_len = %d, sdl_family = %d, sdl_index = %d, sdl_type = %d,\n",
279 sdl->sdl_len, sdl->sdl_family, sdl->sdl_index, sdl->sdl_type);
280 buf[sdl->sdl_nlen] = 0;
282 bcopy(sdl->sdl_data,buf,sdl->sdl_nlen);
283 printf("sdl_nlen = %d, (name = '%s'\n",sdl->sdl_nlen,buf);
284 printf("sdl_alen = %d, ",sdl->sdl_alen);
290 for (i = 0; i<sdl->sdl_alen; i++)
291 printf("0x%2x ",(unsigned char)sdl->sdl_data[i+sdl->sdl_nlen]);
294 printf("sdl_slen = %d, ",sdl->sdl_slen);
300 for (i = 0; i<sdl->sdl_slen; i++)
302 (unsigned char)sdl->sdl_data[i+sdl->sdl_nlen+sdl->sdl_alen]);
307 /*----------------------------------------------------------------------
308 * Dump a socket address, calling a family-specific routine if available.
309 ----------------------------------------------------------------------*/
310 void dump_smart_sockaddr(sa)
313 DPRINTF(IDL_MAJOR_EVENT, ("Entering dump_smart_sockaddr\n"));
315 printf("Dereference a NULL sockaddr? I don't think so.\n");
319 switch (sa->sa_family)
323 dump_sockaddr_in6((struct sockaddr_in6 *)sa);
327 dump_sockaddr_in((struct sockaddr_in *)sa);
330 dump_sockaddr_dl((struct sockaddr_dl *)sa);
339 /*----------------------------------------------------------------------
340 * Dump an IPv6 header.
341 ----------------------------------------------------------------------*/
346 printf("Dereference a NULL ip6? I don't think so.\n");
350 printf("Vers = %d, pri = 0x%x, flow label = 0x%x\n",
351 ip6->ip6_v, ip6->ip6_pri, htonl(ip6->ip6_flbl));
352 printf("Length (conv) = %d, nexthdr = %d, hoplimit = %d.\n",
353 htons(ip6->ip6_len),ip6->ip6_nh,ip6->ip6_hlim);
355 dump_in6_addr(&ip6->ip6_src);
357 dump_in6_addr(&ip6->ip6_dst);
360 /*----------------------------------------------------------------------
361 * Dump an ICMPv6 header. This function is not very smart beyond the
362 * type, code, and checksum.
363 ----------------------------------------------------------------------*/
364 void dump_ipv6_icmp(icp)
370 printf("Dereference a NULL ipv6_icmp? I don't think so.\n");
374 printf("type %d, code %d, cksum (conv) = 0x%x\n",icp->icmp6_type,
375 icp->icmp6_code,htons(icp->icmp6_cksum));
376 printf("First four bytes: 0x%x",htonl(icp->icmp6_flags));
381 /*----------------------------------------------------------------------
382 * Dump only the header fields of a single mbuf.
383 ----------------------------------------------------------------------*/
384 void dump_mbuf_hdr(m)
388 printf("Dereference a NULL mbuf? I don't think so.\n");
392 printf("Single mbuf at %08x\n", m);
393 printf("m_len = %d, m_data = 0x%x, m_type = %d\n",m->m_len,
394 m->m_data, m->m_type);
395 printf("m_flags = 0x%x ",m->m_flags);
396 if (m->m_flags & M_PKTHDR)
397 printf("m_pkthdr.len = %d, m_pkthdr.rcvif = 0x%x",m->m_pkthdr.len,
399 if (m->m_flags & M_EXT)
400 printf(" (IS CLUSTER MBUF)");
401 printf("\nm_next = 0x%x m_nextpkt = 0x%x\n",m->m_next, m->m_nextpkt);
404 /*----------------------------------------------------------------------
405 * Dump the entire contents of a single mbuf.
406 ----------------------------------------------------------------------*/
414 for (i = 0; i < m->m_len; i++)
415 printf("0x%2x%s",(unsigned char)m->m_data[i] , ((i+1) % 16)?" ":"\n");
416 printf((i % 16)?"\n":"");
419 /*----------------------------------------------------------------------
420 * Dump the contents of an mbuf chain. (WARNING: Lots of text may
422 ----------------------------------------------------------------------*/
429 for (walker = m, i = 0; walker != NULL && (i < 10);
430 walker = walker->m_next, i++)
434 /*----------------------------------------------------------------------
435 * Dump an mbuf chain's data in a format similar to tcpdump(8).
436 ----------------------------------------------------------------------*/
443 for (i = count = 0; m && (i < 10); m = m->m_next, i++) {
444 for (j = 0; j < m->m_len; j++, count++) {
445 if (!(count % (2 * 8)))
449 printf("%02x", (u_int8_t)(m->m_data[j]));
455 /*----------------------------------------------------------------------
456 * Dump an IPv6 header index table, which is terminated by an entry with
457 * a NULL mbuf pointer.
458 ----------------------------------------------------------------------*/
459 void dump_ihitab(ihi)
460 struct in6_hdrindex *ihi;
465 printf("Dereference a NULL hdrindex/ihi? I don't think so.\n");
469 /* This is dangerous, make sure ihitab was bzeroed. */
470 while (ihi[i].ihi_mbuf)
472 printf("ihi_nexthdr = %d, ihi_mbuf = 0x%x.\n",ihi[i].ihi_nexthdr,
479 /*----------------------------------------------------------------------
480 * Dump an interface address.
481 ----------------------------------------------------------------------*/
487 printf("ifa of NULL.\n");
491 printf("ifa_addr: ");
492 dump_smart_sockaddr(ifa->ifa_addr);
493 printf("ifa_netmask: ");
494 dump_smart_sockaddr(ifa->ifa_netmask);
497 /*----------------------------------------------------------------------
498 * Dump an interface structure.
499 ----------------------------------------------------------------------*/
504 printf("Dereference a NULL ifnet/ifp? I don't think so.\n");
508 printf("Interface name: %s.\n",ifp->if_name);
509 printf("Interface type: %d. ",ifp->if_type);
510 printf("MTU: %d.\n",ifp->if_mtu);
513 /*----------------------------------------------------------------------
514 * Dump a route structure (sockaddr/rtentry pair).
515 ----------------------------------------------------------------------*/
520 printf("Dereference a NULL route? I don't think so.\n");
524 printf("ro_rt = 0x%x, ro_dst is:\n",ro->ro_rt);
525 dump_smart_sockaddr(&ro->ro_dst);
528 /*----------------------------------------------------------------------
529 * Dump a routing entry.
530 ----------------------------------------------------------------------*/
531 void dump_rtentry(rt)
535 printf("Dereference a NULL rtentry? I don't think so.\n");
539 printf("rt_key is:\n");
540 dump_smart_sockaddr(rt_key(rt));
541 printf("rt_mask is:\n");
542 dump_smart_sockaddr(rt_mask(rt));
543 printf("rt_llinfo = 0x%x ",rt->rt_llinfo);
544 printf("rt_rmx.rmx_mtu = %d ",rt->rt_rmx.rmx_mtu);
545 printf("rt_refcnt = %d ",rt->rt_refcnt);
546 printf("rt_flags = 0x%x\n",rt->rt_flags);
547 printf("rt_ifp is:\n");
548 dump_ifp(rt->rt_ifp);
549 printf("rt_ifa is:\n");
550 dump_ifa(rt->rt_ifa);
553 /*----------------------------------------------------------------------
554 * Dump an Internet v4 protocol control block.
555 ----------------------------------------------------------------------*/
560 printf("Dereference a NULL inpcb? I don't think so.\n");
565 printf("inp_next = 0x%x, inp_prev = 0x%x, inp_head = 0x%x.\n",
566 inp->inp_next, inp->inp_prev, inp->inp_head);
568 printf("inp_socket = 0x%x, inp_ppcb\n",inp->inp_socket,inp->inp_ppcb);
570 dump_in_addr(&inp->inp_faddr);
572 dump_in_addr(&inp->inp_laddr);
573 printf("inp_route: ");
574 dump_route(&inp->inp_route);
576 printf("<Coming soon.>\n");
577 printf("inp_options = 0x%x, inp_moptions{6,} = 0x%x,\n",inp->inp_options,
579 printf("inp_flags = 0x%x, inp_fport = %d, inp_lport = %d.\n",
580 (unsigned)inp->inp_flags,inp->inp_fport, inp->inp_lport);
584 /*----------------------------------------------------------------------
585 * Dump an Internet v6 protocol control block.
586 ----------------------------------------------------------------------*/
587 void dump_in6pcb(in6p)
591 printf("Dereference a NULL in6pcb? I don't think so.\n");
595 printf("in6p_next = 0x%x, in6p_prev = 0x%x, in6p_head = 0x%x.\n",
596 in6p->in6p_next, in6p->in6p_prev, in6p->in6p_head);
597 printf("in6p_socket = 0x%x, in6p_ppcb\n",
598 in6p->in6p_socket, in6p->in6p_ppcb);
600 dump_in6_addr(&in6p->in6p_faddr);
602 dump_in6_addr(&in6p->in6p_laddr);
603 printf("in6p_route: ");
604 dump_route(&in6p->in6p_route);
606 dump_ipv6(&in6p->in6p_ip6);
607 printf("in6p_options = 0x%x, in6p_moptions{6,} = 0x%x,\n",
608 in6p->in6p_options, in6p->in6p_moptions);
609 printf("in6p_flags = 0x%x, in6p_fport = %d, in6p_lport = %d.\n",
610 (unsigned)in6p->in6p_flags, in6p->in6p_fport, in6p->in6p_lport);
615 /*----------------------------------------------------------------------
616 * Dump an IPv6 discovery queue structure.
617 ----------------------------------------------------------------------*/
622 printf("Dereference a NULL discq? I don't think so.\n");
626 printf("dq_next = 0x%x, dq_prev = 0x%x, dq_rt = 0x%x,\n",dq->dq_next,
627 dq->dq_prev, dq->dq_rt);
628 printf("dq_queue = 0x%x.\n",dq->dq_queue);
629 /* Dump first mbuf chain? */
630 /*printf("dq_expire = %d (0x%x).\n",dq->dq_expire,dq->dq_expire);*/
634 /*----------------------------------------------------------------------
636 ----------------------------------------------------------------------*/
637 void dump_buf(buf, len)
643 printf("buf=0x%x len=%d:\n", (unsigned int)buf, len);
644 for (i = 0; i < len; i++) {
645 printf("0x%x ", (u_int8_t)*(buf+i));
651 /*----------------------------------------------------------------------
652 * Dump a key_tblnode structrue
653 ----------------------------------------------------------------------*/
654 void dump_keytblnode(ktblnode)
655 struct key_tblnode *ktblnode;
658 printf("NULL key table node pointer!\n");
661 printf("solist=0x%x ", (unsigned int)ktblnode->solist);
662 printf("secassoc=0x%x ", (unsigned int)ktblnode->secassoc);
663 printf("next=0x%x\n", (unsigned int)ktblnode->next);
666 /*----------------------------------------------------------------------
667 * Dump an ipsec_assoc structure
668 ----------------------------------------------------------------------*/
669 void dump_secassoc(seca)
670 struct key_secassoc *seca;
676 printf("secassoc_len=%u ", seca->len);
677 printf("secassoc_type=%d ", seca->type);
678 printf("secassoc_state=0x%x\n", seca->state);
679 printf("secassoc_label=%u ", seca->label);
680 printf("secassoc_spi=0x%x ", (unsigned int)seca->spi);
681 printf("secassoc_keylen=%u\n", seca->keylen);
682 printf("secassoc_ivlen=%u ", seca->ivlen);
683 printf("secassoc_algorithm=%u ", seca->algorithm);
684 printf("secassoc_lifetype=%u\n", seca->lifetype);
685 printf("secassoc_iv=0x%x:\n", (unsigned int)seca->iv);
686 p = (u_int8_t *)(seca->iv);
687 for (i = 0 ; i < seca->ivlen; i++)
688 printf("0x%x ", *(p + i));
689 printf("secassoc_key=0x%x:\n", (unsigned int)seca->key);
690 p = (u_int8_t *)(seca->key);
691 for (i = 0 ; i < seca->keylen; i++)
692 printf("0x%x ", *(p + i));
693 printf("secassoc_lifetime1=%u ", (unsigned int)seca->lifetime1);
694 printf("secassoc_lifetime2=%u\n", (unsigned int)seca->lifetime2);
695 dump_smart_sockaddr(seca->src);
696 dump_smart_sockaddr(seca->dst);
697 dump_smart_sockaddr(seca->from);
699 printf("can't dump null secassoc pointer!\n");
703 /*----------------------------------------------------------------------
704 * Dump a key_msghdr structure
705 ----------------------------------------------------------------------*/
706 void dump_keymsghdr(km)
707 struct key_msghdr *km;
710 printf("key_msglen=%d\n", km->key_msglen);
711 printf("key_msgvers=%d\n", km->key_msgvers);
712 printf("key_msgtype=%d\n", km->key_msgtype);
713 printf("key_pid=%d\n", km->key_pid);
714 printf("key_seq=%d\n", km->key_seq);
715 printf("key_errno=%d\n", km->key_errno);
716 printf("type=0x%x\n", (unsigned int)km->type);
717 printf("state=0x%x\n", (unsigned int)km->state);
718 printf("label=0x%x\n", (unsigned int)km->label);
719 printf("spi=0x%x\n", (unsigned int)km->spi);
720 printf("keylen=%d\n", km->keylen);
721 printf("ivlen=%d\n", km->ivlen);
722 printf("algorithm=%d\n", km->algorithm);
723 printf("lifetype=0x%x\n", (unsigned int)km->lifetype);
724 printf("lifetime1=%u\n", (unsigned int)km->lifetime1);
725 printf("lifetime2=%u\n", (unsigned int)km->lifetime2);
727 printf("key_msghdr pointer is NULL!\n");
731 /*----------------------------------------------------------------------
732 * Dump a key_msgdata structure
733 ----------------------------------------------------------------------*/
734 void dump_keymsginfo(kp)
735 struct key_msgdata *kp;
740 printf("src addr:\n");
741 dump_smart_sockaddr(kp->src);
742 printf("dest addr:\n");
743 dump_smart_sockaddr(kp->dst);
744 printf("from addr:\n");
745 dump_smart_sockaddr(kp->from);
746 #define dumpbuf(a, b) \
747 { for (i= 0; i < (b); i++) \
748 printf("0x%2x%s", (unsigned char)(*((caddr_t)a+i)),((i+1)%16)?" ":"\n");\
751 dumpbuf(kp->iv, kp->ivlen);
753 dumpbuf(kp->key, kp->keylen);
756 printf("key_msgdata point is NULL!\n");