]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/netkey/key_debug.c
This commit was generated by cvs2svn to compensate for changes in r34461,
[FreeBSD/FreeBSD.git] / sys / netkey / key_debug.c
1 /*
2  * modified by Jun-ichiro itojun Itoh <itojun@itojun.org>, 1997
3  */
4 /*
5  * in6_debug.c  --  Insipired by Craig Metz's Net/2 in6_debug.c, but
6  *                  not quite as heavyweight (initially, anyway).
7  *
8  * The idea is to have globals here, and dump netinet6/ data structures.
9  *
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.
13  */
14
15 /*----------------------------------------------------------------------
16 #       @(#)COPYRIGHT   1.1a (NRL) 17 August 1995
17
18 COPYRIGHT NOTICE
19
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.
23
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.
30
31 NRL LICENSE
32
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:
36
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:
44
45         This product includes software developed at the Information
46         Technology Division, US Naval Research Laboratory.
47
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.
51
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.
63
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).
68
69 ----------------------------------------------------------------------*/
70
71
72 #define INET6_DEBUG_C
73
74 #include "opt_key.h"
75
76 #ifdef KEY
77 #ifdef KEY_DEBUG        /*wraps the whole code*/
78
79 /*#include <netkey/osdep_44bsd.h>*/
80
81 #include <sys/types.h>
82 #include <sys/param.h>
83 #include <sys/socket.h>
84 #include <sys/mbuf.h>
85 #include <sys/systm.h>
86
87 #include <net/if.h>
88 #include <net/if_dl.h>
89 #include <net/route.h>
90
91 #include <netinet/in.h>
92
93 #include <netinet/in_systm.h>
94 #include <netinet/ip.h>
95 #include <netinet/in_pcb.h>
96
97 #ifdef INET6
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>
104 #else /* INET6 */
105 #if 0
106 #include "in6_types.h"
107 #endif
108 #endif /* INET6 */
109
110 #define SA_LEN  1
111 #define SIN_LEN 1
112
113 #ifdef KEY_DEBUG
114 #include <netkey/key.h>
115 #include <netkey/key_debug.h>
116 #endif /* KEY_DEBUG */
117 #ifdef IPSEC_DEBUG
118 #include <netsec/ipsec.h>
119 #endif /* IPSEC_DEBUG */
120
121 #if 0
122 #include <netinet6/in6_debug.h>
123 #endif
124
125 /*
126  * Globals
127  */
128
129 /* The following should be sysctl-tweakable. */
130
131 unsigned int in6_debug_level = IDL_FINISHED + 1;  /* 0 is no debugging */
132
133 /*
134  * Functions and macros.
135  */
136
137 void in6_debug_init()
138 {
139   /* For now, nothing. */
140 }
141
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  ----------------------------------------------------------------------*/
147
148 #ifdef INET6
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;
154 {
155   u_short *shorts = (u_short *)in6_addr;
156   int i = 0;
157
158   if (!in6_addr) {
159     printf("Dereference a NULL in6_addr? I don't think so.\n");
160     return;
161   }
162
163   printf("(conv. for printing) ");
164   while (i < 7)
165     printf("%4x:",htons(shorts[i++]));
166   printf("%4x\n",htons(shorts[7]));
167 }
168 #endif /* INET6 */
169
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;
175 {
176   u_char *chars = (u_char *)in_addr;
177   int i = 0;
178
179   if (!in_addr) {
180     printf("Dereference a NULL in_addr? I don't think so.\n");
181     return;
182   }
183
184   while (i < 3)
185     printf("%d.",chars[i++]);
186   printf("%d\n",chars[3]);
187 }
188
189 #ifdef INET6
190 /*----------------------------------------------------------------------
191  * Dump an IPv6 socket address.
192  ----------------------------------------------------------------------*/
193 void dump_sockaddr_in6(sin6)
194      struct sockaddr_in6 *sin6;
195 {
196   if (!sin6) {
197     printf("Dereference a NULL sockaddr_in6? I don't think so.\n");
198     return;
199   }
200
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);
207 }
208 #endif /* INET6 */
209
210 /*----------------------------------------------------------------------
211  * Dump an IPv4 socket address.
212  ----------------------------------------------------------------------*/
213 void dump_sockaddr_in(sin)
214      struct sockaddr_in *sin;
215 {
216   int i;
217
218   if (!sin) {
219     printf("Dereference a NULL sockaddr_in? I don't think so.\n");
220     return;
221   }
222
223 #ifdef SIN_LEN
224   printf("sin_len = %d, ", sin->sin_len);
225 #endif /* 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 == ");
232   for(i=0;i<8;i++)
233     printf("0x%2x ",sin->sin_zero[i]);
234   printf("\n");
235 }
236
237 /*----------------------------------------------------------------------
238  * Dump a generic socket address.  Use if no family-specific routine is
239  * available.
240  ----------------------------------------------------------------------*/
241 void dump_sockaddr(sa)
242         struct sockaddr *sa;
243 {
244   if (!sa) {
245         printf("Dereference a NULL sockaddr? I don't think so.\n");
246         return;
247   }
248
249 #ifdef SA_LEN
250   printf("sa_len = %d, ", sa->sa_len);
251 #endif /* SA_LEN */
252   printf("sa_family = %d", sa->sa_family);
253 #ifdef SA_LEN
254   printf(", remaining bytes are:\n");
255   {
256     int i;
257     for (i = 0; i <sa->sa_len - 2; i++)
258       printf("0x%2x ",(unsigned char)sa->sa_data[i]);
259   }
260 #endif /* SA_LEN */
261   printf("\n");
262 }
263
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;
270 {
271   char buf[256];
272
273   if (!sdl) {
274         printf("Dereference a NULL sockaddr_dl? I don't think so.\n");
275         return;
276   }
277
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;
281   if (sdl->sdl_nlen)
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);
285   if (sdl->sdl_alen)
286     {
287       int i;
288
289       printf("(addr = ");
290       for (i = 0; i<sdl->sdl_alen; i++)
291         printf("0x%2x ",(unsigned char)sdl->sdl_data[i+sdl->sdl_nlen]);
292     }
293   printf("\n");
294   printf("sdl_slen = %d, ",sdl->sdl_slen);
295   if (sdl->sdl_slen)
296     {
297       int i;
298
299       printf("(addr = ");
300       for (i = 0; i<sdl->sdl_slen; i++)
301         printf("0x%2x ",
302                (unsigned char)sdl->sdl_data[i+sdl->sdl_nlen+sdl->sdl_alen]);
303     }
304   printf("\n");
305 }
306
307 /*----------------------------------------------------------------------
308  * Dump a socket address, calling a family-specific routine if available.
309  ----------------------------------------------------------------------*/
310 void dump_smart_sockaddr(sa)
311         struct sockaddr *sa;
312 {
313   DPRINTF(IDL_MAJOR_EVENT, ("Entering dump_smart_sockaddr\n"));
314   if (!sa) {
315         printf("Dereference a NULL sockaddr? I don't think so.\n");
316         return;
317   }
318
319   switch (sa->sa_family)
320     {
321 #ifdef INET6
322     case AF_INET6:
323       dump_sockaddr_in6((struct sockaddr_in6 *)sa);
324       break;
325 #endif /* INET6 */
326     case AF_INET:
327       dump_sockaddr_in((struct sockaddr_in *)sa);
328       break;
329     case AF_LINK:
330       dump_sockaddr_dl((struct sockaddr_dl *)sa);
331       break;
332     default:
333       dump_sockaddr(sa);
334       break;
335     }
336 }
337
338 #ifdef INET6
339 /*----------------------------------------------------------------------
340  * Dump an IPv6 header.
341  ----------------------------------------------------------------------*/
342 void dump_ipv6(ip6)
343      struct ip6 *ip6;
344 {
345   if (!ip6) {
346         printf("Dereference a NULL ip6? I don't think so.\n");
347         return;
348   }
349
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);
354   printf("Src: ");
355   dump_in6_addr(&ip6->ip6_src);
356   printf("Dst: ");
357   dump_in6_addr(&ip6->ip6_dst);
358 }
359
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)
365      struct icmp6 *icp;
366 {
367   int i;
368
369   if (!icp) {
370         printf("Dereference a NULL ipv6_icmp? I don't think so.\n");
371         return;
372   }
373
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));
377   printf("\n");
378 }
379 #endif /* INET6 */
380
381 /*----------------------------------------------------------------------
382  * Dump only the header fields of a single mbuf.
383  ----------------------------------------------------------------------*/
384 void dump_mbuf_hdr(m)
385      struct mbuf *m;
386 {
387   if (!m) {
388         printf("Dereference a NULL mbuf? I don't think so.\n");
389         return;
390   }
391
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,
398            m->m_pkthdr.rcvif);
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);
402 }
403
404 /*----------------------------------------------------------------------
405  * Dump the entire contents of a single mbuf.
406  ----------------------------------------------------------------------*/
407 void dump_mbuf(m)
408      struct mbuf *m;
409 {
410   int i;
411
412   dump_mbuf_hdr(m);
413   printf("m_data:\n");
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":"");
417 }
418
419 /*----------------------------------------------------------------------
420  * Dump the contents of an mbuf chain.  (WARNING:  Lots of text may
421  * result.
422  ----------------------------------------------------------------------*/
423 void dump_mchain(m)
424      struct mbuf *m;
425 {
426   struct mbuf *walker;
427   int i;
428
429   for (walker = m, i = 0; walker != NULL && (i < 10); 
430        walker = walker->m_next, i++)
431     dump_mbuf(walker);
432 }
433
434 /*----------------------------------------------------------------------
435  * Dump an mbuf chain's data in a format similar to tcpdump(8).
436  ----------------------------------------------------------------------*/
437 void dump_tcpdump(m)
438      struct mbuf *m;
439 {
440   struct mbuf *walker;
441   int i, j, count;
442
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)))
446         printf("\n\t\t\t");
447       if (!(count % 2))
448         printf(" ");
449       printf("%02x", (u_int8_t)(m->m_data[j]));
450     }
451   }
452 }
453
454 #if 0
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;
461 {
462   int i=0;
463
464   if (!ihi) {
465     printf("Dereference a NULL hdrindex/ihi? I don't think so.\n");
466     return;
467   }
468
469   /* This is dangerous, make sure ihitab was bzeroed. */
470   while (ihi[i].ihi_mbuf)
471     {
472       printf("ihi_nexthdr = %d, ihi_mbuf = 0x%x.\n",ihi[i].ihi_nexthdr,
473              ihi[i].ihi_mbuf);
474       i++;
475     }
476 }
477 #endif /* INET6 */
478
479 /*----------------------------------------------------------------------
480  * Dump an interface address.
481  ----------------------------------------------------------------------*/
482 void dump_ifa(ifa)
483      struct ifaddr *ifa;
484 {
485   if (ifa == NULL)
486     {
487       printf("ifa of NULL.\n");
488       return;
489     }
490
491   printf("ifa_addr: ");
492   dump_smart_sockaddr(ifa->ifa_addr);
493   printf("ifa_netmask: ");
494   dump_smart_sockaddr(ifa->ifa_netmask);
495 }
496
497 /*----------------------------------------------------------------------
498  * Dump an interface structure.
499  ----------------------------------------------------------------------*/
500 void dump_ifp(ifp)
501      struct ifnet *ifp;
502 {
503   if (!ifp) {
504     printf("Dereference a NULL ifnet/ifp? I don't think so.\n");
505     return;
506   }
507
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);
511 }
512
513 /*----------------------------------------------------------------------
514  * Dump a route structure (sockaddr/rtentry pair).
515  ----------------------------------------------------------------------*/
516 void dump_route(ro)
517      struct route *ro;
518 {
519   if (!ro) {
520     printf("Dereference a NULL route? I don't think so.\n");
521     return;
522   }
523
524   printf("ro_rt = 0x%x, ro_dst is:\n",ro->ro_rt);
525   dump_smart_sockaddr(&ro->ro_dst);
526 }
527
528 /*----------------------------------------------------------------------
529  * Dump a routing entry.
530  ----------------------------------------------------------------------*/
531 void dump_rtentry(rt)
532      struct rtentry *rt;
533 {
534   if (!rt) {
535     printf("Dereference a NULL rtentry? I don't think so.\n");
536     return;
537   }
538
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);
551 }
552
553 /*----------------------------------------------------------------------
554  * Dump an Internet v4 protocol control block.
555  ----------------------------------------------------------------------*/
556 void dump_inpcb(inp)
557      struct inpcb *inp;
558 {
559   if (!inp) {
560     printf("Dereference a NULL inpcb? I don't think so.\n");
561     return;
562   }
563
564 #if 0
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);
567 #endif
568   printf("inp_socket = 0x%x, inp_ppcb\n",inp->inp_socket,inp->inp_ppcb);
569   printf("faddr:\n");
570   dump_in_addr(&inp->inp_faddr);
571   printf("laddr:\n");
572   dump_in_addr(&inp->inp_laddr);
573   printf("inp_route: ");
574   dump_route(&inp->inp_route);
575   printf("inp_ip:");
576   printf("<Coming soon.>\n");
577   printf("inp_options = 0x%x, inp_moptions{6,} = 0x%x,\n",inp->inp_options,
578          inp->inp_moptions);
579   printf("inp_flags = 0x%x, inp_fport = %d, inp_lport = %d.\n",
580          (unsigned)inp->inp_flags,inp->inp_fport, inp->inp_lport);
581 }
582
583 #ifdef INET6
584 /*----------------------------------------------------------------------
585  * Dump an Internet v6 protocol control block.
586  ----------------------------------------------------------------------*/
587 void dump_in6pcb(in6p)
588      struct in6pcb *in6p;
589 {
590   if (!in6p) {
591     printf("Dereference a NULL in6pcb? I don't think so.\n");
592     return;
593   }
594
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);
599   printf("faddr:\n");
600   dump_in6_addr(&in6p->in6p_faddr);
601   printf("laddr:\n");
602   dump_in6_addr(&in6p->in6p_laddr);
603   printf("in6p_route: ");
604   dump_route(&in6p->in6p_route);
605   printf("in6p_ip6:");
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);
611 }
612 #endif /*INET6*/
613
614 #if 0
615 /*----------------------------------------------------------------------
616  * Dump an IPv6 discovery queue structure.
617  ----------------------------------------------------------------------*/
618 void dump_discq(dq)
619      struct discq *dq;
620 {
621   if (!dq) {
622     printf("Dereference a NULL discq? I don't think so.\n");
623     return;
624   }
625
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);*/
631 }
632 #endif /* INET6 */
633
634 /*----------------------------------------------------------------------
635  * Dump a data buffer 
636  ----------------------------------------------------------------------*/
637 void dump_buf(buf, len)
638      char *buf;
639      int len;
640 {
641   int i;
642
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));
646   }
647   printf("\n");
648 }
649
650
651 /*----------------------------------------------------------------------
652  * Dump a key_tblnode structrue
653  ----------------------------------------------------------------------*/
654 void dump_keytblnode(ktblnode)
655      struct key_tblnode *ktblnode;
656 {
657   if (!ktblnode) {
658     printf("NULL key table node pointer!\n");
659     return;
660   }
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);
664 }
665
666 /*----------------------------------------------------------------------
667  * Dump an ipsec_assoc structure
668  ----------------------------------------------------------------------*/
669 void dump_secassoc(seca)
670         struct key_secassoc *seca;
671 {
672   u_int8_t *p;
673   int i;
674
675   if (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);
698   } else
699     printf("can't dump null secassoc pointer!\n");
700 }
701
702
703 /*----------------------------------------------------------------------
704  * Dump a key_msghdr structure
705  ----------------------------------------------------------------------*/
706 void dump_keymsghdr(km)
707      struct key_msghdr *km;
708 {
709   if (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);
726   } else
727     printf("key_msghdr pointer is NULL!\n");
728 }
729
730
731 /*----------------------------------------------------------------------
732  * Dump a key_msgdata structure
733  ----------------------------------------------------------------------*/
734 void dump_keymsginfo(kp)
735      struct key_msgdata *kp;
736 {
737   int i;
738
739   if (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");\
749       printf("\n"); }
750     printf("iv is:\n");
751     dumpbuf(kp->iv, kp->ivlen);
752     printf("key is:\n");
753     dumpbuf(kp->key, kp->keylen);
754 #undef dumpbuf    
755   } else
756     printf("key_msgdata point is NULL!\n");
757 }
758
759 #endif /*KEY_DEBUG*/
760 #endif /*KEY*/