From de428f0b8f3a959038d06d00fcf2fb4d2ce156d2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 20 Mar 2013 00:36:31 +0100 Subject: Move send functions to a new source file --- src/CMakeLists.txt | 1 + src/babel.c | 45 +------------------------------ src/babel.h | 1 + src/send.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 44 deletions(-) create mode 100644 src/send.c (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0d880b..b962f38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ include_directories(${GMRF_INCLUDE_DIR}) add_library(mmss_proto_babel MODULE babel.c neigh.c + send.c tlv.c tlv_types.c ) diff --git a/src/babel.c b/src/babel.c index 91cd97b..9ae6ff7 100644 --- a/src/babel.c +++ b/src/babel.c @@ -27,8 +27,6 @@ #include "babel.h" #include "neigh.h" #include "packet.h" -#include "tlv.h" -#include "tlv_types.h" #include @@ -37,51 +35,10 @@ const char *gmrf_protocol_name = "babel"; const char *gmrf_protocol_version = "experimental"; -static void add_ihus(gmrf_t *gmrf, gp_babel_packet_t *packet, size_t max_len, const gp_babel_iface_t *iface) { - const gp_babel_neigh_t *neigh; - - for (neigh = iface->neighbours; neigh; neigh = neigh->next) { - gp_babel_tlv_ihu_t *ihu = gp_babel_tlv_add(packet, GP_BABEL_PACKET_MAX, TLV_IHU, sizeof(gp_babel_tlv_ihu_t)+sizeof(gmrf_addr_t)); - if (!ihu) - return; - - ihu->ae = ADDR_ENC_GMRF; - ihu->reserved = 0; - ihu->rxcost = htons(gp_babel_neigh_get_rxcost(gmrf, neigh)); - ihu->interval = htons(GP_BABEL_IHU_INTERVAL); - memcpy(ihu->address, &neigh->addr, sizeof(gmrf_addr_t)); - } -} - static void send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) { gmrf_schedule(gmrf, send_hellos, NULL, GP_BABEL_HELLO_INTERVAL*10); - gmrf_logf(gmrf, LOG_DEBUG, "sending hellos..."); - - gp_babel_packet_t *packet = alloca(sizeof(gp_babel_packet_t)+GP_BABEL_PACKET_MAX); - - packet->version = htons(GP_BABEL_VERSION); - packet->len = 0; - - gp_babel_tlv_hello_t *hello = gp_babel_tlv_add(packet, GP_BABEL_PACKET_MAX, TLV_HELLO, sizeof(gp_babel_tlv_hello_t)); - if (!hello) - return; - - hello->reserved = 0; - hello->interval = htons(GP_BABEL_HELLO_INTERVAL); - - uint16_t len = packet->len; - - gp_babel_iface_t *iface; - for (iface = ctx->interfaces; iface; iface = iface->next) { - hello->seqno = htons(iface->seqno++); - - packet->len = len; - - add_ihus(gmrf, packet, GP_BABEL_PACKET_MAX, iface); - - gmrf_iface_send_bc(gmrf, iface->gmrf_iface, packet, gp_babel_packet_size(packet)); - } + gp_babel_send_hellos(gmrf, ctx); } static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) { diff --git a/src/babel.h b/src/babel.h index bd044ff..d6224ff 100644 --- a/src/babel.h +++ b/src/babel.h @@ -87,5 +87,6 @@ static inline gp_babel_iface_t* gp_babel_get_iface(gmrf_context_t *ctx, gmrf_ifa void gp_babel_handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t *iface, const gmrf_addr_t *source, const gp_babel_packet_t *packet); +void gp_babel_send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx); #endif /* _GMRF_PROTO_BABEL_BABEL_H_ */ diff --git a/src/send.c b/src/send.c new file mode 100644 index 0000000..5f06218 --- /dev/null +++ b/src/send.c @@ -0,0 +1,79 @@ +/* + Copyright (c) 2013, Matthias Schiffer + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "babel.h" +#include "neigh.h" +#include "packet.h" +#include "tlv.h" +#include "tlv_types.h" + +#include + + +static void add_ihus(gmrf_t *gmrf, gp_babel_packet_t *packet, size_t max_len, const gp_babel_iface_t *iface) { + const gp_babel_neigh_t *neigh; + + for (neigh = iface->neighbours; neigh; neigh = neigh->next) { + gp_babel_tlv_ihu_t *ihu = gp_babel_tlv_add(packet, GP_BABEL_PACKET_MAX, TLV_IHU, sizeof(gp_babel_tlv_ihu_t)+sizeof(gmrf_addr_t)); + if (!ihu) + return; + + ihu->ae = ADDR_ENC_GMRF; + ihu->reserved = 0; + ihu->rxcost = htons(gp_babel_neigh_get_rxcost(gmrf, neigh)); + ihu->interval = htons(GP_BABEL_IHU_INTERVAL); + memcpy(ihu->address, &neigh->addr, sizeof(gmrf_addr_t)); + } +} + +void gp_babel_send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx) { + gmrf_logf(gmrf, LOG_DEBUG, "sending hellos..."); + + gp_babel_packet_t *packet = alloca(sizeof(gp_babel_packet_t)+GP_BABEL_PACKET_MAX); + + packet->version = htons(GP_BABEL_VERSION); + packet->len = 0; + + gp_babel_tlv_hello_t *hello = gp_babel_tlv_add(packet, GP_BABEL_PACKET_MAX, TLV_HELLO, sizeof(gp_babel_tlv_hello_t)); + if (!hello) + return; + + hello->reserved = 0; + hello->interval = htons(GP_BABEL_HELLO_INTERVAL); + + uint16_t len = packet->len; + + gp_babel_iface_t *iface; + for (iface = ctx->interfaces; iface; iface = iface->next) { + hello->seqno = htons(iface->seqno++); + + packet->len = len; + + add_ihus(gmrf, packet, GP_BABEL_PACKET_MAX, iface); + + gmrf_iface_send_bc(gmrf, iface->gmrf_iface, packet, gp_babel_packet_size(packet)); + } +} -- cgit v1.2.3