diff --git a/include/net/buf.h b/include/net/buf.h index 28dc23f9b8..eae3dbc89f 100644 --- a/include/net/buf.h +++ b/include/net/buf.h @@ -526,7 +526,7 @@ struct net_buf_pool { * * @return New buffer or NULL if out of buffers. */ -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout, const char *func, int line); #define net_buf_alloc(_pool, _timeout) \ @@ -548,7 +548,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout); * * @return New buffer or NULL if the FIFO is empty. */ -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout, const char *func, int line); #define net_buf_get(_fifo, _timeout) \ @@ -602,7 +602,7 @@ void net_buf_put(struct k_fifo *fifo, struct net_buf *buf); * * @param buf A valid pointer on a buffer */ -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) void net_buf_unref_debug(struct net_buf *buf, const char *func, int line); #define net_buf_unref(_buf) \ net_buf_unref_debug(_buf, __func__, __LINE__) diff --git a/samples/net/ieee802154/cc2520/prj.conf b/samples/net/ieee802154/cc2520/prj.conf index b0c0883831..13f4f91304 100644 --- a/samples/net/ieee802154/cc2520/prj.conf +++ b/samples/net/ieee802154/cc2520/prj.conf @@ -33,8 +33,6 @@ CONFIG_NET_DEBUG_ICMPV6=y CONFIG_NET_DEBUG_CONN=y CONFIG_NET_STATISTICS=y -#CONFIG_NET_BUF_DEBUG=y - CONFIG_NET_L2_IEEE802154=y CONFIG_NET_DEBUG_L2_IEEE802154=y CONFIG_NET_L2_IEEE802154_ORFD=y diff --git a/samples/net/ieee802154/qemu/prj.conf b/samples/net/ieee802154/qemu/prj.conf index 31c27ba172..ee3dae03fd 100644 --- a/samples/net/ieee802154/qemu/prj.conf +++ b/samples/net/ieee802154/qemu/prj.conf @@ -30,7 +30,6 @@ CONFIG_NET_DEBUG_IF=y CONFIG_NET_DEBUG_ICMPV6=y CONFIG_NET_DEBUG_CONN=y CONFIG_NET_STATISTICS=y -#CONFIG_NET_BUF_DEBUG=y CONFIG_NET_L2_IEEE802154=y CONFIG_NET_DEBUG_L2_IEEE802154=y diff --git a/samples/net/mbedtls_sslclient/prj_galileo.conf b/samples/net/mbedtls_sslclient/prj_galileo.conf index ec8445bdbb..fa41271f80 100644 --- a/samples/net/mbedtls_sslclient/prj_galileo.conf +++ b/samples/net/mbedtls_sslclient/prj_galileo.conf @@ -16,7 +16,6 @@ CONFIG_IP_BUF_TX_SIZE=4 #CONFIG_NETWORKING_WITH_LOGGING=y #CONFIG_NETWORK_IP_STACK_DEBUG_NET_BUF=y -#CONFIG_NET_BUF_DEBUG=y #CONFIG_NETWORK_IP_STACK_DEBUG_CONTEXT=y #CONFIG_NETWORK_IP_STACK_DEBUG_TCP_PSOCK=y diff --git a/subsys/net/Kconfig b/subsys/net/Kconfig index 8ca3815a82..a450396bf4 100644 --- a/subsys/net/Kconfig +++ b/subsys/net/Kconfig @@ -25,18 +25,33 @@ config NET_BUF This option enables support for generic network protocol buffers. -config NET_BUF_DEBUG - bool "Network buffer debugging" +config NET_BUF_LOG + bool "Network buffer logging" depends on NET_BUF select STDOUT_CONSOLE select SYS_LOG default n help - Enable debug logs and checks for the generic network buffers. + Enable logs and checks for the generic network buffers. -config NET_BUF_SIMPLE_DEBUG +config SYS_LOG_NET_BUF_LEVEL + int + prompt "Network buffer Logging level" + depends on NET_BUF_LOG + default 1 + range 0 4 + help + Sets log level for network buffers. + Levels are: + 0 OFF, do not write + 1 ERROR, only write SYS_LOG_ERR + 2 WARNING, write SYS_LOG_WRN in adition to previous level + 3 INFO, write SYS_LOG_INF in adition to previous levels + 4 DEBUG, write SYS_LOG_DBG in adition to previous levels + +config NET_BUF_SIMPLE_LOG bool "Network buffer memory debugging" - depends on NET_BUF_DEBUG + depends on NET_BUF_LOG select STDOUT_CONSOLE select SYS_LOG default n diff --git a/subsys/net/buf.c b/subsys/net/buf.c index f288092426..6ba5b042d9 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -24,9 +24,9 @@ #include -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) #define SYS_LOG_DOMAIN "net/buf" -#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG +#define SYS_LOG_LEVEL CONFIG_SYS_LOG_NET_BUF_LEVEL #include #define NET_BUF_DBG(fmt, ...) SYS_LOG_DBG("(%p) " fmt, k_current_get(), \ @@ -44,7 +44,7 @@ #define NET_BUF_WARN(fmt, ...) #define NET_BUF_INFO(fmt, ...) #define NET_BUF_ASSERT(cond) -#endif /* CONFIG_NET_BUF_DEBUG */ +#endif /* CONFIG_NET_BUF_LOG */ /* Helpers to access the storage array, since we don't have access to its * type at this point anymore. @@ -68,7 +68,7 @@ static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool, return buf; } -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout, const char *func, int line) #else @@ -114,7 +114,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout) irq_unlock(key); -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) && SYS_LOG_LEVEL >= SYS_LOG_LEVEL_WARNING if (timeout == K_FOREVER) { buf = k_lifo_get(&pool->free, K_NO_WAIT); if (!buf) { @@ -145,7 +145,7 @@ success: return buf; } -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout, const char *func, int line) #else @@ -202,7 +202,7 @@ void net_buf_put(struct k_fifo *fifo, struct net_buf *buf) k_fifo_put_list(fifo, buf, tail); } -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) void net_buf_unref_debug(struct net_buf *buf, const char *func, int line) #else void net_buf_unref(struct net_buf *buf) @@ -213,7 +213,7 @@ void net_buf_unref(struct net_buf *buf) while (buf) { struct net_buf *frags = buf->frags; -#if defined(CONFIG_NET_BUF_DEBUG) +#if defined(CONFIG_NET_BUF_LOG) if (!buf->ref) { NET_BUF_ERR("%s():%d: buf %p double free", func, line, buf); @@ -324,7 +324,7 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag) return next_frag; } -#if defined(CONFIG_NET_BUF_SIMPLE_DEBUG) +#if defined(CONFIG_NET_BUF_SIMPLE_LOG) #define NET_BUF_SIMPLE_DBG(fmt, ...) NET_BUF_DBG(fmt, ##__VA_ARGS__) #define NET_BUF_SIMPLE_ERR(fmt, ...) NET_BUF_ERR(fmt, ##__VA_ARGS__) #define NET_BUF_SIMPLE_WARN(fmt, ...) NET_BUF_WARN(fmt, ##__VA_ARGS__) @@ -336,7 +336,7 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag) #define NET_BUF_SIMPLE_WARN(fmt, ...) #define NET_BUF_SIMPLE_INFO(fmt, ...) #define NET_BUF_SIMPLE_ASSERT(cond) -#endif /* CONFIG_NET_BUF_SIMPLE_DEBUG */ +#endif /* CONFIG_NET_BUF_SIMPLE_LOG */ void *net_buf_simple_add(struct net_buf_simple *buf, size_t len) { diff --git a/tests/net/6lo/prj.conf b/tests/net/6lo/prj.conf index a82a57b032..76fbd09863 100644 --- a/tests/net/6lo/prj.conf +++ b/tests/net/6lo/prj.conf @@ -16,7 +16,6 @@ CONFIG_SYS_LOG_SHOW_COLOR=y CONFIG_NET_DEBUG_IF=y CONFIG_NET_DEBUG_CORE=y CONFIG_NET_6LO_DEBUG=n -CONFIG_NET_BUF_DEBUG=n CONFIG_NET_DEBUG_NET_BUF=n CONFIG_NET_6LO_CONTEXT=y diff --git a/tests/net/buf/prj.conf b/tests/net/buf/prj.conf index f945785cbf..61c02799ec 100644 --- a/tests/net/buf/prj.conf +++ b/tests/net/buf/prj.conf @@ -1,3 +1,4 @@ CONFIG_NET_BUF=y -#CONFIG_NET_BUF_DEBUG=y +#CONFIG_NET_BUF_LOG=y +#CONFIG_SYS_LOG_NET_BUF_LEVEL=4 CONFIG_ZTEST=y diff --git a/tests/net/nbuf/prj.conf b/tests/net/nbuf/prj.conf index 146ecb6957..8b5f61d884 100644 --- a/tests/net/nbuf/prj.conf +++ b/tests/net/nbuf/prj.conf @@ -1,7 +1,8 @@ CONFIG_NETWORKING=y CONFIG_NET_IPV6=y CONFIG_NET_BUF=y -#CONFIG_NET_BUF_DEBUG=y +#CONFIG_NET_BUF_LOG=y +#CONFIG_SYS_LOG_NET_BUF_LEVEL=4 CONFIG_MAIN_STACK_SIZE=2048 CONFIG_NET_NBUF_RX_COUNT=4 CONFIG_NET_NBUF_TX_COUNT=4