From 703f44cfb322516d88db0048d4dcc5bb5da5304d Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 22 Jun 2022 14:56:11 +0000 Subject: [PATCH] Use struct kroute_full in bgpd_filternexthop() so this code becomes a lot simpler. OK tb@ --- usr.sbin/bgpd/bgpd.c | 16 +++++----------- usr.sbin/bgpd/bgpd.h | 4 ++-- usr.sbin/bgpd/kroute.c | 10 ++++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 67e4d8dda86..68d393e0425 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.246 2022/06/15 10:10:03 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.247 2022/06/22 14:56:11 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1114,25 +1114,19 @@ send_network(int type, struct network_config *net, struct filter_set_head *h) } int -bgpd_filternexthop(struct kroute *kr, struct kroute6 *kr6) +bgpd_filternexthop(struct kroute_full *kf) { /* kernel routes are never filtered */ - if (kr && kr->flags & F_KERNEL && kr->prefixlen != 0) - return (0); - if (kr6 && kr6->flags & F_KERNEL && kr6->prefixlen != 0) + if (kf->flags & F_KERNEL && kf->prefixlen != 0) return (0); if (cflags & BGPD_FLAG_NEXTHOP_BGP) { - if (kr && kr->flags & F_BGPD) - return (0); - if (kr6 && kr6->flags & F_BGPD) + if (kf->flags & F_BGPD) return (0); } if (cflags & BGPD_FLAG_NEXTHOP_DEFAULT) { - if (kr && kr->prefixlen == 0) - return (0); - if (kr6 && kr6->prefixlen == 0) + if (kf->prefixlen == 0) return (0); } diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index ac1545b844d..e1a4dd46e6b 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.433 2022/06/22 14:48:51 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.434 2022/06/22 14:56:12 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -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 *, struct kroute6 *); +int bgpd_filternexthop(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 70534b417eb..8f9a710195e 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.262 2022/06/22 14:48:51 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.263 2022/06/22 14:56:12 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker @@ -2491,8 +2491,9 @@ 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->r, NULL) == 0) - return (kr); + if (matchall || + bgpd_filternexthop(kr_tofull(&kr->r)) == 0) + return (kr); } return (NULL); @@ -2508,7 +2509,8 @@ 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(NULL, &kr6->r) == 0) + if (matchall || + bgpd_filternexthop(kr6_tofull(&kr6->r)) == 0) return (kr6); } -- 2.20.1