From e92044cd961e900667f0300bcd562c9b259ad0d9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 26 Sep 2017 19:46:02 -0400 Subject: [PATCH] zebra: Fix irdp so it doesn't crash when looked at irdp is crashing because it assumes that people have configured it in a certain way. Ensure that this 'way' is honored at least enough so that we don't crash. Signed-off-by: Donald Sharp --- zebra/irdp.h | 2 ++ zebra/irdp_interface.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/zebra/irdp.h b/zebra/irdp.h index ea190b574d..8aa9f3e4b3 100644 --- a/zebra/irdp.h +++ b/zebra/irdp.h @@ -111,6 +111,8 @@ */ struct irdp_interface { + bool started; + unsigned long MaxAdvertInterval; unsigned long MinAdvertInterval; unsigned long Preference; diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 34c78e2a48..0df03860d0 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -63,11 +63,28 @@ extern int irdp_sock; DEFINE_MTYPE_STATIC(ZEBRA, IRDP_IF, "IRDP interface data") +#define IRDP_CONFIGED \ + do { \ + if (!irdp) { \ + vty_out(vty, "Please Configure IRDP before using this command\n"); \ + return CMD_WARNING_CONFIG_FAILED; \ + } \ + } \ + while (0) + static struct irdp_interface *irdp_if_get(struct interface *ifp) { struct zebra_if *zi = ifp->info; + + if (!zi) + return NULL; + if (!zi->irdp) zi->irdp = XCALLOC(MTYPE_IRDP_IF, sizeof(*zi->irdp)); + + if (!zi->irdp->started) + return NULL; + return zi->irdp; } @@ -203,6 +220,7 @@ static void irdp_if_start(struct interface *ifp, int multicast, assert(irdp); + irdp->started = true; if (irdp->flags & IF_ACTIVE) { zlog_warn("IRDP: Interface is already active %s", ifp->name); return; @@ -307,6 +325,7 @@ static void irdp_if_shutdown(struct interface *ifp) if (!irdp) return; + if (irdp->flags & IF_SHUTDOWN) { zlog_warn("IRDP: Interface is already shutdown %s", ifp->name); return; @@ -326,6 +345,9 @@ static void irdp_if_no_shutdown(struct interface *ifp) { struct irdp_interface *irdp = irdp_if_get(ifp); + if (!irdp) + return; + if (!(irdp->flags & IF_SHUTDOWN)) { zlog_warn("IRDP: Interface is not shutdown %s", ifp->name); return; @@ -458,6 +480,8 @@ DEFUN (ip_irdp_holdtime, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + irdp->Lifetime = atoi(argv[idx_number]->arg); return CMD_SUCCESS; } @@ -474,6 +498,8 @@ DEFUN (ip_irdp_minadvertinterval, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + if ((unsigned)atoi(argv[idx_number]->arg) <= irdp->MaxAdvertInterval) { irdp->MinAdvertInterval = atoi(argv[idx_number]->arg); return CMD_SUCCESS; @@ -497,6 +523,8 @@ DEFUN (ip_irdp_maxadvertinterval, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + if (irdp->MinAdvertInterval <= (unsigned)atoi(argv[idx_number]->arg)) { irdp->MaxAdvertInterval = atoi(argv[idx_number]->arg); return CMD_SUCCESS; @@ -525,6 +553,8 @@ DEFUN (ip_irdp_preference, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + irdp->Preference = atoi(argv[idx_number]->arg); return CMD_SUCCESS; } @@ -549,6 +579,8 @@ DEFUN (ip_irdp_address_preference, int ret; struct Adv *adv; + IRDP_CONFIGED; + ret = inet_aton(argv[idx_ipv4]->arg, &ip); if (!ret) return CMD_WARNING_CONFIG_FAILED; @@ -586,6 +618,8 @@ DEFUN (no_ip_irdp_address_preference, int ret; struct Adv *adv; + IRDP_CONFIGED; + ret = inet_aton(argv[idx_ipv4]->arg, &ip); if (!ret) return CMD_WARNING_CONFIG_FAILED; @@ -611,6 +645,8 @@ DEFUN (ip_irdp_debug_messages, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + irdp->flags |= IF_DEBUG_MESSAGES; return CMD_SUCCESS; @@ -627,6 +663,8 @@ DEFUN (ip_irdp_debug_misc, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + irdp->flags |= IF_DEBUG_MISC; return CMD_SUCCESS; @@ -643,6 +681,8 @@ DEFUN (ip_irdp_debug_packet, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + irdp->flags |= IF_DEBUG_PACKET; return CMD_SUCCESS; @@ -660,6 +700,8 @@ DEFUN (ip_irdp_debug_disable, VTY_DECLVAR_CONTEXT(interface, ifp); struct irdp_interface *irdp = irdp_if_get(ifp); + IRDP_CONFIGED; + irdp->flags &= ~IF_DEBUG_PACKET; irdp->flags &= ~IF_DEBUG_MESSAGES; irdp->flags &= ~IF_DEBUG_MISC; -- 2.39.5