diff options
Diffstat (limited to 'proto')
-rw-r--r-- | proto/rip/config.Y | 57 | ||||
-rw-r--r-- | proto/rip/rip.c | 57 | ||||
-rw-r--r-- | proto/rip/rip.h | 14 |
3 files changed, 97 insertions, 31 deletions
diff --git a/proto/rip/config.Y b/proto/rip/config.Y index 3e668f4..fbe6fe1 100644 --- a/proto/rip/config.Y +++ b/proto/rip/config.Y @@ -7,17 +7,23 @@ CF_HDR #include "proto/rip/rip.h" +#include "nest/iface.h" + +void rip_dev_add_iface(char *); +struct iface_patt *rip_get_iface(void); + +#define THIS_PROTO ((struct rip_proto *) this_proto) CF_DECLS -CF_KEYWORDS(RIP, INFINITY) +CF_KEYWORDS(RIP, INFINITY, METRIC, PORT, PERIOD, GARBAGETIME) CF_GRAMMAR CF_ADDTO(proto, rip_proto '}') rip_proto_start: proto_start RIP { - this_proto = proto_new(&proto_rip, sizeof(struct rip_data)); + this_proto = proto_new(&proto_rip, sizeof(struct rip_proto)); rip_init_instance(this_proto); } ; @@ -25,12 +31,51 @@ rip_proto_start: proto_start RIP { rip_proto: rip_proto_start proto_name '{' | rip_proto proto_item ';' - | rip_proto INFINITY expr ';' { - if ($3 < 0 || $3 > 64) cf_error("Invalid infinity"); - ((struct rip_data *) this_proto)->infinity = $3; - } + | rip_proto INFINITY expr ';' { THIS_PROTO->infinity = $3; } + | rip_proto PORT expr ';' { THIS_PROTO->port = $3; } + | rip_proto PERIOD expr ';' { THIS_PROTO->period = $3; } + | rip_proto GARBAGETIME expr ';' { THIS_PROTO->garbage_time = $3; } + | rip_proto rip_iface_list ';' + ; + +rip_iface_item: + | METRIC expr { + struct iface_patt *k = rip_get_iface(); + k->u.rip.metric = $2; + } + ; + +rip_iface_opts: + '{' + | rip_iface_opts rip_iface_item ';' + ; + +rip_iface_empty: /* EMPTY */ | rip_iface_opts '}' ; + +rip_iface_list: + INTERFACE TEXT rip_iface_empty { rip_dev_add_iface($2); } + | dev_iface_list ',' TEXT rip_iface_empty { rip_dev_add_iface($3); } ; CF_CODE +void +rip_dev_add_iface(char *n) +{ + struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt)); + + k->pattern = cfg_strcpy(n); + add_tail(&THIS_PROTO->iface_list, &k->n); +} + +struct iface_patt * +rip_get_iface(void) +{ + struct iface_patt *k = TAIL(THIS_PROTO->iface_list); + if (!k) + cf_error( "This cannot happen" ); + return k; +} + + CF_END diff --git a/proto/rip/rip.c b/proto/rip/rip.c index 23e8645..8a738f9 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -22,15 +22,6 @@ #include "rip.h" -/* FIXME: should be 520 */ -#define RIP_PORT 1520 - -/* FIXME: should be 30 */ -#define RIP_TIME 5 - -/* FIXME: should be 120+180 */ -#define RIP_GB_TIME 30 - static void rip_reply(struct proto *p) { @@ -218,6 +209,17 @@ rip_sendto( struct proto *p, ip_addr daddr, int dport, struct rip_interface *rif rip_tx(c->rif->sock); } +struct rip_interface* +find_interface(struct proto *p, struct iface *what) +{ + struct rip_interface *i; + /* FIXME: We really want to use some kind of hash-table */ + WALK_LIST (i, P->interfaces) + if (i->iface == what) + return i; + return NULL; +} + /* * Input processing */ @@ -237,6 +239,7 @@ advertise_entry( struct proto *p, struct rip_block *b, ip_addr whotoldme ) rte *r; net *n; neighbor *neighbor; + struct rip_interface *i; bzero(&A, sizeof(A)); A.proto = p; @@ -256,11 +259,13 @@ advertise_entry( struct proto *p, struct rip_block *b, ip_addr whotoldme ) } A.iface = neighbor->iface; + i = find_interface(p, A.iface); /* set to: interface of nexthop */ a = rta_lookup(&A); n = net_get( &master_table, 0, b->network, ipa_mklen( b->netmask )); /* FIXME: should verify that it really is netmask */ r = rte_get_temp(a); - r->u.rip.metric = ntohl(b->metric); + r->u.rip.metric = ntohl(b->metric) + i->metric; + if (r->u.rip.metric > P->infinity) r->u.rip.metric = P->infinity; r->u.rip.tag = ntohl(b->tag); r->net = n; r->pflags = 0; /* Here go my flags */ @@ -311,7 +316,7 @@ rip_process_packet( struct proto *p, struct rip_packet *packet, int num, ip_addr rip_sendto( p, whotoldme, port, NULL ); /* no broadcast */ break; case RIPCMD_RESPONSE: debug( "*** Rtable from %I\n", whotoldme ); - if (port != RIP_PORT) { + if (port != P->port) { log( L_ERR "%I send me routing info from port %d\n", whotoldme, port ); #if 0 return 0; @@ -400,7 +405,7 @@ rip_timer(timer *t) rte = SKIP_BACK( struct rte, u.rip.garbage, e ); debug( "Garbage: " ); rte_dump( rte ); - if (now - rte->lastmod > (RIP_GB_TIME)) { + if (now - rte->lastmod > P->garbage_time) { debug( "RIP: entry is too old: " ); rte_dump( rte ); rte_discard(rte); } @@ -436,7 +441,7 @@ rip_start(struct proto *p) P->timer = tm_new( p->pool ); P->timer->data = p; P->timer->randomize = 5; - P->timer->recurrent = RIP_TIME; + P->timer->recurrent = P->period; P->timer->hook = rip_timer; tm_start( P->timer, 5 ); CHK_MAGIC; @@ -497,7 +502,7 @@ new_iface(struct proto *p, struct iface *new) i->sock = sk_new( p->pool ); i->sock->type = SK_UDP; - i->sock->sport = RIP_PORT; + i->sock->sport = P->port; i->sock->rx_hook = rip_rx; i->sock->data = i; i->sock->rbsize = 10240; @@ -506,7 +511,7 @@ new_iface(struct proto *p, struct iface *new) i->sock->tx_hook = rip_tx; i->sock->err_hook = rip_tx_err; i->sock->daddr = IPA_NONE; - i->sock->dport = RIP_PORT; + i->sock->dport = P->port; if (new->flags & IF_BROADCAST) i->sock->daddr = new->brd; @@ -528,15 +533,19 @@ rip_if_notify(struct proto *p, unsigned c, struct iface *old, struct iface *new) debug( "RIP: if notify\n" ); if (old) { struct rip_interface *i; - WALK_LIST (i, P->interfaces) - if (i->iface == old) { - rem_node(NODE i); - kill_iface(p, i); - } + i = find_interface(p, old); + if (i) { + rem_node(NODE i); + kill_iface(p, i); + } } if (new) { struct rip_interface *i; + struct iface_patt *k = iface_patt_match(&P->iface_list, new); + + if (!k) return; /* We are not interested in this interface */ i = new_iface(p, new); + i->metric = k->u.rip.metric; add_head( &P->interfaces, NODE i ); } } @@ -620,7 +629,13 @@ rip_init_instance(struct proto *p) p->rte_insert = rip_rte_insert; p->rte_remove = rip_rte_remove; p->dump = rip_dump; - P->infinity = 16; + + P->infinity = 16; + P->port = 520; + P->period = 30; + P->garbage_time = 120+180; + + init_list(&P->iface_list); } static void diff --git a/proto/rip/rip.h b/proto/rip/rip.h index d63bb1a..cbb2ccd 100644 --- a/proto/rip/rip.h +++ b/proto/rip/rip.h @@ -64,21 +64,27 @@ struct rip_interface { struct iface *iface; sock *sock; struct rip_connection *busy; + + int metric; /* User configurable data */ }; -struct rip_data { +struct rip_proto { struct proto inherited; timer *timer; list connections; list rtable; list garbage; - list interfaces; + list interfaces; /* Interfaces we really know about */ + list iface_list; /* Patterns configured */ int magic; - int infinity; /* How much is infinity? Should be 16 */ + int infinity; /* User configurable data */ + int port; + int period; + int garbage_time; }; -#define P ((struct rip_data *) p) +#define P ((struct rip_proto *) p) #define E ((struct rip_entry *) e) #define RIP_MAGIC 81861253 |