From ce68a032c2a4e3dd8056b0a1232693cd500ca4b1 Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 21 Sep 2022 21:12:03 +0000 Subject: [PATCH] The values for fib_priority are OS dependent. To help portability move the RTP_BGP and similar defines all into kroute.c and export them via kr_default_prio() and kr_check_prio(). OK tb@ --- usr.sbin/bgpd/bgpd.h | 4 +++- usr.sbin/bgpd/kroute.c | 16 +++++++++++++++- usr.sbin/bgpd/parse.y | 14 ++++++-------- usr.sbin/bgpd/printconf.c | 4 ++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 115b93d9c23..7eedb84f988 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.452 2022/08/31 15:51:44 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.453 2022/09/21 21:12:03 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1281,6 +1281,8 @@ RB_PROTOTYPE(roa_tree, roa, entry, roa_cmp); /* kroute.c */ int kr_init(int *, uint8_t); +int kr_default_prio(void); +int kr_check_prio(long long); int ktable_update(u_int, char *, int); void ktable_preload(void); void ktable_postload(void); diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 1975088bc6d..a398b97f0c4 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.299 2022/09/15 08:20:14 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.300 2022/09/21 21:12:03 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -257,6 +257,20 @@ kr_init(int *fd, uint8_t fib_prio) return (0); } +int +kr_default_prio(void) +{ + return RTP_BGP; +} + +int +kr_check_prio(long long prio) +{ + if (prio <= RTP_LOCAL || prio > RTP_MAX) + return 0; + return 1; +} + int ktable_new(u_int rtableid, u_int rdomid, char *name, int fs) { diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index a5484cf28ab..ce44288b993 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.435 2022/08/17 15:15:26 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.436 2022/09/21 21:12:04 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -708,9 +708,8 @@ conf_main : AS as4number { TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } | FIBPRIORITY NUMBER { - if ($2 <= RTP_LOCAL || $2 > RTP_MAX) { - yyerror("fib-priority %lld must be between " - "%u and %u", $2, RTP_LOCAL + 1, RTP_MAX); + if (!kr_check_prio($2)) { + yyerror("fib-priority %lld out of range", $2); YYERROR; } conf->fib_priority = $2; @@ -1046,9 +1045,8 @@ network : NETWORK prefix filter_set { } | NETWORK family PRIORITY NUMBER filter_set { struct network *n; - if ($4 <= RTP_LOCAL && $4 > RTP_MAX) { - yyerror("priority %lld must be between " - "%u and %u", $4, RTP_LOCAL + 1, RTP_MAX); + if (!kr_check_prio($4)) { + yyerror("priority %lld out of range", $4); YYERROR; } @@ -3598,7 +3596,7 @@ init_config(struct bgpd_config *c) c->holdtime = INTERVAL_HOLD; c->connectretry = INTERVAL_CONNECTRETRY; c->bgpid = get_bgpid(); - c->fib_priority = RTP_BGP; + c->fib_priority = kr_default_prio(); c->default_tableid = getrtable(); if (!ktable_exists(c->default_tableid, &rdomid)) fatalx("current routing table %u does not exist", diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index a395d175467..605ed0009a7 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.158 2022/08/17 09:15:06 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.159 2022/09/21 21:12:04 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -417,7 +417,7 @@ print_mainconf(struct bgpd_config *conf) printf("nexthop qualify via bgp\n"); if (conf->flags & BGPD_FLAG_NEXTHOP_DEFAULT) printf("nexthop qualify via default\n"); - if (conf->fib_priority != RTP_BGP) + if (conf->fib_priority != kr_default_prio()) printf("fib-priority %hhu\n", conf->fib_priority); printf("\n"); } -- 2.20.1