Commit 77b753a1 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement forwarding of replies.

parent f1f3076c
...@@ -7,10 +7,10 @@ DEFINES = $(PLATFORM_DEFINES) ...@@ -7,10 +7,10 @@ DEFINES = $(PLATFORM_DEFINES)
CFLAGS = $(CDEBUGFLAGS) $(DEFINES) $(EXTRA_DEFINES) CFLAGS = $(CDEBUGFLAGS) $(DEFINES) $(EXTRA_DEFINES)
SRCS = babel.c net.c kernel.c util.c source.c neighbour.c \ SRCS = babel.c net.c kernel.c util.c source.c neighbour.c \
route.c xroute.c message.c route.c xroute.c message.c request.c
OBJS = babel.o net.o kernel.o util.o source.o neighbour.o \ OBJS = babel.o net.o kernel.o util.o source.o neighbour.o \
route.o xroute.o message.o route.o xroute.o message.o request.o
babel: $(OBJS) babel: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o babel $(OBJS) $(LDLIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o babel $(OBJS) $(LDLIBS)
......
...@@ -47,6 +47,7 @@ THE SOFTWARE. ...@@ -47,6 +47,7 @@ THE SOFTWARE.
#include "route.h" #include "route.h"
#include "xroute.h" #include "xroute.h"
#include "message.h" #include "message.h"
#include "request.h"
struct timeval now; struct timeval now;
...@@ -497,6 +498,7 @@ main(int argc, char **argv) ...@@ -497,6 +498,7 @@ main(int argc, char **argv)
if(now.tv_sec >= expiry_time) { if(now.tv_sec >= expiry_time) {
expire_routes(); expire_routes();
expire_requests();
expiry_time = now.tv_sec + 20 + random() % 20; expiry_time = now.tv_sec + 20 + random() % 20;
} }
......
...@@ -34,6 +34,7 @@ THE SOFTWARE. ...@@ -34,6 +34,7 @@ THE SOFTWARE.
#include "neighbour.h" #include "neighbour.h"
#include "route.h" #include "route.h"
#include "xroute.h" #include "xroute.h"
#include "request.h"
#include "message.h" #include "message.h"
struct timeval update_flush_time = {0, 0}; struct timeval update_flush_time = {0, 0};
...@@ -248,7 +249,8 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix, ...@@ -248,7 +249,8 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
if(hop_count > 1) { if(hop_count > 1) {
send_unicast_request(route->nexthop, prefix, plen, send_unicast_request(route->nexthop, prefix, plen,
hop_count - 1, seqno, router_hash); hop_count - 1, seqno, router_hash);
/* We should record sending this request at this point. */ record_request(prefix, plen, seqno, router_hash,
neigh->network);
} }
} else { } else {
send_update(neigh->network, 1, prefix, plen); send_update(neigh->network, 1, prefix, plen);
...@@ -512,7 +514,8 @@ static void ...@@ -512,7 +514,8 @@ static void
really_send_update(struct network *net, really_send_update(struct network *net,
const unsigned char *address, const unsigned char *address,
const unsigned char *prefix, unsigned char plen, const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short metric) unsigned short seqno, unsigned short metric,
unsigned short router_hash)
{ {
if(in_prefix(address, prefix, plen)) { if(in_prefix(address, prefix, plen)) {
send_message(net, 3, plen, 0, seqno, metric, address); send_message(net, 3, plen, 0, seqno, metric, address);
...@@ -524,6 +527,7 @@ really_send_update(struct network *net, ...@@ -524,6 +527,7 @@ really_send_update(struct network *net,
send_message(net, 3, 0xFF, 0, 0, 0xFFFF, address); send_message(net, 3, 0xFF, 0, 0, 0xFFFF, address);
send_message(net, 4, plen, 0, seqno, metric, prefix); send_message(net, 4, plen, 0, seqno, metric, prefix);
} }
satisfy_request(prefix, plen, seqno, router_hash, net);
} }
void void
...@@ -551,7 +555,8 @@ flushupdates(void) ...@@ -551,7 +555,8 @@ flushupdates(void)
if(xroute) { if(xroute) {
really_send_update(net, myid, really_send_update(net, myid,
xroute->prefix, xroute->plen, xroute->prefix, xroute->plen,
myseqno, xroute->metric); myseqno, xroute->metric,
hash_id(myid));
continue; continue;
} }
route = find_installed_route(buffered_updates[i].prefix, route = find_installed_route(buffered_updates[i].prefix,
...@@ -565,7 +570,8 @@ flushupdates(void) ...@@ -565,7 +570,8 @@ flushupdates(void)
really_send_update(net, route->src->address, really_send_update(net, route->src->address,
route->src->prefix, route->src->prefix,
route->src->plen, route->src->plen,
seqno, metric); seqno, metric,
hash_id(route->src->address));
update_source(route->src, seqno, metric); update_source(route->src, seqno, metric);
continue; continue;
} }
...@@ -575,7 +581,7 @@ flushupdates(void) ...@@ -575,7 +581,7 @@ flushupdates(void)
really_send_update(net, src->address, src->prefix, src->plen, really_send_update(net, src->address, src->prefix, src->plen,
src->metric >= INFINITY ? src->metric >= INFINITY ?
src->seqno : seqno_plus(src->seqno, 1), src->seqno : seqno_plus(src->seqno, 1),
INFINITY); INFINITY, hash_id(src->address));
continue; continue;
} }
} }
...@@ -628,6 +634,20 @@ send_update(struct network *net, int urgent, ...@@ -628,6 +634,20 @@ send_update(struct network *net, int urgent,
const unsigned char *prefix, unsigned char plen) const unsigned char *prefix, unsigned char plen)
{ {
int i; int i;
struct request *request;
/* This is needed here, since really_send_update only handles the
case where network is not null. */
request = find_request(prefix, plen, NULL);
if(request) {
struct route *route;
route = find_installed_route(prefix, plen);
if(route) {
urgent = 1;
satisfy_request(prefix, plen, route->seqno,
hash_id(route->src->address), net);
}
}
if(net == NULL) { if(net == NULL) {
for(i = 0; i < numnets; i++) for(i = 0; i < numnets; i++)
...@@ -722,7 +742,7 @@ send_self_retract(struct network *net) ...@@ -722,7 +742,7 @@ send_self_retract(struct network *net)
for(i = 0; i < numxroutes; i++) { for(i = 0; i < numxroutes; i++) {
if(xroutes[i].exported) if(xroutes[i].exported)
really_send_update(net, myid, xroutes[i].prefix, xroutes[i].plen, really_send_update(net, myid, xroutes[i].prefix, xroutes[i].plen,
myseqno, 0xFFFF); myseqno, 0xFFFF, hash_id(myid));
} }
schedule_update_flush(net, 1); schedule_update_flush(net, 1);
} }
......
/*
Copyright (c) 2007 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include "babel.h"
#include "util.h"
#include "neighbour.h"
#include "request.h"
struct request *recorded_requests = NULL;
static int
request_match(struct request *request,
const unsigned char *prefix, unsigned char plen)
{
return request->plen == plen && memcmp(request->prefix, prefix, 16) == 0;
}
struct request *
find_request(const unsigned char *prefix, unsigned char plen,
struct request **previous_return)
{
struct request *request, *previous;
previous = NULL;
request = recorded_requests;
while(request) {
if(request_match(request, prefix, plen)) {
if(previous_return)
*previous_return = previous;
return request;
}
previous = request;
request = request->next;
}
return NULL;
}
int
record_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *network)
{
struct request *request;
request = find_request(prefix, plen, NULL);
if(request) {
if(request->router_hash == router_hash ||
seqno_compare(request->seqno, seqno) > 0) {
return 0;
} else {
request->router_hash = router_hash;
request->seqno = seqno;
request->time = now.tv_sec;
if(request->network != network)
request->network = NULL;
return 1;
}
} else {
request = malloc(sizeof(struct request));
if(request == NULL)
return -1;
memcpy(request->prefix, prefix, 16);
request->plen = plen;
request->seqno = seqno;
request->router_hash = router_hash;
request->time = now.tv_sec;
request->network = network;
request->next = recorded_requests;
recorded_requests = request;
return 1;
}
}
int
satisfy_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *network)
{
struct request *request, *previous;
request = find_request(prefix, plen, &previous);
if(request == NULL)
return 0;
if(network != NULL && request->network != network)
return 0;
if(request->router_hash != router_hash ||
seqno_compare(request->seqno, seqno) <= 0) {
if(previous == NULL)
recorded_requests = request->next;
else
previous->next = request->next;
free(request);
return 1;
}
return 0;
}
void
expire_requests()
{
struct request *request, *previous;
previous = NULL;
request = recorded_requests;
while(request) {
if(request->time < now.tv_sec - 60) {
if(previous == NULL) {
recorded_requests = request->next;
request = recorded_requests;
} else {
previous->next = request->next;
request = previous->next;
}
free(request);
} else {
request = request->next;
}
}
}
/*
Copyright (c) 2007 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
struct request {
unsigned char prefix[16];
unsigned char plen;
unsigned short seqno;
unsigned short router_hash;
struct network *network;
int time;
struct request *next;
};
struct request *find_request(const unsigned char *prefix, unsigned char plen,
struct request **previous_return);
int record_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *net);
int satisfy_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *net);
void expire_requests(void);
...@@ -34,6 +34,7 @@ THE SOFTWARE. ...@@ -34,6 +34,7 @@ THE SOFTWARE.
#include "route.h" #include "route.h"
#include "xroute.h" #include "xroute.h"
#include "message.h" #include "message.h"
#include "request.h"
struct route routes[MAXROUTES]; struct route routes[MAXROUTES];
int numroutes = 0; int numroutes = 0;
...@@ -452,7 +453,8 @@ send_triggered_update(struct route *route, struct source *oldsrc, int oldmetric) ...@@ -452,7 +453,8 @@ send_triggered_update(struct route *route, struct source *oldsrc, int oldmetric)
/* Switching sources can cause transient routing loops, so always send /* Switching sources can cause transient routing loops, so always send
updates in that case. Retractions are always urgent. */ updates in that case. Retractions are always urgent. */
urgent = (route->src != oldsrc) || urgent = (route->src != oldsrc) ||
(oldmetric < INFINITY && newmetric >= INFINITY); (oldmetric < INFINITY && newmetric >= INFINITY) ||
find_request(route->src->prefix, route->src->plen, NULL);
if(urgent || if(urgent ||
(newmetric >= oldmetric + 256 || oldmetric >= newmetric + 256)) (newmetric >= oldmetric + 256 || oldmetric >= newmetric + 256))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment