diff options
Diffstat (limited to 'ffd/send.c')
-rw-r--r-- | ffd/send.c | 34 |
1 files changed, 27 insertions, 7 deletions
@@ -126,7 +126,12 @@ static bool add_node_id(ffd_packet_t *packet, size_t max_len, ffd_node_id_t node return true; } -static bool add_update(ffd_packet_t *packet, size_t max_len, ffd_node_id_t *node_id, const ffd_announce_t *announce) { +static bool add_update(ffd_packet_t *packet, size_t max_len, ffd_node_id_t *node_id, ffd_announce_t *announce, bool with_data) { + if (announce->len && !announce->data) { + /* incomplete announce, handle like non-existant announce */ + return true; + } + uint16_t len = packet->len; if (!node_id || !ffd_are_node_ids_equal(node_id, &announce->node)) { @@ -145,32 +150,42 @@ static bool add_update(ffd_packet_t *packet, size_t max_len, ffd_node_id_t *node ffd_metric_seqno_t metric = ffd_announce_get_metric(announce); - update->interval = htons(announce->interval); + update->flags = 0; + update->reserved = 0; + update->interval = htons(FFD_UPDATE_INTERVAL); update->seqno = htons(metric.seqno); update->metric = htons(metric.metric); update->type = htons(announce->type); update->key = htons(announce->key); - memcpy(update->data, announce->data, announce->len); + if (announce->len) { + update->flags |= FFD_UPDATE_WITH_DATA; + + if (with_data) { + memcpy(update->data, announce->data, announce->len); + } + } + + announce->feasability_distance = metric; return true; } -void ffd_send_update(ffd_iface_t *iface, ffd_neigh_t *neigh, const ffd_announce_t *announce) { +void ffd_send_update(ffd_iface_t *iface, ffd_neigh_t *neigh, ffd_announce_t *announce, bool with_data) { ffd_packet_t *packet = alloca(sizeof(ffd_packet_t)+FFD_PACKET_MAX); packet->version_magic = htons(FFD_VERSION_MAGIC); packet->len = 0; if (announce) { - add_update(packet, FFD_PACKET_MAX, NULL, announce); + add_update(packet, FFD_PACKET_MAX, NULL, announce, with_data); } else { ffd_node_id_t node_id = FFD_NODE_ID_UNSPEC; ffd_announce_t *a; for (a = announce_list; a; a = a->next) { - if (!add_update(packet, FFD_PACKET_MAX, &node_id, a)) { + if (!add_update(packet, FFD_PACKET_MAX, &node_id, a, with_data)) { if (!send_eth(&ffd_addr, iface->ifindex, packet, sizeof(ffd_packet_t)+ntohs(packet->len))) fprintf(stderr, "send_eth: %m\n"); @@ -186,7 +201,7 @@ void ffd_send_update(ffd_iface_t *iface, ffd_neigh_t *neigh, const ffd_announce_ } } -void ffd_send_announce_request(ffd_iface_t *iface, ffd_neigh_t *neigh, ffd_node_id_t node, uint16_t type, uint16_t key) { +void ffd_send_announce_request(ffd_iface_t *iface, ffd_neigh_t *neigh, ffd_node_id_t node, uint16_t type, uint16_t key, bool with_data) { ffd_packet_t *packet = alloca(sizeof(ffd_packet_t)+FFD_PACKET_MAX); packet->version_magic = htons(FFD_VERSION_MAGIC); @@ -197,9 +212,14 @@ void ffd_send_announce_request(ffd_iface_t *iface, ffd_neigh_t *neigh, ffd_node_ return; req->node = node; + req->flags = 0; + req->reserved = 0; req->type = htons(type); req->key = htons(key); + if (with_data) + req->flags |= FFD_UPDATE_WITH_DATA; + if (!send_eth(&ffd_addr, iface->ifindex, packet, sizeof(ffd_packet_t)+ntohs(packet->len))) fprintf(stderr, "send_eth: %m\n"); } |