From cf8932d5ba4eb27e3180db182e6d7b16fff796bb Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 8 Mar 2016 10:16:20 +1030 Subject: [PATCH] Use trigger for interface up/down --- directory_client.c | 5 +++++ monitor.c | 11 +++++++++++ overlay_interface.c | 10 +++------- overlay_interface.h | 2 ++ route_link.c | 4 +++- route_link.h | 1 - 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/directory_client.c b/directory_client.c index 2a90dcf0..f7e1dba0 100644 --- a/directory_client.c +++ b/directory_client.c @@ -137,3 +137,8 @@ int directory_registration(){ return 0; } +static void interface_change(struct overlay_interface *UNUSED(interface)){ + directory_registration(); +} + +DEFINE_TRIGGER(iupdown, interface_change); diff --git a/monitor.c b/monitor.c index 4b9be052..a2a8bdc2 100644 --- a/monitor.c +++ b/monitor.c @@ -685,3 +685,14 @@ int monitor_tell_formatted(int mask, char *fmt, ...){ monitor_tell_clients(msg, n, mask); return 0; } + +static void monitor_interface_change(struct overlay_interface *interface){ + if (interface->state==INTERFACE_STATE_UP) + monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:UP\n", interface->name); + else if(interface->state==INTERFACE_STATE_DOWN) + monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:DOWN\n", interface->name); +} + +DEFINE_TRIGGER(iupdown, monitor_interface_change); + + diff --git a/overlay_interface.c b/overlay_interface.c index f86e4dfb..2572dff3 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -88,11 +88,10 @@ void overlay_interface_close(overlay_interface *interface) radio_link_free(interface); interface->state=INTERFACE_STATE_DOWN; - monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:DOWN\n", interface->name); INFOF("Interface %s addr %s is down", interface->name, alloca_socket_address(&interface->address)); + CALL_TRIGGER(iupdown, interface); - link_interface_down(interface); } void overlay_interface_close_all() @@ -649,15 +648,12 @@ overlay_interface_init(const char *name, return -1; 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)); - - directory_registration(); - INFOF("Allowing a maximum of %d packets every %"PRId64"ms", interface->destination->transfer_limit.burst_size, interface->destination->transfer_limit.burst_length); - + + CALL_TRIGGER(iupdown, interface); return 0; cleanup: diff --git a/overlay_interface.h b/overlay_interface.h index 23157373..21c0c67c 100644 --- a/overlay_interface.h +++ b/overlay_interface.h @@ -136,4 +136,6 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o void interface_state_html(struct strbuf *b, struct overlay_interface *interface); void overlay_interface_monitor_up(); +DECLARE_TRIGGER(iupdown, struct overlay_interface *); + #endif // __SERVAL_DNA__OVERLAY_INTERFACE_H diff --git a/route_link.c b/route_link.c index df455543..f9d05fdc 100644 --- a/route_link.c +++ b/route_link.c @@ -1580,11 +1580,13 @@ void link_explained(struct subscriber *subscriber) update_alarm(__WHENCE__, now + 5); } -void link_interface_down(struct overlay_interface *UNUSED(interface)) +static void link_interface_change(struct overlay_interface *UNUSED(interface)) { clean_neighbours(gettime_ms()); } +DEFINE_TRIGGER(iupdown, link_interface_change); + /* if an ancient node on the network uses their old protocol to tell us that they can hear us; - send the same format back at them - treat the link as up. diff --git a/route_link.h b/route_link.h index 7328eec4..9676c909 100644 --- a/route_link.h +++ b/route_link.h @@ -42,7 +42,6 @@ int link_received_duplicate(struct decode_context *context, int payload_seq); int link_received_packet(struct decode_context *context, int sender_seq, uint8_t unicast); int link_unicast_ack(struct subscriber *subscriber, struct overlay_interface *interface, struct socket_address *addr); void link_explained(struct subscriber *subscriber); -void link_interface_down(struct overlay_interface *interface); int link_state_legacy_ack(struct overlay_frame *frame, time_ms_t now); #endif