summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2022-07-23 10:24:02 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2022-07-23 10:24:02 +0000
commitaf87665261b256914621a7a88f9dc768bd5bd690 (patch)
treec88cdd31b8320f0ac125d4d72bfdc0bdf566e915
parentc0f10c09e4649ba12c4eea67e8be8a2d59c4ae05 (diff)
Refactor and rename bgpd_filternexthop() to bgpd_oknexthop()
Simplify the logic and adjust kroute_match() which makes the code easier to understand. OK tb@
-rw-r--r--usr.sbin/bgpd/bgpd.c24
-rw-r--r--usr.sbin/bgpd/bgpd.h4
-rw-r--r--usr.sbin/bgpd/kroute.c12
3 files changed, 17 insertions, 23 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index 600e1f89795..2a2b515fdc6 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -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);
}
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index ef75e651206..ce50f2bc7d9 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -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 *);
diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c
index d261d4220e0..49a73201822 100644
--- a/usr.sbin/bgpd/kroute.c
+++ b/usr.sbin/bgpd/kroute.c
@@ -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);
}