summaryrefslogtreecommitdiffstats
path: root/sys/net/vnet.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/net/vnet.h')
-rw-r--r--sys/net/vnet.h48
1 files changed, 32 insertions, 16 deletions
diff --git a/sys/net/vnet.h b/sys/net/vnet.h
index 76123c7..6bdf163 100644
--- a/sys/net/vnet.h
+++ b/sys/net/vnet.h
@@ -118,22 +118,27 @@ void vnet_destroy(struct vnet *vnet);
* Various macros -- get and set the current network stack, but also
* assertions.
*/
+#if defined(INVARIANTS) || defined(VNET_DEBUG)
+#define VNET_ASSERT(exp, msg) do { \
+ if (!(exp)) \
+ panic msg; \
+} while (0)
+#else
+#define VNET_ASSERT(exp, msg) do { \
+} while (0)
+#endif
+
#ifdef VNET_DEBUG
void vnet_log_recursion(struct vnet *, const char *, int);
-#define VNET_ASSERT(condition) \
- if (!(condition)) { \
- printf("VNET_ASSERT @ %s:%d %s():\n", \
- __FILE__, __LINE__, __FUNCTION__); \
- panic(#condition); \
- }
-
#define CURVNET_SET_QUIET(arg) \
- VNET_ASSERT((arg)->vnet_magic_n == VNET_MAGIC_N); \
+ VNET_ASSERT((arg) != NULL && (arg)->vnet_magic_n == VNET_MAGIC_N, \
+ ("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p", \
+ __FILE__, __LINE__, __func__, curvnet, (arg))); \
struct vnet *saved_vnet = curvnet; \
const char *saved_vnet_lpush = curthread->td_vnet_lpush; \
curvnet = arg; \
- curthread->td_vnet_lpush = __FUNCTION__;
+ curthread->td_vnet_lpush = __func__;
#define CURVNET_SET_VERBOSE(arg) \
CURVNET_SET_QUIET(arg) \
@@ -143,21 +148,31 @@ void vnet_log_recursion(struct vnet *, const char *, int);
#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg)
#define CURVNET_RESTORE() \
- VNET_ASSERT(saved_vnet == NULL || \
- saved_vnet->vnet_magic_n == VNET_MAGIC_N); \
+ VNET_ASSERT(curvnet != NULL && (saved_vnet == NULL || \
+ saved_vnet->vnet_magic_n == VNET_MAGIC_N), \
+ ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p", \
+ __FILE__, __LINE__, __func__, curvnet, saved_vnet)); \
curvnet = saved_vnet; \
curthread->td_vnet_lpush = saved_vnet_lpush;
#else /* !VNET_DEBUG */
-#define VNET_ASSERT(condition)
-#define CURVNET_SET(arg) \
+#define CURVNET_SET_QUIET(arg) \
+ VNET_ASSERT((arg) != NULL && (arg)->vnet_magic_n == VNET_MAGIC_N, \
+ ("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p", \
+ __FILE__, __LINE__, __func__, curvnet, (arg))); \
struct vnet *saved_vnet = curvnet; \
curvnet = arg;
-#define CURVNET_SET_VERBOSE(arg) CURVNET_SET(arg)
-#define CURVNET_SET_QUIET(arg) CURVNET_SET(arg)
+#define CURVNET_SET_VERBOSE(arg) \
+ CURVNET_SET_QUIET(arg)
+
+#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg)
#define CURVNET_RESTORE() \
+ VNET_ASSERT(curvnet != NULL && (saved_vnet == NULL || \
+ saved_vnet->vnet_magic_n == VNET_MAGIC_N), \
+ ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p", \
+ __FILE__, __LINE__, __func__, curvnet, saved_vnet)); \
curvnet = saved_vnet;
#endif /* VNET_DEBUG */
@@ -236,6 +251,7 @@ int vnet_sysctl_handle_uint(SYSCTL_HANDLER_ARGS);
ptr, val, vnet_sysctl_handle_int, "I", descr)
#define SYSCTL_VNET_PROC(parent, nbr, name, access, ptr, arg, handler, \
fmt, descr) \
+ CTASSERT(((access) & CTLTYPE) != 0); \
SYSCTL_OID(parent, nbr, name, CTLFLAG_VNET|(access), ptr, arg, \
handler, fmt, descr)
#define SYSCTL_VNET_OPAQUE(parent, nbr, name, access, ptr, len, fmt, \
@@ -350,7 +366,7 @@ do { \
*/
#define curvnet NULL
-#define VNET_ASSERT(condition)
+#define VNET_ASSERT(exp, msg)
#define CURVNET_SET(arg)
#define CURVNET_SET_QUIET(arg)
#define CURVNET_RESTORE()
OpenPOWER on IntegriCloud