More rip fixes (config data moved to struct rip_proto_config), still

not tested.
This commit is contained in:
Pavel Machek 1999-02-15 13:34:43 +00:00
parent b5fe3dc21c
commit 293e313ec9
3 changed files with 39 additions and 33 deletions

View file

@ -24,7 +24,7 @@ CF_HDR
void rip_dev_add_iface(char *); void rip_dev_add_iface(char *);
struct rip_patt *rip_get_iface(void); struct rip_patt *rip_get_iface(void);
#define THIS_PROTO ((struct rip_proto *) this_proto) #define RIP_PROTO ((struct rip_proto_config *) this_proto)
CF_DECLS CF_DECLS
@ -37,18 +37,18 @@ CF_GRAMMAR
CF_ADDTO(proto, rip_proto '}') CF_ADDTO(proto, rip_proto '}')
rip_proto_start: proto_start RIP { rip_proto_start: proto_start RIP {
this_proto = proto_new(&proto_rip, sizeof(struct rip_proto)); RIP_PROTO = proto_new(&proto_rip, sizeof(struct rip_proto));
rip_init_instance(this_proto); rip_init_instance(RIP_PROTO);
} }
; ;
rip_proto: rip_proto:
rip_proto_start proto_name '{' rip_proto_start proto_name '{'
| rip_proto proto_item ';' | rip_proto proto_item ';'
| rip_proto INFINITY expr ';' { THIS_PROTO->infinity = $3; } | rip_proto INFINITY expr ';' { RIP_PROTO->infinity = $3; }
| rip_proto PORT expr ';' { THIS_PROTO->port = $3; } | rip_proto PORT expr ';' { RIP_PROTO->port = $3; }
| rip_proto PERIOD expr ';' { THIS_PROTO->period = $3; } | rip_proto PERIOD expr ';' { RIP_PROTO->period = $3; }
| rip_proto GARBAGETIME expr ';' { THIS_PROTO->garbage_time = $3; } | rip_proto GARBAGETIME expr ';' { RIP_PROTO->garbage_time = $3; }
| rip_proto rip_iface_list ';' | rip_proto rip_iface_list ';'
; ;
@ -91,13 +91,13 @@ rip_dev_add_iface(char *n)
struct rip_patt *k = cfg_alloc(sizeof(struct rip_patt)); struct rip_patt *k = cfg_alloc(sizeof(struct rip_patt));
k->i.pattern = cfg_strdup(n); k->i.pattern = cfg_strdup(n);
add_tail(&THIS_PROTO->iface_list, &k->i.n); add_tail(&RIP_PROTO->iface_list, &k->i.n);
} }
struct rip_patt * struct rip_patt *
rip_get_iface(void) rip_get_iface(void)
{ {
struct rip_patt *k = TAIL(THIS_PROTO->iface_list); struct rip_patt *k = TAIL(RIP_PROTO->iface_list);
if (!k) if (!k)
cf_error( "This cannot happen" ); cf_error( "This cannot happen" );
return k; return k;

View file

@ -22,6 +22,10 @@
#include "rip.h" #include "rip.h"
#define P ((struct rip_proto *) p)
#define P_CF ((struct rip_proto_config *)p->cf)
#define E ((struct rip_entry *) e)
static void static void
rip_reply(struct proto *p) rip_reply(struct proto *p)
{ {
@ -89,7 +93,7 @@ rip_tx( sock *s )
if (ipa_equal(e->whotoldme, s->daddr)) { if (ipa_equal(e->whotoldme, s->daddr)) {
DBG( "(split horizont)" ); DBG( "(split horizont)" );
/* FIXME: should we do it in all cases? */ /* FIXME: should we do it in all cases? */
packet->block[i].metric = P->infinity; packet->block[i].metric = P_CF->infinity;
} }
ipa_hton( packet->block[i].network ); ipa_hton( packet->block[i].network );
ipa_hton( packet->block[i].netmask ); ipa_hton( packet->block[i].netmask );
@ -214,7 +218,7 @@ advertise_entry( struct proto *p, struct rip_block *b, ip_addr whotoldme )
n = net_get( &master_table, 0, b->network, ipa_mklen( b->netmask )); /* FIXME: should verify that it really is netmask */ 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 = rte_get_temp(a);
r->u.rip.metric = ntohl(b->metric) + i->metric; r->u.rip.metric = ntohl(b->metric) + i->metric;
if (r->u.rip.metric > P->infinity) r->u.rip.metric = P->infinity; if (r->u.rip.metric > P_CF->infinity) r->u.rip.metric = P_CF->infinity;
r->u.rip.tag = ntohl(b->tag); r->u.rip.tag = ntohl(b->tag);
r->net = n; r->net = n;
r->pflags = 0; /* Here go my flags */ r->pflags = 0; /* Here go my flags */
@ -230,7 +234,7 @@ process_block( struct proto *p, struct rip_block *block, ip_addr whotoldme )
ip_addr network = block->network; ip_addr network = block->network;
CHK_MAGIC; CHK_MAGIC;
if ((!metric) || (metric > P->infinity)) { if ((!metric) || (metric > P_CF->infinity)) {
log( L_WARN "Got metric %d from %I", metric, whotoldme ); log( L_WARN "Got metric %d from %I", metric, whotoldme );
return; return;
} }
@ -262,7 +266,7 @@ rip_process_packet( struct proto *p, struct rip_packet *packet, int num, ip_addr
rip_sendto( p, whotoldme, port, NULL ); /* no broadcast */ rip_sendto( p, whotoldme, port, NULL ); /* no broadcast */
break; break;
case RIPCMD_RESPONSE: DBG( "*** Rtable from %I\n", whotoldme ); case RIPCMD_RESPONSE: DBG( "*** Rtable from %I\n", whotoldme );
if (port != P->port) { if (port != P_CF->port) {
log( L_ERR "%I send me routing info from port %d", whotoldme, port ); log( L_ERR "%I send me routing info from port %d", whotoldme, port );
#if 0 #if 0
return 0; return 0;
@ -351,7 +355,7 @@ rip_timer(timer *t)
rte = SKIP_BACK( struct rte, u.rip.garbage, e ); rte = SKIP_BACK( struct rte, u.rip.garbage, e );
DBG( "Garbage: " ); rte_dump( rte ); DBG( "Garbage: " ); rte_dump( rte );
if (now - rte->lastmod > P->garbage_time) { if (now - rte->lastmod > P_CF->garbage_time) {
debug( "RIP: entry is too old: " ); rte_dump( rte ); debug( "RIP: entry is too old: " ); rte_dump( rte );
rte_discard(rte); rte_discard(rte);
} }
@ -392,7 +396,7 @@ rip_start(struct proto *p)
P->timer = tm_new( p->pool ); P->timer = tm_new( p->pool );
P->timer->data = p; P->timer->data = p;
P->timer->randomize = 5; P->timer->randomize = 5;
P->timer->recurrent = P->period; P->timer->recurrent = P_CF->period;
P->timer->hook = rip_timer; P->timer->hook = rip_timer;
tm_start( P->timer, 5 ); tm_start( P->timer, 5 );
rif = new_iface(p, NULL, 0); /* Initialize dummy interface */ rif = new_iface(p, NULL, 0); /* Initialize dummy interface */
@ -467,7 +471,7 @@ new_iface(struct proto *p, struct iface *new, unsigned long flags)
rif->sock = sk_new( p->pool ); rif->sock = sk_new( p->pool );
rif->sock->type = want_multicast?SK_UDP_MC:SK_UDP; rif->sock->type = want_multicast?SK_UDP_MC:SK_UDP;
rif->sock->sport = P->port; rif->sock->sport = P_CF->port;
rif->sock->rx_hook = rip_rx; rif->sock->rx_hook = rip_rx;
rif->sock->data = rif; rif->sock->data = rif;
rif->sock->rbsize = 10240; rif->sock->rbsize = 10240;
@ -476,7 +480,7 @@ new_iface(struct proto *p, struct iface *new, unsigned long flags)
rif->sock->tx_hook = rip_tx; rif->sock->tx_hook = rip_tx;
rif->sock->err_hook = rip_tx_err; rif->sock->err_hook = rip_tx_err;
rif->sock->daddr = IPA_NONE; rif->sock->daddr = IPA_NONE;
rif->sock->dport = P->port; rif->sock->dport = P_CF->port;
rif->sock->ttl = 1; /* FIXME: care must be taken not to send requested responses from this socket */ rif->sock->ttl = 1; /* FIXME: care must be taken not to send requested responses from this socket */
if (want_multicast) if (want_multicast)
@ -510,7 +514,7 @@ rip_if_notify(struct proto *p, unsigned c, struct iface *new, struct iface *old)
} }
if (new) { if (new) {
struct rip_interface *rif; struct rip_interface *rif;
struct iface_patt *k = iface_patt_match(&P->iface_list, new); struct iface_patt *k = iface_patt_match(&P_CF->iface_list, new);
if (!k) return; /* We are not interested in this interface */ if (!k) return; /* We are not interested in this interface */
DBG("adding interface %s\n", new->name ); DBG("adding interface %s\n", new->name );
@ -595,12 +599,13 @@ rip_init_instance(struct proto *p)
p->rte_insert = rip_rte_insert; p->rte_insert = rip_rte_insert;
p->rte_remove = rip_rte_remove; p->rte_remove = rip_rte_remove;
P->infinity = 16; #warning FIXME: this is almost certianly wrong, I need to setup config elsewhere
P->port = 520; P_CF->infinity = 16;
P->period = 30; P_CF->port = 520;
P->garbage_time = 120+180; P_CF->period = 30;
P_CF->garbage_time = 120+180;
init_list(&P->iface_list); init_list(&P_CF->iface_list);
} }
static void static void

View file

@ -82,15 +82,8 @@ struct rip_patt {
int mode; int mode;
}; };
struct rip_proto { struct rip_proto_config {
struct proto inherited;
timer *timer;
list connections;
struct fib rtable;
list garbage;
list interfaces; /* Interfaces we really know about */
list iface_list; /* Patterns configured */ list iface_list; /* Patterns configured */
int magic;
int infinity; /* User configurable data */ int infinity; /* User configurable data */
int port; int port;
@ -98,8 +91,16 @@ struct rip_proto {
int garbage_time; int garbage_time;
}; };
#define P ((struct rip_proto *) p) struct rip_proto {
#define E ((struct rip_entry *) e) struct proto inherited;
timer *timer;
list connections;
struct fib rtable;
list garbage;
list interfaces; /* Interfaces we really know about */
int magic;
};
#define RIP_MAGIC 81861253 #define RIP_MAGIC 81861253
#define CHK_MAGIC do { if (P->magic != RIP_MAGIC) bug( "Not enough magic\n" ); } while (0) #define CHK_MAGIC do { if (P->magic != RIP_MAGIC) bug( "Not enough magic\n" ); } while (0)