On Wed, Sep 21, 2022 at 07:55:24PM +0200, Claudio Jeker wrote: > Different systems need different ways to define fib-priority. > Introduce two kroute specific helper functions that are used by the parser > so that the RTP_XYZ defines no longer leak outside of kroute.c > > kr_default_prio() on OpenBSD returns RTP_BGP. On Linux that will be > RTPROT_BGP and on FreeBSD it will be 3 (for RTF_PROTO3). > > kr_check_prio() checks that the value is in the valid range. Now the error > message from parse.y is a bit less helpful but I think that is OK.
ok tb > > -- > :wq Claudio > > Index: bgpd.h > =================================================================== > RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v > retrieving revision 1.452 > diff -u -p -r1.452 bgpd.h > --- bgpd.h 31 Aug 2022 15:51:44 -0000 1.452 > +++ bgpd.h 21 Sep 2022 17:48:53 -0000 > @@ -1281,6 +1281,8 @@ RB_PROTOTYPE(roa_tree, roa, entry, roa_c > > /* 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); > Index: kroute.c > =================================================================== > RCS file: /cvs/src/usr.sbin/bgpd/kroute.c,v > retrieving revision 1.299 > diff -u -p -r1.299 kroute.c > --- kroute.c 15 Sep 2022 08:20:14 -0000 1.299 > +++ kroute.c 21 Sep 2022 17:43:12 -0000 > @@ -258,6 +258,20 @@ kr_init(int *fd, uint8_t fib_prio) > } > > 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) > { > struct ktable **xkrt; > Index: parse.y > =================================================================== > RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v > retrieving revision 1.435 > diff -u -p -r1.435 parse.y > --- parse.y 17 Aug 2022 15:15:26 -0000 1.435 > +++ parse.y 21 Sep 2022 17:47:40 -0000 > @@ -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", > Index: printconf.c > =================================================================== > RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v > retrieving revision 1.158 > diff -u -p -r1.158 printconf.c > --- printconf.c 17 Aug 2022 09:15:06 -0000 1.158 > +++ printconf.c 21 Sep 2022 17:38:57 -0000 > @@ -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"); > } >