1 //==========================================================================
3 // include/netinet6_sys_debug.h
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
10 // -------------------------------------------
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
15 // -------------------------------------------
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
22 // Contributors: gthomas
28 //####DESCRIPTIONEND####
30 //==========================================================================
34 %%% portions-copyright-nrl-95
35 Portions of this software are Copyright 1995-1998 by Randall Atkinson,
36 Ronald Lee, Daniel McDonald, Bao Phan, and Chris Winters. All Rights
37 Reserved. All rights under this copyright have been assigned to the US
38 Naval Research Laboratory (NRL). The NRL Copyright Notice and License
39 Agreement Version 1.1 (January 17, 1995) applies to these portions of the
41 You should have received a copy of the license with this software. If you
42 didn't get a copy, you may request one from <license@ipv6.nrl.navy.mil>.
46 #ifndef _NETINET6_SYS_DEBUG_H
47 #define _NETINET6_SYS_DEBUG_H 1
50 #include <sys/osdep.h>
53 #include <netinet6/osdep.h>
54 #else /* __OpenBSD__ */
55 #include <sys/osdep.h>
56 #endif /* __OpenBSD__ */
57 #endif /* DEBUG_NRL */
59 /* Non-ANSI compilers don't stand a chance. You PROBABLY need GNU C. */
61 #error An ANSI C compiler is required here.
64 #ifndef _KERN_DEBUG_GENERIC_C
65 extern int debug_level;
66 #endif /* _KERN_DEBUG_GENERIC_DEBUG_C */
68 /* Debugging levels */
70 #define __DEBUG_LEVEL_ALL (INT_MAX-1) /* Report all messages. */
71 #define __DEBUG_LEVEL_NONE 0 /* Report no messages. */
73 #define __DEBUG_LEVEL_CRITICAL 3
74 #define __DEBUG_LEVEL_ERROR 7
75 #define __DEBUG_LEVEL_MAJOREVENT 10
76 #define __DEBUG_LEVEL_EVENT 15
77 #define __DEBUG_LEVEL_GROSSEVENT 20
78 #define __DEBUG_LEVEL_FINISHED 1000
80 /* Compatibility macros */
82 #define __DEBUG_LEVEL_MAJOR_EVENT __DEBUG_LEVEL_MAJOREVENT
83 #define __DEBUG_LEVEL_GROSS_EVENT __DEBUG_LEVEL_GROSSEVENT
84 #define __DEBUG_LEVEL_IDL_CRITICAL __DEBUG_LEVEL_CRITICAL
85 #define __DEBUG_LEVEL_IDL_ERROR __DEBUG_LEVEL_ERROR
86 #define __DEBUG_LEVEL_IDL_MAJOR_EVENT __DEBUG_LEVEL_MAJOREVENT
87 #define __DEBUG_LEVEL_IDL_EVENT __DEBUG_LEVEL_EVENT
88 #define __DEBUG_LEVEL_IDL_GROSS_EVENT __DEBUG_LEVEL_GROSSEVENT
89 #define __DEBUG_LEVEL_IDL_FINISHED __DEBUG_LEVEL_FINISHED
91 /* Unless you have optimization turned off and your compiler is drain bamaged,
92 this will turn in to a syntactically inert no-op - cmetz */
93 #define __DEBUG_NOP do { } while (0)
97 * Make sure argument for DPRINTF is in parentheses.
99 * For both DPRINTF and DDO, and attempt was made to make both macros
100 * be usable as normal C statments. There is a small amount of compiler
101 * trickery (if-else clauses with effectively null statements), which may
102 * cause a few compilers to complain.
105 #ifndef __GENERIC_DEBUG_LEVEL
106 #define __GENERIC_DEBUG_LEVEL debug_level
107 #endif /* __GENERIC_DEBUG_LEVEL */
110 * DPRINTF() is a general printf statement. The "arg" is literally what
111 * would follow the function name printf, which means it has to be in
112 * parenthesis. Unlimited arguments can be used this way.
115 * DPRINTF(IDL_MAJOR_EVENT,("Hello, world. IP version %d.\n",vers));
118 #define DPRINTF(lev,arg) \
119 if (__DEBUG_LEVEL_ ## lev <= __GENERIC_DEBUG_LEVEL) { \
125 * DDO() executes a series of statements at a certain debug level. The
126 * "stmt" argument is a statement in the sense of a "statement list" in a
127 * C grammar. "stmt" does not have to end with a semicolon.
130 * DDO(IDL_CRITICAL,dump_ipv6(header), dump_inpcb(inp));
133 #define DDO(lev,stmt) \
134 if (__DEBUG_LEVEL_ ## lev <= __GENERIC_DEBUG_LEVEL) { \
140 * DP() is a shortcut for DPRINTF(). Basically:
142 * DP(lev, var, fmt) == DPRINTF(IDL_lev, ("var = %fmt\n", var))
144 * It is handy for printing single variables without a lot of typing.
148 * DP(CRITICAL,length,d);
149 * same as DPRINTF(IDL_CRITICAL, ("length = %d\n", length))
152 #define DP(lev, var, fmt) \
153 DPRINTF(lev, (#var " = %" #fmt "\n", var))
156 #if defined(__GNUC__) && (__GNUC__ >= 2)
157 #define DEBUG_STATUS debug_status(__FILE__ ":" __FUNCTION__, __LINE__, __builtin_return_address(0))
158 #else /* defined(__GNUC__) && (__GNUC__ >= 2) */
159 #define DEBUG_STATUS debug_status(__FILE__, __LINE__, (void *)0)
160 #endif /* defined(__GNUC__) && (__GNUC__ >= 2) */
167 #define DS() DPRINTF(IDL_CRITICAL, ("%s\n", DEBUG_STATUS))
168 #else /* DEBUG_NRL */
170 #define DPRINTF(lev,arg) __DEBUG_NOP
172 #define DDO(lev, stmt) __DEBUG_NOP
174 #define DP(x, y, z) __DEBUG_NOP
176 #define DS() __DEBUG_NOP
177 #endif /* DEBUG_NRL */
180 void *debug_malloc_malloc(unsigned int n, char *creator);
181 void debug_malloc_free(void *p);
182 void debug_malloc_dump(void);
183 void debug_malloc_flush(void);
184 #endif /* DEBUG_MALLOC */
187 char *debug_status(char *filefunction, unsigned int line, void *returnaddress);
188 void dump_buf_small(void *, int);
189 void debug_dump_buf(void *, int);
190 void dump_packet(void *buf, int len);
196 void dump_flags(struct dump_flags *, int);
199 void dump_sockaddr(struct sockaddr *);
200 void dump_smart_sockaddr(void *);
204 void dump_skb(struct sk_buff *);
205 #endif /* __linux__ */
209 void dump_sockaddr_dl(struct sockaddr_dl *);
211 void dump_mbuf_flags(struct mbuf *);
212 void dump_mbuf_hdr(struct mbuf *);
213 void dump_mbuf(struct mbuf *);
214 void dump_mchain_hdr(struct mbuf *);
215 void dump_mchain(struct mbuf *);
216 void dump_mbuf_tcpdump(struct mbuf *);
218 void dump_ifa(struct ifaddr *);
220 void dump_ifp(struct ifnet *);
222 void dump_route(struct route *);
224 void dump_rtentry(struct rtentry *);
226 void dump_inpcb(struct inpcb *);
227 #if __NetBSD__ || __OpenBSD__
229 void dump_inpcbs(struct inpcbtable *);
230 #else /* __NetBSD__ || __OpenBSD__ */
231 void dump_inpcbs(struct inpcb *);
232 #endif /* __NetBSD__ || __OpenBSD__ */
233 #endif /* OSDEP_BSD */
237 void dump_in_addr(struct in_addr *);
239 void dump_sockaddr_in(struct sockaddr_in *);
243 #include <netinet6/debug_inet6.h>
245 #endif /* DEBUG_NRL */
247 #endif /* _NETINET6_SYS_DEBUG_H */