From 3d468f66043d444476004d004954503b17fdf96d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 23 Oct 2017 10:10:06 -0400 Subject: [PATCH] zebra: Move clear_nhlfe_installed to calling functions The function clear_nhlfe_installed is to be called when we get a install failure of some sort for a lsp change. Since an install failure can happen in both linux and openBSD moving the function call northbound is a good idea. I've also added it to the kernel_del_lsp for completeness on failure as well, even though neither linux or openBSD currently can fail a uninstall. This still leaves the hole where if we have multiple nhlfes and have an install failure we are not quite doing the right thing by just blanketly calling clear_nhlfe_installed. Signed-off-by: Donald Sharp --- zebra/rt_netlink.c | 19 ------------------- zebra/rt_netlink.h | 1 - zebra/zebra_mpls.c | 37 ++++++++++++++++++++++++++++++++----- zebra/zebra_mpls_netlink.c | 4 ---- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 67abe53c39..e8333ef0cf 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -2474,23 +2474,4 @@ int netlink_mpls_multipath(int cmd, zebra_lsp_t *lsp) return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns, 0); } - -/* - * Handle failure in LSP install, clear flags for NHLFE. - */ -void clear_nhlfe_installed(zebra_lsp_t *lsp) -{ - zebra_nhlfe_t *nhlfe; - struct nexthop *nexthop; - - for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { - nexthop = nhlfe->nexthop; - if (!nexthop) - continue; - - UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED); - UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); - } -} - #endif /* HAVE_NETLINK */ diff --git a/zebra/rt_netlink.h b/zebra/rt_netlink.h index 980ff915cc..afb03f878d 100644 --- a/zebra/rt_netlink.h +++ b/zebra/rt_netlink.h @@ -54,7 +54,6 @@ void rt_netlink_init(void); -extern void clear_nhlfe_installed(zebra_lsp_t *lsp); extern int netlink_mpls_multipath(int cmd, zebra_lsp_t *lsp); extern int netlink_route_change(struct sockaddr_nl *snl, struct nlmsghdr *h, diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 7b87355ed4..3765849adf 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -129,6 +129,24 @@ static int mpls_processq_init(struct zebra_t *zebra); /* Static functions */ +/* + * Handle failure in LSP install, clear flags for NHLFE. + */ +static void clear_nhlfe_installed(zebra_lsp_t *lsp) +{ + zebra_nhlfe_t *nhlfe; + struct nexthop *nexthop; + + for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { + nexthop = nhlfe->nexthop; + if (!nexthop) + continue; + + UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED); + UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); + } +} + /* * Install label forwarding entry based on labeled-route entry. */ @@ -821,11 +839,16 @@ static void lsp_select_best_nhlfe(zebra_lsp_t *lsp) */ static void lsp_uninstall_from_kernel(struct hash_backet *backet, void *ctxt) { + int ret; zebra_lsp_t *lsp; lsp = (zebra_lsp_t *)backet->data; - if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) - kernel_del_lsp(lsp); + if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) { + ret = kernel_del_lsp(lsp); + + if (!ret) + clear_nhlfe_installed(lsp); + } } /* @@ -846,6 +869,7 @@ static void lsp_schedule(struct hash_backet *backet, void *ctxt) */ static wq_item_status lsp_process(struct work_queue *wq, void *data) { + int ret = 1; zebra_lsp_t *lsp; zebra_nhlfe_t *oldbest, *newbest; char buf[BUFSIZ], buf2[BUFSIZ]; @@ -877,20 +901,23 @@ static wq_item_status lsp_process(struct work_queue *wq, void *data) if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) { /* Not already installed */ if (newbest) { - kernel_add_lsp(lsp); + ret = kernel_add_lsp(lsp); zvrf->lsp_installs++; } } else { /* Installed, may need an update and/or delete. */ if (!newbest) { - kernel_del_lsp(lsp); + ret = kernel_del_lsp(lsp); zvrf->lsp_removals++; } else if (CHECK_FLAG(lsp->flags, LSP_FLAG_CHANGED)) { - kernel_upd_lsp(lsp); + ret = kernel_upd_lsp(lsp); zvrf->lsp_installs++; } } + if (!ret) + clear_nhlfe_installed(lsp); + return WQ_SUCCESS; } diff --git a/zebra/zebra_mpls_netlink.c b/zebra/zebra_mpls_netlink.c index 8b30783a9a..8b8d018d03 100644 --- a/zebra/zebra_mpls_netlink.c +++ b/zebra/zebra_mpls_netlink.c @@ -40,8 +40,6 @@ int kernel_add_lsp(zebra_lsp_t *lsp) ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp); if (!ret) SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED); - else - clear_nhlfe_installed(lsp); return ret; } @@ -74,8 +72,6 @@ int kernel_upd_lsp(zebra_lsp_t *lsp) ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp); if (!ret) SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED); - else - clear_nhlfe_installed(lsp); return ret; } -- 2.39.5