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);
}
;
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
#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)
{
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
*/
rte *r;
net *n;
neighbor *neighbor;
+ struct rip_interface *i;
bzero(&A, sizeof(A));
A.proto = p;
}
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 */
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;
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);
}
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;
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;
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;
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 );
}
}
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