diff --git a/configure.ac b/configure.ac index 744e34e..bd1f3ac 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,11 @@ AC_ARG_ENABLE([pthreads], [enable_pthreads="$enableval"], [enable_pthreads="yes"]) AM_CONDITIONAL([DISABLE_PTHREADS], [test "$enable_pthreads" = "no"]) +AC_ARG_ENABLE([debug], + AS_HELP_STRING([--disable-debug], [Do not include debugging statements]), + [enable_debug="$enableval"], [enable_debug="yes"]) +AM_CONDITIONAL([ENABLE_DEBUG], [test "$enable_debug" = "no" ]) + AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required])) if test "x$enable_pthreads" = "xno"; then @@ -100,6 +105,10 @@ else AC_CHECK_LIB([pthread], [pthread_mutex_lock], [], AC_MSG_ERROR([libpthread is required])) fi +if test "x$enable_debug" = "xyes"; then + AC_DEFINE([NL_DEBUG], [1], [Define to 1 to enable debugging]) +fi + AC_CONFIG_SUBDIRS([doc]) AC_CONFIG_FILES([ diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h index 6ae6d17..2e511bf 100644 --- a/include/netlink-private/netlink.h +++ b/include/netlink-private/netlink.h @@ -80,24 +80,29 @@ struct trans_list { struct nl_list_head list; }; -#define NL_DEBUG 1 - -#define NL_DBG(LVL,FMT,ARG...) \ - do { \ - if (LVL <= nl_debug) \ - fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \ +#ifdef NL_DEBUG +#define NL_DBG(LVL,FMT,ARG...) \ + do { \ + if (LVL <= nl_debug) \ + fprintf(stderr, \ + "DBG<" #LVL ">%20s:%-4u %s: " FMT, \ + __FILE__, __LINE__, \ + __PRETTY_FUNCTION__, ##ARG); \ } while (0) +#else /* NL_DEBUG */ +#define NL_DBG(LVL,FMT,ARG...) do { } while(0) +#endif /* NL_DEBUG */ #define BUG() \ do { \ - NL_DBG(1, "BUG: %s:%d\n", \ - __FILE__, __LINE__); \ + fprintf(stderr, "BUG at file position %s:%d:%s\n", \ + __FILE__, __LINE__, __PRETTY_FUNCTION__); \ assert(0); \ } while (0) #define APPBUG(msg) \ do { \ - NL_DBG(1, "APPLICATION BUG: %s:%d:%s: %s\n", \ + fprintf(stderr, "APPLICATION BUG: %s:%d:%s: %s\n", \ __FILE__, __LINE__, __PRETTY_FUNCTION__, msg); \ assert(0); \ } while(0) diff --git a/lib/route/neigh.c b/lib/route/neigh.c index 288bb85..ad26b4d 100644 --- a/lib/route/neigh.c +++ b/lib/route/neigh.c @@ -211,7 +211,9 @@ static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey, uint32_t n_ifindex; char n_addr[0]; } __attribute__((packed)) *nkey; +#ifdef NL_DEBUG char buf[INET6_ADDRSTRLEN+5]; +#endif if (neigh->n_family == AF_BRIDGE) { if (neigh->n_lladdr) diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c index 795047f..f2de523 100644 --- a/lib/route/route_obj.c +++ b/lib/route/route_obj.c @@ -307,7 +307,9 @@ static void route_keygen(struct nl_object *obj, uint32_t *hashkey, uint32_t rt_prio; char rt_addr[0]; } __attribute__((packed)) *rkey; +#ifdef NL_DEBUG char buf[INET6_ADDRSTRLEN+5]; +#endif if (route->rt_dst) addr = route->rt_dst; @@ -449,8 +451,10 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj) struct rtnl_route *new_route = (struct rtnl_route *) new_obj; struct rtnl_route *old_route = (struct rtnl_route *) old_obj; struct rtnl_nexthop *new_nh; - char buf[INET6_ADDRSTRLEN+5]; int action = new_obj->ce_msgtype; +#ifdef NL_DEBUG + char buf[INET6_ADDRSTRLEN+5]; +#endif /* * ipv6 ECMP route notifications from the kernel come as diff --git a/lib/utils.c b/lib/utils.c index 3bfa604..3012fea 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -49,6 +49,7 @@ int nl_debug = 0; /** @cond SKIP */ +#ifdef NL_DEBUG struct nl_dump_params nl_debug_dp = { .dp_type = NL_DUMP_DETAILS, }; @@ -65,6 +66,7 @@ static void __init nl_debug_init(void) nl_debug_dp.dp_fd = stderr; } +#endif int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *)) {