mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Refactor and rename bgpd_filternexthop() to bgpd_oknexthop()
Simplify the logic and adjust kroute_match() which makes the code easier to understand. OK tb@
This commit is contained in:
parent
e9dce5e767
commit
b369529143
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bgpd.c,v 1.251 2022/07/22 17:26:58 claudio Exp $ */
|
||||
/* $OpenBSD: bgpd.c,v 1.252 2022/07/23 10:24:00 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@ -1115,23 +1115,19 @@ send_network(int type, struct network_config *net, struct filter_set_head *h)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if a route can be used for nexthop resolution.
|
||||
*/
|
||||
int
|
||||
bgpd_filternexthop(struct kroute_full *kf)
|
||||
bgpd_oknexthop(struct kroute_full *kf)
|
||||
{
|
||||
/* kernel routes are never filtered */
|
||||
if (kf->flags & F_KERNEL && kf->prefixlen != 0)
|
||||
return (0);
|
||||
if (kf->flags & F_BGPD)
|
||||
return ((cflags & BGPD_FLAG_NEXTHOP_BGP) != 0);
|
||||
|
||||
if (cflags & BGPD_FLAG_NEXTHOP_BGP) {
|
||||
if (kf->flags & F_BGPD)
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (cflags & BGPD_FLAG_NEXTHOP_DEFAULT) {
|
||||
if (kf->prefixlen == 0)
|
||||
return (0);
|
||||
}
|
||||
if (kf->prefixlen == 0)
|
||||
return ((cflags & BGPD_FLAG_NEXTHOP_DEFAULT) != 0);
|
||||
|
||||
/* any other route is fine */
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bgpd.h,v 1.444 2022/07/22 17:26:58 claudio Exp $ */
|
||||
/* $OpenBSD: bgpd.h,v 1.445 2022/07/23 10:24:01 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@ -1265,7 +1265,7 @@ void send_nexthop_update(struct kroute_nexthop *);
|
||||
void send_imsg_session(int, pid_t, void *, uint16_t);
|
||||
int send_network(int, struct network_config *,
|
||||
struct filter_set_head *);
|
||||
int bgpd_filternexthop(struct kroute_full *);
|
||||
int bgpd_oknexthop(struct kroute_full *);
|
||||
void set_pollfd(struct pollfd *, struct imsgbuf *);
|
||||
int handle_pollfd(struct pollfd *, struct imsgbuf *);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: kroute.c,v 1.278 2022/07/22 17:26:58 claudio Exp $ */
|
||||
/* $OpenBSD: kroute.c,v 1.279 2022/07/23 10:24:01 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
|
||||
@ -2444,7 +2444,7 @@ knexthop_send_update(struct knexthop *kn)
|
||||
}
|
||||
|
||||
struct kroute *
|
||||
kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
|
||||
kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchany)
|
||||
{
|
||||
int i;
|
||||
struct kroute *kr;
|
||||
@ -2453,8 +2453,7 @@ kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
|
||||
for (i = 32; i >= 0; i--) {
|
||||
applymask(&masked, key, i);
|
||||
if ((kr = kroute_find(kt, &masked, i, RTP_ANY)) != NULL)
|
||||
if (matchall ||
|
||||
bgpd_filternexthop(kr_tofull(kr)) == 0)
|
||||
if (matchany || bgpd_oknexthop(kr_tofull(kr)))
|
||||
return (kr);
|
||||
}
|
||||
|
||||
@ -2462,7 +2461,7 @@ kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
|
||||
}
|
||||
|
||||
struct kroute6 *
|
||||
kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
|
||||
kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchany)
|
||||
{
|
||||
int i;
|
||||
struct kroute6 *kr6;
|
||||
@ -2471,8 +2470,7 @@ kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
|
||||
for (i = 128; i >= 0; i--) {
|
||||
applymask(&masked, key, i);
|
||||
if ((kr6 = kroute6_find(kt, &masked, i, RTP_ANY)) != NULL)
|
||||
if (matchall ||
|
||||
bgpd_filternexthop(kr6_tofull(kr6)) == 0)
|
||||
if (matchany || bgpd_oknexthop(kr6_tofull(kr6)))
|
||||
return (kr6);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user