diff options
Diffstat (limited to 'src/send.c')
-rw-r--r-- | src/send.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -115,8 +115,8 @@ static inline bool add_node_id(gp_babel_packet_buf_t *buf, const gp_babel_node_i return true; } -static bool add_update(gp_babel_packet_buf_t *buf, gp_babel_node_id_t *node_id, gp_babel_announce_t *announce, bool with_data, bool targetted) { - if (announce->len && !announce->data) { +static bool add_update(gp_babel_packet_buf_t *buf, gp_babel_node_id_t *node_id, gp_babel_announce_t *announce, bool with_payload, bool targetted) { + if (announce->len && !announce->payload) { /* incomplete announce, handle like non-existent announce */ return true; } @@ -131,8 +131,8 @@ static bool add_update(gp_babel_packet_buf_t *buf, gp_babel_node_id_t *node_id, *node_id = announce->node; } - uint8_t data_len = (with_data && announce->metric.metric != GP_BABEL_INFINITY) ? announce->len : 0; - gp_babel_tlv_update_t *update = gp_babel_tlv_add(buf, TLV_UPDATE, sizeof(gp_babel_tlv_update_t)+data_len); + uint8_t payload_len = (with_payload && announce->metric.metric != GP_BABEL_INFINITY) ? announce->len : 0; + gp_babel_tlv_update_t *update = gp_babel_tlv_add(buf, TLV_UPDATE, sizeof(gp_babel_tlv_update_t)+payload_len); if (!update) { /* reset length to remove possibly added node ID record */ buf->packet.len = len; @@ -147,8 +147,12 @@ static bool add_update(gp_babel_packet_buf_t *buf, gp_babel_node_id_t *node_id, update->type = htons(announce->type); update->key = htons(announce->key); - if (data_len) - memcpy(update->data, announce->data, data_len); + if (announce->metric.metric != GP_BABEL_INFINITY && announce->len) { + update->flags |= GP_BABEL_UPDATE_FLAG_HAS_PAYLOAD; + + if (payload_len) + memcpy(update->payload, announce->payload, payload_len); + } if (gp_babel_is_metric_better(announce->metric, announce->feasibility_distance)) announce->feasibility_distance = announce->metric; @@ -159,18 +163,18 @@ static bool add_update(gp_babel_packet_buf_t *buf, gp_babel_node_id_t *node_id, return true; } -void gp_babel_send_update(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t *iface, gp_babel_neigh_t *neigh, gp_babel_announce_t *announce, bool with_data) { +void gp_babel_send_update(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t *iface, gp_babel_neigh_t *neigh, gp_babel_announce_t *announce, bool with_payload) { gp_babel_packet_buf_t *buf = gp_babel_packet_alloca(GP_BABEL_PACKET_MAX); if (announce) { - add_update(buf, NULL, announce, with_data, neigh); + add_update(buf, NULL, announce, with_payload, neigh); } else { gp_babel_node_id_t node_id = gp_babel_node_id_unspec; gp_babel_announce_t *a; for (a = ctx->announces; a; a = a->next) { - if (!add_update(buf, &node_id, a, with_data, neigh)) { + if (!add_update(buf, &node_id, a, with_payload, neigh)) { if (neigh) send_neigh(gmrf, neigh, &buf->packet); else @@ -179,7 +183,7 @@ void gp_babel_send_update(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t *i node_id = gp_babel_node_id_unspec; buf->packet.len = 0; - if (!add_update(buf, &node_id, a, with_data, neigh)) { + if (!add_update(buf, &node_id, a, with_payload, neigh)) { gmrf_logf(gmrf, LOG_ERR, "add_update failed"); return; } |