Use logging module for IPv6

This commit is contained in:
Simon Duquennoy 2017-06-20 17:23:49 +02:00
parent b9bd08c4a9
commit 9f0177570d
11 changed files with 416 additions and 396 deletions

53
core/net/ipv6/ipv6-log.h Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Default log levels for a number of modules
* \author
* Simon Duquennoy <simon.duquennoy@ri.se>
*/
/** \addtogroup uip6
* @{ */
#ifndef __IPV6_LOG_CONF_H__
#define __IPV6_LOG_CONF_H__
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6"
#define LOG_LEVEL IPV6_LOG_LEVEL
#endif /* __IPV6_LOG_CONF_H__ */
/** @} */

View File

@ -52,8 +52,10 @@
#include "net/packetbuf.h"
#include "net/ipv6/uip-ds6-nbr.h"
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 Neighbor"
#define LOG_LEVEL IPV6_LOG_LEVEL
#ifdef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED
#define NEIGHBOR_STATE_CHANGED(n) UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED(n)
@ -105,19 +107,19 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr,
stimer_set(&nbr->sendns, 0);
nbr->nscount = 0;
#endif /* UIP_ND6_SEND_NS */
PRINTF("Adding neighbor with ip addr ");
PRINT6ADDR(ipaddr);
PRINTF(" link addr ");
PRINTLLADDR(lladdr);
PRINTF(" state %u\n", state);
LOG_INFO("Adding neighbor with ip addr ");
LOG_INFO_6ADDR(ipaddr);
LOG_INFO(" link addr ");
LOG_INFO_LLADDR((linkaddr_t*)lladdr);
LOG_INFO(" state %u\n", state);
NEIGHBOR_STATE_CHANGED(nbr);
return nbr;
} else {
PRINTF("uip_ds6_nbr_add drop ip addr ");
PRINT6ADDR(ipaddr);
PRINTF(" link addr (%p) ", lladdr);
PRINTLLADDR(lladdr);
PRINTF(" state %u\n", state);
LOG_INFO("Add drop ip addr ");
LOG_INFO_6ADDR(ipaddr);
LOG_INFO(" link addr (%p) ", lladdr);
LOG_INFO_LLADDR((linkaddr_t*)lladdr);
LOG_INFO(" state %u\n", state);
return NULL;
}
}
@ -237,9 +239,9 @@ uip_ds6_link_neighbor_callback(int status, int numtx)
if(nbr != NULL && nbr->state != NBR_INCOMPLETE) {
nbr->state = NBR_REACHABLE;
stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000);
PRINTF("uip-ds6-neighbor : received a link layer ACK : ");
PRINTLLADDR((uip_lladdr_t *)dest);
PRINTF(" is reachable.\n");
LOG_INFO("received a link layer ACK : ");
LOG_INFO_LLADDR((uip_lladdr_t *)dest);
LOG_INFO(" is reachable.\n");
}
}
#endif /* UIP_DS6_LL_NUD */
@ -264,22 +266,22 @@ uip_ds6_neighbor_periodic(void)
mimics the 6LoWPAN-ND behavior.
*/
if(uip_ds6_defrt_lookup(&nbr->ipaddr) != NULL) {
PRINTF("REACHABLE: defrt moving to DELAY (");
PRINT6ADDR(&nbr->ipaddr);
PRINTF(")\n");
LOG_INFO("REACHABLE: defrt moving to DELAY (");
LOG_INFO_6ADDR(&nbr->ipaddr);
LOG_INFO(")\n");
nbr->state = NBR_DELAY;
stimer_set(&nbr->reachable, UIP_ND6_DELAY_FIRST_PROBE_TIME);
nbr->nscount = 0;
} else {
PRINTF("REACHABLE: moving to STALE (");
PRINT6ADDR(&nbr->ipaddr);
PRINTF(")\n");
LOG_INFO("REACHABLE: moving to STALE (");
LOG_INFO_6ADDR(&nbr->ipaddr);
LOG_INFO(")\n");
nbr->state = NBR_STALE;
}
#else /* UIP_CONF_IPV6_RPL */
PRINTF("REACHABLE: moving to STALE (");
PRINT6ADDR(&nbr->ipaddr);
PRINTF(")\n");
LOG_INFO("REACHABLE: moving to STALE (");
LOG_INFO_6ADDR(&nbr->ipaddr);
LOG_INFO(")\n");
nbr->state = NBR_STALE;
#endif /* UIP_CONF_IPV6_RPL */
}
@ -289,7 +291,7 @@ uip_ds6_neighbor_periodic(void)
uip_ds6_nbr_rm(nbr);
} else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
nbr->nscount++;
PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount);
LOG_INFO("NBR_INCOMPLETE: NS %u\n", nbr->nscount);
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
}
@ -298,14 +300,14 @@ uip_ds6_neighbor_periodic(void)
if(stimer_expired(&nbr->reachable)) {
nbr->state = NBR_PROBE;
nbr->nscount = 0;
PRINTF("DELAY: moving to PROBE\n");
LOG_INFO("DELAY: moving to PROBE\n");
stimer_set(&nbr->sendns, 0);
}
break;
case NBR_PROBE:
if(nbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
uip_ds6_defrt_t *locdefrt;
PRINTF("PROBE END\n");
LOG_INFO("PROBE END\n");
if((locdefrt = uip_ds6_defrt_lookup(&nbr->ipaddr)) != NULL) {
if (!locdefrt->isinfinite) {
uip_ds6_defrt_rm(locdefrt);
@ -314,7 +316,7 @@ uip_ds6_neighbor_periodic(void)
uip_ds6_nbr_rm(nbr);
} else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
nbr->nscount++;
PRINTF("PROBE: NS %u\n", nbr->nscount);
LOG_INFO("PROBE: NS %u\n", nbr->nscount);
uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr);
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
}

View File

@ -45,7 +45,10 @@
#include "lib/memb.h"
#include "net/nbr-table.h"
#include <string.h>
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 Route"
#define LOG_LEVEL IPV6_LOG_LEVEL
/* A configurable function called after adding a new neighbor as next hop */
#ifdef NETSTACK_CONF_ROUTING_NEIGHBOR_ADDED_CALLBACK
@ -86,12 +89,8 @@ MEMB(defaultroutermemb, uip_ds6_defrt_t, UIP_DS6_DEFRT_NB);
LIST(notificationlist);
#endif
#undef DEBUG
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
/*---------------------------------------------------------------------------*/
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
static void
assert_nbr_routes_list_sane(void)
{
@ -117,7 +116,7 @@ assert_nbr_routes_list_sane(void)
num_routes, count, UIP_CONF_MAX_ROUTES);
}
}
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
/*---------------------------------------------------------------------------*/
#if UIP_DS6_NOTIFICATIONS
static void
@ -258,9 +257,9 @@ uip_ds6_route_lookup(uip_ipaddr_t *addr)
uip_ds6_route_t *found_route;
uint8_t longestmatch;
PRINTF("uip-ds6-route: Looking up route for ");
PRINT6ADDR(addr);
PRINTF("\n");
LOG_INFO("Looking up route for ");
LOG_INFO_6ADDR(addr);
LOG_INFO("\n");
found_route = NULL;
@ -280,13 +279,13 @@ uip_ds6_route_lookup(uip_ipaddr_t *addr)
}
if(found_route != NULL) {
PRINTF("uip-ds6-route: Found route: ");
PRINT6ADDR(addr);
PRINTF(" via ");
PRINT6ADDR(uip_ds6_route_nexthop(found_route));
PRINTF("\n");
LOG_INFO("Found route: ");
LOG_INFO_6ADDR(addr);
LOG_INFO(" via ");
LOG_INFO_6ADDR(uip_ds6_route_nexthop(found_route));
LOG_INFO("\n");
} else {
PRINTF("uip-ds6-route: No route found\n");
LOG_WARN("No route found\n");
}
if(found_route != NULL && found_route != list_head(routelist)) {
@ -313,16 +312,16 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
uip_ds6_route_t *r;
struct uip_ds6_route_neighbor_route *nbrr;
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
/* Get link-layer address of next hop, make sure it is in neighbor table */
const uip_lladdr_t *nexthop_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(nexthop);
if(nexthop_lladdr == NULL) {
PRINTF("uip_ds6_route_add: neighbor link-local address unknown for ");
PRINT6ADDR(nexthop);
PRINTF("\n");
LOG_WARN("Add: neighbor link-local address unknown for ");
LOG_WARN_6ADDR(nexthop);
LOG_WARN("\n");
return NULL;
}
@ -337,9 +336,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
/* no need to update route - already correct! */
return r;
}
PRINTF("uip_ds6_route_add: old route for ");
PRINT6ADDR(ipaddr);
PRINTF(" found, deleting it\n");
LOG_INFO("Add: old route for ");
LOG_INFO_6ADDR(ipaddr);
LOG_INFO(" found, deleting it\n");
uip_ds6_route_rm(r);
}
@ -360,9 +359,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
if(oldest == NULL) {
return NULL;
}
PRINTF("uip_ds6_route_add: dropping route to ");
PRINT6ADDR(&oldest->ipaddr);
PRINTF("\n");
LOG_INFO("Add: dropping route to ");
LOG_INFO_6ADDR(&oldest->ipaddr);
LOG_INFO("\n");
uip_ds6_route_rm(oldest);
}
@ -390,7 +389,7 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
if(routes == NULL) {
/* This should not happen, as we explicitly deallocated one
route table entry above. */
PRINTF("uip_ds6_route_add: could not allocate neighbor table entry\n");
LOG_ERR("Add: could not allocate neighbor table entry\n");
return NULL;
}
LIST_STRUCT_INIT(routes, route_list);
@ -405,7 +404,7 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
if(r == NULL) {
/* This should not happen, as we explicitly deallocated one
route table entry above. */
PRINTF("uip_ds6_route_add: could not allocate route\n");
LOG_ERR("Add: could not allocate route\n");
return NULL;
}
@ -417,7 +416,7 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
if(nbrr == NULL) {
/* This should not happen, as we explicitly deallocated one
route table entry above. */
PRINTF("uip_ds6_route_add: could not allocate neighbor route list entry\n");
LOG_ERR("Add: could not allocate neighbor route list entry\n");
memb_free(&routememb, r);
return NULL;
}
@ -428,7 +427,7 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
r->neighbor_routes = routes;
num_routes++;
PRINTF("uip_ds6_route_add num %d\n", num_routes);
LOG_INFO("Add: num %d\n", num_routes);
/* lock this entry so that nexthop is not removed */
nbr_table_lock(nbr_routes, routes);
@ -441,20 +440,20 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
memset(&r->state, 0, sizeof(UIP_DS6_ROUTE_STATE_TYPE));
#endif
PRINTF("uip_ds6_route_add: adding route: ");
PRINT6ADDR(ipaddr);
PRINTF(" via ");
PRINT6ADDR(nexthop);
PRINTF("\n");
ANNOTATE("#L %u 1;blue\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
LOG_INFO("Add: adding route: ");
LOG_INFO_6ADDR(ipaddr);
LOG_INFO(" via ");
LOG_INFO_6ADDR(nexthop);
LOG_INFO("\n");
LOG_ANNOTATE("#L %u 1;blue\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop);
#endif
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
return r;
#else /* (UIP_CONF_MAX_ROUTES != 0) */
@ -468,14 +467,14 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
{
#if (UIP_CONF_MAX_ROUTES != 0)
struct uip_ds6_route_neighbor_route *neighbor_route;
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
if(route != NULL && route->neighbor_routes != NULL) {
PRINTF("uip_ds6_route_rm: removing route: ");
PRINT6ADDR(&route->ipaddr);
PRINTF("\n");
LOG_INFO("Rm: removing route: ");
LOG_INFO_6ADDR(&route->ipaddr);
LOG_INFO("\n");
/* Remove the route from the route list */
list_remove(routelist, route);
@ -486,21 +485,21 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
neighbor_route = list_item_next(neighbor_route));
if(neighbor_route == NULL) {
PRINTF("uip_ds6_route_rm: neighbor_route was NULL for ");
uip_debug_ipaddr_print(&route->ipaddr);
PRINTF("\n");
LOG_INFO("Rm: neighbor_route was NULL for ");
LOG_INFO_6ADDR(&route->ipaddr);
LOG_INFO("\n");
}
list_remove(route->neighbor_routes->route_list, neighbor_route);
if(list_head(route->neighbor_routes->route_list) == NULL) {
/* If this was the only route using this neighbor, remove the
neighbor from the table - this implicitly unlocks nexthop */
#if (DEBUG) & DEBUG_ANNOTATE
#if LOG_ANNOTATE_ENABLED
uip_ipaddr_t *nexthop = uip_ds6_route_nexthop(route);
if(nexthop != NULL) {
ANNOTATE("#L %u 0\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
LOG_ANNOTATE("#L %u 0\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
}
#endif /* (DEBUG) & DEBUG_ANNOTATE */
PRINTF("uip_ds6_route_rm: removing neighbor too\n");
#endif /* LOG_ANNOTATE_ENABLED */
LOG_INFO("Rm: removing neighbor too\n");
nbr_table_remove(nbr_routes, route->neighbor_routes->route_list);
#ifdef NETSTACK_CONF_ROUTING_NEIGHBOR_REMOVED_CALLBACK
NETSTACK_CONF_ROUTING_NEIGHBOR_REMOVED_CALLBACK(
@ -512,7 +511,7 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
num_routes--;
PRINTF("uip_ds6_route_rm num %d\n", num_routes);
LOG_INFO("Rm: num %d\n", num_routes);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM,
@ -520,9 +519,9 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
#endif
}
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
#endif /* (UIP_CONF_MAX_ROUTES != 0) */
return;
@ -532,10 +531,9 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
static void
rm_routelist(struct uip_ds6_route_neighbor_routes *routes)
{
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
PRINTF("uip_ds6_route_rm_routelist\n");
#endif /* LOG_DBG_ENABLED */
if(routes != NULL && routes->route_list != NULL) {
struct uip_ds6_route_neighbor_route *r;
r = list_head(routes->route_list);
@ -545,9 +543,9 @@ rm_routelist(struct uip_ds6_route_neighbor_routes *routes)
}
nbr_table_remove(nbr_routes, routes);
}
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
}
/*---------------------------------------------------------------------------*/
static void
@ -583,23 +581,23 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
{
uip_ds6_defrt_t *d;
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
PRINTF("uip_ds6_defrt_add\n");
LOG_INFO("Add default\n");
d = uip_ds6_defrt_lookup(ipaddr);
if(d == NULL) {
d = memb_alloc(&defaultroutermemb);
if(d == NULL) {
PRINTF("uip_ds6_defrt_add: could not add default route to ");
PRINT6ADDR(ipaddr);
PRINTF(", out of memory\n");
LOG_ERR("Add default: could not add default route to ");
LOG_ERR_6ADDR(ipaddr);
LOG_ERR(", out of memory\n");
return NULL;
} else {
PRINTF("uip_ds6_defrt_add: adding default route to ");
PRINT6ADDR(ipaddr);
PRINTF("\n");
LOG_INFO("Add default: adding default route to ");
LOG_INFO_6ADDR(ipaddr);
LOG_INFO("\n");
}
list_push(defaultrouterlist, d);
@ -613,15 +611,15 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
d->isinfinite = 1;
}
ANNOTATE("#L %u 1\n", ipaddr->u8[sizeof(uip_ipaddr_t) - 1]);
LOG_ANNOTATE("#L %u 1\n", ipaddr->u8[sizeof(uip_ipaddr_t) - 1]);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr);
#endif
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
return d;
}
@ -631,19 +629,19 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt)
{
uip_ds6_defrt_t *d;
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
/* Make sure that the defrt is in the list before we remove it. */
for(d = list_head(defaultrouterlist);
d != NULL;
d = list_item_next(d)) {
if(d == defrt) {
PRINTF("Removing default route\n");
LOG_INFO("Removing default\n");
list_remove(defaultrouterlist, defrt);
memb_free(&defaultroutermemb, defrt);
ANNOTATE("#L %u 0\n", defrt->ipaddr.u8[sizeof(uip_ipaddr_t) - 1]);
LOG_ANNOTATE("#L %u 0\n", defrt->ipaddr.u8[sizeof(uip_ipaddr_t) - 1]);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_RM,
&defrt->ipaddr, &defrt->ipaddr);
@ -651,9 +649,9 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt)
return;
}
}
#if DEBUG != DEBUG_NONE
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
#endif /* LOG_DBG_ENABLED */
}
/*---------------------------------------------------------------------------*/
@ -682,20 +680,20 @@ uip_ds6_defrt_choose(void)
for(d = list_head(defaultrouterlist);
d != NULL;
d = list_item_next(d)) {
PRINTF("Defrt, IP address ");
PRINT6ADDR(&d->ipaddr);
PRINTF("\n");
LOG_INFO("Default route, IP address ");
LOG_INFO_6ADDR(&d->ipaddr);
LOG_INFO("\n");
bestnbr = uip_ds6_nbr_lookup(&d->ipaddr);
if(bestnbr != NULL && bestnbr->state != NBR_INCOMPLETE) {
PRINTF("Defrt found, IP address ");
PRINT6ADDR(&d->ipaddr);
PRINTF("\n");
LOG_INFO("Default route found, IP address ");
LOG_INFO_6ADDR(&d->ipaddr);
LOG_INFO("\n");
return &d->ipaddr;
} else {
addr = &d->ipaddr;
PRINTF("Defrt INCOMPLETE found, IP address ");
PRINT6ADDR(&d->ipaddr);
PRINTF("\n");
LOG_INFO("Default route Incomplete found, IP address ");
LOG_INFO_6ADDR(&d->ipaddr);
LOG_INFO("\n");
}
}
return addr;
@ -709,7 +707,7 @@ uip_ds6_defrt_periodic(void)
while(d != NULL) {
if(!d->isinfinite &&
stimer_expired(&d->lifetime)) {
PRINTF("uip_ds6_defrt_periodic: defrt lifetime expired\n");
LOG_INFO("Default route periodic: defrt lifetime expired\n");
uip_ds6_defrt_rm(d);
d = list_head(defaultrouterlist);
} else {

View File

@ -51,8 +51,10 @@
#include "net/ipv6/multicast/uip-mcast6.h"
#include "net/ip/uip-packetqueue.h"
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 Data Structures"
#define LOG_LEVEL IPV6_LOG_LEVEL
struct etimer uip_ds6_timer_periodic; /**< Timer for maintenance of data structures */
@ -97,8 +99,7 @@ uip_ds6_init(void)
uip_ds6_neighbors_init();
uip_ds6_route_init();
PRINTF("Init of IPv6 data structures\n");
PRINTF("%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",
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);
memset(uip_ds6_prefix_list, 0, sizeof(uip_ds6_prefix_list));
@ -247,13 +248,13 @@ uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen,
locprefix->l_a_reserved = flags;
locprefix->vlifetime = vtime;
locprefix->plifetime = ptime;
PRINTF("Adding prefix ");
PRINT6ADDR(&locprefix->ipaddr);
PRINTF("length %u, flags %x, Valid lifetime %lx, Preffered lifetime %lx\n",
LOG_INFO("Adding prefix ");
LOG_INFO_6ADDR(&locprefix->ipaddr);
LOG_INFO("length %u, flags %x, Valid lifetime %lx, Preffered lifetime %lx\n",
ipaddrlen, flags, vtime, ptime);
return locprefix;
} else {
PRINTF("No more space in Prefix list\n");
LOG_INFO("No more space in Prefix list\n");
}
return NULL;
}
@ -277,9 +278,9 @@ uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen,
} else {
locprefix->isinfinite = 1;
}
PRINTF("Adding prefix ");
PRINT6ADDR(&locprefix->ipaddr);
PRINTF("length %u, vlifetime %lu\n", ipaddrlen, interval);
LOG_INFO("Adding prefix ");
LOG_INFO_6ADDR(&locprefix->ipaddr);
LOG_INFO("length %u, vlifetime %lu\n", ipaddrlen, interval);
return locprefix;
}
return NULL;
@ -613,9 +614,9 @@ uip_ds6_dad(uip_ds6_addr_t *addr)
* If we arrive here it means DAD succeeded, otherwise the dad process
* would have been interrupted in ds6_dad_ns/na_input
*/
PRINTF("DAD succeeded, ipaddr: ");
PRINT6ADDR(&addr->ipaddr);
PRINTF("\n");
LOG_INFO("DAD succeeded, ipaddr: ");
LOG_INFO_6ADDR(&addr->ipaddr);
LOG_INFO("\n");
addr->state = ADDR_PREFERRED;
return;
@ -630,7 +631,7 @@ int
uip_ds6_dad_failed(uip_ds6_addr_t *addr)
{
if(uip_is_addr_linklocal(&addr->ipaddr)) {
PRINTF("Contiki shutdown, DAD for link local address failed\n");
LOG_ERR("Contiki shutdown, DAD for link local address failed\n");
return 0;
}
uip_ds6_addr_rm(addr);
@ -651,7 +652,7 @@ uip_ds6_send_ra_sollicited(void)
* the RA (setting the timer to 0 below). We keep the code logic for
* the days contiki will support appropriate timers */
rand_time = 0;
PRINTF("Solicited RA, random time %u\n", rand_time);
LOG_INFO("Solicited RA, random time %u\n", rand_time);
if(stimer_remaining(&uip_ds6_timer_ra) > rand_time) {
if(stimer_elapsed(&uip_ds6_timer_ra) < UIP_ND6_MIN_DELAY_BETWEEN_RAS) {
@ -672,21 +673,21 @@ uip_ds6_send_ra_periodic(void)
if(racount > 0) {
/* send previously scheduled RA */
uip_nd6_ra_output(NULL);
PRINTF("Sending periodic RA\n");
LOG_INFO("Sending periodic RA\n");
}
rand_time = UIP_ND6_MIN_RA_INTERVAL + random_rand() %
(uint16_t) (UIP_ND6_MAX_RA_INTERVAL - UIP_ND6_MIN_RA_INTERVAL);
PRINTF("Random time 1 = %u\n", rand_time);
LOG_DBG("Random time 1 = %u\n", rand_time);
if(racount < UIP_ND6_MAX_INITIAL_RAS) {
if(rand_time > UIP_ND6_MAX_INITIAL_RA_INTERVAL) {
rand_time = UIP_ND6_MAX_INITIAL_RA_INTERVAL;
PRINTF("Random time 2 = %u\n", rand_time);
LOG_DBG("Random time 2 = %u\n", rand_time);
}
racount++;
}
PRINTF("Random time 3 = %u\n", rand_time);
LOG_DBG("Random time 3 = %u\n", rand_time);
stimer_set(&uip_ds6_timer_ra, rand_time);
}
@ -698,13 +699,13 @@ uip_ds6_send_rs(void)
{
if((uip_ds6_defrt_choose() == NULL)
&& (rscount < UIP_ND6_MAX_RTR_SOLICITATIONS)) {
PRINTF("Sending RS %u\n", rscount);
LOG_INFO("Sending RS %u\n", rscount);
uip_nd6_rs_output();
rscount++;
etimer_set(&uip_ds6_timer_rs,
UIP_ND6_RTR_SOLICITATION_INTERVAL * CLOCK_SECOND);
} else {
PRINTF("Router found ? (boolean): %u\n",
LOG_INFO("Router found ? (boolean): %u\n",
(uip_ds6_defrt_choose() != NULL));
etimer_stop(&uip_ds6_timer_rs);
}

View File

@ -47,16 +47,10 @@
#include "net/ipv6/uip-icmp6.h"
#include "contiki-default-conf.h"
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#endif
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 ICMPv6"
#define LOG_LEVEL IPV6_LOG_LEVEL
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
@ -125,11 +119,11 @@ echo_request_input(void)
* headers in the request otherwise we need to remove the extension
* headers and change a few fields
*/
PRINTF("Received Echo Request from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
LOG_INFO("Received Echo Request from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO("\n");
/* IP header */
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
@ -170,11 +164,11 @@ echo_request_input(void)
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
PRINTF("Sending Echo Reply to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("\n");
LOG_INFO("Sending Echo Reply to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO("\n");
UIP_STAT(++uip_stat.icmp.sent);
return;
}
@ -257,11 +251,11 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
UIP_STAT(++uip_stat.icmp.sent);
PRINTF("Sending ICMPv6 ERROR message type %d code %d to ", type, code);
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("\n");
LOG_WARN("Sending ICMPv6 ERROR message type %d code %d to ", type, code);
LOG_WARN_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_WARN(" from ");
LOG_WARN_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_WARN("\n");
return;
}
@ -301,11 +295,11 @@ echo_reply_input(void)
int ttl;
uip_ipaddr_t sender;
PRINTF("Received Echo Reply from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
LOG_INFO("Received Echo Reply from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO("\n");
uip_ipaddr_copy(&sender, &UIP_IP_BUF->srcipaddr);
ttl = UIP_IP_BUF->ttl;

View File

@ -75,18 +75,10 @@
#include "net/ip/uip-nameserver.h"
#include "lib/random.h"
/*------------------------------------------------------------------*/
#define DEBUG 0
#include "net/ip/uip-debug.h"
#if UIP_LOGGING
#include <stdio.h>
void uip_log(char *msg);
#define UIP_LOG(m) uip_log(m)
#else
#define UIP_LOG(m)
#endif /* UIP_LOGGING == 1 */
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 NDP"
#define LOG_LEVEL IPV6_LOG_LEVEL
/*------------------------------------------------------------------*/
/** @{ */
@ -186,20 +178,20 @@ static void
ns_input(void)
{
uint8_t flags;
PRINTF("Received NS from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" with target address ");
PRINT6ADDR((uip_ipaddr_t *) (&UIP_ND6_NS_BUF->tgtipaddr));
PRINTF("\n");
LOG_INFO("Received NS from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" with target address ");
LOG_INFO_6ADDR((uip_ipaddr_t *) (&UIP_ND6_NS_BUF->tgtipaddr));
LOG_INFO("\n");
UIP_STAT(++uip_stat.nd6.recv);
#if UIP_CONF_IPV6_CHECKS
if((UIP_IP_BUF->ttl != UIP_ND6_HOP_LIMIT) ||
(uip_is_addr_mcast(&UIP_ND6_NS_BUF->tgtipaddr)) ||
(UIP_ICMP_BUF->icode != 0)) {
PRINTF("NS received is bad\n");
LOG_ERR("NS received is bad\n");
goto discard;
}
#endif /* UIP_CONF_IPV6_CHECKS */
@ -210,7 +202,7 @@ ns_input(void)
while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) {
#if UIP_CONF_IPV6_CHECKS
if(UIP_ND6_OPT_HDR_BUF->len == 0) {
PRINTF("NS received is bad\n");
LOG_ERR("NS received is bad\n");
goto discard;
}
#endif /* UIP_CONF_IPV6_CHECKS */
@ -220,7 +212,7 @@ ns_input(void)
#if UIP_CONF_IPV6_CHECKS
/* There must be NO option in a DAD NS */
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
PRINTF("NS received is bad\n");
LOG_ERR("NS received is bad\n");
goto discard;
} else {
#endif /*UIP_CONF_IPV6_CHECKS */
@ -253,7 +245,7 @@ ns_input(void)
#endif /*UIP_CONF_IPV6_CHECKS */
break;
default:
PRINTF("ND option not supported in NS");
LOG_WARN("ND option not supported in NS");
break;
}
nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3);
@ -266,7 +258,7 @@ ns_input(void)
#if UIP_ND6_DEF_MAXDADNS > 0
#if UIP_CONF_IPV6_CHECKS
if(!uip_is_addr_solicited_node(&UIP_IP_BUF->destipaddr)) {
PRINTF("NS received is bad\n");
LOG_ERR("NS received is bad\n");
goto discard;
}
#endif /* UIP_CONF_IPV6_CHECKS */
@ -292,7 +284,7 @@ ns_input(void)
* NA in response of DAD NS we sent, hence DAD will fail anyway. If we
* were not doing DAD, it means there is a duplicate in the network!
*/
PRINTF("NS received is bad\n");
LOG_ERR("NS received is bad\n");
goto discard;
}
#endif /*UIP_CONF_IPV6_CHECKS */
@ -313,7 +305,7 @@ ns_input(void)
goto create_na;
} else {
#if UIP_CONF_IPV6_CHECKS
PRINTF("NS received is bad\n");
LOG_ERR("NS received is bad\n");
goto discard;
#endif /* UIP_CONF_IPV6_CHECKS */
}
@ -352,13 +344,13 @@ create_na:
UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN;
UIP_STAT(++uip_stat.nd6.sent);
PRINTF("Sending NA to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" with target address ");
PRINT6ADDR(&UIP_ND6_NA_BUF->tgtipaddr);
PRINTF("\n");
LOG_INFO("Sending NA to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" with target address ");
LOG_INFO_6ADDR(&UIP_ND6_NA_BUF->tgtipaddr);
LOG_INFO("\n");
return;
discard:
@ -401,7 +393,7 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
}
if (uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
PRINTF("Dropping NS due to no suitable source address\n");
LOG_ERR("Dropping NS due to no suitable source address\n");
uip_clear_buf();
return;
}
@ -423,13 +415,13 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
UIP_STAT(++uip_stat.nd6.sent);
PRINTF("Sending NS to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" with target address ");
PRINT6ADDR(tgt);
PRINTF("\n");
LOG_INFO("Sending NS to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" with target address ");
LOG_INFO_6ADDR(tgt);
LOG_INFO("\n");
return;
}
#endif /* UIP_ND6_SEND_NS */
@ -462,13 +454,13 @@ na_input(void)
uint8_t is_override;
uip_lladdr_t lladdr_aligned;
PRINTF("Received NA from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" with target address ");
PRINT6ADDR((uip_ipaddr_t *) (&UIP_ND6_NA_BUF->tgtipaddr));
PRINTF("\n");
LOG_INFO("Received NA from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" with target address ");
LOG_INFO_6ADDR((uip_ipaddr_t *) (&UIP_ND6_NA_BUF->tgtipaddr));
LOG_INFO("\n");
UIP_STAT(++uip_stat.nd6.recv);
/*
@ -487,7 +479,7 @@ na_input(void)
(UIP_ICMP_BUF->icode != 0) ||
(uip_is_addr_mcast(&UIP_ND6_NA_BUF->tgtipaddr)) ||
(is_solicited && uip_is_addr_mcast(&UIP_IP_BUF->destipaddr))) {
PRINTF("NA received is bad\n");
LOG_ERR("NA received is bad\n");
goto discard;
}
#endif /*UIP_CONF_IPV6_CHECKS */
@ -498,7 +490,7 @@ na_input(void)
while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) {
#if UIP_CONF_IPV6_CHECKS
if(UIP_ND6_OPT_HDR_BUF->len == 0) {
PRINTF("NA received is bad\n");
LOG_ERR("NA received is bad\n");
goto discard;
}
#endif /*UIP_CONF_IPV6_CHECKS */
@ -507,7 +499,7 @@ na_input(void)
nd6_opt_llao = (uint8_t *)UIP_ND6_OPT_HDR_BUF;
break;
default:
PRINTF("ND option not supported in NA\n");
LOG_WARN("ND option not supported in NA\n");
break;
}
nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3);
@ -520,7 +512,7 @@ na_input(void)
uip_ds6_dad_failed(addr);
}
#endif /*UIP_ND6_DEF_MAXDADNS > 0 */
PRINTF("NA received is bad\n");
LOG_ERR("NA received is bad\n");
goto discard;
} else {
const uip_lladdr_t *lladdr;
@ -618,11 +610,11 @@ static void
rs_input(void)
{
PRINTF("Received RS from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
LOG_INFO("Received RS from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO("\n");
UIP_STAT(++uip_stat.nd6.recv);
@ -633,7 +625,7 @@ rs_input(void)
* if the NA is solicited, dest must not be multicast
*/
if((UIP_IP_BUF->ttl != UIP_ND6_HOP_LIMIT) || (UIP_ICMP_BUF->icode != 0)) {
PRINTF("RS received is bad\n");
LOG_ERR("RS received is bad\n");
goto discard;
}
#endif /*UIP_CONF_IPV6_CHECKS */
@ -646,7 +638,7 @@ rs_input(void)
while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) {
#if UIP_CONF_IPV6_CHECKS
if(UIP_ND6_OPT_HDR_BUF->len == 0) {
PRINTF("RS received is bad\n");
LOG_ERR("RS received is bad\n");
goto discard;
}
#endif /*UIP_CONF_IPV6_CHECKS */
@ -655,7 +647,7 @@ rs_input(void)
nd6_opt_llao = (uint8_t *)UIP_ND6_OPT_HDR_BUF;
break;
default:
PRINTF("ND option not supported in RS\n");
LOG_WARN("ND option not supported in RS\n");
break;
}
nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3);
@ -664,7 +656,7 @@ rs_input(void)
if(nd6_opt_llao != NULL) {
#if UIP_CONF_IPV6_CHECKS
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
PRINTF("RS received is bad\n");
LOG_ERR("RS received is bad\n");
goto discard;
} else {
#endif /*UIP_CONF_IPV6_CHECKS */
@ -792,7 +784,7 @@ uip_nd6_ra_output(uip_ipaddr_t * dest)
i++;
}
UIP_ND6_OPT_RDNSS_BUF->len = UIP_ND6_OPT_RDNSS_LEN + (i << 1);
PRINTF("%d nameservers reported\n", i);
LOG_INFO("%d nameservers reported\n", i);
uip_len += UIP_ND6_OPT_RDNSS_BUF->len << 3;
nd6_opt_offset += UIP_ND6_OPT_RDNSS_BUF->len << 3;
}
@ -806,11 +798,11 @@ uip_nd6_ra_output(uip_ipaddr_t * dest)
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
UIP_STAT(++uip_stat.nd6.sent);
PRINTF("Sending RA to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("\n");
LOG_INFO("Sending RA to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO("\n");
return;
}
#endif /* UIP_ND6_SEND_RA */
@ -848,11 +840,11 @@ uip_nd6_rs_output(void)
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
UIP_STAT(++uip_stat.nd6.sent);
PRINTF("Sendin RS to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("\n");
LOG_INFO("Sending RS to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO("\n");
return;
}
/*---------------------------------------------------------------------------*/
@ -870,25 +862,25 @@ ra_input(void)
{
uip_lladdr_t lladdr_aligned;
PRINTF("Received RA from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
LOG_INFO("Received RA from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO("\n");
UIP_STAT(++uip_stat.nd6.recv);
#if UIP_CONF_IPV6_CHECKS
if((UIP_IP_BUF->ttl != UIP_ND6_HOP_LIMIT) ||
(!uip_is_addr_linklocal(&UIP_IP_BUF->srcipaddr)) ||
(UIP_ICMP_BUF->icode != 0)) {
PRINTF("RA received is bad");
LOG_ERR("RA received is bad");
goto discard;
}
#endif /*UIP_CONF_IPV6_CHECKS */
if(UIP_ND6_RA_BUF->cur_ttl != 0) {
uip_ds6_if.cur_hop_limit = UIP_ND6_RA_BUF->cur_ttl;
PRINTF("uip_ds6_if.cur_hop_limit %u\n", uip_ds6_if.cur_hop_limit);
LOG_INFO("uip_ds6_if.cur_hop_limit %u\n", uip_ds6_if.cur_hop_limit);
}
if(UIP_ND6_RA_BUF->reachable_time != 0) {
@ -906,12 +898,12 @@ ra_input(void)
nd6_opt_offset = UIP_ND6_RA_LEN;
while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) {
if(UIP_ND6_OPT_HDR_BUF->len == 0) {
PRINTF("RA received is bad");
LOG_ERR("RA received is bad");
goto discard;
}
switch (UIP_ND6_OPT_HDR_BUF->type) {
case UIP_ND6_OPT_SLLAO:
PRINTF("Processing SLLAO option in RA\n");
LOG_DBG("Processing SLLAO option in RA\n");
nd6_opt_llao = (uint8_t *) UIP_ND6_OPT_HDR_BUF;
nbr = uip_ds6_nbr_lookup(&UIP_IP_BUF->srcipaddr);
if(!extract_lladdr_from_llao_aligned(&lladdr_aligned)) {
@ -942,12 +934,12 @@ ra_input(void)
}
break;
case UIP_ND6_OPT_MTU:
PRINTF("Processing MTU option in RA\n");
LOG_DBG("Processing MTU option in RA\n");
uip_ds6_if.link_mtu =
uip_ntohl(((uip_nd6_opt_mtu *) UIP_ND6_OPT_HDR_BUF)->mtu);
break;
case UIP_ND6_OPT_PREFIX_INFO:
PRINTF("Processing PREFIX option in RA\n");
LOG_DBG("Processing PREFIX option in RA\n");
nd6_opt_prefix_info = (uip_nd6_opt_prefix_info *) UIP_ND6_OPT_HDR_BUF;
if((uip_ntohl(nd6_opt_prefix_info->validlt) >=
uip_ntohl(nd6_opt_prefix_info->preferredlt))
@ -978,9 +970,9 @@ ra_input(void)
prefix->isinfinite = 1;
break;
default:
PRINTF("Updating timer of prefix ");
PRINT6ADDR(&prefix->ipaddr);
PRINTF(" new value %lu\n", uip_ntohl(nd6_opt_prefix_info->validlt));
LOG_DBG("Updating timer of prefix ");
LOG_DBG_6ADDR(&prefix->ipaddr);
LOG_DBG(" new value %lu\n", uip_ntohl(nd6_opt_prefix_info->validlt));
stimer_set(&prefix->vlifetime,
uip_ntohl(nd6_opt_prefix_info->validlt));
prefix->isinfinite = 0;
@ -1003,17 +995,17 @@ ra_input(void)
if((uip_ntohl(nd6_opt_prefix_info->validlt) > 2 * 60 * 60) ||
(uip_ntohl(nd6_opt_prefix_info->validlt) >
stimer_remaining(&addr->vlifetime))) {
PRINTF("Updating timer of address ");
PRINT6ADDR(&addr->ipaddr);
PRINTF(" new value %lu\n",
LOG_DBG("Updating timer of address ");
LOG_DBG_6ADDR(&addr->ipaddr);
LOG_DBG(" new value %lu\n",
uip_ntohl(nd6_opt_prefix_info->validlt));
stimer_set(&addr->vlifetime,
uip_ntohl(nd6_opt_prefix_info->validlt));
} else {
stimer_set(&addr->vlifetime, 2 * 60 * 60);
PRINTF("Updating timer of address ");
PRINT6ADDR(&addr->ipaddr);
PRINTF(" new value %lu\n", (unsigned long)(2 * 60 * 60));
LOG_DBG("Updating timer of address ");
LOG_DBG_6ADDR(&addr->ipaddr);
LOG_DBG(" new value %lu\n", (unsigned long)(2 * 60 * 60));
}
addr->isinfinite = 0;
} else {
@ -1035,14 +1027,14 @@ ra_input(void)
#if UIP_ND6_RA_RDNSS
case UIP_ND6_OPT_RDNSS:
if(UIP_ND6_RA_BUF->flags_reserved & (UIP_ND6_O_FLAG << 6)) {
PRINTF("Processing RDNSS option\n");
LOG_DBG("Processing RDNSS option\n");
uint8_t naddr = (UIP_ND6_OPT_RDNSS_BUF->len - 1) / 2;
uip_ipaddr_t *ip = (uip_ipaddr_t *)(&UIP_ND6_OPT_RDNSS_BUF->ip);
PRINTF("got %d nameservers\n", naddr);
LOG_DBG("got %d nameservers\n", naddr);
while(naddr-- > 0) {
PRINTF(" nameserver: ");
PRINT6ADDR(ip);
PRINTF(" lifetime: %lx\n", uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime));
LOG_DBG(" nameserver: ");
LOG_DBG_6ADDR(ip);
LOG_DBG(" lifetime: %lx\n", uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime));
uip_nameserver_update(ip, uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime));
ip++;
}
@ -1050,7 +1042,7 @@ ra_input(void)
break;
#endif /* UIP_ND6_RA_RDNSS */
default:
PRINTF("ND option not supported in RA");
LOG_ERR("ND option not supported in RA");
break;
}
nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3);

View File

@ -89,27 +89,10 @@
#include "net/ipv6/uip-ds6-nbr.h"
#endif /* UIP_ND6_SEND_NS */
#include <string.h>
/*---------------------------------------------------------------------------*/
/* For Debug, logging, statistics */
/*---------------------------------------------------------------------------*/
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
#if UIP_LOGGING == 1
#include <stdio.h>
void uip_log(char *msg);
#define UIP_LOG(m) uip_log(m)
#else
#define UIP_LOG(m)
#endif /* UIP_LOGGING == 1 */
#if UIP_STATISTICS == 1
struct uip_stats uip_stat;
#endif /* UIP_STATISTICS == 1 */
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6"
#define LOG_LEVEL IPV6_LOG_LEVEL
/*---------------------------------------------------------------------------*/
/**
@ -366,7 +349,7 @@ uip_ipchksum(void)
uint16_t sum;
sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
LOG_DBG("uip_ipchksum: sum 0x%04x\n", sum);
return (sum == 0) ? 0xffff : uip_htons(sum);
}
#endif
@ -388,7 +371,7 @@ upper_layer_chksum(uint8_t proto)
upper_layer_len = (((uint16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1] - uip_ext_len);
PRINTF("Upper layer checksum len: %d from: %d\n", upper_layer_len,
LOG_DBG("Upper layer checksum len: %d from: %d\n", upper_layer_len,
UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len);
/* First sum pseudoheader. */
@ -538,10 +521,10 @@ remove_ext_hdr(void)
{
/* Remove ext header before TCP/UDP processing. */
if(uip_ext_len > 0) {
PRINTF("Cutting ext-header before processing (extlen: %d, uiplen: %d)\n",
LOG_DBG("Cutting ext-header before processing (extlen: %d, uiplen: %d)\n",
uip_ext_len, uip_len);
if(uip_len < UIP_IPH_LEN + uip_ext_len) {
PRINTF("ERROR: uip_len too short compared to ext len\n");
LOG_ERR("ERROR: uip_len too short compared to ext len\n");
uip_clear_buf();
return;
}
@ -677,7 +660,7 @@ uip_reass(void)
/* We first write the unfragmentable part of IP header into the reassembly
buffer. The reset the other reassembly variables. */
if(uip_reass_on == 0) {
PRINTF("Starting reassembly\n");
LOG_INFO("Starting reassembly\n");
memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN);
/* temporary in case we do not receive the fragment with offset 0 first */
etimer_set(&uip_reass_timer, UIP_REASS_MAXAGE*CLOCK_SECOND);
@ -698,8 +681,8 @@ uip_reass(void)
len = uip_len - uip_ext_len - UIP_IPH_LEN - UIP_FRAGH_LEN;
offset = (uip_ntohs(UIP_FRAG_BUF->offsetresmore) & 0xfff8);
/* in byte, originaly in multiple of 8 bytes*/
PRINTF("len %d\n", len);
PRINTF("offset %d\n", offset);
LOG_INFO("len %d\n", len);
LOG_INFO("offset %d\n", offset);
if(offset == 0){
uip_reassflags |= UIP_REASS_FLAG_FIRSTFRAG;
/*
@ -709,11 +692,11 @@ uip_reass(void)
*/
*uip_next_hdr = UIP_FRAG_BUF->next;
memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN);
PRINTF("src ");
PRINT6ADDR(&FBUF->srcipaddr);
PRINTF("dest ");
PRINT6ADDR(&FBUF->destipaddr);
PRINTF("next %d\n", UIP_IP_BUF->proto);
LOG_INFO("src ");
LOG_INFO_6ADDR(&FBUF->srcipaddr);
LOG_INFO("dest ");
LOG_INFO_6ADDR(&FBUF->destipaddr);
LOG_INFO("next %d\n", UIP_IP_BUF->proto);
}
@ -732,7 +715,7 @@ uip_reass(void)
uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
/*calculate the size of the entire packet*/
uip_reasslen = offset + len;
PRINTF("LAST FRAGMENT reasslen %d\n", uip_reasslen);
LOG_INFO("last fragment reasslen %d\n", uip_reasslen);
} else {
/* If len is not a multiple of 8 octets and the M flag of that fragment
is 1, then that fragment must be discarded and an ICMP Parameter
@ -800,14 +783,14 @@ uip_reass(void)
memcpy(UIP_IP_BUF, FBUF, uip_reasslen);
UIP_IP_BUF->len[0] = ((uip_reasslen - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_reasslen - UIP_IPH_LEN) & 0xff);
PRINTF("REASSEMBLED PAQUET %d (%d)\n", uip_reasslen,
LOG_INFO("reassembled packet %d (%d)\n", uip_reasslen,
(UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]);
return uip_reasslen;
}
} else {
PRINTF("Already reassembling another paquet\n");
LOG_WARN("Already reassembling another paquet\n");
}
return 0;
}
@ -821,7 +804,7 @@ uip_reass_over(void)
etimer_stop(&uip_reass_timer);
if(uip_reassflags & UIP_REASS_FLAG_FIRSTFRAG){
PRINTF("FRAG INTERRUPTED TOO LATE\n");
LOG_ERR("fragmentation timeout\n");
/* If the first fragment has been received, an ICMP Time Exceeded
-- Fragment Reassembly Time Exceeded message should be sent to the
source of that fragment. */
@ -877,11 +860,11 @@ ext_hdr_options_process(void)
* hence we can only have
*/
case UIP_EXT_HDR_OPT_PAD1:
PRINTF("Processing PAD1 option\n");
LOG_DBG("Processing PAD1 option\n");
uip_ext_opt_offset += 1;
break;
case UIP_EXT_HDR_OPT_PADN:
PRINTF("Processing PADN option\n");
LOG_DBG("Processing PADN option\n");
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2;
break;
case UIP_EXT_HDR_OPT_RPL:
@ -894,9 +877,9 @@ ext_hdr_options_process(void)
* present) is processed.
*/
#if UIP_CONF_IPV6_RPL
PRINTF("Processing RPL option\n");
LOG_DBG("Processing RPL option\n");
if(!rpl_verify_hbh_header(uip_ext_opt_offset)) {
PRINTF("RPL Option Error: Dropping Packet\n");
LOG_ERR("RPL Option Error: Dropping Packet\n");
return 1;
}
#endif /* UIP_CONF_IPV6_RPL */
@ -916,7 +899,7 @@ ext_hdr_options_process(void)
* Problem, Code 2, message to the packet's Source Address,
* pointing to the unrecognized Option Type.
*/
PRINTF("MSB %x\n", UIP_EXT_HDR_OPT_BUF->type);
LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF->type);
switch(UIP_EXT_HDR_OPT_BUF->type & 0xC0) {
case 0:
break;
@ -1113,7 +1096,7 @@ uip_process(uint8_t flag)
if((UIP_IP_BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.vhlerr);
UIP_LOG("ipv6: invalid version.");
LOG_ERR("invalid version.");
goto drop;
}
/*
@ -1139,19 +1122,19 @@ uip_process(uint8_t flag)
* header (40 bytes).
*/
} else {
UIP_LOG("ip: packet shorter than reported in IP header.");
LOG_ERR("packet shorter than reported in IP header.");
goto drop;
}
PRINTF("IPv6 packet received from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
LOG_INFO("packet received from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO(" to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO("\n");
if(uip_is_addr_mcast(&UIP_IP_BUF->srcipaddr)){
UIP_STAT(++uip_stat.ip.drop);
PRINTF("Dropping packet, src is mcast\n");
LOG_ERR("Dropping packet, src is mcast\n");
goto drop;
}
@ -1182,11 +1165,11 @@ uip_process(uint8_t flag)
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
break;
case 1:
PRINTF("Dropping packet after extension header processing\n");
LOG_ERR("Dropping packet after extension header processing\n");
/* silently discard */
goto drop;
case 2:
PRINTF("Sending error message after extension header processing\n");
LOG_ERR("Sending error message after extension header processing\n");
/* send icmp error message (created in ext_hdr_options_process)
* and discard*/
goto send;
@ -1241,9 +1224,9 @@ uip_process(uint8_t flag)
}
UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1;
PRINTF("Forwarding packet to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
LOG_INFO("Forwarding packet to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO("\n");
UIP_STAT(++uip_stat.ip.forwarded);
goto send;
} else {
@ -1252,12 +1235,12 @@ uip_process(uint8_t flag)
(!uip_is_addr_loopback(&UIP_IP_BUF->destipaddr)) &&
(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) &&
(!uip_ds6_is_addr_onlink((&UIP_IP_BUF->destipaddr)))) {
PRINTF("LL source address with off link destination, dropping\n");
LOG_ERR("LL source address with off link destination, dropping\n");
uip_icmp6_error_output(ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_NOTNEIGHBOR, 0);
goto send;
}
PRINTF("Dropping packet, not for me and link local or multicast\n");
LOG_ERR("Dropping packet, not for me and link local or multicast\n");
UIP_STAT(++uip_stat.ip.drop);
goto drop;
}
@ -1266,7 +1249,7 @@ uip_process(uint8_t flag)
if(!uip_ds6_is_my_addr(&UIP_IP_BUF->destipaddr) &&
!uip_ds6_is_my_maddr(&UIP_IP_BUF->destipaddr) &&
!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
PRINTF("Dropping packet, not for me\n");
LOG_ERR("Dropping packet, not for me\n");
UIP_STAT(++uip_stat.ip.drop);
goto drop;
}
@ -1300,7 +1283,7 @@ uip_process(uint8_t flag)
/* ICMPv6 */
goto icmp6_input;
case UIP_PROTO_HBHO:
PRINTF("Processing hbh header\n");
LOG_DBG("Processing hbh header\n");
/* Hop by hop option header */
#if UIP_CONF_IPV6_CHECKS
/* Hop by hop option header. If we saw one HBH already, drop */
@ -1328,7 +1311,7 @@ uip_process(uint8_t flag)
case UIP_PROTO_DESTO:
#if UIP_CONF_IPV6_CHECKS
/* Destination option header. if we saw two already, drop */
PRINTF("Processing desto header\n");
LOG_DBG("Processing desto header\n");
if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO1) {
if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO2) {
goto bad_hdr;
@ -1371,7 +1354,7 @@ uip_process(uint8_t flag)
* to the routing type
*/
PRINTF("Processing Routing header\n");
LOG_DBG("Processing Routing header\n");
if(UIP_ROUTING_BUF->seg_left > 0) {
#if UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING
if(rpl_process_srh_header()) {
@ -1380,7 +1363,7 @@ uip_process(uint8_t flag)
#endif /* UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING */
uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, UIP_IPH_LEN + uip_ext_len + 2);
UIP_STAT(++uip_stat.ip.drop);
UIP_LOG("ip6: unrecognized routing type");
LOG_ERR("unrecognized routing type");
goto send;
}
uip_next_hdr = &UIP_EXT_BUF->next;
@ -1389,7 +1372,7 @@ uip_process(uint8_t flag)
case UIP_PROTO_FRAG:
/* Fragmentation header:call the reassembly function, then leave */
#if UIP_CONF_IPV6_REASSEMBLY
PRINTF("Processing frag header\n");
LOG_INFO("Processing fragmentation header\n");
uip_len = uip_reass();
if(uip_len == 0) {
goto drop;
@ -1400,7 +1383,7 @@ uip_process(uint8_t flag)
}
/*packet is reassembled, reset the next hdr to the beginning
of the IP header and restart the parsing of the reassembled pkt*/
PRINTF("Processing reassembled packet\n");
LOG_INFO("Processing reassembled packet\n");
uip_ext_len = 0;
uip_ext_bitmap = 0;
uip_next_hdr = &UIP_IP_BUF->proto;
@ -1408,7 +1391,7 @@ uip_process(uint8_t flag)
#else /* UIP_CONF_IPV6_REASSEMBLY */
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.fragerr);
UIP_LOG("ip: fragment dropped.");
LOG_ERR("fragment dropped.");
goto drop;
#endif /* UIP_CONF_IPV6_REASSEMBLY */
case UIP_PROTO_NONE:
@ -1425,21 +1408,20 @@ uip_process(uint8_t flag)
uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER, (uint32_t)(uip_next_hdr - (uint8_t *)UIP_IP_BUF));
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.protoerr);
UIP_LOG("ip6: unrecognized header");
LOG_ERR("unrecognized header");
goto send;
/* End of headers processing */
icmp6_input:
/* This is IPv6 ICMPv6 processing code. */
PRINTF("icmp6_input: length %d type: %d \n", uip_len, UIP_ICMP_BUF->type);
LOG_INFO("icmp6: input length %d type: %d \n", uip_len, UIP_ICMP_BUF->type);
#if UIP_CONF_IPV6_CHECKS
/* Compute and check the ICMP header checksum */
if(uip_icmp6chksum() != 0xffff) {
UIP_STAT(++uip_stat.icmp.drop);
UIP_STAT(++uip_stat.icmp.chkerr);
UIP_LOG("icmpv6: bad checksum.");
PRINTF("icmpv6: bad checksum.\n");
LOG_ERR("icmpv6: bad checksum.");
goto drop;
}
#endif /*UIP_CONF_IPV6_CHECKS*/
@ -1464,10 +1446,10 @@ uip_process(uint8_t flag)
*/
if(uip_icmp6_input(UIP_ICMP_BUF->type,
UIP_ICMP_BUF->icode) == UIP_ICMP6_INPUT_ERROR) {
PRINTF("Unknown ICMPv6 message type/code %d\n", UIP_ICMP_BUF->type);
LOG_ERR("Unknown ICMPv6 message type/code %d\n", UIP_ICMP_BUF->type);
UIP_STAT(++uip_stat.icmp.drop);
UIP_STAT(++uip_stat.icmp.typeerr);
UIP_LOG("icmp6: unknown ICMPv6 message.");
LOG_ERR("icmp6: unknown ICMPv6 message.");
uip_clear_buf();
}
@ -1486,7 +1468,7 @@ uip_process(uint8_t flag)
remove_ext_hdr();
UIP_IP_BUF->proto = UIP_PROTO_UDP;
PRINTF("Receiving UDP packet\n");
LOG_INFO("Receiving UDP packet\n");
/* UDP processing is really just a hack. We don't do anything to the
UDP/IP headers, but let the UDP application do all the hard
@ -1501,7 +1483,7 @@ uip_process(uint8_t flag)
if(UIP_UDP_BUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
UIP_STAT(++uip_stat.udp.drop);
UIP_STAT(++uip_stat.udp.chkerr);
PRINTF("udp: bad checksum 0x%04x 0x%04x\n", UIP_UDP_BUF->udpchksum,
LOG_ERR("udp: bad checksum 0x%04x 0x%04x\n", UIP_UDP_BUF->udpchksum,
uip_udpchksum());
goto drop;
}
@ -1509,7 +1491,7 @@ uip_process(uint8_t flag)
/* Make sure that the UDP destination port number is not zero. */
if(UIP_UDP_BUF->destport == 0) {
PRINTF("udp: zero port.\n");
LOG_ERR("udp: zero port.\n");
goto drop;
}
@ -1533,14 +1515,14 @@ uip_process(uint8_t flag)
goto udp_found;
}
}
PRINTF("udp: no matching connection found\n");
LOG_ERR("udp: no matching connection found\n");
UIP_STAT(++uip_stat.udp.drop);
uip_icmp6_error_output(ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
goto send;
udp_found:
PRINTF("In udp_found\n");
LOG_DBG("In udp_found\n");
UIP_STAT(++uip_stat.udp.recv);
uip_len = uip_len - UIP_IPUDPH_LEN;
@ -1552,7 +1534,7 @@ uip_process(uint8_t flag)
UIP_UDP_APPCALL();
udp_send:
PRINTF("In udp_send\n");
LOG_DBG("In udp_send\n");
if(uip_slen == 0) {
goto drop;
@ -1598,21 +1580,21 @@ uip_process(uint8_t flag)
UIP_IP_BUF->proto = UIP_PROTO_TCP;
UIP_STAT(++uip_stat.tcp.recv);
PRINTF("Receiving TCP packet\n");
LOG_INFO("Receiving TCP packet\n");
/* Start of TCP input header processing code. */
if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
checksum. */
UIP_STAT(++uip_stat.tcp.drop);
UIP_STAT(++uip_stat.tcp.chkerr);
PRINTF("tcp: bad checksum 0x%04x 0x%04x\n", UIP_TCP_BUF->tcpchksum,
LOG_ERR("tcp: bad checksum 0x%04x 0x%04x\n", UIP_TCP_BUF->tcpchksum,
uip_tcpchksum());
goto drop;
}
/* Make sure that the TCP port number is not zero. */
if(UIP_TCP_BUF->destport == 0 || UIP_TCP_BUF->srcport == 0) {
PRINTF("tcp: zero port.");
LOG_ERR("tcp: zero port.");
goto drop;
}
@ -1648,7 +1630,7 @@ uip_process(uint8_t flag)
UIP_STAT(++uip_stat.tcp.synrst);
reset:
PRINTF("In reset\n");
LOG_WARN("In reset\n");
/* We do not send resets in response to resets. */
if(UIP_TCP_BUF->flags & TCP_RST) {
goto drop;
@ -1703,7 +1685,7 @@ uip_process(uint8_t flag)
with a connection in LISTEN. In that case, we should create a new
connection and send a SYNACK in return. */
found_listen:
PRINTF("In found listen\n");
LOG_DBG("In found listen\n");
/* First we check if there are any connections avaliable. Unused
connections are kept in the same table as used connections, but
unused ones have the tcpstate set to CLOSED. Also, connections in
@ -1729,7 +1711,7 @@ uip_process(uint8_t flag)
the remote end will retransmit the packet at a time when we
have more spare connections. */
UIP_STAT(++uip_stat.tcp.syndrop);
UIP_LOG("tcp: found no unused connections.");
LOG_ERR("tcp: found no unused connections.");
goto drop;
}
uip_conn = uip_connr;
@ -1814,7 +1796,7 @@ uip_process(uint8_t flag)
/* This label will be jumped to if we found an active connection. */
found:
PRINTF("In found\n");
LOG_DBG("In found\n");
uip_conn = uip_connr;
uip_flags = 0;
/* We do a very naive form of TCP reset processing; we just accept
@ -1823,7 +1805,7 @@ uip_process(uint8_t flag)
before we accept the reset. */
if(UIP_TCP_BUF->flags & TCP_RST) {
uip_connr->tcpstateflags = UIP_CLOSED;
UIP_LOG("tcp: got reset, aborting connection.");
LOG_WARN("tcp: got reset, aborting connection.");
uip_flags = UIP_ABORT;
UIP_APPCALL();
goto drop;
@ -2253,7 +2235,7 @@ uip_process(uint8_t flag)
headers before calculating the checksum and finally send the
packet. */
tcp_send:
PRINTF("In tcp_send\n");
LOG_DBG("In tcp_send\n");
UIP_TCP_BUF->ackno[0] = uip_connr->rcv_nxt[0];
UIP_TCP_BUF->ackno[1] = uip_connr->rcv_nxt[1];
@ -2270,11 +2252,11 @@ uip_process(uint8_t flag)
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &uip_connr->ripaddr);
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
PRINTF("Sending TCP packet to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("\n");
LOG_INFO("Sending TCP packet to ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO(" from ");
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
LOG_INFO("\n");
if(uip_connr->tcpstateflags & UIP_STOPPED) {
/* If the connection has issued uip_stop(), we advertise a zero
@ -2307,7 +2289,7 @@ uip_process(uint8_t flag)
UIP_IP_BUF->tcflow = 0x00;
UIP_IP_BUF->flow = 0x00;
send:
PRINTF("Sending packet with length %d (%d)\n", uip_len,
LOG_INFO("Sending packet with length %d (%d)\n", uip_len,
(UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]);
UIP_STAT(++uip_stat.ip.sent);

View File

@ -38,8 +38,10 @@
#include <stdio.h>
#include <string.h>
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 Websocket"
#define LOG_LEVEL IPV6_LOG_LEVEL
enum {
STATE_WAITING_FOR_HEADER,
@ -78,7 +80,7 @@ send_get(struct websocket_http_client_state *s)
tcp_socket_send_str(tcps, s->subprotocol);
tcp_socket_send_str(tcps, "\r\n");
tcp_socket_send_str(tcps, "\r\n");
PRINTF("websocket-http-client: send_get(): output buffer left %d\n", tcp_socket_max_sendlen(tcps));
LOG_INFO("send_get(): output buffer left %d\n", tcp_socket_max_sendlen(tcps));
}
/*---------------------------------------------------------------------------*/
static void
@ -153,7 +155,7 @@ parse_header_byte(struct websocket_http_client_state *s,
(s->proxy_port == 0 && s->http_status != 101)) {
/* This is a websocket request, so the server should have answered
with a 101 Switching protocols response. */
PRINTF("Websocket HTTP client didn't get the 101 status code (got %d), closing connection\n",
LOG_WARN("didn't get the 101 status code (got %d), closing connection\n",
s->http_status);
websocket_http_client_close(s);
while(1) {
@ -261,7 +263,7 @@ websocket_http_client_get(struct websocket_http_client_state *s)
uip_ip6addr_t *addr;
uint16_t port;
PRINTF("websocket_http_client_get: connecting to %s with file %s subprotocol %s header %s\n",
LOG_INFO("Get: connecting to %s with file %s subprotocol %s header %s\n",
s->host, s->file, s->subprotocol, s->header);

View File

@ -37,6 +37,11 @@
#include "websocket.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6 Websocket"
#define LOG_LEVEL IPV6_LOG_LEVEL
PROCESS(websocket_process, "Websockets process");
#define MAX_HOSTLEN 64
@ -66,9 +71,6 @@ struct websocket_frame_mask {
uint8_t mask[4];
};
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
/*---------------------------------------------------------------------------*/
static int
parse_url(const char *url, char *host, uint16_t *portptr, char *path)
@ -148,11 +150,11 @@ static int
start_get(struct websocket *s)
{
if(websocket_http_client_get(&(s->s)) == 0) {
PRINTF("Out of memory error\n");
LOG_ERR("Out of memory error\n");
s->state = WEBSOCKET_STATE_CLOSED;
return WEBSOCKET_ERR;
} else {
PRINTF("Connecting...\n");
LOG_INFO("Connecting...\n");
s->state = WEBSOCKET_STATE_HTTP_REQUEST_SENT;
return WEBSOCKET_OK;
}
@ -192,13 +194,13 @@ PROCESS_THREAD(websocket_process, ev, data)
if(ret == RESOLV_STATUS_CACHED) {
/* Hostname found, restart get. */
if(s->state == WEBSOCKET_STATE_DNS_REQUEST_SENT) {
PRINTF("Restarting get\n");
LOG_INFO("Restarting get\n");
start_get(s);
}
} else {
if(s->state == WEBSOCKET_STATE_DNS_REQUEST_SENT) {
/* Hostname not found, kill connection. */
/* PRINTF("XXX killing connection\n");*/
LOG_ERR("killing connection\n");
call(s, WEBSOCKET_HOSTNAME_NOT_FOUND, NULL, 0);
}
}
@ -219,7 +221,7 @@ websocket_http_client_aborted(struct websocket_http_client_state *client_state)
if(client_state != NULL) {
struct websocket *s = (struct websocket *)
((char *)client_state - offsetof(struct websocket, s));
PRINTF("Websocket reset\n");
LOG_WARN("Websocket reset\n");
s->state = WEBSOCKET_STATE_CLOSED;
call(s, WEBSOCKET_RESET, NULL, 0);
}
@ -234,7 +236,7 @@ websocket_http_client_timedout(struct websocket_http_client_state *client_state)
if(client_state != NULL) {
struct websocket *s = (struct websocket *)
((char *)client_state - offsetof(struct websocket, s));
PRINTF("Websocket timed out\n");
LOG_WARN("Websocket timed out\n");
s->state = WEBSOCKET_STATE_CLOSED;
call(s, WEBSOCKET_TIMEDOUT, NULL, 0);
}
@ -250,7 +252,7 @@ websocket_http_client_closed(struct websocket_http_client_state *client_state)
if(client_state != NULL) {
struct websocket *s = (struct websocket *)
((char *)client_state - offsetof(struct websocket, s));
PRINTF("Websocket closed.\n");
LOG_INFO("Websocket closed.\n");
s->state = WEBSOCKET_STATE_CLOSED;
call(s, WEBSOCKET_CLOSED, NULL, 0);
}
@ -265,7 +267,7 @@ websocket_http_client_connected(struct websocket_http_client_state *client_state
struct websocket *s = (struct websocket *)
((char *)client_state - offsetof(struct websocket, s));
PRINTF("Websocket connected\n");
LOG_INFO("Websocket connected\n");
s->state = WEBSOCKET_STATE_WAITING_FOR_HEADER;
call(s, WEBSOCKET_CONNECTED, NULL, 0);
}
@ -409,10 +411,10 @@ websocket_http_client_datahandler(struct websocket_http_client_state *client_sta
See if the application data chunk is masked or not. If it is,
we copy the bitmask into the s->mask field. */
if((hdr->len & WEBSOCKET_MASK_BIT) == 0) {
/* PRINTF("No mask\n");*/
/* LOG_INFO("No mask\n");*/
} else {
memcpy(s->mask, &maskptr->mask, sizeof(s->mask));
/* PRINTF("There was a mask, %02x %02x %02x %02x\n",
/* LOG_INFO("There was a mask, %02x %02x %02x %02x\n",
s->mask[0], s->mask[1], s->mask[2], s->mask[3]);*/
}
@ -429,13 +431,13 @@ websocket_http_client_datahandler(struct websocket_http_client_state *client_sta
if(s->left > 0) {
websocket_http_client_send(&s->s, (const uint8_t*)data, s->left);
}
PRINTF("Got ping\n");
LOG_INFO("Got ping\n");
call(s, WEBSOCKET_PINGED, NULL, 0);
s->state = WEBSOCKET_STATE_WAITING_FOR_HEADER;
} else if(s->opcode == WEBSOCKET_OPCODE_PONG) {
/* If the opcode is pong, we call the application to let it
know we got a pong. */
PRINTF("Got pong\n");
LOG_INFO("Got pong\n");
call(s, WEBSOCKET_PONG_RECEIVED, NULL, 0);
s->state = WEBSOCKET_STATE_WAITING_FOR_HEADER;
} else if(s->opcode == WEBSOCKET_OPCODE_CLOSE) {
@ -446,7 +448,7 @@ websocket_http_client_datahandler(struct websocket_http_client_state *client_sta
if(s->left > 0) {
websocket_http_client_send(&s->s, (const uint8_t*)data, s->left);
}
PRINTF("websocket: got close, sending close\n");
LOG_INFO("Got close, sending close\n");
s->state = WEBSOCKET_STATE_WAITING_FOR_HEADER;
websocket_http_client_close(&s->s);
} else if(s->opcode == WEBSOCKET_OPCODE_BIN ||
@ -477,15 +479,12 @@ websocket_http_client_datahandler(struct websocket_http_client_state *client_sta
/* Need to keep parsing the incoming data to check for more
frames, if the incoming datalen is > than s->left. */
if(datalen > 0) {
PRINTF("XXX 1 again\n");
websocket_http_client_datahandler(client_state,
data, datalen);
}
}
} else if(s->state == WEBSOCKET_STATE_RECEIVING_DATA) {
/* XXX todo: mask if needed. */
/* PRINTF("Calling with s->left %d datalen %d\n",
s->left, datalen);*/
if(datalen > 0) {
if(datalen < s->left) {
call(s, WEBSOCKET_DATA, data, datalen);
@ -505,7 +504,6 @@ websocket_http_client_datahandler(struct websocket_http_client_state *client_sta
/* Need to keep parsing the incoming data to check for more
frames, if the incoming datalen is > than len. */
if(datalen > 0) {
PRINTF("XXX 2 again (datalen %d s->left %d)\n", datalen, (int)s->left);
websocket_http_client_datahandler(client_state,
data, datalen);
@ -558,7 +556,7 @@ websocket_open(struct websocket *s, const char *url,
}
if(s->state != WEBSOCKET_STATE_CLOSED) {
PRINTF("websocket_open: closing websocket before opening it again.\n");
LOG_INFO("Open: closing websocket before opening it again.\n");
websocket_close(s);
}
s->callback = c;
@ -577,7 +575,7 @@ websocket_open(struct websocket *s, const char *url,
if(ret != RESOLV_STATUS_CACHED) {
resolv_query(host);
s->state = WEBSOCKET_STATE_DNS_REQUEST_SENT;
PRINTF("Resolving host...\n");
LOG_INFO("Resolving host...\n");
return WEBSOCKET_OK;
}
}
@ -608,26 +606,26 @@ send_data(struct websocket *s, const void *data,
struct websocket_frame_hdr *hdr;
struct websocket_frame_mask *mask;
PRINTF("websocket send data len %d %.*s\n", datalen, datalen, (char *)data);
LOG_INFO("send data len %d %.*s\n", datalen, datalen, (char *)data);
if(s->state == WEBSOCKET_STATE_CLOSED ||
s->state == WEBSOCKET_STATE_DNS_REQUEST_SENT ||
s->state == WEBSOCKET_STATE_HTTP_REQUEST_SENT) {
/* Trying to send data on a non-connected websocket. */
PRINTF("websocket send fail: not connected\n");
LOG_ERR("send fail: not connected\n");
return -1;
}
/* We need to have 4 + 4 additional bytes for the websocket framing
header. */
if(4 + 4 + datalen > websocket_http_client_sendbuflen(&s->s)) {
PRINTF("websocket: too few bytes left (%d left, %d needed)\n",
LOG_ERR("too few bytes left (%d left, %d needed)\n",
websocket_http_client_sendbuflen(&s->s),
4 + 4 + datalen);
return -1;
}
if(datalen > sizeof(buf) - 4 - 4) {
PRINTF("websocket: trying to send too large data chunk %d > %d\n",
LOG_ERR("trying to send too large data chunk %d > %d\n",
datalen, sizeof(buf) - 4 - 4);
return -1;
}

View File

@ -54,7 +54,11 @@
#ifndef TCPIP_LOG_LEVEL
#define TCPIP_LOG_LEVEL LOG_LEVEL_NONE
#endif /* SICSLOWPAN_LOG_LEVEL */
#endif /* TCPIP_LOG_LEVEL */
#ifndef IPV6_LOG_LEVEL
#define IPV6_LOG_LEVEL LOG_LEVEL_NONE
#endif /* IPV6_LOG_LEVEL */
#endif /* __LOG_CONF_H__ */

View File

@ -136,13 +136,7 @@ void uip_debug_ipaddr_print(const uip_ipaddr_t *addr);
#define LOG_WARN_ENABLED (LOG_LEVEL >= LOG_LEVEL_WARN)
#define LOG_INFO_ENABLED (LOG_LEVEL >= LOG_LEVEL_INFO)
#define LOG_DBG_ENABLED (LOG_LEVEL >= LOG_LEVEL_DDG)
/* For support of ANNOTATE without net-debug.h */
#if (DEBUG) & DEBUG_ANNOTATE
#define ANNOTATE(...) printf(__VA_ARGS__)
#else
#define ANNOTATE(...)
#endif /* (DEBUG) & DEBUG_ANNOTATE */
#define LOG_ANNOTATE_ENABLED (LOG_LEVEL >= LOG_LEVEL_ANNOTATE)
#endif /* __LOG_H__ */