aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/interceptor/sshdebug.h
blob: c1c0836446fe44e8e2bb3d1bb37ad323b1c8c7ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* Netfilter Driver for IPSec VPN Client
 *
 * Copyright(c)   2012 Samsung Electronics
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/*
 * sshdebug.h
 *
 * Debug macros and assertions.
 *
 */

#ifndef SSHDEBUG_H
#define SSHDEBUG_H

#ifdef DEBUG_LIGHT

/* Debug level */
extern unsigned int ssh_debug_level;

#define SSH_FATAL(_fmt...) panic(_fmt)

#define SSH_NOTREACHED							   \
  panic("%s:%d: Unreachable code reached!", __FILE__, __LINE__)

#define SSH_DEBUG(level, varcall)					   \
  do {									   \
    if ((level) <= ssh_debug_level)					   \
      {									   \
	printk("%s:%d: ", __FILE__, __LINE__);				   \
	printk varcall;							   \
	printk("\n");							   \
      }									   \
  } while (0)

#define SSH_ASSERT(cond)                                                   \
  do {                                                                     \
    if (!(cond))                                                           \
      panic("%s:%d: Assertion failed: %s\n", __FILE__, __LINE__, "#cond"); \
  } while (0)
#define SSH_VERIFY(cond)  SSH_ASSERT(cond)
#define SSH_PRECOND(cond) SSH_ASSERT(cond)

static inline void
ssh_debug_hexdump(const unsigned char *buf, const size_t len)
{
  size_t i;

  for (i = 0; (i + 16) < len; i += 16)
    printk("%08x: %02x%02x %02x%02x %02x%02x %02x%02x "
	   "%02x%02x %02x%02x %02x%02x %02x%02x\n",
	   (unsigned int) i,
	   (unsigned int) buf[i+0], (unsigned int) buf[i+1],
	   (unsigned int) buf[i+2], (unsigned int) buf[i+3],
	   (unsigned int) buf[i+4], (unsigned int) buf[i+5],
	   (unsigned int) buf[i+6], (unsigned int) buf[i+7],
	   (unsigned int) buf[i+8], (unsigned int) buf[i+9],
	   (unsigned int) buf[i+10], (unsigned int) buf[i+11],
	   (unsigned int) buf[i+12], (unsigned int) buf[i+13],
	   (unsigned int) buf[i+14], (unsigned int) buf[i+15]);
  if (i >= len)
    return;

  printk("%08x: ", (unsigned int) i);
  for (; i < len; i++)
    printk("%02x%s", (unsigned int) buf[i], ((i % 2) == 1 ? " " : ""));
  printk("\n");
}

#define SSH_DEBUG_HEXDUMP(level, varcall, buf, len)	\
  do {						        \
    if ((level) <= ssh_debug_level)			\
      {							\
	printk("%s:%d: ", __FILE__, __LINE__);		\
	printk varcall;					\
	printk("\n");					\
	ssh_debug_hexdump((buf), (len));		\
      }							\
  } while (0)

#else /* !DEBUG_LIGHT */

#define SSH_FATAL(_fmt...) panic(_fmt)

#define SSH_NOTREACHED                                                     \
  panic("%s:%d: Unreachable code reached!", __FILE__, __LINE__)

#define SSH_DEBUG(level, varcall)

#define SSH_VERIFY(cond)                                                   \
  do {                                                                     \
    if (!(cond))                                                           \
      panic("%s:%d: Verify failed: %s\n", __FILE__, __LINE__, "#cond");    \
  } while (0)

#ifdef __COVERITY__
#define SSH_ASSERT(cond)                                                   \
  do {                                                                     \
    if (!(cond))                                                           \
      panic("%s:%d: Assertion failed: %s\n", __FILE__, __LINE__, "#cond"); \
  } while (0)
#else /* __COVERITY__ */
#define SSH_ASSERT(cond)
#endif /* __COVERITY__ */

#define SSH_PRECOND(cond) SSH_ASSERT(cond)

#define SSH_DEBUG_HEXDUMP(level, varcall, buf, len)

#endif /* DEBUG_LIGHT */



/* *********************************************************************
 *   DEBUG LEVELS
 * *********************************************************************/

/* *********************************************************************
 * Debug type definitions for debug level mapping
 * *********************************************************************/

/* Use debug code definitions below, not the debug level numbers
   (except 11-15). */

/** Software malfunction. */
#define SSH_D_ERROR  0

/** Software failure, but caused by a packet coming from network. */
#define SSH_D_NETFAULT 3

/** Data formatted incorrectly coming from a network or other outside source.*/
#define SSH_D_NETGARB 3

/** Nonfatal failure in a high or middle-level operation. */
#define SSH_D_FAIL 3

/** Uncommon situation. */
#define SSH_D_UNCOMMON 6

/** Success in a high-level operation. */
#define SSH_D_HIGHOK 4

/** Success in a middle-level operation. */
#define SSH_D_MIDOK 7

/** Success in a low-level operation. */
#define SSH_D_LOWOK 9

/** Start of a high-level operation. */
#define SSH_D_HIGHSTART 5

/** Start of a middle-level operation. */
#define SSH_D_MIDSTART 8

/** Start of a low-level operation. */
#define SSH_D_LOWSTART 10

/** Nice-to-know information. */
#define SSH_D_NICETOKNOW 7

/** Data block dump. */
#define SSH_D_DATADUMP 8

/** Packet dump. */
#define SSH_D_PCKDMP 9

/** Middle result of an operation, loop-internal information. */
#define SSH_D_MIDRESULT 10

#endif /* SSHDEBUG_H */