Commit 0ddb7103 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Basic filtering infrastructure.

parent 6dc2fe8b
...@@ -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 request.c route.c xroute.c message.c request.c filter.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 request.o route.o xroute.o message.o request.o filter.o
babel: $(OBJS) babel: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o babel $(OBJS) $(LDLIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o babel $(OBJS) $(LDLIBS)
......
/*
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.
*/
int
import_filter(const unsigned char *id,
const unsigned char *prefix, unsigned short plen,
const unsigned char *nexthop)
{
return 0;
}
int
export_filter(const unsigned char *id,
const unsigned char *prefix, unsigned short plen)
{
return 0;
}
/*
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.
*/
int import_filter(const unsigned char *id,
const unsigned char *prefix, unsigned short plen,
const unsigned char *nexthop);
int export_filter(const unsigned char *id,
const unsigned char *prefix, unsigned short plen);
...@@ -36,6 +36,7 @@ THE SOFTWARE. ...@@ -36,6 +36,7 @@ THE SOFTWARE.
#include "xroute.h" #include "xroute.h"
#include "request.h" #include "request.h"
#include "message.h" #include "message.h"
#include "filter.h"
struct timeval update_flush_time = {0, 0}; struct timeval update_flush_time = {0, 0};
...@@ -522,15 +523,17 @@ really_send_update(struct network *net, ...@@ -522,15 +523,17 @@ really_send_update(struct network *net,
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)
{ {
if(in_prefix(address, prefix, plen)) { if(!export_filter(address, prefix, plen)) {
send_message(net, 3, plen, 0, seqno, metric, address); if(in_prefix(address, prefix, plen)) {
} else { send_message(net, 3, plen, 0, seqno, metric, address);
unsigned const char *sid; } else {
start_message(net, 48); unsigned const char *sid;
sid = message_source_id(net); start_message(net, 48);
if(sid == NULL || memcmp(address, sid, 16) != 0) sid = message_source_id(net);
send_message(net, 3, 0xFF, 0, 0, 0xFFFF, address); if(sid == NULL || memcmp(address, sid, 16) != 0)
send_message(net, 4, plen, 0, seqno, metric, prefix); send_message(net, 3, 0xFF, 0, 0, 0xFFFF, address);
send_message(net, 4, plen, 0, seqno, metric, prefix);
}
} }
satisfy_request(prefix, plen, seqno, hash_id(address), net); satisfy_request(prefix, plen, seqno, hash_id(address), net);
} }
......
...@@ -30,6 +30,7 @@ THE SOFTWARE. ...@@ -30,6 +30,7 @@ THE SOFTWARE.
#include "neighbour.h" #include "neighbour.h"
#include "request.h" #include "request.h"
#include "message.h" #include "message.h"
#include "filter.h"
int request_resend_time = 0; int request_resend_time = 0;
struct request *recorded_requests = NULL; struct request *recorded_requests = NULL;
...@@ -69,6 +70,10 @@ record_request(const unsigned char *prefix, unsigned char plen, ...@@ -69,6 +70,10 @@ record_request(const unsigned char *prefix, unsigned char plen,
{ {
struct request *request; struct request *request;
if(import_filter(NULL, prefix, plen, NULL) ||
export_filter(NULL, prefix, plen))
return 0;
request = find_request(prefix, plen, NULL); request = find_request(prefix, plen, NULL);
if(request) { if(request) {
if(request->resend && resend) if(request->resend && resend)
......
...@@ -35,6 +35,7 @@ THE SOFTWARE. ...@@ -35,6 +35,7 @@ THE SOFTWARE.
#include "xroute.h" #include "xroute.h"
#include "message.h" #include "message.h"
#include "request.h" #include "request.h"
#include "filter.h"
struct route routes[MAXROUTES]; struct route routes[MAXROUTES];
int numroutes = 0; int numroutes = 0;
...@@ -318,6 +319,9 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -318,6 +319,9 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
return NULL; return NULL;
} }
if(import_filter(a, p, plen, nexthop->id))
return NULL;
src = find_source(a, p, plen, 1, seqno); src = find_source(a, p, plen, 1, seqno);
if(src == NULL) if(src == NULL)
return NULL; return NULL;
......
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