diff --git a/constants.h b/constants.h index 6e9ea62b..f8859a68 100644 --- a/constants.h +++ b/constants.h @@ -127,6 +127,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define MONITOR_RHIZOME (1<<1) #define MONITOR_PEERS (1<<2) #define MONITOR_DNAHELPER (1<<3) +#define MONITOR_LINKS (1<<4) #define MAX_SIGNATURES 16 diff --git a/monitor.c b/monitor.c index 5bf29eba..d1ff7505 100644 --- a/monitor.c +++ b/monitor.c @@ -401,6 +401,8 @@ static int monitor_set(const struct cli_parsed *parsed, void *context) c->flags|=MONITOR_PEERS; else if (strcase_startswith(parsed->args[1],"dnahelper", NULL)) c->flags|=MONITOR_DNAHELPER; + else if (strcase_startswith(parsed->args[1],"links", NULL)) + c->flags|=MONITOR_LINKS; else return monitor_write_error(c,"Unknown monitor type"); @@ -422,6 +424,8 @@ static int monitor_clear(const struct cli_parsed *parsed, void *context) c->flags&=~MONITOR_PEERS; else if (strcase_startswith(parsed->args[1],"dnahelper", NULL)) c->flags&=~MONITOR_DNAHELPER; + else if (strcase_startswith(parsed->args[1],"links", NULL)) + c->flags&=~MONITOR_LINKS; else return monitor_write_error(c,"Unknown monitor type"); @@ -620,6 +624,14 @@ int monitor_announce_unreachable_peer(const unsigned char *sid) return monitor_tell_formatted(MONITOR_PEERS, "\nOLDPEER:%s\n", alloca_tohex_sid(sid)); } +int monitor_announce_link(int hop_count, struct subscriber *transmitter, struct subscriber *receiver) +{ + return monitor_tell_formatted(MONITOR_LINKS, "\nLINK:%d:%s:%s\n", + hop_count, + transmitter?alloca_tohex_sid(transmitter->sid):"", + alloca_tohex_sid(receiver->sid)); +} + // test if any monitor clients are interested in a particular type of event int monitor_client_interested(int mask){ int i; diff --git a/route_link.c b/route_link.c index 1273f7e6..91a152ed 100644 --- a/route_link.c +++ b/route_link.c @@ -275,23 +275,6 @@ next: if (next_hop == subscriber && (interface != subscriber->interface)) changed = 1; - if (changed){ - if (config.debug.linkstate){ - if (next_hop == subscriber){ - DEBUGF("LINK STATE; neighbour %s is reachable on interface %s", - alloca_tohex_sid(subscriber->sid), - interface->name); - } else { - DEBUGF("LINK STATE; next hop for %s is now %d hops, %s via %s", - alloca_tohex_sid(subscriber->sid), - best_hop_count, - next_hop?alloca_tohex_sid(next_hop->sid):"UNREACHABLE", - transmitter?alloca_tohex_sid(transmitter->sid):"NONE"); - } - } - state->next_update = now; - } - state->next_hop = next_hop; state->transmitter = transmitter; state->hop_count = best_hop_count; @@ -317,6 +300,24 @@ next: subscriber->next_hop = next_hop; set_reachable(subscriber, reachable); + if (changed){ + if (config.debug.linkstate){ + if (next_hop == subscriber){ + DEBUGF("LINK STATE; neighbour %s is reachable on interface %s", + alloca_tohex_sid(subscriber->sid), + interface->name); + } else { + DEBUGF("LINK STATE; next hop for %s is now %d hops, %s via %s", + alloca_tohex_sid(subscriber->sid), + best_hop_count, + next_hop?alloca_tohex_sid(next_hop->sid):"UNREACHABLE", + transmitter?alloca_tohex_sid(transmitter->sid):"NONE"); + } + } + monitor_announce_link(best_hop_count, transmitter, subscriber); + state->next_update = now; + } + return 0; } diff --git a/serval.h b/serval.h index 17873ba6..c38cc290 100644 --- a/serval.h +++ b/serval.h @@ -688,6 +688,7 @@ int monitor_setup_sockets(); int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax); int monitor_announce_peer(const unsigned char *sid); int monitor_announce_unreachable_peer(const unsigned char *sid); +int monitor_announce_link(int hop_count, struct subscriber *transmitter, struct subscriber *receiver); int monitor_tell_clients(char *msg, int msglen, int mask); int monitor_tell_formatted(int mask, char *fmt, ...); int monitor_client_interested(int mask);