diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2011-07-07 17:43:39 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2011-07-08 01:14:52 +0200 |
commit | beeda6af44e72e3a20fcd2837b231a04354790fa (patch) | |
tree | e76d8b473df61139842e88316712bfbef05e2a86 | |
parent | 7d4e923603fdb43b6f017e5ef78e37d0891c699c (diff) | |
download | bird-beeda6af44e72e3a20fcd2837b231a04354790fa.tar bird-beeda6af44e72e3a20fcd2837b231a04354790fa.zip |
Removes timers for stub interfaces. Also fixes some minor bugs.
-rw-r--r-- | proto/ospf/hello.c | 12 | ||||
-rw-r--r-- | proto/ospf/hello.h | 2 | ||||
-rw-r--r-- | proto/ospf/iface.c | 74 | ||||
-rw-r--r-- | sysdep/unix/timer.h | 11 |
4 files changed, 50 insertions, 49 deletions
diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index 76c95c4..0a94e4c 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -217,15 +217,14 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, if (ifa->type == OSPF_IT_NBMA) { if ((ifa->priority == 0) && (n->priority > 0)) - ospf_hello_send(NULL, OHS_HELLO, n); + ospf_hello_send(n->ifa, OHS_HELLO, n); } ospf_neigh_sm(n, INM_HELLOREC); } void -ospf_hello_send(timer *timer, int kind, struct ospf_neighbor *dirn) +ospf_hello_send(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn) { - struct ospf_iface *ifa; struct ospf_hello_packet *pkt; struct ospf_packet *op; struct proto *p; @@ -234,11 +233,6 @@ ospf_hello_send(timer *timer, int kind, struct ospf_neighbor *dirn) int i; struct nbma_node *nb; - if (timer == NULL) - ifa = dirn->ifa; - else - ifa = (struct ospf_iface *) timer->data; - if (ifa->state <= OSPF_IS_LOOP) return; @@ -313,7 +307,7 @@ ospf_hello_send(timer *timer, int kind, struct ospf_neighbor *dirn) break; case OSPF_IT_NBMA: - if (timer == NULL) /* Response to received hello */ + if (dirn) /* Response to received hello */ { ospf_send_to(ifa, dirn->ip); break; diff --git a/proto/ospf/hello.h b/proto/ospf/hello.h index 3675c05..0e47669 100644 --- a/proto/ospf/hello.h +++ b/proto/ospf/hello.h @@ -12,7 +12,7 @@ void ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, struct ospf_neighbor *n, ip_addr faddr); -void ospf_hello_send(timer *timer, int kind, struct ospf_neighbor *dirn); +void ospf_hello_send(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn); #define OHS_HELLO 0 #define OHS_POLL 1 diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index f50798c..cced710 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -21,13 +21,13 @@ char *ospf_it[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" }; static void poll_timer_hook(timer * timer) { - ospf_hello_send(timer, OHS_POLL, NULL); + ospf_hello_send(timer->data, OHS_POLL, NULL); } static void hello_timer_hook(timer * timer) { - ospf_hello_send(timer, OHS_HELLO, NULL); + ospf_hello_send(timer->data, OHS_HELLO, NULL); } static void @@ -232,7 +232,7 @@ void ospf_iface_shutdown(struct ospf_iface *ifa) { if (ifa->state > OSPF_IS_DOWN) - ospf_hello_send(ifa->hello_timer, OHS_SHUTDOWN, NULL); + ospf_hello_send(ifa, OHS_SHUTDOWN, NULL); } /** @@ -323,16 +323,18 @@ ospf_iface_sm(struct ospf_iface *ifa, int event) else { ospf_iface_chstate(ifa, OSPF_IS_WAITING); - tm_start(ifa->wait_timer, ifa->waitint); + if (ifa->wait_timer) + tm_start(ifa->wait_timer, ifa->waitint); } } - tm_start(ifa->hello_timer, ifa->helloint); + if (ifa->hello_timer) + tm_start(ifa->hello_timer, ifa->helloint); if (ifa->poll_timer) tm_start(ifa->poll_timer, ifa->pollint); - hello_timer_hook(ifa->hello_timer); + ospf_hello_send(ifa, OHS_HELLO, NULL); schedule_link_lsa(ifa); } break; @@ -424,6 +426,17 @@ ospf_iface_add(struct object_lock *lock) ifa->stub = 1; } + if (! ifa->stub) + { + ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint); + + if (ifa->type == OSPF_IT_NBMA) + ifa->poll_timer = tm_new_set(ifa->pool, poll_timer_hook, ifa, 0, ifa->pollint); + + if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA)) + ifa->wait_timer = tm_new_set(ifa->pool, wait_timer_hook, ifa, 0, 0); + } + /* Do iface UP, unless there is no link and we use link detection */ ospf_iface_sm(ifa, (ifa->check_link && !(ifa->iface->flags & IF_LINK_UP)) ? ISM_LOOP : ISM_UP); } @@ -548,33 +561,6 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i if (ipa_in_net(nb->ip, addr->prefix, addr->pxlen)) add_nbma_node(ifa, nb, 0); - DBG("%s: Installing hello timer. (%u)\n", p->name, ifa->helloint); - ifa->hello_timer = tm_new(pool); - ifa->hello_timer->data = ifa; - ifa->hello_timer->randomize = 0; - ifa->hello_timer->hook = hello_timer_hook; - ifa->hello_timer->recurrent = ifa->helloint; - - if (ifa->type == OSPF_IT_NBMA) - { - DBG("%s: Installing poll timer. (%u)\n", p->name, ifa->pollint); - ifa->poll_timer = tm_new(pool); - ifa->poll_timer->data = ifa; - ifa->poll_timer->randomize = 0; - ifa->poll_timer->hook = poll_timer_hook; - ifa->poll_timer->recurrent = ifa->pollint; - } - - if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA)) - { - DBG("%s: Installing wait timer. (%u)\n", p->name, ifa->waitint); - ifa->wait_timer = tm_new(pool); - ifa->wait_timer->data = ifa; - ifa->wait_timer->randomize = 0; - ifa->wait_timer->hook = wait_timer_hook; - ifa->wait_timer->recurrent = 0; - } - ifa->state = OSPF_IS_DOWN; add_tail(&oa->po->iface_list, NODE ifa); @@ -607,6 +593,18 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i olock_acquire(lock); } +static void +ospf_iface_change_timer(timer *tm, unsigned val) +{ + if (!tm) + return; + + tm->recurrent = val; + + if (tm->expires) + tm_start(tm, val); +} + int ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) { @@ -636,8 +634,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) ifname, ifa->helloint, new->helloint); ifa->helloint = new->helloint; - ifa->hello_timer->recurrent = ifa->helloint; - tm_start(ifa->hello_timer, ifa->helloint); + ospf_iface_change_timer(ifa->hello_timer, ifa->helloint); } /* RXMT TIMER */ @@ -655,9 +652,8 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) OSPF_TRACE(D_EVENTS, "Changing poll interval on interface %s from %d to %d", ifname, ifa->pollint, new->pollint); - ifa->pollint = new->helloint; - ifa->poll_timer->recurrent = ifa->pollint; - tm_start(ifa->poll_timer, ifa->pollint); + ifa->pollint = new->pollint; + ospf_iface_change_timer(ifa->poll_timer, ifa->pollint); } /* WAIT TIMER */ @@ -667,7 +663,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) ifname, ifa->waitint, new->waitint); ifa->waitint = new->waitint; - if (ifa->wait_timer->expires != 0) + if (ifa->wait_timer && ifa->wait_timer->expires) tm_start(ifa->wait_timer, ifa->waitint); } diff --git a/sysdep/unix/timer.h b/sysdep/unix/timer.h index 3ed6ff1..a20df48 100644 --- a/sysdep/unix/timer.h +++ b/sysdep/unix/timer.h @@ -30,6 +30,17 @@ void tm_start(timer *, unsigned after); void tm_stop(timer *); void tm_dump_all(void); +static inline timer * +tm_new_set(pool *p, void (*hook)(struct timer *), void *data, unsigned rand, unsigned rec) +{ + timer *t = tm_new(p); + t->hook = hook; + t->data = data; + t->randomize = rand; + t->recurrent = rec; + return t; +} + extern bird_clock_t now; /* Relative, monotonic time in seconds */ extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */ |