net: Use lighter printk() instead of printf()

Use printk(), snprintk() instead of printf() and snprintf().
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf()
will not output anything without it.

Change-Id: I9ad778e318fe999e79ec34182f2de8574e45b7d4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2017-01-23 13:05:40 +02:00 committed by Jukka Rissanen
commit 4540a73b59
12 changed files with 57 additions and 49 deletions

View file

@ -388,46 +388,46 @@ void prepare_register_debug_print(char *dst, int dst_len,
{ {
if (remote_addr && remote_addr->family == AF_INET6) { if (remote_addr && remote_addr->family == AF_INET6) {
#if defined(CONFIG_NET_IPV6) #if defined(CONFIG_NET_IPV6)
snprintf(dst, dst_len, snprintk(dst, dst_len, "%s",
net_sprint_ipv6_addr(&net_sin6(remote_addr)-> net_sprint_ipv6_addr(&net_sin6(remote_addr)->
sin6_addr)); sin6_addr));
#else #else
snprintf(dst, dst_len, "?"); snprintk(dst, dst_len, "%s", "?");
#endif #endif
} else if (remote_addr && remote_addr->family == AF_INET) { } else if (remote_addr && remote_addr->family == AF_INET) {
#if defined(CONFIG_NET_IPV4) #if defined(CONFIG_NET_IPV4)
snprintf(dst, dst_len, snprintk(dst, dst_len, "%s",
net_sprint_ipv4_addr(&net_sin(remote_addr)-> net_sprint_ipv4_addr(&net_sin(remote_addr)->
sin_addr)); sin_addr));
#else #else
snprintf(dst, dst_len, "?"); snprintk(dst, dst_len, "%s", "?");
#endif #endif
} else { } else {
snprintf(dst, dst_len, "-"); snprintk(dst, dst_len, "%s", "-");
} }
if (local_addr && local_addr->family == AF_INET6) { if (local_addr && local_addr->family == AF_INET6) {
#if defined(CONFIG_NET_IPV6) #if defined(CONFIG_NET_IPV6)
snprintf(src, src_len, snprintk(src, src_len, "%s",
net_sprint_ipv6_addr(&net_sin6(local_addr)-> net_sprint_ipv6_addr(&net_sin6(local_addr)->
sin6_addr)); sin6_addr));
#else #else
snprintf(src, src_len, "?"); snprintk(src, src_len, "%s", "?");
#endif #endif
} else if (local_addr && local_addr->family == AF_INET) { } else if (local_addr && local_addr->family == AF_INET) {
#if defined(CONFIG_NET_IPV4) #if defined(CONFIG_NET_IPV4)
snprintf(src, src_len, snprintk(src, src_len, "%s",
net_sprint_ipv4_addr(&net_sin(local_addr)-> net_sprint_ipv4_addr(&net_sin(local_addr)->
sin_addr)); sin_addr));
#else #else
snprintf(src, src_len, "?"); snprintk(src, src_len, "%s", "?");
#endif #endif
} else { } else {
snprintf(src, src_len, "-"); snprintk(src, src_len, "%s", "-");
} }
} }
#endif /* CONFIG_NET_DEBUG_CONN */ #endif /* CONFIG_NET_DEBUG_CONN */

View file

@ -32,7 +32,7 @@ static inline enum net_verdict handle_echo_request(struct net_buf *buf)
#if defined(CONFIG_NET_DEBUG_ICMPV4) #if defined(CONFIG_NET_DEBUG_ICMPV4)
char out[sizeof("xxx.xxx.xxx.xxx")]; char out[sizeof("xxx.xxx.xxx.xxx")];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst)); net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
NET_DBG("Received Echo Request from %s to %s", NET_DBG("Received Echo Request from %s to %s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out); net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out);
@ -49,7 +49,7 @@ static inline enum net_verdict handle_echo_request(struct net_buf *buf)
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv4(buf); NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv4(buf);
#if defined(CONFIG_NET_DEBUG_ICMPV4) #if defined(CONFIG_NET_DEBUG_ICMPV4)
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst)); net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
NET_DBG("Sending Echo Reply from %s to %s", NET_DBG("Sending Echo Reply from %s to %s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out); net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out);
@ -138,7 +138,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
do { do {
char out[NET_IPV4_ADDR_LEN]; char out[NET_IPV4_ADDR_LEN];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst)); net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
NET_DBG("Sending ICMPv4 Echo Request type %d" NET_DBG("Sending ICMPv4 Echo Request type %d"
@ -252,7 +252,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
do { do {
char out[sizeof("xxx.xxx.xxx.xxx")]; char out[sizeof("xxx.xxx.xxx.xxx")];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst)); net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
NET_DBG("Sending ICMPv4 Error Message type %d code %d " NET_DBG("Sending ICMPv4 Error Message type %d code %d "
"from %s to %s", type, code, "from %s to %s", type, code,

View file

@ -69,7 +69,7 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
do { do {
char out[NET_IPV6_ADDR_LEN]; char out[NET_IPV6_ADDR_LEN];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(orig)->dst)); net_sprint_ipv6_addr(&NET_IPV6_BUF(orig)->dst));
NET_DBG("Received Echo Request from %s to %s", NET_DBG("Received Echo Request from %s to %s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(orig)->src), out); net_sprint_ipv6_addr(&NET_IPV6_BUF(orig)->src), out);
@ -142,7 +142,7 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
do { do {
char out[NET_IPV6_ADDR_LEN]; char out[NET_IPV6_ADDR_LEN];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst)); net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
NET_DBG("Sending Echo Reply from %s to %s", NET_DBG("Sending Echo Reply from %s to %s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out); net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out);
@ -260,7 +260,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
#if defined(CONFIG_NET_DEBUG_ICMPV6) #if defined(CONFIG_NET_DEBUG_ICMPV6)
do { do {
char out[NET_IPV6_ADDR_LEN]; char out[NET_IPV6_ADDR_LEN];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst)); net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
NET_DBG("Sending ICMPv6 Error Message type %d code %d param %d" NET_DBG("Sending ICMPv6 Error Message type %d code %d param %d"
" from %s to %s", type, code, param, " from %s to %s", type, code, param,
@ -323,7 +323,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
do { do {
char out[NET_IPV6_ADDR_LEN]; char out[NET_IPV6_ADDR_LEN];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst)); net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
NET_DBG("Sending ICMPv6 Echo Request type %d" NET_DBG("Sending ICMPv6 Echo Request type %d"
" from %s to %s", NET_ICMPV6_ECHO_REQUEST, " from %s to %s", NET_ICMPV6_ECHO_REQUEST,

View file

@ -422,8 +422,8 @@ static inline void dbg_update_neighbor_lladdr(struct net_linkaddr *new_lladdr,
{ {
char out[sizeof("xx:xx:xx:xx:xx:xx:xx:xx")]; char out[sizeof("xx:xx:xx:xx:xx:xx:xx:xx")];
snprintf(out, sizeof(out), net_sprint_ll_addr(old_lladdr->addr, snprintk(out, sizeof(out), "%s",
old_lladdr->len)); net_sprint_ll_addr(old_lladdr->addr, old_lladdr->len));
NET_DBG("Updating neighbor %s lladdr %s (was %s)", NET_DBG("Updating neighbor %s lladdr %s (was %s)",
net_sprint_ipv6_addr(addr), net_sprint_ipv6_addr(addr),
@ -727,7 +727,8 @@ static inline void handle_ns_neighbor(struct net_buf *buf,
do { \ do { \
char out[NET_IPV6_ADDR_LEN]; \ char out[NET_IPV6_ADDR_LEN]; \
\ \
snprintf(out, sizeof(out), net_sprint_ipv6_addr(dst)); \ snprintk(out, sizeof(out), "%s", \
net_sprint_ipv6_addr(dst)); \
\ \
NET_DBG("%s %s from %s to %s", action, \ NET_DBG("%s %s from %s to %s", action, \
pkt_str, net_sprint_ipv6_addr(src), out); \ pkt_str, net_sprint_ipv6_addr(src), out); \
@ -745,8 +746,10 @@ static inline void handle_ns_neighbor(struct net_buf *buf,
char out[NET_IPV6_ADDR_LEN]; \ char out[NET_IPV6_ADDR_LEN]; \
char tgt[NET_IPV6_ADDR_LEN]; \ char tgt[NET_IPV6_ADDR_LEN]; \
\ \
snprintf(out, sizeof(out), net_sprint_ipv6_addr(dst)); \ snprintk(out, sizeof(out), "%s", \
snprintf(tgt, sizeof(tgt), net_sprint_ipv6_addr(target)); \ net_sprint_ipv6_addr(dst)); \
snprintk(tgt, sizeof(tgt), "%s", \
net_sprint_ipv6_addr(target)); \
\ \
NET_DBG("%s %s from %s to %s, target %s", action, \ NET_DBG("%s %s from %s to %s, target %s", action, \
pkt_str, net_sprint_ipv6_addr(src), out, tgt); \ pkt_str, net_sprint_ipv6_addr(src), out, tgt); \

View file

@ -449,7 +449,7 @@ enum net_verdict net_arp_input(struct net_buf *buf)
#if defined(CONFIG_NET_DEBUG_ARP) #if defined(CONFIG_NET_DEBUG_ARP)
do { do {
char out[sizeof("xxx.xxx.xxx.xxx")]; char out[sizeof("xxx.xxx.xxx.xxx")];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&arp_hdr->src_ipaddr)); net_sprint_ipv4_addr(&arp_hdr->src_ipaddr));
NET_DBG("ARP request from %s [%s] for %s", NET_DBG("ARP request from %s [%s] for %s",
out, out,

View file

@ -36,7 +36,7 @@ const struct net_eth_addr *net_eth_broadcast_addr(void)
do { \ do { \
char out[sizeof("xx:xx:xx:xx:xx:xx")]; \ char out[sizeof("xx:xx:xx:xx:xx:xx")]; \
\ \
snprintf(out, sizeof(out), \ snprintk(out, sizeof(out), "%s", \
net_sprint_ll_addr(net_nbuf_ll_src(buf)->addr, \ net_sprint_ll_addr(net_nbuf_ll_src(buf)->addr, \
sizeof(struct net_eth_addr))); \ sizeof(struct net_eth_addr))); \
\ \

View file

@ -31,7 +31,7 @@
#if 0 #if 0
#include <stdio.h> #include <misc/printk.h>
static inline void hexdump(uint8_t *pkt, uint16_t length, uint8_t reserve) static inline void hexdump(uint8_t *pkt, uint16_t length, uint8_t reserve)
{ {
@ -40,25 +40,25 @@ static inline void hexdump(uint8_t *pkt, uint16_t length, uint8_t reserve)
for (i = 0; i < length;) { for (i = 0; i < length;) {
int j; int j;
printf("\t"); printk("\t");
for (j = 0; j < 10 && i < length; j++, i++) { for (j = 0; j < 10 && i < length; j++, i++) {
#if defined(CONFIG_SYS_LOG_SHOW_COLOR) #if defined(CONFIG_SYS_LOG_SHOW_COLOR)
if (i < reserve && reserve) { if (i < reserve && reserve) {
printf(SYS_LOG_COLOR_YELLOW); printk(SYS_LOG_COLOR_YELLOW);
} else { } else {
printf(SYS_LOG_COLOR_OFF); printk(SYS_LOG_COLOR_OFF);
} }
#endif #endif
printf("%02x ", *pkt++); printk("%02x ", *pkt++);
} }
#if defined(CONFIG_SYS_LOG_SHOW_COLOR) #if defined(CONFIG_SYS_LOG_SHOW_COLOR)
if (i < reserve) { if (i < reserve) {
printf(SYS_LOG_COLOR_OFF); printk(SYS_LOG_COLOR_OFF);
} }
#endif #endif
printf("\n"); printk("\n");
} }
} }
@ -67,7 +67,7 @@ static void pkt_hexdump(struct net_buf *buf, bool each_frag_reserve)
uint16_t reserve = each_frag_reserve ? net_nbuf_ll_reserve(buf) : 0; uint16_t reserve = each_frag_reserve ? net_nbuf_ll_reserve(buf) : 0;
struct net_buf *frag; struct net_buf *frag;
printf("IEEE 802.15.4 packet content:\n"); printk("IEEE 802.15.4 packet content:\n");
frag = buf->frags; frag = buf->frags;
while (frag) { while (frag) {

View file

@ -204,7 +204,8 @@ static inline enum net_verdict process_ipv6_pkt(struct net_buf *buf)
#if defined(CONFIG_NET_DEBUG_CORE) #if defined(CONFIG_NET_DEBUG_CORE)
do { do {
char out[NET_IPV6_ADDR_LEN]; char out[NET_IPV6_ADDR_LEN];
snprintf(out, sizeof(out), net_sprint_ipv6_addr(&hdr->dst)); snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&hdr->dst));
NET_DBG("IPv6 packet len %d received from %s to %s", NET_DBG("IPv6 packet len %d received from %s to %s",
real_len, net_sprint_ipv6_addr(&hdr->src), out); real_len, net_sprint_ipv6_addr(&hdr->src), out);
} while (0); } while (0);
@ -406,7 +407,8 @@ static inline enum net_verdict process_ipv4_pkt(struct net_buf *buf)
#if defined(CONFIG_NET_DEBUG_CORE) #if defined(CONFIG_NET_DEBUG_CORE)
do { do {
char out[sizeof("xxx.xxx.xxx.xxx")]; char out[sizeof("xxx.xxx.xxx.xxx")];
snprintf(out, sizeof(out), net_sprint_ipv4_addr(&hdr->dst)); snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&hdr->dst));
NET_DBG("IPv4 packet received from %s to %s", NET_DBG("IPv4 packet received from %s to %s",
net_sprint_ipv4_addr(&hdr->src), out); net_sprint_ipv4_addr(&hdr->src), out);
} while (0); } while (0);

View file

@ -11,7 +11,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <misc/printk.h>
#include <net/net_context.h> #include <net/net_context.h>
#include <net/nbuf.h> #include <net/nbuf.h>
@ -118,23 +118,23 @@ static inline void net_hexdump(const char *str, const uint8_t *packet,
while (length--) { while (length--) {
if (n % 16 == 0) { if (n % 16 == 0) {
printf("%s %08X ", str, n); printk("%s %08X ", str, n);
} }
printf("%02X ", *packet++); printk("%02X ", *packet++);
n++; n++;
if (n % 8 == 0) { if (n % 8 == 0) {
if (n % 16 == 0) { if (n % 16 == 0) {
printf("\n"); printk("\n");
} else { } else {
printf(" "); printk(" ");
} }
} }
} }
if (n % 16) { if (n % 16) {
printf("\n"); printk("\n");
} }
} }

View file

@ -243,7 +243,7 @@ static int nbr_nexthop_put(struct net_nbr *nbr)
\ \
NET_ASSERT_INFO(naddr, "Unknown nexthop address"); \ NET_ASSERT_INFO(naddr, "Unknown nexthop address"); \
\ \
snprintf(out, sizeof(out), \ snprintk(out, sizeof(out), "%s", \
net_sprint_ipv6_addr(dst)); \ net_sprint_ipv6_addr(dst)); \
NET_DBG("%s route to %s via %s (iface %p)", str, out, \ NET_DBG("%s route to %s via %s (iface %p)", str, out, \
net_sprint_ipv6_addr(naddr), route->iface); \ net_sprint_ipv6_addr(naddr), route->iface); \
@ -363,7 +363,7 @@ struct net_route_entry *net_route_add(struct net_if *iface,
struct in6_addr *tmp; struct in6_addr *tmp;
struct net_linkaddr_storage *llstorage; struct net_linkaddr_storage *llstorage;
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&route->addr)); net_sprint_ipv6_addr(&route->addr));
tmp = net_route_get_nexthop(route); tmp = net_route_get_nexthop(route);

View file

@ -121,7 +121,7 @@ net_rpl_of0_best_parent(struct net_if *iface,
do { do {
char out[NET_IPV6_ADDR_LEN]; char out[NET_IPV6_ADDR_LEN];
snprintf(out, sizeof(out), snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr( net_sprint_ipv6_addr(
net_rpl_get_parent_addr(iface, net_rpl_get_parent_addr(iface,
parent2))); parent2)));

View file

@ -210,7 +210,7 @@ NET_NBR_TABLE_INIT(NET_NBR_LOCAL, rpl_parents, net_rpl_neighbor_pool,
do { \ do { \
char out[NET_IPV6_ADDR_LEN]; \ char out[NET_IPV6_ADDR_LEN]; \
\ \
snprintf(out, sizeof(out), \ snprintk(out, sizeof(out), "%s", \
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst)); \ net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst)); \
NET_DBG("Received %s from %s to %s", req, \ NET_DBG("Received %s from %s to %s", req, \
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out); \ net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out); \
@ -221,8 +221,10 @@ NET_NBR_TABLE_INIT(NET_NBR_LOCAL, rpl_parents, net_rpl_neighbor_pool,
char out[NET_IPV6_ADDR_LEN]; \ char out[NET_IPV6_ADDR_LEN]; \
char prf[NET_IPV6_ADDR_LEN]; \ char prf[NET_IPV6_ADDR_LEN]; \
\ \
snprintf(out, sizeof(out), net_sprint_ipv6_addr(dst)); \ snprintk(out, sizeof(out), "%s", \
snprintf(prf, sizeof(prf), net_sprint_ipv6_addr(prefix)); \ net_sprint_ipv6_addr(dst)); \
snprintk(prf, sizeof(prf), "%s", \
net_sprint_ipv6_addr(prefix)); \
NET_DBG("Send DAO with prefix %s from %s to %s", \ NET_DBG("Send DAO with prefix %s from %s to %s", \
prf, net_sprint_ipv6_addr(src), out); \ prf, net_sprint_ipv6_addr(src), out); \
} while (0) } while (0)
@ -231,7 +233,8 @@ NET_NBR_TABLE_INIT(NET_NBR_LOCAL, rpl_parents, net_rpl_neighbor_pool,
do { \ do { \
char out[NET_IPV6_ADDR_LEN]; \ char out[NET_IPV6_ADDR_LEN]; \
\ \
snprintf(out, sizeof(out), net_sprint_ipv6_addr(dst)); \ snprintk(out, sizeof(out), "%s", \
net_sprint_ipv6_addr(dst)); \
NET_DBG("Send DAO-ACK (id %d, seq %d) from %s to %s", \ NET_DBG("Send DAO-ACK (id %d, seq %d) from %s to %s", \
id, seq, net_sprint_ipv6_addr(src), out); \ id, seq, net_sprint_ipv6_addr(src), out); \
} while (0) } while (0)
@ -384,7 +387,7 @@ static void net_rpl_print_neighbors(void)
do { \ do { \
char out[NET_IPV6_ADDR_LEN]; \ char out[NET_IPV6_ADDR_LEN]; \
\ \
snprintf(out, sizeof(out), \ snprintk(out, sizeof(out), "%s", \
net_sprint_ipv6_addr(addr)); \ net_sprint_ipv6_addr(addr)); \
NET_DBG("%s route to %s via %s (iface %p)", str, out, \ NET_DBG("%s route to %s via %s (iface %p)", str, out, \
net_sprint_ipv6_addr(nexthop), route->iface); \ net_sprint_ipv6_addr(nexthop), route->iface); \