Add monitor message for interface up/down events

This commit is contained in:
Jeremy Lakeman 2014-06-13 13:34:10 +09:30
parent ee37385ec7
commit 628a52ca87
4 changed files with 19 additions and 0 deletions

View File

@ -103,6 +103,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define MONITOR_DNAHELPER (1<<3) #define MONITOR_DNAHELPER (1<<3)
#define MONITOR_LINKS (1<<4) #define MONITOR_LINKS (1<<4)
#define MONITOR_QUIT (1<<5) #define MONITOR_QUIT (1<<5)
#define MONITOR_INTERFACE (1<<6)
#define MAX_SIGNATURES 16 #define MAX_SIGNATURES 16

View File

@ -61,6 +61,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "str.h" #include "str.h"
#include "strbuf_helpers.h" #include "strbuf_helpers.h"
#include "overlay_address.h" #include "overlay_address.h"
#include "overlay_interface.h"
#include "monitor-client.h" #include "monitor-client.h"
#include "socket.h" #include "socket.h"
#include "dataformats.h" #include "dataformats.h"
@ -422,6 +423,9 @@ static int monitor_set(const struct cli_parsed *parsed, struct cli_context *cont
link_state_announce_links(); link_state_announce_links();
}else if (strcase_startswith(parsed->args[1],"quit", NULL)){ }else if (strcase_startswith(parsed->args[1],"quit", NULL)){
c->flags|=MONITOR_QUIT; c->flags|=MONITOR_QUIT;
}else if (strcase_startswith(parsed->args[1],"interface", NULL)){
c->flags|=MONITOR_INTERFACE;
overlay_interface_monitor_up();
}else }else
return monitor_write_error(c,"Unknown monitor type"); return monitor_write_error(c,"Unknown monitor type");
@ -447,6 +451,8 @@ static int monitor_clear(const struct cli_parsed *parsed, struct cli_context *co
c->flags&=~MONITOR_LINKS; c->flags&=~MONITOR_LINKS;
else if (strcase_startswith(parsed->args[1],"quit", NULL)) else if (strcase_startswith(parsed->args[1],"quit", NULL))
c->flags&=~MONITOR_QUIT; c->flags&=~MONITOR_QUIT;
else if (strcase_startswith(parsed->args[1],"interface", NULL))
c->flags&=~MONITOR_INTERFACE;
else else
return monitor_write_error(c,"Unknown monitor type"); return monitor_write_error(c,"Unknown monitor type");

View File

@ -60,6 +60,7 @@ static void overlay_interface_poll(struct sched_ent *alarm);
static void static void
overlay_interface_close(overlay_interface *interface){ overlay_interface_close(overlay_interface *interface){
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:DOWN\n", interface->name);
INFOF("Interface %s addr %s is down", INFOF("Interface %s addr %s is down",
interface->name, alloca_socket_address(&interface->address)); interface->name, alloca_socket_address(&interface->address));
if (interface->address.addr.sa_family == AF_UNIX) if (interface->address.addr.sa_family == AF_UNIX)
@ -84,6 +85,15 @@ void overlay_interface_close_all()
} }
} }
void overlay_interface_monitor_up()
{
unsigned i;
for (i=0;i<OVERLAY_MAX_INTERFACES;i++){
if (overlay_interfaces[i].state == INTERFACE_STATE_UP)
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:UP\n", overlay_interfaces[i].name);
}
}
void interface_state_html(struct strbuf *b, struct overlay_interface *interface) void interface_state_html(struct strbuf *b, struct overlay_interface *interface)
{ {
switch(interface->state){ switch(interface->state){
@ -537,6 +547,7 @@ overlay_interface_init(const char *name, struct socket_address *addr,
interface->alarm.deadline=interface->alarm.alarm; interface->alarm.deadline=interface->alarm.alarm;
schedule(&interface->alarm); schedule(&interface->alarm);
interface->state=INTERFACE_STATE_UP; interface->state=INTERFACE_STATE_UP;
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:UP\n", interface->name);
INFOF("Interface %s addr %s, is up",interface->name, alloca_socket_address(addr)); INFOF("Interface %s addr %s, is up",interface->name, alloca_socket_address(addr));
directory_registration(); directory_registration();

View File

@ -160,5 +160,6 @@ overlay_interface * overlay_interface_find_name(const char *name);
int overlay_interface_compare(overlay_interface *one, overlay_interface *two); int overlay_interface_compare(overlay_interface *one, overlay_interface *two);
int overlay_broadcast_ensemble(struct network_destination *destination, struct overlay_buffer *buffer); int overlay_broadcast_ensemble(struct network_destination *destination, struct overlay_buffer *buffer);
void interface_state_html(struct strbuf *b, struct overlay_interface *interface); void interface_state_html(struct strbuf *b, struct overlay_interface *interface);
void overlay_interface_monitor_up();
#endif // __SERVAL_DNA__OVERLAY_INTERFACE_H #endif // __SERVAL_DNA__OVERLAY_INTERFACE_H