diff options
Diffstat (limited to 'proto/rip')
-rw-r--r-- | proto/rip/config.Y | 18 | ||||
-rw-r--r-- | proto/rip/rip.c | 33 | ||||
-rw-r--r-- | proto/rip/rip.h | 17 |
3 files changed, 37 insertions, 31 deletions
diff --git a/proto/rip/config.Y b/proto/rip/config.Y index 7d6c9932..c1ed78e7 100644 --- a/proto/rip/config.Y +++ b/proto/rip/config.Y @@ -24,7 +24,7 @@ CF_HDR void rip_dev_add_iface(char *); 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 @@ -37,18 +37,18 @@ CF_GRAMMAR CF_ADDTO(proto, rip_proto '}') rip_proto_start: proto_start RIP { - this_proto = proto_new(&proto_rip, sizeof(struct rip_proto)); - rip_init_instance(this_proto); + RIP_PROTO = proto_new(&proto_rip, sizeof(struct rip_proto)); + rip_init_instance(RIP_PROTO); } ; rip_proto: rip_proto_start proto_name '{' | rip_proto proto_item ';' - | 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 INFINITY expr ';' { RIP_PROTO->infinity = $3; } + | rip_proto PORT expr ';' { RIP_PROTO->port = $3; } + | rip_proto PERIOD expr ';' { RIP_PROTO->period = $3; } + | rip_proto GARBAGETIME expr ';' { RIP_PROTO->garbage_time = $3; } | 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)); 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 * rip_get_iface(void) { - struct rip_patt *k = TAIL(THIS_PROTO->iface_list); + struct rip_patt *k = TAIL(RIP_PROTO->iface_list); if (!k) cf_error( "This cannot happen" ); return k; diff --git a/proto/rip/rip.c b/proto/rip/rip.c index 12492946..cb0add45 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -22,6 +22,10 @@ #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 rip_reply(struct proto *p) { @@ -89,7 +93,7 @@ rip_tx( sock *s ) if (ipa_equal(e->whotoldme, s->daddr)) { DBG( "(split horizont)" ); /* 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].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 */ r = rte_get_temp(a); 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->net = n; 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; CHK_MAGIC; - if ((!metric) || (metric > P->infinity)) { + if ((!metric) || (metric > P_CF->infinity)) { log( L_WARN "Got metric %d from %I", metric, whotoldme ); 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 */ break; 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 ); #if 0 return 0; @@ -351,7 +355,7 @@ rip_timer(timer *t) rte = SKIP_BACK( struct rte, u.rip.garbage, e ); 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 ); rte_discard(rte); } @@ -392,7 +396,7 @@ rip_start(struct proto *p) P->timer = tm_new( p->pool ); P->timer->data = p; P->timer->randomize = 5; - P->timer->recurrent = P->period; + P->timer->recurrent = P_CF->period; P->timer->hook = rip_timer; tm_start( P->timer, 5 ); 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->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->data = rif; 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->err_hook = rip_tx_err; 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 */ if (want_multicast) @@ -510,7 +514,7 @@ rip_if_notify(struct proto *p, unsigned c, struct iface *new, struct iface *old) } if (new) { 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 */ 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_remove = rip_rte_remove; - P->infinity = 16; - P->port = 520; - P->period = 30; - P->garbage_time = 120+180; +#warning FIXME: this is almost certianly wrong, I need to setup config elsewhere + P_CF->infinity = 16; + P_CF->port = 520; + P_CF->period = 30; + P_CF->garbage_time = 120+180; - init_list(&P->iface_list); + init_list(&P_CF->iface_list); } static void diff --git a/proto/rip/rip.h b/proto/rip/rip.h index 4839016d..e79c95d3 100644 --- a/proto/rip/rip.h +++ b/proto/rip/rip.h @@ -82,6 +82,15 @@ struct rip_patt { int mode; }; +struct rip_proto_config { + list iface_list; /* Patterns configured */ + + int infinity; /* User configurable data */ + int port; + int period; + int garbage_time; +}; + struct rip_proto { struct proto inherited; timer *timer; @@ -89,17 +98,9 @@ struct rip_proto { struct fib rtable; list garbage; list interfaces; /* Interfaces we really know about */ - list iface_list; /* Patterns configured */ int magic; - - int infinity; /* User configurable data */ - int port; - int period; - int garbage_time; }; -#define P ((struct rip_proto *) p) -#define E ((struct rip_entry *) e) #define RIP_MAGIC 81861253 #define CHK_MAGIC do { if (P->magic != RIP_MAGIC) bug( "Not enough magic\n" ); } while (0) |