From 538665fefe81fa991eb3779faa72ea43b9a6e655 Mon Sep 17 00:00:00 2001 From: Michel Machado Date: Wed, 15 Sep 2021 14:22:58 -0400 Subject: [PATCH] cps: correct returned error code for RTM_DELROUTE Although the Linux kernel uses ENOENT for similar situations (e.g. when RTM_NEWROUTE tries to replace an entry that does not exist), it uses ESRCH for RTM_DELROUTE. Thus, this patch replaces ENOENT with ESRCH when returning a not-found error for RTM_DELROUTE. This patch was motivated by many enigmatic log entries from Bird like this one: bird[]: Netlink: No such file or directory --- cps/rd.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cps/rd.c b/cps/rd.c index f928d95d..c7c64de3 100644 --- a/cps/rd.c +++ b/cps/rd.c @@ -289,20 +289,31 @@ static int del_route(struct route_update *update, const struct cps_config *cps_conf) { struct gk_fib *prefix_fib; - int ret; - ret = get_prefix_fib(update, &cps_conf->gk->lpm_tbl, &prefix_fib); + int ret = get_prefix_fib(update, &cps_conf->gk->lpm_tbl, &prefix_fib); if (ret < 0) - return ret; + goto error; - if (prefix_fib == NULL) - return -ENOENT; + if (prefix_fib == NULL) { + ret = -ENOENT; + goto error; + } ret = can_rd_del_route(update, prefix_fib); if (ret < 0) - return ret; + goto error; - return del_fib_entry_numerical(&update->prefix_info, cps_conf->gk); + ret = del_fib_entry_numerical(&update->prefix_info, cps_conf->gk); + +error: + /* + * Although the Linux kernel uses ENOENT for similar situations (e.g. + * when RTM_NEWROUTE tries to replace an entry that does not exist), + * it uses ESRCH for RTM_DELROUTE. + */ + if (ret == -ENOENT) + return -ESRCH; + return ret; } /*