From a71c3f3c1fd3f99dda004c32396a005c8a4df41d Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Wed, 22 May 2013 11:57:38 +0930 Subject: [PATCH] Don't send broadcast payloads on interfaces with no neighbours --- overlay_queue.c | 19 ++++++++++++------- route_link.c | 14 +++++++++++++- serval.h | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/overlay_queue.c b/overlay_queue.c index fb94bb27..a4e9ae10 100644 --- a/overlay_queue.c +++ b/overlay_queue.c @@ -200,7 +200,8 @@ int overlay_payload_enqueue(struct overlay_frame *p) // make sure there is an interface up that allows broadcasts for(i=0;ibroadcast_sent_via[i]=0; drop=0; }else @@ -297,7 +298,8 @@ overlay_calc_queue_time(overlay_txqueue *queue, struct overlay_frame *frame){ int i; for(i=0;ibroadcast_sent_via[i]) + if (overlay_interfaces[i].state!=INTERFACE_STATE_UP || + frame->broadcast_sent_via[i] || + !link_state_interface_has_neighbour(&overlay_interfaces[i])) continue; keep=1; time_ms_t next_allowed = limit_next_allowed(&overlay_interfaces[i].transfer_limit); @@ -490,18 +494,20 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim // check if there is still a broadcast to be sent for(i=0;ibroadcast_sent_via[i]){ keep_payload=1; break; } + } } } - + if (!keep_payload){ frame = overlay_queue_remove(queue, frame); continue; - } + } skip: // if we can't send the payload now, check when we should try next @@ -547,7 +553,6 @@ overlay_fill_send_packet(struct outgoing_packet *packet, time_ms_t now) { static void overlay_send_packet(struct sched_ent *alarm){ struct outgoing_packet packet; bzero(&packet, sizeof(struct outgoing_packet)); - overlay_fill_send_packet(&packet, gettime_ms()); } diff --git a/route_link.c b/route_link.c index c4cb3020..90c2930c 100644 --- a/route_link.c +++ b/route_link.c @@ -67,7 +67,7 @@ struct neighbour_link{ char unicast; int ack_sequence; - uint32_t ack_mask; + uint64_t ack_mask; }; struct neighbour{ @@ -655,6 +655,18 @@ struct neighbour_link * get_neighbour_link(struct neighbour *neighbour, struct o return link; } +int link_state_interface_has_neighbour(struct overlay_interface *interface) +{ + struct neighbour *neighbour = neighbours; + while(neighbour){ + if (neighbour->best_link && neighbour->best_link->interface == interface) + return 1; + + neighbour = neighbour->_next; + } + return 0; +} + // track stats for receiving packets from this neighbour int link_received_packet(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int sender_seq, int unicast) { diff --git a/serval.h b/serval.h index 64146973..e3c343c3 100644 --- a/serval.h +++ b/serval.h @@ -835,6 +835,7 @@ void link_explained(struct subscriber *subscriber); void link_interface_down(struct overlay_interface *interface); int link_state_announce_links(); int link_state_legacy_ack(struct overlay_frame *frame, time_ms_t now); +int link_state_interface_has_neighbour(struct overlay_interface *interface); int generate_nonce(unsigned char *nonce,int bytes);