1998-07-10 03:39:04 +08:00
|
|
|
/*
|
|
|
|
* Rest in pieces - RIP protocol
|
|
|
|
*
|
1998-10-08 03:33:50 +08:00
|
|
|
* Copyright (c) 1998 Pavel Machek <pavel@ucw.cz>
|
1998-07-10 03:39:04 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOCAL_DEBUG
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
|
|
|
#include "lib/socket.h"
|
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/lists.h"
|
|
|
|
#include "lib/timer.h"
|
|
|
|
|
|
|
|
#include "rip.h"
|
|
|
|
|
|
|
|
int infinity = 16;
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: should be 520 */
|
1998-07-10 03:39:04 +08:00
|
|
|
#define RIP_PORT 1520
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: should be 30 */
|
1998-07-29 05:44:11 +08:00
|
|
|
#define RIP_TIME 5
|
1998-07-10 03:39:04 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
rip_reply(struct proto *p)
|
|
|
|
{
|
1998-07-30 15:43:45 +08:00
|
|
|
#if 0
|
1998-07-10 03:39:04 +08:00
|
|
|
P->listen->tbuf = "ACK!";
|
|
|
|
sk_send_to( P->listen, 5, P->listen->faddr, P->listen->fport );
|
1998-07-30 15:43:45 +08:00
|
|
|
#endif
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
/*
|
|
|
|
* Entries
|
|
|
|
*/
|
1998-07-10 03:39:04 +08:00
|
|
|
|
|
|
|
static struct rip_entry *
|
1998-10-08 03:33:50 +08:00
|
|
|
find_entry( struct proto *p, ip_addr network, int pxlen )
|
1998-07-10 03:39:04 +08:00
|
|
|
{
|
|
|
|
struct node *e;
|
|
|
|
|
|
|
|
CHK_MAGIC;
|
|
|
|
WALK_LIST( e, P->rtable ) {
|
|
|
|
if (ipa_equal( network, E->network ) &&
|
1998-10-08 03:33:50 +08:00
|
|
|
(pxlen == E->pxlen)) {
|
1998-07-10 03:39:04 +08:00
|
|
|
return E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* Let main routing table know about our new entry */
|
|
|
|
static void
|
|
|
|
advertise_entry( struct proto *p, struct rip_entry *e )
|
|
|
|
{
|
|
|
|
rta *a, A;
|
|
|
|
rte *r;
|
|
|
|
net *n;
|
|
|
|
|
|
|
|
bzero(&A, sizeof(A));
|
|
|
|
A.proto = p;
|
|
|
|
A.source = RTS_RIP;
|
|
|
|
A.scope = SCOPE_UNIVERSE;
|
|
|
|
A.cast = RTC_UNICAST;
|
|
|
|
A.dest = RTD_ROUTER;
|
|
|
|
A.tos = 0;
|
|
|
|
A.flags = 0;
|
|
|
|
A.gw = e->nexthop;
|
|
|
|
A.from = e->whotoldme;
|
|
|
|
A.iface = /* FIXME: need to set somehow */ NULL;
|
|
|
|
/* set to: interface of nexthop */
|
|
|
|
a = rta_lookup(&A);
|
|
|
|
n = net_get( &master_table, 0, e->network, e->pxlen );
|
|
|
|
r = rte_get_temp(a);
|
|
|
|
r->pflags = 0; /* Here go my flags */
|
|
|
|
rte_update( n, p, r );
|
|
|
|
}
|
|
|
|
|
1998-07-10 03:39:04 +08:00
|
|
|
static struct rip_entry *
|
1998-10-08 03:33:50 +08:00
|
|
|
new_entry( struct proto *p )
|
1998-07-10 03:39:04 +08:00
|
|
|
{
|
|
|
|
struct rip_entry *e;
|
|
|
|
e = mb_alloc(p->pool, sizeof( struct rip_entry ));
|
1998-10-08 03:33:50 +08:00
|
|
|
bzero( e, sizeof( struct rip_entry ));
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new entry from data rip_block */
|
|
|
|
static struct rip_entry *
|
|
|
|
new_entry_from_block( struct proto *p, struct rip_block *b, ip_addr whotoldme )
|
|
|
|
{
|
|
|
|
struct rip_entry *e = new_entry( p );
|
|
|
|
|
1998-07-10 03:39:04 +08:00
|
|
|
e->whotoldme = whotoldme;
|
1998-07-29 05:44:11 +08:00
|
|
|
e->network = b->network;
|
|
|
|
e->pxlen = ipa_mklen( b->netmask );
|
1998-07-10 03:39:04 +08:00
|
|
|
/* FIXME: verify that it is really netmask */
|
1998-07-29 05:44:11 +08:00
|
|
|
if (ipa_nonzero(b->nexthop))
|
|
|
|
e->nexthop = b->nexthop;
|
1998-07-10 03:39:04 +08:00
|
|
|
else
|
|
|
|
e->nexthop = whotoldme;
|
|
|
|
e->tag = ntohs( b->tag );
|
|
|
|
e->metric = ntohl( b->metric );
|
|
|
|
e->updated = e->changed = now;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* Delete one of entries */
|
1998-07-10 03:39:04 +08:00
|
|
|
static void
|
1998-10-08 03:33:50 +08:00
|
|
|
kill_entry_ourrt( struct proto *p, struct rip_entry *e )
|
1998-07-10 03:39:04 +08:00
|
|
|
{
|
|
|
|
struct rip_connection *c;
|
1998-07-29 05:44:11 +08:00
|
|
|
net *n;
|
|
|
|
|
1998-07-10 03:39:04 +08:00
|
|
|
rem_node( NODE e );
|
|
|
|
WALK_LIST( c, P->connections ) {
|
1998-10-08 03:33:50 +08:00
|
|
|
if (c->sendptr == e) {
|
|
|
|
debug( "Deleting from under someone's sendptr...\n" );
|
|
|
|
c->sendptr = (void *) (NODE c->sendptr)->next;
|
|
|
|
}
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
mb_free( e );
|
|
|
|
}
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* Delete one of entries */
|
|
|
|
static void
|
|
|
|
kill_entry_mainrt( struct proto *p, struct rip_entry *e )
|
|
|
|
{
|
|
|
|
struct rip_connection *c;
|
|
|
|
net *n;
|
|
|
|
|
|
|
|
n = net_find(&master_table, 0, e->network, e->pxlen );
|
|
|
|
if (!n) log( L_ERR "Could not find entry to delete in main routing table.\n" );
|
|
|
|
else rte_update( n, p, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kill_entry( struct proto *p, struct rip_entry *e )
|
|
|
|
{
|
|
|
|
kill_entry_mainrt( p, e );
|
|
|
|
kill_entry_ourrt( p, e );
|
|
|
|
}
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
/*
|
|
|
|
* Output processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_tx_err( sock *s, int err )
|
|
|
|
{
|
|
|
|
struct rip_connection *c = s->data;
|
|
|
|
struct proto *p = c->proto;
|
|
|
|
log( L_ERR "Unexpected error at rip transmit\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_tx( sock *s )
|
|
|
|
{
|
|
|
|
struct rip_connection *c = s->data;
|
|
|
|
struct proto *p = c->proto;
|
|
|
|
struct rip_packet *packet = (void *) s->tbuf;
|
|
|
|
int i, done = 0;
|
|
|
|
|
|
|
|
givemore:
|
|
|
|
|
|
|
|
debug( "Preparing packet to send: " );
|
|
|
|
|
|
|
|
if (!(NODE c->sendptr)->next) {
|
|
|
|
debug( "Looks like I'm done\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-07-30 15:43:45 +08:00
|
|
|
packet->heading.command = RIPCMD_RESPONSE;
|
1998-07-29 05:44:11 +08:00
|
|
|
packet->heading.version = RIP_V2;
|
1998-07-30 15:43:45 +08:00
|
|
|
packet->heading.unused = 0;
|
1998-07-29 05:44:11 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 25; i++) {
|
|
|
|
if (!(NODE c->sendptr)->next)
|
|
|
|
break;
|
|
|
|
debug( "." );
|
1998-07-30 15:43:45 +08:00
|
|
|
packet->block[i].family = htons( 2 ); /* AF_INET */
|
1998-10-08 03:33:50 +08:00
|
|
|
packet->block[i].tag = htons( 0 ); /* FIXME: What should I set it to? */
|
1998-07-29 05:44:11 +08:00
|
|
|
packet->block[i].network = c->sendptr->network;
|
|
|
|
packet->block[i].netmask = ipa_mkmask( c->sendptr->pxlen );
|
|
|
|
packet->block[i].nexthop = IPA_NONE; /* FIXME: How should I set it? */
|
|
|
|
packet->block[i].metric = htonl( c->sendptr->metric );
|
1998-10-08 03:33:50 +08:00
|
|
|
if (ipa_equal(c->sendptr->whotoldme, s->daddr)) {
|
|
|
|
debug( "(split horizont)" );
|
|
|
|
/* FIXME: should we do it in all cases? */
|
|
|
|
packet->block[i].metric = infinity;
|
|
|
|
}
|
1998-07-29 05:44:11 +08:00
|
|
|
ipa_hton( packet->block[i].network );
|
|
|
|
ipa_hton( packet->block[i].netmask );
|
|
|
|
ipa_hton( packet->block[i].nexthop );
|
|
|
|
|
|
|
|
c->sendptr = (void *) (NODE c->sendptr)->next;
|
|
|
|
}
|
|
|
|
|
1998-07-30 15:43:45 +08:00
|
|
|
debug( ", sending %d blocks, ", i );
|
1998-07-29 05:44:11 +08:00
|
|
|
|
1998-07-30 15:43:45 +08:00
|
|
|
i = sk_send( s, sizeof( struct rip_packet_heading ) + i*sizeof( struct rip_block ) );
|
1998-07-29 05:44:11 +08:00
|
|
|
if (i<0) rip_tx_err( s, i );
|
|
|
|
if (i>0) {
|
|
|
|
debug( "it wants more\n" );
|
|
|
|
goto givemore;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug( "blocked\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_sendto( struct proto *p, ip_addr daddr, int dport )
|
|
|
|
{
|
|
|
|
struct rip_connection *c = mb_alloc( p->pool, sizeof( struct rip_connection ));
|
|
|
|
static int num = 0;
|
|
|
|
|
|
|
|
c->addr = daddr;
|
|
|
|
c->proto = p;
|
|
|
|
c->num = num++;
|
|
|
|
|
|
|
|
c->send = sk_new( p->pool );
|
|
|
|
c->send->type = SK_UDP;
|
|
|
|
c->send->sport = RIP_PORT;
|
|
|
|
c->send->dport = dport;
|
|
|
|
c->send->daddr = daddr;
|
|
|
|
c->send->rx_hook = NULL;
|
|
|
|
c->send->tx_hook = rip_tx;
|
|
|
|
c->send->err_hook = rip_tx_err;
|
|
|
|
c->send->data = c;
|
|
|
|
c->send->tbuf = mb_alloc( p->pool, sizeof( struct rip_packet ));
|
|
|
|
if (sk_open(c->send)<0) {
|
1998-07-30 15:43:45 +08:00
|
|
|
log( L_ERR "Could not open socket for data send to %I:%d\n", daddr, dport );
|
1998-07-29 05:44:11 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->sendptr = HEAD( P->rtable );
|
|
|
|
add_head( &P->connections, NODE c );
|
|
|
|
debug( "Sending my routing table to %I:%d\n", daddr, dport );
|
|
|
|
|
|
|
|
rip_tx( c->send );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Input processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
process_authentication( struct proto *p, struct rip_block *block )
|
|
|
|
{
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: Should do md5 authentication */
|
1998-07-29 05:44:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-07-10 03:39:04 +08:00
|
|
|
#define DELETE( msg ) { debug( msg ); kill_entry( p, e ); e = NULL; }
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_block( struct proto *p, struct rip_block *block, ip_addr whotoldme )
|
|
|
|
{
|
|
|
|
struct rip_entry *e;
|
|
|
|
int metric = ntohl( block->metric );
|
1998-07-29 05:44:11 +08:00
|
|
|
ip_addr network = block->network;
|
1998-07-10 03:39:04 +08:00
|
|
|
|
|
|
|
CHK_MAGIC;
|
|
|
|
if ((!metric) || (metric > infinity)) {
|
|
|
|
log( L_WARN "Got metric %d from %I\n", metric, whotoldme );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: Check if destination looks valid - ie not net 0 or 127 */
|
1998-07-10 03:39:04 +08:00
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: Should add configurable ammount */
|
1998-07-10 03:39:04 +08:00
|
|
|
if (metric < infinity)
|
|
|
|
metric++;
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
debug( "block: %I tells me: %I/%I available, metric %d... ", whotoldme, network, block->netmask, metric );
|
1998-07-10 03:39:04 +08:00
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
e = find_entry( p, network, ipa_mklen( block->netmask ));
|
1998-07-10 03:39:04 +08:00
|
|
|
if (e && (e->metric > metric)) /* || if same metrics and this is much newer */
|
|
|
|
DELETE( "better metrics... " );
|
|
|
|
|
|
|
|
if (e && ((e->updated - now) > 180))
|
|
|
|
DELETE( "more than 180 seconds old... " );
|
|
|
|
|
|
|
|
if (e && ipa_equal( whotoldme, e->whotoldme ) &&
|
|
|
|
(e->metric == metric)) {
|
|
|
|
debug( "old news, updating time" );
|
|
|
|
e->updated = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e) {
|
|
|
|
debug( "this is new" );
|
1998-10-08 03:33:50 +08:00
|
|
|
e = new_entry_from_block( p, block, whotoldme );
|
|
|
|
if (!e) {
|
|
|
|
debug( "Something went wrong with new_entry?\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
advertise_entry( p, e );
|
1998-07-10 03:39:04 +08:00
|
|
|
add_head( &P->rtable, NODE e );
|
|
|
|
}
|
|
|
|
|
|
|
|
debug( "\n" );
|
|
|
|
}
|
|
|
|
#undef DELETE
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
#define BAD( x ) { log( L_WARN "RIP/%s: " x "\n", p->name ); return 1; }
|
|
|
|
|
|
|
|
static int
|
1998-07-10 03:39:04 +08:00
|
|
|
rip_process_packet( struct proto *p, struct rip_packet *packet, int num, ip_addr whotoldme, int port )
|
|
|
|
{
|
|
|
|
int i;
|
1998-07-29 05:44:11 +08:00
|
|
|
int native_class = 0;
|
1998-07-10 03:39:04 +08:00
|
|
|
|
|
|
|
switch( packet->heading.version ) {
|
1998-07-29 05:44:11 +08:00
|
|
|
case RIP_V1: debug( "Rip1: " ); break;
|
|
|
|
case RIP_V2: debug( "Rip2: " ); break;
|
1998-07-10 03:39:04 +08:00
|
|
|
default: BAD( "Unknown version" );
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( packet->heading.command ) {
|
1998-10-08 03:33:50 +08:00
|
|
|
case RIPCMD_REQUEST: debug( "Asked to send my routing table\n" );
|
1998-07-29 05:44:11 +08:00
|
|
|
rip_sendto( p, whotoldme, port );
|
|
|
|
break;
|
1998-10-08 03:33:50 +08:00
|
|
|
case RIPCMD_RESPONSE: debug( "Part of routing table came\n" );
|
1998-07-10 03:39:04 +08:00
|
|
|
if (port != RIP_PORT) {
|
|
|
|
log( L_AUTH "%I send me routing info from port %d\n", whotoldme, port );
|
1998-07-29 05:44:11 +08:00
|
|
|
return 0;
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!neigh_find( p, &whotoldme, 0 )) {
|
|
|
|
log( L_AUTH "%I send me routing info but he is not my neighbour\n", whotoldme );
|
1998-07-29 05:44:11 +08:00
|
|
|
return 0;
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: Should check if it is not my own packet */
|
1998-07-10 03:39:04 +08:00
|
|
|
|
|
|
|
for (i=0; i<num; i++) {
|
|
|
|
struct rip_block *block = &packet->block[i];
|
|
|
|
if (block->family == 0xffff)
|
|
|
|
if (!i) {
|
|
|
|
if (process_authentication(p, block))
|
|
|
|
BAD( "Authentication failed\n" );
|
|
|
|
} else BAD( "Authentication is not the first!" );
|
1998-07-29 05:44:11 +08:00
|
|
|
ipa_ntoh( block->network );
|
|
|
|
ipa_ntoh( block->netmask );
|
|
|
|
ipa_ntoh( block->nexthop );
|
|
|
|
if (packet->heading.version == RIP_V1) {
|
|
|
|
block->netmask = block->network; /* MJ: why are macros like this?! */
|
|
|
|
ipa_class_mask( block->netmask );
|
|
|
|
}
|
1998-07-10 03:39:04 +08:00
|
|
|
process_block( p, block, whotoldme );
|
|
|
|
}
|
|
|
|
break;
|
1998-10-08 03:33:50 +08:00
|
|
|
case RIPCMD_TRACEON:
|
|
|
|
case RIPCMD_TRACEOFF: BAD( "I was asked for traceon/traceoff\n" );
|
1998-07-10 03:39:04 +08:00
|
|
|
case 5: BAD( "Some Sun extension around here\n" );
|
|
|
|
default: BAD( "Unknown command" );
|
|
|
|
}
|
|
|
|
|
|
|
|
rip_reply(p);
|
1998-07-29 05:44:11 +08:00
|
|
|
return 0;
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
static int
|
1998-07-10 03:39:04 +08:00
|
|
|
rip_rx(sock *s, int size)
|
|
|
|
{
|
|
|
|
struct proto *p = s->data;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
CHK_MAGIC;
|
|
|
|
debug( "RIP: message came: %d bytes\n", size );
|
|
|
|
size -= sizeof( struct rip_packet_heading );
|
|
|
|
if (size < 0) BAD( "Too small packet" );
|
|
|
|
if (size % sizeof( struct rip_block )) BAD( "Odd sized packet" );
|
|
|
|
num = size / sizeof( struct rip_block );
|
|
|
|
if (num>25) BAD( "Too many blocks" );
|
|
|
|
|
|
|
|
rip_process_packet( p, (struct rip_packet *) s->rbuf, num, s->faddr, s->fport );
|
1998-07-29 05:44:11 +08:00
|
|
|
return 1;
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
/*
|
|
|
|
* Interface to rest of bird
|
|
|
|
*/
|
|
|
|
|
1998-07-10 03:39:04 +08:00
|
|
|
static void
|
|
|
|
rip_dump_entry( struct rip_entry *e )
|
|
|
|
{
|
1998-10-08 03:33:50 +08:00
|
|
|
debug( "%I told me %d/%d ago: to %I/%d go via %I, metric %d ",
|
1998-07-29 05:44:11 +08:00
|
|
|
e->whotoldme, e->updated-now, e->changed-now, e->network, e->pxlen, e->nexthop, e->metric );
|
1998-10-08 03:33:50 +08:00
|
|
|
if (e->flags & RIP_F_EXTERNAL) debug( "[external]" );
|
|
|
|
debug( "\n" );
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_timer(timer *t)
|
|
|
|
{
|
|
|
|
struct proto *p = t->data;
|
|
|
|
struct rip_entry *e, *et;
|
|
|
|
|
|
|
|
CHK_MAGIC;
|
|
|
|
debug( "RIP: tick tock\n" );
|
|
|
|
|
|
|
|
WALK_LIST_DELSAFE( e, et, P->rtable ) {
|
1998-10-08 03:33:50 +08:00
|
|
|
if (!(E->flags & RIP_F_EXTERNAL))
|
|
|
|
if ((now - E->updated) > (180+120)) {
|
|
|
|
debug( "RIP: entry is too old: " );
|
|
|
|
rip_dump_entry( E );
|
|
|
|
kill_entry( p, E );
|
|
|
|
}
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
1998-07-29 05:44:11 +08:00
|
|
|
|
1998-07-30 15:43:45 +08:00
|
|
|
#if 0
|
1998-07-29 05:44:11 +08:00
|
|
|
debug( "RIP: Broadcasting routing tables\n" );
|
|
|
|
rip_sendto( p, _MI( 0x0a000001 ), RIP_PORT );
|
1998-07-30 15:43:45 +08:00
|
|
|
#endif
|
1998-07-29 05:44:11 +08:00
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
/* FIXME: Should broadcast routing tables to all known interfaces every 30 seconds */
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
debug( "RIP: tick tock done\n" );
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_start(struct proto *p)
|
|
|
|
{
|
|
|
|
debug( "RIP: initializing instance...\n" );
|
|
|
|
|
|
|
|
P->listen = sk_new( p->pool );
|
|
|
|
P->listen->type = SK_UDP;
|
|
|
|
P->listen->sport = RIP_PORT;
|
|
|
|
P->listen->rx_hook = rip_rx;
|
|
|
|
P->listen->data = p;
|
|
|
|
P->listen->rbsize = 10240;
|
|
|
|
P->magic = RIP_MAGIC;
|
|
|
|
if (sk_open(P->listen)<0)
|
|
|
|
die( "RIP/%s: could not listen\n", p->name );
|
|
|
|
init_list( &P->rtable );
|
|
|
|
init_list( &P->connections );
|
|
|
|
P->timer = tm_new( p->pool );
|
|
|
|
P->timer->data = p;
|
|
|
|
P->timer->randomize = 5;
|
1998-07-29 05:44:11 +08:00
|
|
|
P->timer->recurrent = RIP_TIME;
|
1998-07-10 03:39:04 +08:00
|
|
|
P->timer->hook = rip_timer;
|
1998-07-29 05:44:11 +08:00
|
|
|
tm_start( P->timer, 5 );
|
1998-07-10 03:39:04 +08:00
|
|
|
|
|
|
|
debug( "RIP: ...done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_init(struct protocol *p)
|
|
|
|
{
|
|
|
|
debug( "RIP: initializing RIP...\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_dump(struct proto *p)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
node *w, *e;
|
|
|
|
i = 0;
|
|
|
|
WALK_LIST( w, P->connections ) {
|
1998-07-29 05:44:11 +08:00
|
|
|
struct rip_connection *n = (void *) w;
|
|
|
|
debug( "RIP: connection #%d: %I\n", n->num, n->addr );
|
1998-07-10 03:39:04 +08:00
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
WALK_LIST( e, P->rtable ) {
|
|
|
|
debug( "RIP: entry #%d: ", i++ );
|
|
|
|
rip_dump_entry( E );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-29 05:44:11 +08:00
|
|
|
static void
|
|
|
|
rip_if_notify(struct proto *p, unsigned c, struct iface *old, struct iface *new)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-10-08 03:33:50 +08:00
|
|
|
static void
|
|
|
|
rip_rt_notify(struct proto *p, struct network *net, struct rte *new, struct rte *old)
|
|
|
|
{
|
|
|
|
debug( "rip: new entry came\n" );
|
|
|
|
/* FIXME: should add/delete that entry from my routing tables, and
|
|
|
|
set it so that it never times out */
|
|
|
|
|
|
|
|
if (old) {
|
|
|
|
struct rip_entry *e = find_entry( p, net->n.prefix, net->n.pxlen );
|
|
|
|
if (!e)
|
|
|
|
log( L_ERR "Deleting nonexistent entry?!\n" );
|
|
|
|
|
|
|
|
kill_entry_ourrt( p, e );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: what do we do if we already know route to that target? We were not prepared to that. */
|
|
|
|
|
|
|
|
if (new) {
|
|
|
|
struct rip_entry *e = new_entry( p );
|
|
|
|
|
|
|
|
e->whotoldme = IPA_NONE;
|
|
|
|
e->network = net->n.prefix;
|
|
|
|
e->pxlen = net->n.pxlen;
|
|
|
|
e->nexthop = IPA_NONE; /* FIXME: is it correct? */
|
|
|
|
e->tag = 0; /* FIXME: how to set tag? */
|
|
|
|
e->metric = 1; /* FIXME: how to set metric? */
|
|
|
|
e->updated = e->changed = now;
|
|
|
|
e->flags = RIP_F_EXTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-10 03:39:04 +08:00
|
|
|
static void
|
|
|
|
rip_preconfig(struct protocol *x)
|
|
|
|
{
|
|
|
|
struct proto *p = proto_new(&proto_rip, sizeof(struct rip_data));
|
|
|
|
|
|
|
|
debug( "RIP: preconfig\n" );
|
|
|
|
p->preference = DEF_PREF_DIRECT;
|
|
|
|
p->start = rip_start;
|
|
|
|
p->if_notify = rip_if_notify;
|
1998-10-08 03:33:50 +08:00
|
|
|
p->rt_notify = rip_rt_notify;
|
1998-07-10 03:39:04 +08:00
|
|
|
p->dump = rip_dump;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rip_postconfig(struct protocol *p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct protocol proto_rip = {
|
|
|
|
{ NULL, NULL },
|
|
|
|
"RIP",
|
|
|
|
0,
|
|
|
|
rip_init,
|
|
|
|
rip_preconfig,
|
|
|
|
rip_postconfig
|
|
|
|
};
|
|
|
|
|