Add link state monitor commands

This commit is contained in:
Jeremy Lakeman 2013-05-02 14:27:23 +09:30
parent a29c1d3468
commit 79f4a78278
4 changed files with 32 additions and 17 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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);