From be418160a7695ae2b003ec0e42418d8cbd29bb84 Mon Sep 17 00:00:00 2001 From: rgirada Date: Tue, 20 Jul 2021 03:24:56 -0700 Subject: [PATCH] ospfd: OSPF hello packets not sent with configured hello timer Description : ospf hello timer is not getting refelcted upon changing the hello interval. Signed-off-by: Rajesh Girada --- ospfd/ospf_interface.c | 52 ++++++++++++++++++++++++++++++++++++++++++ ospfd/ospf_interface.h | 3 ++- ospfd/ospf_vty.c | 15 ++++++++++-- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 029f929c11..e0e61a2664 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -1447,6 +1447,58 @@ static int ospf_ifp_destroy(struct interface *ifp) return 0; } +/* Resetting ospf hello timer */ +void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr, + bool is_addr) +{ + struct route_node *rn; + + if (is_addr) { + struct prefix p; + struct ospf_interface *oi = NULL; + + p.u.prefix4 = addr; + p.family = AF_INET; + + oi = ospf_if_table_lookup(ifp, &p); + + if (oi) { + /* Send hello before restart the hello timer + * to avoid session flaps in case of bigger + * hello interval configurations. + */ + ospf_hello_send(oi); + + /* Restart hello timer for this interface */ + OSPF_ISM_TIMER_OFF(oi->t_hello); + OSPF_HELLO_TIMER_ON(oi); + } + + return; + } + + for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { + struct ospf_interface *oi = rn->info; + + if (!oi) + continue; + + /* If hello interval configured on this oi, don't restart. */ + if (OSPF_IF_PARAM_CONFIGURED(oi->params, v_hello)) + continue; + + /* Send hello before restart the hello timer + * to avoid session flaps in case of bigger + * hello interval configurations. + */ + ospf_hello_send(oi); + + /* Restart the hello timer. */ + OSPF_ISM_TIMER_OFF(oi->t_hello); + OSPF_HELLO_TIMER_ON(oi); + } +} + void ospf_if_init(void) { if_zapi_callbacks(ospf_ifp_create, ospf_ifp_up, diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h index 4a21147246..7ba6a2b6d7 100644 --- a/ospfd/ospf_interface.h +++ b/ospfd/ospf_interface.h @@ -345,7 +345,8 @@ extern void ospf_if_set_multicast(struct ospf_interface *); extern void ospf_if_interface(struct interface *ifp); extern uint32_t ospf_if_count_area_params(struct interface *ifp); - +extern void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr, + bool is_addr); DECLARE_HOOK(ospf_vl_add, (struct ospf_vl_data * vd), (vd)); DECLARE_HOOK(ospf_vl_delete, (struct ospf_vl_data * vd), (vd)); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 2cb3ec0894..a148a85628 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -8305,10 +8305,12 @@ DEFUN (ip_ospf_hello_interval, { VTY_DECLVAR_CONTEXT(interface, ifp); int idx = 0; - struct in_addr addr; + struct in_addr addr = {.s_addr = 0L}; struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); uint32_t seconds = 0; + bool is_addr = false; + uint32_t old_interval = 0; argv_find(argv, argc, "(1-65535)", &idx); seconds = strtol(argv[idx]->arg, NULL, 10); @@ -8322,8 +8324,15 @@ DEFUN (ip_ospf_hello_interval, params = ospf_get_if_params(ifp, addr); ospf_if_update_params(ifp, addr); + is_addr = true; } + old_interval = params->v_hello; + + /* Return, if same interval is configured. */ + if (old_interval == seconds) + return CMD_SUCCESS; + SET_IF_PARAM(params, v_hello); params->v_hello = seconds; @@ -8338,6 +8347,8 @@ DEFUN (ip_ospf_hello_interval, params->v_wait = 4 * seconds; } + ospf_reset_hello_timer(ifp, addr, is_addr); + return CMD_SUCCESS; } @@ -8364,7 +8375,7 @@ DEFUN (no_ip_ospf_hello_interval, { VTY_DECLVAR_CONTEXT(interface, ifp); int idx = 0; - struct in_addr addr; + struct in_addr addr = {.s_addr = 0L}; struct ospf_if_params *params; struct route_node *rn; -- 2.39.5