Merge pull request #137 from simonduq/pr/logging-fixes

Minor logging fixes
This commit is contained in:
Simon Duquennoy 2017-10-31 22:04:46 +01:00 committed by GitHub
commit d9ae1118ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 20 deletions

View File

@ -50,9 +50,10 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#define DEBUG DEBUG_NONE
#include "net/ipv6/uip-debug.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Tun6"
#define LOG_LEVEL LOG_LEVEL_WARN
#ifdef linux
#include <linux/if.h>
@ -92,7 +93,7 @@ static ssystem(const char *fmt, ...)
va_start(ap, fmt);
vsnprintf(cmd, sizeof(cmd), fmt, ap);
va_end(ap);
printf("%s\n", cmd);
LOG_INFO("%s\n", cmd);
fflush(stdout);
return system(cmd);
}
@ -144,9 +145,9 @@ tun_alloc(char *dev)
{
struct ifreq ifr;
int fd, err;
PRINTF("Opening: %s\n", dev);
LOG_INFO("Opening: %s\n", dev);
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
PRINTF("Failed to open tun device\n");
/* Error message handled by caller */
return -1;
}
@ -160,14 +161,14 @@ tun_alloc(char *dev)
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
}
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
PRINTF("Failed to do ioctl on fd\n");
/* Error message handled by caller */
close(fd);
return err;
}
PRINTF("Using '%s' vs '%s'\n", dev, ifr.ifr_name);
LOG_INFO("Using '%s' vs '%s'\n", dev, ifr.ifr_name);
strncpy(dev, ifr.ifr_name, strlen(dev));
PRINTF("Using %s\n", dev);
LOG_INFO("Using %s\n", dev);
return fd;
}
#else
@ -183,7 +184,7 @@ devopen(const char *dev, int flags)
static int
tun_alloc(char *dev)
{
PRINTF("Opening: %s\n", dev);
LOG_INFO("Opening: %s\n", dev);
return devopen(dev, O_RDWR);
}
#endif
@ -205,16 +206,16 @@ tun_init()
{
setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */
PRINTF("Initializing tun interface\n");
LOG_INFO("Initializing tun interface\n");
tunfd = tun_alloc(config_tundev);
if(tunfd == -1) {
printf("Warning: failed to open tun device (you may be lacking permission). Running without network.\n");
LOG_WARN("Failed to open tun device (you may be lacking permission). Running without network.\n");
/* err(1, "failed to allocate tun device ``%s''", config_tundev); */
return;
}
PRINTF("Tun open:%d\n", tunfd);
LOG_INFO("Tun open:%d\n", tunfd);
select_set_callback(tunfd, &tun_select_callback);
@ -253,7 +254,7 @@ tun_input(unsigned char *data, int maxlen)
static uint8_t
output(const linkaddr_t *localdest)
{
PRINTF("SUT: %u\n", uip_len);
LOG_DBG("SUT: %u\n", uip_len);
if(uip_len > 0) {
return tun_output(&uip_buf[UIP_LLH_LEN], uip_len);
}
@ -277,11 +278,11 @@ handle_fd(fd_set *rset, fd_set *wset)
{
int size;
PRINTF("Tun6-handle FD\n");
LOG_INFO("Tun6-handle FD\n");
if(FD_ISSET(tunfd, rset)) {
size = tun_input(&uip_buf[UIP_LLH_LEN], sizeof(uip_buf));
PRINTF("TUN data incoming read:%d\n", size);
LOG_DBG("TUN data incoming read:%d\n", size);
uip_len = size;
tcpip_input();
}
@ -291,7 +292,7 @@ handle_fd(fd_set *rset, fd_set *wset)
static void input(void)
{
/* should not happen */
PRINTF("Tun6 - input\n");
LOG_DBG("Tun6 - input\n");
}

View File

@ -99,9 +99,14 @@ uip_ds6_init(void)
uip_ds6_neighbors_init();
uip_ds6_route_init();
LOG_INFO("Init: %u neighbors\n%u default routers\n%u prefixes\n%u routes\n%u unicast addresses\n%u multicast addresses\n%u anycast addresses\n",
NBR_TABLE_MAX_NEIGHBORS, UIP_DS6_DEFRT_NB, UIP_DS6_PREFIX_NB, UIP_DS6_ROUTE_NB,
UIP_DS6_ADDR_NB, UIP_DS6_MADDR_NB, UIP_DS6_AADDR_NB);
LOG_INFO("Init: %u neighbors\n", NBR_TABLE_MAX_NEIGHBORS);
LOG_INFO("%u default routers\n", UIP_DS6_DEFRT_NB);
LOG_INFO("%u prefixes\n", UIP_DS6_PREFIX_NB);
LOG_INFO("%u routes\n", UIP_DS6_ROUTE_NB);
LOG_INFO("%u unicast addresses\n", UIP_DS6_ADDR_NB);
LOG_INFO("%u multicast addresses\n", UIP_DS6_MADDR_NB);
LOG_INFO("%u anycast addresses\n", UIP_DS6_AADDR_NB);
memset(uip_ds6_prefix_list, 0, sizeof(uip_ds6_prefix_list));
memset(&uip_ds6_if, 0, sizeof(uip_ds6_if));
uip_ds6_addr_size = sizeof(struct uip_ds6_addr);