From 83c33193959cb5b0b814105c10c45f51f27e7fb3 Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 2 Jun 2022 09:29:34 +0000 Subject: [PATCH] Cleanup ktable_exists() usage and its warning message. Check the return value in all cases and use a common idiom for this check. OK tb@ --- usr.sbin/bgpd/kroute.c | 4 ++-- usr.sbin/bgpd/parse.y | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 6295aa0b757..59ff04bc75b 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.246 2022/05/23 13:40:12 deraadt Exp $ */ +/* $OpenBSD: kroute.c,v 1.247 2022/06/02 09:29:34 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -440,7 +440,7 @@ ktable_exists(u_int rtableid, u_int *rdomid) if (errno == ENOENT) /* table nonexistent */ return (0); - log_warn("%s: sysctl", __func__); + log_warn("sysctl net.route.rtableid"); /* must return 0 so that the table is considered non-existent */ return (0); } diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index a0cd7b30cfa..6a9d08c3f0a 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.425 2022/05/31 09:45:33 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.426 2022/06/02 09:29:34 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -873,7 +873,7 @@ conf_main : AS as4number { RT_TABLEID_MAX); YYERROR; } - if (ktable_exists($2, NULL) != 1) { + if (!ktable_exists($2, NULL)) { yyerror("rtable id %lld does not exist", $2); YYERROR; } @@ -3496,7 +3496,9 @@ init_config(struct bgpd_config *c) c->bgpid = get_bgpid(); c->fib_priority = RTP_BGP; c->default_tableid = getrtable(); - ktable_exists(c->default_tableid, &rdomid); + if (!ktable_exists(c->default_tableid, &rdomid)) + fatalx("current routing table %u does not exist", + c->default_tableid); if (rdomid != c->default_tableid) fatalx("current routing table %u is not a routing domain", c->default_tableid); @@ -4233,7 +4235,7 @@ rib_add_fib(struct rde_rib *rr, u_int rtableid) { u_int rdom; - if (ktable_exists(rtableid, &rdom) != 1) { + if (!ktable_exists(rtableid, &rdom)) { yyerror("rtable id %u does not exist", rtableid); return (-1); } -- 2.20.1