summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/netinet6/debug.h212
-rw-r--r--sys/netinet6/osdep.h260
2 files changed, 472 insertions, 0 deletions
diff --git a/sys/netinet6/debug.h b/sys/netinet6/debug.h
new file mode 100644
index 00000000000..738283d8a28
--- /dev/null
+++ b/sys/netinet6/debug.h
@@ -0,0 +1,212 @@
+/*
+%%% portions-copyright-nrl-95
+Portions of this software are Copyright 1995-1998 by Randall Atkinson,
+Ronald Lee, Daniel McDonald, Bao Phan, and Chris Winters. All Rights
+Reserved. All rights under this copyright have been assigned to the US
+Naval Research Laboratory (NRL). The NRL Copyright Notice and License
+Agreement Version 1.1 (January 17, 1995) applies to these portions of the
+software.
+You should have received a copy of the license with this software. If you
+didn't get a copy, you may request one from <license@ipv6.nrl.navy.mil>.
+
+*/
+
+#ifndef _SYS_DEBUG_H
+#define _SYS_DEBUG_H 1
+
+#ifdef DEBUG_NRL_SYS
+#include <sys/osdep.h>
+#endif /* DEBUG_NRL_SYS */
+#ifdef DEBUG_NRL_NETINET6
+#include <netinet6/osdep.h>
+#endif /* DEBUG_NRL_NETINET6 */
+
+/* Non-ANSI compilers don't stand a chance. You PROBABLY need GNU C. */
+#ifndef __STDC__
+#error An ANSI C compiler is required here.
+#endif /* __STDC__ */
+
+#ifndef _KERN_DEBUG_GENERIC_C
+extern int debug_level;
+#endif /* _KERN_DEBUG_GENERIC_DEBUG_C */
+
+/* Debugging levels */
+
+#define __DEBUG_LEVEL_ALL (INT_MAX-1) /* Report all messages. */
+#define __DEBUG_LEVEL_NONE 0 /* Report no messages. */
+
+#define __DEBUG_LEVEL_CRITICAL 3
+#define __DEBUG_LEVEL_ERROR 7
+#define __DEBUG_LEVEL_MAJOREVENT 10
+#define __DEBUG_LEVEL_EVENT 15
+#define __DEBUG_LEVEL_GROSSEVENT 20
+#define __DEBUG_LEVEL_FINISHED 1000
+
+/* Compatibility macros */
+
+#define __DEBUG_LEVEL_MAJOR_EVENT __DEBUG_LEVEL_MAJOREVENT
+#define __DEBUG_LEVEL_GROSS_EVENT __DEBUG_LEVEL_GROSSEVENT
+#define __DEBUG_LEVEL_IDL_CRITICAL __DEBUG_LEVEL_CRITICAL
+#define __DEBUG_LEVEL_IDL_ERROR __DEBUG_LEVEL_ERROR
+#define __DEBUG_LEVEL_IDL_MAJOR_EVENT __DEBUG_LEVEL_MAJOREVENT
+#define __DEBUG_LEVEL_IDL_EVENT __DEBUG_LEVEL_EVENT
+#define __DEBUG_LEVEL_IDL_GROSS_EVENT __DEBUG_LEVEL_GROSSEVENT
+#define __DEBUG_LEVEL_IDL_FINISHED __DEBUG_LEVEL_FINISHED
+
+/* Unless you have optimization turned off and your compiler is drain bamaged,
+ this will turn in to a syntactically inert no-op - cmetz */
+#define __DEBUG_NOP do { } while (0)
+
+#ifdef DEBUG_NRL
+/*
+ * Make sure argument for DPRINTF is in parentheses.
+ *
+ * For both DPRINTF and DDO, and attempt was made to make both macros
+ * be usable as normal C statments. There is a small amount of compiler
+ * trickery (if-else clauses with effectively null statements), which may
+ * cause a few compilers to complain.
+ */
+
+#ifndef __GENERIC_DEBUG_LEVEL
+#define __GENERIC_DEBUG_LEVEL debug_level
+#endif /* __GENERIC_DEBUG_LEVEL */
+
+/*
+ * DPRINTF() is a general printf statement. The "arg" is literally what
+ * would follow the function name printf, which means it has to be in
+ * parenthesis. Unlimited arguments can be used this way.
+ *
+ * EXAMPLE:
+ * DPRINTF(IDL_MAJOR_EVENT,("Hello, world. IP version %d.\n",vers));
+ */
+#undef DPRINTF
+#define DPRINTF(lev,arg) \
+ if (__DEBUG_LEVEL_ ## lev <= __GENERIC_DEBUG_LEVEL) { \
+ printf arg; \
+ } else \
+ __DEBUG_NOP
+
+/*
+ * DDO() executes a series of statements at a certain debug level. The
+ * "stmt" argument is a statement in the sense of a "statement list" in a
+ * C grammar. "stmt" does not have to end with a semicolon.
+ *
+ * EXAMPLE:
+ * DDO(IDL_CRITICAL,dump_ipv6(header), dump_inpcb(inp));
+ */
+#undef DDO
+#define DDO(lev,stmt) \
+ if (__DEBUG_LEVEL_ ## lev <= __GENERIC_DEBUG_LEVEL) { \
+ stmt ; \
+ } else \
+ __DEBUG_NOP
+
+/*
+ * DP() is a shortcut for DPRINTF(). Basically:
+ *
+ * DP(lev, var, fmt) == DPRINTF(IDL_lev, ("var = %fmt\n", var))
+ *
+ * It is handy for printing single variables without a lot of typing.
+ *
+ * EXAMPLE:
+ *
+ * DP(CRITICAL,length,d);
+ * same as DPRINTF(IDL_CRITICAL, ("length = %d\n", length))
+ */
+#undef DP
+#define DP(lev, var, fmt) \
+ DPRINTF(lev, (#var " = %" #fmt "\n", var))
+
+#undef DEBUG_STATUS
+#if defined(__GNUC__) && (__GNUC__ >= 2)
+#define DEBUG_STATUS debug_status(__FILE__ ":" __FUNCTION__, __LINE__, __builtin_return_address(0))
+#else /* defined(__GNUC__) && (__GNUC__ >= 2) */
+#define DEBUG_STATUS debug_status(__FILE__, __LINE__, (void *)0)
+#endif /* defined(__GNUC__) && (__GNUC__ >= 2) */
+
+/* Call as:
+
+ DS();
+*/
+#undef DS
+#define DS() DPRINTF(IDL_CRITICAL, ("%s\n", DEBUG_STATUS))
+#else /* DEBUG_NRL */
+#undef DPRINTF
+#define DPRINTF(lev,arg) __DEBUG_NOP
+#undef DDO
+#define DDO(lev, stmt) __DEBUG_NOP
+#undef DP
+#define DP(x, y, z) __DEBUG_NOP
+#undef DS
+#define DS() __DEBUG_NOP
+#endif /* DEBUG_NRL */
+
+#ifdef DEBUG_MALLOC
+void *debug_malloc_malloc(unsigned int n, char *creator);
+void debug_malloc_free(void *p);
+void debug_malloc_dump(void);
+void debug_malloc_flush(void);
+#endif /* DEBUG_MALLOC */
+
+#ifdef DEBUG_NRL
+char *debug_status(char *filefunction, unsigned int line, void *returnaddress);
+void dump_buf_small(void *, int);
+void debug_dump_buf(void *, int);
+void dump_packet(void *buf, int len);
+
+struct dump_flags {
+ int val;
+ char *name;
+};
+void dump_flags(struct dump_flags *, int);
+
+struct sockaddr;
+void dump_sockaddr(struct sockaddr *);
+void dump_smart_sockaddr(void *);
+
+#ifdef __linux__
+struct sk_buff;
+void dump_skb(struct sk_buff *);
+#endif /* __linux__ */
+
+#ifdef OSDEP_BSD
+struct sockaddr_dl;
+void dump_sockaddr_dl(struct sockaddr_dl *);
+struct mbuf;
+void dump_mbuf_flags(struct mbuf *);
+void dump_mbuf_hdr(struct mbuf *);
+void dump_mbuf(struct mbuf *);
+void dump_mchain_hdr(struct mbuf *);
+void dump_mchain(struct mbuf *);
+void dump_mbuf_tcpdump(struct mbuf *);
+struct ifaddr;
+void dump_ifa(struct ifaddr *);
+struct ifnet;
+void dump_ifp(struct ifnet *);
+struct route;
+void dump_route(struct route *);
+struct rtentry;
+void dump_rtentry(struct rtentry *);
+struct inpcb;
+void dump_inpcb(struct inpcb *);
+#if __NetBSD__ || __OpenBSD__
+struct inpcbtable;
+void dump_inpcbs(struct inpcbtable *);
+#else /* __NetBSD__ || __OpenBSD__ */
+void dump_inpcbs(struct inpcb *);
+#endif /* __NetBSD__ || __OpenBSD__ */
+#endif /* OSDEP_BSD */
+
+#ifdef INET
+struct in_addr;
+void dump_in_addr(struct in_addr *);
+struct sockaddr_in;
+void dump_sockaddr_in(struct sockaddr_in *);
+#endif /* INET */
+
+#ifdef INET6
+#include <netinet6/debug_inet6.h>
+#endif /* INET6 */
+#endif /* DEBUG_NRL */
+
+#endif /* _SYS_DEBUG_H */
diff --git a/sys/netinet6/osdep.h b/sys/netinet6/osdep.h
new file mode 100644
index 00000000000..13f87c7c9e2
--- /dev/null
+++ b/sys/netinet6/osdep.h
@@ -0,0 +1,260 @@
+/*
+%%% copyright-nrl-97
+This software is Copyright 1997-1998 by Randall Atkinson, Ronald Lee,
+Daniel McDonald, Bao Phan, and Chris Winters. All Rights Reserved. All
+rights under this copyright have been assigned to the US Naval Research
+Laboratory (NRL). The NRL Copyright Notice and License Agreement Version
+1.1 (January 17, 1995) applies to this software.
+You should have received a copy of the license with this software. If you
+didn't get a copy, you may request one from <license@ipv6.nrl.navy.mil>.
+
+%%% copyright-cmetz-97
+This software is Copyright 1997-1998 by Craig Metz, All Rights Reserved.
+The Inner Net License Version 2 applies to this software.
+You should have received a copy of the license with this software. If
+you didn't get a copy, you may request one from <license@inner.net>.
+
+*/
+#ifndef __OSDEP_H
+#define __OSDEP_H 1
+
+#if __linux__
+#ifdef __KERNEL__
+#define KERNEL 1
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/socket.h>
+#include <net/sock.h>
+#include <linux/random.h>
+#include <asm/uaccess.h>
+#include <linux/malloc.h>
+
+#define printf printk
+
+/* XXX */
+#define OSDEP_CRITICALDCL unsigned long flags;
+#define OSDEP_CRITICALSTART save_flags(flags); cli()
+#define OSDEP_CRITICALEND restore_flags(flags)
+
+#define OSDEP_TIMESECONDS (xtime.tv_sec)
+
+#define OSDEP_PROCESS struct task_struct
+#define OSDEP_PROCESSCURRENT (current)
+#define OSDEP_PROCESSPARENT(x) ((x)->p_pptr)
+#define OSDEP_PROCESSPID(x) ((x)->pid)
+
+#define OSDEP_PCAST(x) ((unsigned int)(x) & 0xffffffff)
+#define OSDEP_SOCKET struct sock
+#define OSDEP_PACKET struct sk_buff
+struct sk_buff;
+
+#define OSDEP_REAL_MALLOC(n) kmalloc(n, GFP_ATOMIC)
+#define OSDEP_REAL_FREE(p) kfree(p)
+
+#define OSDEP_SOCKETFAMILY(socket) (socket->family)
+#define OSDEP_SOCKETPRIVELEGED(socket) (suser())
+
+static inline uint32_t __osdep_pseudorandom(void)
+{
+ static uint32_t seed=152;
+ seed=seed*69069+1;
+ return seed^jiffies;
+};
+#define OSDEP_PSEUDORANDOM __osdep_pseudorandom()
+
+static inline int __osdep_datatopacket(void *data, int len, OSDEP_PACKET **packet)
+{
+ if (!(*packet = alloc_skb(len, GFP_ATOMIC)))
+ return -ENOMEM;
+
+ memcpy((*packet)->h.raw = skb_put(*packet, len), data, len);
+
+ return 0;
+};
+#define OSDEP_DATATOPACKET(data, len, packet) __osdep_datatopacket(data, len, packet)
+#define OSDEP_ZEROPACKET(packet) memset(packet->head, 0, packet->end - packet->head)
+#define OSDEP_FREEPACKET(packet) kfree_skb(packet)
+
+#define OSDEP_COPYFROMUSER(dst, src, len) \
+ (copy_from_user(dst, src, len) ? -EFAULT : 0)
+
+#define OSDEP_COPYTOUSER(dst, src, len) \
+ (copy_to_user(dst, src, len) ? -EFAULT : 0)
+
+#define __P(x) x
+#else /* __KERNEL__ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <errno.h>
+#endif /* __KERNEL__ */
+
+#define OSDEP_SALEN 0
+#define OSDEP_ERROR(x) (-(x))
+
+#ifndef IN6_IS_ADDR_UNSPECIFIED
+#define IN6_IS_ADDR_UNSPECIFIED(a) \
+ ((((uint32_t *)(a))[0] == 0) && (((uint32_t *)(a))[1] == 0) && \
+ (((uint32_t *)(a))[2] == 0) && (((uint32_t *)(a))[3] == 0))
+#endif /* IN6_IS_ADDR_UNSPECIFIED */
+
+/* Stupid C trick: We can define the structures that are members of union
+ sockaddr_union as empty and later redefine them as non-empty. We CAN'T,
+ however, define them as non-empty and later redefine them as empty. So
+ the empty declarations must be wrapped to ensure that we don't do that.
+
+ WARNING: gcc < 2.8 generates incorrect debugging information for this;
+ the symptom is that gdb thinks that all struct sockaddr_*'s are empty
+ structures. gcc >= 2.8 correctly figures out what's going on. - cmetz
+*/
+
+#ifdef KERNEL
+#ifndef _NETINET_IN_H_
+/* struct sockaddr_in {}; */
+#endif /* _NETINET_IN_H_ */
+#ifndef _NETINET6_IN6_H
+/* struct sockaddr_in6 {}; */
+#endif /* _NETINET6_IN6_H */
+#ifndef _SYS_UN_H_
+struct sockaddr_un {};
+#endif /* _SYS_UN_H_ */
+
+union sockaddr_union {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+ struct sockaddr_un sun;
+ char __maxsize[128]; /* should probably be MHLEN on BSD */
+};
+
+static inline uint8_t __osdep_sa_len(struct sockaddr *sockaddr)
+{
+ switch(sockaddr->sa_family) {
+ case AF_INET:
+ return 16; /* sizeof(struct sockaddr_in); */
+ case AF_INET6:
+ return 24; /* sizeof(struct sockaddr_in6); */
+ default:
+ return 0;
+ };
+};
+#define SA_LEN(sockaddr) __osdep_sa_len(sockaddr)
+#endif /* KERNEL */
+#endif /* __linux__ */
+
+#if __NetBSD__ || __bsdi__ || __OpenBSD__ || __FreeBSD__
+#define OSDEP_BSD 1
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#ifdef KERNEL
+#ifndef ATSH_ADD
+#include <sys/systm.h>
+#endif /* ATSH_ADD */
+#ifndef MLEN
+#include <sys/mbuf.h>
+#endif /* MLEN */
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#ifndef SB_MAX
+#include <sys/socketvar.h>
+#endif /* SB_MAX */
+#include <sys/proc.h>
+#ifndef RTM_RTTUNIT
+#include <net/route.h>
+#endif /* RTM_RTTUNIT */
+#endif /* KERNEL */
+struct ifnet;
+struct mbuf;
+#include <netinet/in.h>
+struct route6;
+
+#ifdef KERNEL
+/* XXX */
+#define OSDEP_CRITICALDCL int __s;
+#define OSDEP_CRITICALSTART __s = splnet()
+#define OSDEP_CRITICALEND splx(__s)
+
+#ifdef __FreeBSD__
+#define OSDEP_TIMESECONDS (time_second)
+#else /* __FreeBSD__ */
+#define OSDEP_TIMESECONDS (time.tv_sec)
+#endif /* __FreeBSD__ */
+
+#define OSDEP_PROCESS struct proc
+#if !defined(_BSDI_VERSION) || (_BSDI_VERSION < 199802)
+#define OSDEP_PROCESSCURRENT (curproc)
+#else /* !defined(_BSDI_VERSION) || (_BSDI_VERSION < 199802) */
+#include <machine/pcpu.h>
+#define OSDEP_PROCESSCURRENT (PCPU(curproc))
+#endif /* !defined(_BSDI_VERSION) || (_BSDI_VERSION < 199802) */
+#define OSDEP_PROCESSPARENT(x) ((x)->p_pptr)
+#define OSDEP_PROCESSPID(x) ((x)->p_pid)
+
+#ifdef SS_PRIV
+#define OSDEP_SOCKETPRIVELEGED(socket) (socket->so_state & SS_PRIV)
+#else /* SS_PRIV */
+/* XXX? */
+#define OSDEP_SOCKETPRIVELEGED(socket) (!curproc || !curproc->p_ucred || !curproc->p_ucred->cr_uid)
+#endif /* SS_PRIV */
+#define OSDEP_PCAST(x) ((unsigned int)(x) & 0xffffffff)
+#define OSDEP_SOCKET struct socket
+#define OSDEP_PACKET struct mbuf
+struct mbuf;
+
+#define OSDEP_REAL_MALLOC(n) malloc((unsigned long)(n), M_TEMP, M_DONTWAIT)
+#define OSDEP_REAL_FREE(p) free((void *)p, M_TEMP)
+#define OSDEP_FAMILY(socket) (socket->so_proto->pr_domain->dom_family)
+#define OSDEP_PSEUDORANDOM (uint32_t)random()
+
+#if !__FreeBSD__
+struct ifnet;
+struct mbuf *m_devget(char *, int, int, struct ifnet *, void (*)(const void *, void *, size_t));
+#endif /* !__FreeBSD__ */
+
+static __inline__ int __osdep_datatopacket(void *data, int len, OSDEP_PACKET **packet)
+{
+ if (!(*packet = m_devget(data, len, 0, NULL, NULL)))
+ return -ENOMEM;
+
+ return 0;
+};
+
+#define OSDEP_DATATOPACKET(data, len, packet) __osdep_datatopacket(data, len, packet)
+
+#define OSDEP_ZEROPACKET(packet) m_zero(packet)
+#define OSDEP_FREEPACKET(packet) m_freem(packet)
+
+#define memcpy(dst, src, len) bcopy(src, dst, len)
+#define memmove(dst, src, len) bcopy(src, dst, len)
+#define memset(p, zero, len) bzero(p, len) /* XXX */
+#define memcmp(p1, p2, len) bcmp(p1, p2, len)
+
+#define OSDEP_COPYFROMUSER(dst, src, len) copyin(src, dst, len)
+#define OSDEP_COPYTOUSER(dst, src, len) copyout(src, dst, len)
+
+#if __FreeBSD__
+#define M_SOCKET M_TEMP
+#define MT_SOOPTS MT_DATA
+#endif /* __FreeBSD__ */
+#endif /* KERNEL */
+#define OSDEP_SALEN 1
+#define OSDEP_ERROR(x) (x)
+#endif /* __NetBSD__ || __bsdi__ || __OpenBSD__ || __FreeBSD__ */
+
+#define ENETSECURITYPOLICY -ECOMM
+
+#ifdef DEBUG_MALLOC
+#undef OSDEP_MALLOC
+#undef OSDEP_FREE
+#define OSDEP_MALLOC(n) debug_malloc_malloc(n, DEBUG_STATUS)
+#define OSDEP_FREE(p) debug_malloc_free(p)
+#else /* DEBUG_MALLOC */
+#undef OSDEP_MALLOC
+#define OSDEP_MALLOC(n) OSDEP_REAL_MALLOC(n)
+#undef OSDEP_FREE
+#define OSDEP_FREE(p) OSDEP_REAL_FREE(p)
+#endif /* DEBUG_MALLOC */
+
+#endif /* __OSDEP_H */