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 /proto/ospf/iface.c | |
parent | 7d4e923603fdb43b6f017e5ef78e37d0891c699c (diff) |
Removes timers for stub interfaces. Also fixes some minor bugs.
Diffstat (limited to 'proto/ospf/iface.c')
-rw-r--r-- | proto/ospf/iface.c | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index f50798c1..cced7105 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); } |