#include "message.h"
#include "kernel.h"
#include "babel_main.h"
+#include "babel_errors.h"
static unsigned char packet_header[4] = {42, 2};
}
if(i + 1 > alen) {
- zlog_err("Received truncated attributes.");
+ zlog_ferr(BABEL_ERR_PACKET, "Received truncated attributes.");
return;
}
len = a[i + 1];
if(i + len > alen) {
- zlog_err("Received truncated attributes.");
+ zlog_ferr(BABEL_ERR_PACKET, "Received truncated attributes.");
return;
}
/* Nothing. */
} else if(type == SUBTLV_DIVERSITY) {
if(len > DIVERSITY_HOPS) {
- zlog_err("Received overlong channel information (%d > %d).n",
- len, DIVERSITY_HOPS);
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received overlong channel information (%d > %d).n",
+ len, DIVERSITY_HOPS);
len = DIVERSITY_HOPS;
}
if(memchr(a + i + 2, 0, len) != NULL) {
/* 0 is reserved. */
- zlog_err("Channel information contains 0!");
+ zlog_ferr(BABEL_ERR_PACKET, "Channel information contains 0!");
return;
}
memset(channels, 0, DIVERSITY_HOPS);
}
if(i + 1 > alen) {
- zlog_err("Received truncated sub-TLV on Hello message.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on Hello message.");
return -1;
}
len = a[i + 1];
if(i + len > alen) {
- zlog_err("Received truncated sub-TLV on Hello message.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on Hello message.");
return -1;
}
DO_NTOHL(*hello_send_us, a + i + 2);
ret = 1;
} else {
- zlog_err("Received incorrect RTT sub-TLV on Hello message.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received incorrect RTT sub-TLV on Hello message.");
}
} else {
debugf(BABEL_DEBUG_COMMON,
}
if(i + 1 > alen) {
- zlog_err("Received truncated sub-TLV on IHU message.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on IHU message.");
return -1;
}
len = a[i + 1];
if(i + len > alen) {
- zlog_err("Received truncated sub-TLV on IHU message.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on IHU message.");
return -1;
}
ret = 1;
}
else {
- zlog_err("Received incorrect RTT sub-TLV on IHU message.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received incorrect RTT sub-TLV on IHU message.");
}
} else {
debugf(BABEL_DEBUG_COMMON,
}
if(!linklocal(from)) {
- zlog_err("Received packet from non-local address %s.",
- format_address(from));
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received packet from non-local address %s.",
+ format_address(from));
return;
}
if (babel_packet_examin (packet, packetlen)) {
- zlog_err("Received malformed packet on %s from %s.",
- ifp->name, format_address(from));
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received malformed packet on %s from %s.",
+ ifp->name, format_address(from));
return;
}
neigh = find_neighbour(from, ifp);
if(neigh == NULL) {
- zlog_err("Couldn't allocate neighbour.");
+ zlog_ferr(BABEL_ERR_PACKET, "Couldn't allocate neighbour.");
return;
}
DO_NTOHS(bodylen, packet + 2);
if(bodylen + 4 > packetlen) {
- zlog_err("Received truncated packet (%d + 4 > %d).",
+ zlog_ferr(BABEL_ERR_PACKET, "Received truncated packet (%d + 4 > %d).",
bodylen, packetlen);
bodylen = packetlen - 4;
}
have_router_id = 1;
}
if(!have_router_id && message[2] != 0) {
- zlog_err("Received prefix with no router id.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received prefix with no router id.");
goto fail;
}
debugf(BABEL_DEBUG_COMMON,"Received update%s%s for %s from %s on %s.",
if(message[2] == 0) {
if(metric < 0xFFFF) {
- zlog_err("Received wildcard update with finite metric.");
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Received wildcard update with finite metric.");
goto done;
}
retract_neighbour_routes(neigh);
continue;
fail:
- zlog_err("Couldn't parse packet (%d, %d) from %s on %s.",
- message[0], message[1], format_address(from), ifp->name);
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Couldn't parse packet (%d, %d) from %s on %s.",
+ message[0], message[1], format_address(from), ifp->name);
goto done;
}
DO_HTONL(babel_ifp->sendbuf + babel_ifp->buffered_hello + 10, time);
return 1;
} else {
- zlog_err("No space left for timestamp sub-TLV "
+ zlog_ferr(BABEL_ERR_PACKET, "No space left for timestamp sub-TLV "
"(this shouldn't happen)");
return -1;
}
babel_ifp->sendbuf, babel_ifp->buffered,
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0)
- zlog_err("send: %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_PACKET, "send: %s", safe_strerror(errno));
} else {
- zlog_err("Warning: bucket full, dropping packet to %s.",
- ifp->name);
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Warning: bucket full, dropping packet to %s.",
+ ifp->name);
}
}
VALGRIND_MAKE_MEM_UNDEFINED(babel_ifp->sendbuf, babel_ifp->bufsize);
if(!unicast_buffer)
unicast_buffer = malloc(UNICAST_BUFSIZE);
if(!unicast_buffer) {
- zlog_err("malloc(unicast_buffer): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_MEMORY, "malloc(unicast_buffer): %s",
+ safe_strerror(errno));
return -1;
}
unicast_buffer, unicast_buffered,
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0)
- zlog_err("send(unicast): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_PACKET, "send(unicast): %s",
+ safe_strerror(errno));
} else {
- zlog_err("Warning: bucket full, dropping unicast packet to %s if %s.",
- format_address(unicast_neighbour->address),
- unicast_neighbour->ifp->name);
+ zlog_ferr(BABEL_ERR_PACKET,
+ "Warning: bucket full, dropping unicast packet to %s if %s.",
+ format_address(unicast_neighbour->address),
+ unicast_neighbour->ifp->name);
}
done:
again:
babel_ifp->buffered_updates = malloc(n *sizeof(struct buffered_update));
if(babel_ifp->buffered_updates == NULL) {
- zlog_err("malloc(buffered_updates): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_MEMORY, "malloc(buffered_updates): %s",
+ safe_strerror(errno));
if(n > 4) {
/* Try again with a tiny buffer. */
n = 4;
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
set_timeout(&babel_ifp->update_timeout, babel_ifp->update_interval);
babel_ifp->last_update_time = babel_now.tv_sec;
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate xroute stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate xroute stream.");
}
}
#include "xroute.h"
#include "message.h"
#include "resend.h"
+#include "babel_errors.h"
static void consider_route(struct babel_route *route);
struct babel_route **routes = NULL;
static int route_slots = 0, max_route_slots = 0;
int kernel_metric = 0;
-int diversity_kind = DIVERSITY_NONE;
+enum babel_diversity diversity_kind = DIVERSITY_NONE;
int diversity_factor = BABEL_DEFAULT_DIVERSITY_FACTOR;
int keep_unfeasible = 0;
return;
if(!route_feasible(route))
- zlog_err("WARNING: installing unfeasible route "
- "(this shouldn't happen).");
+ zlog_ferr(BABEL_ERR_ROUTE, "WARNING: installing unfeasible route "
+ "(this shouldn't happen).");
i = find_route_slot(route->src->prefix, route->src->plen, NULL);
assert(i >= 0 && i < route_slots);
if(routes[i] != route && routes[i]->installed) {
- zlog_err("WARNING: attempting to install duplicate route "
- "(this shouldn't happen).");
+ zlog_ferr(BABEL_ERR_ROUTE,
+ "WARNING: attempting to install duplicate route "
+ "(this shouldn't happen).");
return;
}
metric_to_kernel(route_metric(route)), NULL, 0, 0);
if(rc < 0) {
int save = errno;
- zlog_err("kernel_route(ADD): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_ROUTE, "kernel_route(ADD): %s",
+ safe_strerror(errno));
if(save != EEXIST)
return;
}
route->neigh->ifp->ifindex,
metric_to_kernel(route_metric(route)), NULL, 0, 0);
if(rc < 0)
- zlog_err("kernel_route(FLUSH): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_ROUTE, "kernel_route(FLUSH): %s",
+ safe_strerror(errno));
route->installed = 0;
}
return;
if(!route_feasible(new))
- zlog_err("WARNING: switching to unfeasible route "
- "(this shouldn't happen).");
+ zlog_ferr(BABEL_ERR_ROUTE, "WARNING: switching to unfeasible route "
+ "(this shouldn't happen).");
rc = kernel_route(ROUTE_MODIFY, old->src->prefix, old->src->plen,
old->nexthop, old->neigh->ifp->ifindex,
new->nexthop, new->neigh->ifp->ifindex,
metric_to_kernel(route_metric(new)));
if(rc < 0) {
- zlog_err("kernel_route(MODIFY): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_ROUTE, "kernel_route(MODIFY): %s",
+ safe_strerror(errno));
return;
}
route->nexthop, route->neigh->ifp->ifindex,
new);
if(rc < 0) {
- zlog_err("kernel_route(MODIFY metric): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_ROUTE, "kernel_route(MODIFY metric): %s",
+ safe_strerror(errno));
return;
}
}
}
}
return 0;
- default:
- zlog_err("Unknown kind of diversity.");
- return 1;
}
+
+ return 1;
}
int
return NULL;
if(martian_prefix(prefix, plen)) {
- zlog_err("Rejecting martian route to %s through %s.",
+ zlog_ferr(BABEL_ERR_ROUTE, "Rejecting martian route to %s through %s.",
format_prefix(prefix, plen), format_address(nexthop));
return NULL;
}
route->next = NULL;
new_route = insert_route(route);
if(new_route == NULL) {
- zlog_err("Couldn't insert route.");
+ zlog_ferr(BABEL_ERR_ROUTE, "Couldn't insert route.");
free(route);
return NULL;
}