From 5914bc92ce32536cb64d9d2c32f8ab589ce6c696 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Wed, 19 Sep 2012 09:50:29 +0930 Subject: [PATCH] Use a directory service as a default route --- overlay_address.c | 8 ++++++++ overlay_address.h | 2 ++ overlay_interface.c | 8 +++++++- overlay_payload.c | 8 +++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/overlay_address.c b/overlay_address.c index 0c57a779..dc7172c9 100644 --- a/overlay_address.c +++ b/overlay_address.c @@ -166,6 +166,14 @@ int subscriber_is_reachable(struct subscriber *subscriber){ if (!subscriber) return REACHABLE_NONE; + // is there a default route? + if (subscriber->reachable==REACHABLE_NONE && + directory_service && + subscriber!=directory_service && + subscriber_is_reachable(directory_service)!=REACHABLE_NONE){ + return REACHABLE_DEFAULT_ROUTE; + } + if (subscriber->reachable==REACHABLE_INDIRECT){ if (!subscriber->next_hop) return REACHABLE_NONE; diff --git a/overlay_address.h b/overlay_address.h index 30d33772..30e1ffea 100644 --- a/overlay_address.h +++ b/overlay_address.h @@ -41,6 +41,8 @@ // this subscriber is in our keystore #define REACHABLE_SELF 5 +#define REACHABLE_DEFAULT_ROUTE 6 + /* Codes used to describe abbreviated addresses. Values 0x10 - 0xff are the first byte of, and implicit indicators of addresses written in full */ #define OA_CODE_SELF 0x00 diff --git a/overlay_interface.c b/overlay_interface.c index 556b3e88..9c789d3b 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -1025,8 +1025,14 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim case REACHABLE_INDIRECT: next_hop=next_hop->next_hop; + frame->sendBroadcast=0; + break; + + case REACHABLE_DEFAULT_ROUTE: + next_hop=directory_service; + frame->sendBroadcast=0; + break; - // fall through case REACHABLE_DIRECT: case REACHABLE_UNICAST: frame->sendBroadcast=0; diff --git a/overlay_payload.c b/overlay_payload.c index 9cef6362..239e8a10 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -189,9 +189,11 @@ int overlay_payload_enqueue(int q, struct overlay_frame *p) if (!p) return WHY("Cannot queue NULL"); - if (p->destination && - (p->destination->reachable == REACHABLE_NONE || p->destination->reachable == REACHABLE_SELF)) - return WHYF("Destination %s is unreachable (%d)", alloca_tohex_sid(p->destination->sid), p->destination->reachable); + if (p->destination){ + int r = subscriber_is_reachable(p->destination); + if (r == REACHABLE_SELF || r == REACHABLE_NONE) + return WHYF("Destination %s is unreachable (%d)", alloca_tohex_sid(p->destination->sid), r); + } if (debug&DEBUG_PACKETTX) DEBUGF("Enqueuing packet for %s* (q[%d]length = %d)",