diff --git a/headerfiles.mk b/headerfiles.mk index b7c96e91..595f628d 100644 --- a/headerfiles.mk +++ b/headerfiles.mk @@ -15,6 +15,7 @@ HDRS= fifo.h \ serval_types.h \ serval.h \ server.h \ + route_link.h \ keyring.h \ socket.h \ cli.h \ diff --git a/keyring.c b/keyring.c index 1d61a0dd..86570809 100644 --- a/keyring.c +++ b/keyring.c @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "mem.h" #include "rotbuf.h" #include "server.h" +#include "route_link.h" static keyring_file *keyring_open_or_create(const char *path, int writeable); static int keyring_initialise(keyring_file *k); diff --git a/monitor.c b/monitor.c index 1f8f8c21..4b9be052 100644 --- a/monitor.c +++ b/monitor.c @@ -66,6 +66,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "socket.h" #include "dataformats.h" #include "server.h" +#include "route_link.h" #ifdef HAVE_UCRED_H #include diff --git a/overlay_address.c b/overlay_address.c index 0311d62e..662971ca 100644 --- a/overlay_address.c +++ b/overlay_address.c @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "overlay_interface.h" #include "overlay_packet.h" #include "server.h" +#include "route_link.h" #define MAX_BPIS 1024 #define BPI_MASK 0x3ff diff --git a/overlay_interface.c b/overlay_interface.c index 865d3e35..934ec462 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "str.h" #include "radio_link.h" #include "server.h" +#include "route_link.h" #ifdef HAVE_IFADDRS_H #include diff --git a/overlay_link.c b/overlay_link.c index 7210221b..c1c17593 100644 --- a/overlay_link.c +++ b/overlay_link.c @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "overlay_packet.h" #include "keyring.h" #include "strbuf_helpers.h" +#include "route_link.h" int set_reachable(struct subscriber *subscriber, struct network_destination *destination, struct subscriber *next_hop){ diff --git a/overlay_mdp_services.c b/overlay_mdp_services.c index 8e3a0078..6e419ae1 100644 --- a/overlay_mdp_services.c +++ b/overlay_mdp_services.c @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "debug.h" #include "keyring.h" #include "dataformats.h" +#include "route_link.h" int rhizome_mdp_send_block(struct subscriber *dest, const rhizome_bid_t *bid, uint64_t version, uint64_t fileOffset, uint32_t bitmap, uint16_t blockLength) { diff --git a/overlay_olsr.c b/overlay_olsr.c index e1708388..9680e1f1 100644 --- a/overlay_olsr.c +++ b/overlay_olsr.c @@ -66,6 +66,7 @@ #include "overlay_packet.h" #include "overlay_buffer.h" #include "overlay_address.h" +#include "route_link.h" #define PACKET_FORMAT_NUMBER 123 diff --git a/overlay_packetformats.c b/overlay_packetformats.c index 4218b35c..9203d880 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "overlay_buffer.h" #include "overlay_interface.h" #include "overlay_packet.h" - +#include "route_link.h" struct sockaddr_in loopback; @@ -260,7 +260,7 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface *interface, struct socket_address *addr, struct overlay_buffer *buffer){ IN(); - + context->interface = interface; if (interface->ifconfig.point_to_point && interface->other_device) context->point_to_point_device = interface->other_device; @@ -422,7 +422,10 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s unsigned char *current = ob_ptr(b)+ob_position(b); if (IF_DEBUG(overlayframes)) dump("Payload Header", header_start, current - header_start); - ret = WHYF("Invalid payload length (%zd)", payload_len); + ret = WHYF("Payload length %zd suggests frame should be %zd bytes, but was only %zd", + payload_len, ob_position(b)+payload_len, len); + + // TODO signal reduced MTU? goto end; } break; diff --git a/overlay_queue.c b/overlay_queue.c index fcb76c6b..48e00a94 100644 --- a/overlay_queue.c +++ b/overlay_queue.c @@ -26,6 +26,7 @@ #include "radio_link.h" #include "str.h" #include "strbuf.h" +#include "route_link.h" typedef struct overlay_txqueue { struct overlay_frame *first; diff --git a/route_link.c b/route_link.c index 4a9a28f3..f617a018 100644 --- a/route_link.c +++ b/route_link.c @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "keyring.h" #include "server.h" #include "mdp_client.h" +#include "route_link.h" /* Link state routing; @@ -746,6 +747,22 @@ int link_interface_has_neighbours(struct overlay_interface *interface) return 0; } +int link_destination_has_neighbours(struct network_destination *dest) +{ + struct neighbour *n = neighbours; + time_ms_t now = gettime_ms(); + while(n){ + struct link_out *l = n->out_links; + while(l){ + if (l->destination == dest && l->timeout >= now) + return 1; + l=l->_next; + } + n=n->_next; + } + return 0; +} + static int send_legacy_self_announce_ack(struct neighbour *neighbour, struct link_in *link, time_ms_t now){ struct overlay_frame *frame=emalloc_zero(sizeof(struct overlay_frame)); frame->type = OF_TYPE_SELFANNOUNCE_ACK; @@ -1232,7 +1249,7 @@ static void create_out_links(struct neighbour *neighbour, overlay_interface *int } // track stats for receiving packets from this neighbour -int link_received_packet(struct decode_context *context, int sender_seq, char unicast) +int link_received_packet(struct decode_context *context, int sender_seq, uint8_t unicast) { if (!context->sender) return 0; diff --git a/route_link.h b/route_link.h new file mode 100644 index 00000000..9aa1bcf6 --- /dev/null +++ b/route_link.h @@ -0,0 +1,49 @@ +/* +Serval DNA header file +Copyright (C) 2015 Serval Project Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef __SERVAL_DNA__ROUTE_LINK_H +#define __SERVAL_DNA__ROUTE_LINK_H + +struct strbuf; +struct overlay_interface; +struct network_destination; +struct subscriber; +struct overlay_frame; +struct decode_context; +struct internal_mdp_header; + +int link_state_announce_links(); +void link_neighbour_short_status_html(struct strbuf *b, const char *link_prefix); +void link_neighbour_status_html(struct strbuf *b, struct subscriber *neighbour); +int link_has_neighbours(); +int link_interface_has_neighbours(struct overlay_interface *interface); +int link_destination_has_neighbours(struct network_destination *dest); +int link_stop_routing(struct subscriber *subscriber); +int link_add_destinations(struct overlay_frame *frame); +int link_state_should_forward_broadcast(struct subscriber *transmitter); +int link_state_ack_soon(struct subscriber *subscriber); +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); +int link_receive(struct internal_mdp_header *header, struct overlay_buffer *payload); +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 diff --git a/serval.h b/serval.h index ce8b1236..a67df4ff 100644 --- a/serval.h +++ b/serval.h @@ -302,21 +302,4 @@ int unpack_uint(unsigned char *buffer, int buff_size, uint64_t *v); void rhizome_fetch_log_short_status(); extern char crash_handler_clue[1024]; -int link_received_duplicate(struct decode_context *context, int payload_seq); -int link_received_packet(struct decode_context *context, int sender_seq, char unicast); -int link_receive(struct internal_mdp_header *header, struct overlay_buffer *payload); -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_ack_soon(struct subscriber *sender); -int link_state_should_forward_broadcast(struct subscriber *transmitter); -int link_unicast_ack(struct subscriber *subscriber, struct overlay_interface *interface, struct socket_address *addr); -int link_add_destinations(struct overlay_frame *frame); -void link_neighbour_short_status_html(struct strbuf *b, const char *link_prefix); -void link_neighbour_status_html(struct strbuf *b, struct subscriber *neighbour); -int link_stop_routing(struct subscriber *subscriber); -int link_has_neighbours(); -int link_interface_has_neighbours(struct overlay_interface *interface); - #endif // __SERVAL_DNA__SERVAL_H diff --git a/server.c b/server.c index e45da876..d7936b1e 100644 --- a/server.c +++ b/server.c @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "keyring.h" #include "commandline.h" #include "mdp_client.h" +#include "route_link.h" #define PROC_SUBDIR "proc" #define PIDFILE_NAME "servald.pid" diff --git a/server_httpd.c b/server_httpd.c index 59a1c82b..095f022a 100644 --- a/server_httpd.c +++ b/server_httpd.c @@ -5,6 +5,7 @@ #include "overlay_address.h" #include "overlay_interface.h" #include "os.h" +#include "route_link.h" DECLARE_HANDLER("/static/", static_page); DECLARE_HANDLER("/interface/", interface_page);