summaryrefslogtreecommitdiffstats
path: root/src/tlv_types.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-07-29 02:11:47 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-07-29 02:11:47 +0200
commit94e334a1fecc30b538d4551c035bf913927b21ae (patch)
treeb371fd0e4a8db9e672ebabd9d952a6544a165887 /src/tlv_types.c
parenta6fa92d1c8774a704fd4a869fc5d7799528b084f (diff)
downloadbabel-94e334a1fecc30b538d4551c035bf913927b21ae.tar
babel-94e334a1fecc30b538d4551c035bf913927b21ae.zip
Adapt to new gmrf API
Diffstat (limited to 'src/tlv_types.c')
-rw-r--r--src/tlv_types.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/src/tlv_types.c b/src/tlv_types.c
index cc380ea..6e94d51 100644
--- a/src/tlv_types.c
+++ b/src/tlv_types.c
@@ -33,7 +33,7 @@
typedef struct handle_tlv_arg {
- gp_babel_iface_t *iface;
+ gmrf_iface_state_t *iface;
const gmrf_addr_t *source;
gp_babel_node_id_t node_id;
@@ -43,53 +43,53 @@ static inline gp_babel_neigh_t* get_tlv_neigh(handle_tlv_arg_t *arg) {
return gp_babel_neigh_get(arg->iface, arg->source);
}
-static void handle_tlv_ack_req(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_ack_req_t *tlv_req, size_t len, handle_tlv_arg_t *arg) {
+static void handle_tlv_ack_req(gmrf_context_t *ctx, const gp_babel_tlv_ack_req_t *tlv_req, size_t len, handle_tlv_arg_t *arg) {
if (len < sizeof(gp_babel_tlv_ack_req_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short acknowledement request TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short acknowledement request TLV.");
return;
}
- gp_babel_send_ack(gmrf, ctx, get_tlv_neigh(arg), ntohs(tlv_req->nonce));
+ gp_babel_send_ack(ctx, get_tlv_neigh(arg), ntohs(tlv_req->nonce));
}
-static void handle_tlv_ack(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_ack_t *tlv_ack, size_t len, handle_tlv_arg_t *arg) {
+static void handle_tlv_ack(gmrf_context_t *ctx, const gp_babel_tlv_ack_t *tlv_ack, size_t len, handle_tlv_arg_t *arg) {
if (len < sizeof(gp_babel_tlv_ack_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short acknowledement TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short acknowledement TLV.");
return;
}
//gp_babel_ack_handle(ntohs(tlv_ack->nonce));
}
-static void handle_tlv_hello(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_hello_t *tlv_hello, size_t len, handle_tlv_arg_t *arg) {
+static void handle_tlv_hello(gmrf_context_t *ctx, const gp_babel_tlv_hello_t *tlv_hello, size_t len, handle_tlv_arg_t *arg) {
if (len < sizeof(gp_babel_tlv_hello_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short hello TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short hello TLV.");
return;
}
- gmrf_logf(gmrf, LOG_DEBUG, "received hello from %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s] with seqno %04x.",
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "received hello from %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s] with seqno %04x.",
arg->source->d[0], arg->source->d[1], arg->source->d[2], arg->source->d[3],
arg->source->d[4], arg->source->d[5], arg->source->d[6], arg->source->d[7],
- gmrf_iface_get_name(gmrf, arg->iface->gmrf_iface), ntohs(tlv_hello->seqno));
+ gmrf_iface_get_name(ctx->gmrf, arg->iface->gmrf_iface), ntohs(tlv_hello->seqno));
gp_babel_neigh_t *neigh = get_tlv_neigh(arg);
uint16_t seqno = ntohs(tlv_hello->seqno);
if (neigh->last_hello != gmrf_time_unspec) {
- int timediff = (gmrf_now(gmrf) - neigh->last_hello)/10;
+ int timediff = (gmrf_now(ctx->gmrf) - neigh->last_hello)/10;
uint16_t seqexp = neigh->last_seqno + (timediff - neigh->hello_interval/2)/neigh->hello_interval;
/* cast to int16_t to ensure correct handling of seqno wrapping */
if (abs((int16_t)(seqno - seqexp)) > 16) {
- gmrf_logf(gmrf, LOG_INFO, "neighbour was reset.");
+ gmrf_logf(ctx->gmrf, LOG_INFO, "neighbour was reset.");
neigh->hello_log = 0;
neigh->txcost = GP_BABEL_INFINITY;
}
else {
int16_t seqdiff = seqno - neigh->last_seqno;
if (seqdiff <= 0) {
- gmrf_logf(gmrf, LOG_DEBUG, "seqno already seen, ignoring.");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "seqno already seen, ignoring.");
return;
}
@@ -97,33 +97,33 @@ static void handle_tlv_hello(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_t
}
}
else {
- gmrf_logf(gmrf, LOG_DEBUG, "received hello from new neighbour.");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "received hello from new neighbour.");
}
neigh->hello_log |= 1;
neigh->hello_interval = ntohs(tlv_hello->interval);
neigh->last_seqno = seqno;
- neigh->last_hello = gmrf_now(gmrf);
+ neigh->last_hello = gmrf_now(ctx->gmrf);
if (neigh->hello_log == 1) /* new or reset neighbour */
gp_babel_neigh_reset(arg->iface, neigh);
- gmrf_logf(gmrf, LOG_DEBUG, "accepted hello, log %04x, rxcost is %u, cost is %u now.", neigh->hello_log, gp_babel_neigh_get_rxcost(gmrf, neigh), gp_babel_neigh_get_cost(gmrf, neigh));
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "accepted hello, log %04x, rxcost is %u, cost is %u now.", neigh->hello_log, gp_babel_neigh_get_rxcost(ctx, neigh), gp_babel_neigh_get_cost(ctx, neigh));
}
-static void handle_tlv_ihu(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_ihu_t *tlv_ihu, size_t len, handle_tlv_arg_t *arg) {
+static void handle_tlv_ihu(gmrf_context_t *ctx, const gp_babel_tlv_ihu_t *tlv_ihu, size_t len, handle_tlv_arg_t *arg) {
if (len < sizeof(gp_babel_tlv_ihu_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short IHU TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short IHU TLV.");
return;
}
if (tlv_ihu->ae == ADDR_ENC_GMRF) {
if (len < sizeof(gp_babel_tlv_ihu_t)+sizeof(gmrf_addr_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short IHU TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short IHU TLV.");
return;
}
- gmrf_addr_t iface_addr = gmrf_iface_get_addr(gmrf, arg->iface->gmrf_iface);
+ gmrf_addr_t iface_addr = gmrf_iface_get_addr(ctx->gmrf, arg->iface->gmrf_iface);
if (memcmp(tlv_ihu->address, &iface_addr, sizeof(gmrf_addr_t)) != 0)
return;
}
@@ -133,48 +133,48 @@ static void handle_tlv_ihu(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv
gp_babel_neigh_t *neigh = get_tlv_neigh(arg);
neigh->ihu_interval = ntohs(tlv_ihu->interval);
- neigh->last_ihu = gmrf_now(gmrf);
+ neigh->last_ihu = gmrf_now(ctx->gmrf);
neigh->txcost = ntohs(tlv_ihu->rxcost);
- gmrf_logf(gmrf, LOG_DEBUG, "accepted IHU, txcost is %u, cost is %u now.", gp_babel_neigh_get_txcost(gmrf, neigh), gp_babel_neigh_get_cost(gmrf, neigh));
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "accepted IHU, txcost is %u, cost is %u now.", gp_babel_neigh_get_txcost(ctx, neigh), gp_babel_neigh_get_cost(ctx, neigh));
}
-static void handle_tlv_node_id(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_node_id_t *tlv_node_id, size_t len, handle_tlv_arg_t *arg) {
+static void handle_tlv_node_id(gmrf_context_t *ctx, const gp_babel_tlv_node_id_t *tlv_node_id, size_t len, handle_tlv_arg_t *arg) {
if (len < sizeof(gp_babel_tlv_node_id_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short node id TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short node id TLV.");
return;
}
arg->node_id = tlv_node_id->id;
}
-static void handle_tlv_update(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_update_t *tlv_update, size_t len, handle_tlv_arg_t *arg) {
+static void handle_tlv_update(gmrf_context_t *ctx, const gp_babel_tlv_update_t *tlv_update, size_t len, handle_tlv_arg_t *arg) {
if (len < sizeof(gp_babel_tlv_update_t)) {
- gmrf_logf(gmrf, LOG_WARNING, "received short update TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received short update TLV.");
return;
}
if (gp_babel_node_id_is_unspec(&arg->node_id)) {
- gmrf_logf(gmrf, LOG_WARNING, "received update TLV without node id TLV.");
+ gmrf_logf(ctx->gmrf, LOG_WARNING, "received update TLV without node id TLV.");
return;
}
if (gp_babel_node_id_equal(&arg->node_id, &ctx->self)) {
- gmrf_logf(gmrf, LOG_DEBUG, "update source is myself.");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "update source is myself.");
return;
}
- gp_babel_announce_t *announce = gp_babel_announce_get(gmrf, ctx, &arg->node_id, ntohs(tlv_update->type), ntohs(tlv_update->key));
+ gp_babel_announce_t *announce = gp_babel_announce_get(ctx, &arg->node_id, ntohs(tlv_update->type), ntohs(tlv_update->key));
gp_babel_metric_seqno_t ms = { ntohs(tlv_update->metric), ntohs(tlv_update->seqno) };
bool feasible = gp_babel_is_feasible(announce, ms);
gp_babel_neigh_t *neigh = get_tlv_neigh(arg);
gp_babel_nexthop_t *nexthop = gp_babel_announce_nexthop_find(announce, neigh);
- gmrf_logf(gmrf, LOG_DEBUG, "update received from %04x%04x, metric %u, seqno %04x.",
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "update received from %04x%04x, metric %u, seqno %04x.",
ntohl(*(uint32_t*)arg->node_id.id), ntohl(*(uint32_t*)(arg->node_id.id+4)),
ms.metric, ms.seqno);
- gmrf_logf(gmrf, LOG_DEBUG, "the update is %sfeasible and there is %s nexthop.", feasible ? "" : "not ", nexthop ? "a" : "no");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "the update is %sfeasible and there is %s nexthop.", feasible ? "" : "not ", nexthop ? "a" : "no");
if (!nexthop) {
if (feasible && tlv_update->metric != GP_BABEL_INFINITY /* no need to ntohs */)
@@ -182,16 +182,16 @@ static void handle_tlv_update(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_
}
else {
if (!feasible && nexthop == announce->selected) {
- gmrf_logf(gmrf, LOG_DEBUG, "requesting new seqno");
- gp_babel_send_seqno_request_for(gmrf, ctx, neigh, announce);
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "requesting new seqno");
+ gp_babel_send_seqno_request_for(ctx, neigh, announce);
nexthop = NULL;
}
}
if (!feasible && nexthop && nexthop != announce->selected) {
- if (ms.metric + gp_babel_neigh_get_cost(gmrf, neigh) < announce->metric.metric) {
- gmrf_logf(gmrf, LOG_DEBUG, "requesting new seqno");
- gp_babel_send_seqno_request_for(gmrf, ctx, neigh, announce);
+ if (ms.metric + gp_babel_neigh_get_cost(ctx, neigh) < announce->metric.metric) {
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "requesting new seqno");
+ gp_babel_send_seqno_request_for(ctx, neigh, announce);
}
}
@@ -206,56 +206,56 @@ static void handle_tlv_update(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_
/* request payload */
if (nexthop)
- gp_babel_send_announce_request(gmrf, ctx, NULL, neigh, &announce->node, announce->type, announce->key, true);
+ gp_babel_send_announce_request(ctx, NULL, neigh, &announce->node, announce->type, announce->key, true);
}
}
if (!nexthop)
return;
- gmrf_logf(gmrf, LOG_DEBUG, "the update was accepted.");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "the update was accepted.");
- gp_babel_announce_update_nexthop(gmrf, ctx, announce, nexthop, ms, ntohs(tlv_update->interval));
+ gp_babel_announce_update_nexthop(ctx, announce, nexthop, ms, ntohs(tlv_update->interval));
}
-static void handle_tlv(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_tlv_type_t type, const void *data, size_t len, void *arg) {
+static void handle_tlv(gmrf_context_t *ctx, gp_babel_tlv_type_t type, const void *data, size_t len, void *arg) {
handle_tlv_arg_t *tlv_arg = arg;
switch (type) {
case TLV_ACK_REQ:
- handle_tlv_ack_req(gmrf, ctx, data, len, tlv_arg);
+ handle_tlv_ack_req(ctx, data, len, tlv_arg);
return;
case TLV_ACK:
- handle_tlv_ack(gmrf, ctx, data, len, tlv_arg);
+ handle_tlv_ack(ctx, data, len, tlv_arg);
return;
case TLV_HELLO:
- handle_tlv_hello(gmrf, ctx, data, len, tlv_arg);
+ handle_tlv_hello(ctx, data, len, tlv_arg);
return;
case TLV_IHU:
- handle_tlv_ihu(gmrf, ctx, data, len, tlv_arg);
+ handle_tlv_ihu(ctx, data, len, tlv_arg);
return;
case TLV_NODE_ID:
- handle_tlv_node_id(gmrf, ctx, data, len, tlv_arg);
+ handle_tlv_node_id(ctx, data, len, tlv_arg);
return;
case TLV_UPDATE:
- handle_tlv_update(gmrf, ctx, data, len, tlv_arg);
+ handle_tlv_update(ctx, data, len, tlv_arg);
return;
default:
- gmrf_logf(gmrf, LOG_DEBUG, "received unknown TLV %u on %s.", type, gmrf_iface_get_name(gmrf, tlv_arg->iface->gmrf_iface));
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "received unknown TLV %u on %s.", type, gmrf_iface_get_name(ctx->gmrf, tlv_arg->iface->gmrf_iface));
return;
}
}
-void gp_babel_handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t *iface, const gmrf_addr_t *source, const gp_babel_packet_t *packet) {
+void gp_babel_handle_packet(gmrf_context_t *ctx, gmrf_iface_state_t *iface, const gmrf_addr_t *source, const gp_babel_packet_t *packet) {
handle_tlv_arg_t arg = { .iface = iface, .source = source };
- if (!gp_babel_tlv_parse(gmrf, ctx, packet, handle_tlv, &arg)) {
- gmrf_logf(gmrf, LOG_DEBUG, "received invalid packet.");
+ if (!gp_babel_tlv_parse(ctx, packet, handle_tlv, &arg)) {
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "received invalid packet.");
}
}