From: claudio Date: Fri, 22 Jul 2022 17:26:58 +0000 (+0000) Subject: Revert previous commit. The RTP_MINE checks on struct kroute_full are X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=aae7fbb021ca33282796f4b26dee648dfb98074f;p=openbsd Revert previous commit. The RTP_MINE checks on struct kroute_full are not correct because kr_tofull() replaces RTP_MINE with the real priority. Noticed because of incorrect nexthop selection. --- diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 0c63a2ad4e0..600e1f89795 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.250 2022/07/22 11:17:48 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.251 2022/07/22 17:26:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1119,7 +1119,7 @@ int bgpd_filternexthop(struct kroute_full *kf) { /* kernel routes are never filtered */ - if (kf->priority != RTP_MINE && kf->prefixlen != 0) + if (kf->flags & F_KERNEL && kf->prefixlen != 0) return (0); if (cflags & BGPD_FLAG_NEXTHOP_BGP) { diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index e1f34883a41..ef75e651206 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.443 2022/07/22 11:17:48 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.444 2022/07/22 17:26:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -54,8 +54,6 @@ #define MAX_RTSOCK_BUF (2 * 1024 * 1024) #define MAX_COMM_MATCH 3 -#define RTP_MINE 0xff /* internal route priority */ - #define BGPD_OPT_VERBOSE 0x0001 #define BGPD_OPT_VERBOSE2 0x0002 #define BGPD_OPT_NOACTION 0x0004 @@ -76,11 +74,12 @@ #define SOCKET_NAME "/var/run/bgpd.sock" #define F_BGPD 0x0001 -#define F_BGPD_INSERTED 0x0002 +#define F_KERNEL 0x0002 #define F_CONNECTED 0x0004 #define F_NEXTHOP 0x0008 #define F_DOWN 0x0010 #define F_STATIC 0x0020 +#define F_BGPD_INSERTED 0x0040 #define F_REJECT 0x0080 #define F_BLACKHOLE 0x0100 #define F_LONGER 0x0200 diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 6047432f1ec..d261d4220e0 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.277 2022/07/22 11:17:48 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.278 2022/07/22 17:26:58 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker @@ -42,6 +42,8 @@ #include "bgpd.h" #include "log.h" +#define RTP_MINE 0xff + struct ktable **krt; u_int krt_size; @@ -1337,7 +1339,7 @@ kr_redistribute(int type, struct ktable *kt, struct kroute_full *kf) return; } - if (kf->priority == RTP_MINE) + if (!(kf->flags & F_KERNEL)) return; switch (kf->prefix.aid) { @@ -1758,7 +1760,8 @@ kroute_insert(struct ktable *kt, struct kroute_full *kf) krm->next = kr; } - if (kf->priority != RTP_MINE && kf->flags & F_CONNECTED) + if ((kr->flags & (F_KERNEL | F_CONNECTED)) == + (F_KERNEL | F_CONNECTED)) if (kif_kr_insert(kr) == -1) return (-1); @@ -1798,7 +1801,8 @@ kroute_insert(struct ktable *kt, struct kroute_full *kf) kr6m->next = kr6; } - if (kf->priority != RTP_MINE && kf->flags & F_CONNECTED) + if ((kr6->flags & (F_KERNEL | F_CONNECTED)) == + (F_KERNEL | F_CONNECTED)) if (kif_kr6_insert(kr6) == -1) return (-1); @@ -1809,7 +1813,7 @@ kroute_insert(struct ktable *kt, struct kroute_full *kf) } /* XXX this is wrong for nexthop validated via BGP */ - if (kf->priority != RTP_MINE) { + if (kf->flags & F_KERNEL) { RB_FOREACH(h, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &h->nexthop, kf->prefixlen) == 0) @@ -1869,7 +1873,7 @@ kroute_remove(struct ktable *kt, struct kroute *kr) if (s->kroute == kr) knexthop_validate(kt, s); - if (kr->priority != RTP_MINE && kr == krm && kr->next == NULL) + if (kr->flags & F_KERNEL && kr == krm && kr->next == NULL) /* again remove only once */ kr_redistribute(IMSG_NETWORK_REMOVE, kt, kr_tofull(kr)); @@ -1987,7 +1991,7 @@ kroute6_remove(struct ktable *kt, struct kroute6 *kr) if (s->kroute == kr) knexthop_validate(kt, s); - if (kr->priority != RTP_MINE && kr == krm && kr->next == NULL) + if (kr->flags & F_KERNEL && kr == krm && kr->next == NULL) /* again remove only once */ kr_redistribute(IMSG_NETWORK_REMOVE, kt, kr6_tofull(kr)); @@ -3182,6 +3186,7 @@ dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct kroute_full *kf) } memset(kf, 0, sizeof(*kf)); + kf->flags = F_KERNEL; if (rtm->rtm_flags & RTF_STATIC) kf->flags |= F_STATIC; @@ -3190,12 +3195,7 @@ dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct kroute_full *kf) if (rtm->rtm_flags & RTF_REJECT) kf->flags |= F_REJECT; - /* adjust priority here */ - if (rtm->rtm_priority == kr_state.fib_prio) - kf->priority = RTP_MINE; - else - kf->priority = rtm->rtm_priority; - + kf->priority = rtm->rtm_priority; label = (struct sockaddr_rtlabel *)rti_info[RTAX_LABEL]; if (label != NULL) if (strlcpy(kf->label, label->sr_label, sizeof(kf->label)) >= @@ -3265,6 +3265,9 @@ kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (0); + if (!(kr->flags & F_KERNEL)) + return (0); + if (mpath) { /* get the correct route */ if ((kr = kroute_matchgw(kr, &kf->nexthop)) == NULL) { @@ -3273,10 +3276,6 @@ kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) return (0); } } - if (kf->priority == RTP_MINE) { - kr->flags &= ~F_BGPD_INSERTED; - return (0); - } if (kroute_remove(kt, kr) == -1) return (-1); break; @@ -3284,6 +3283,9 @@ kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (0); + if (!(kr6->flags & F_KERNEL)) + return (0); + if (mpath) { /* get the correct route */ if ((kr6 = kroute6_matchgw(kr6, &kf->nexthop)) == @@ -3293,10 +3295,6 @@ kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) return (0); } } - if (kf->priority == RTP_MINE) { - kr6->flags &= ~F_BGPD_INSERTED; - return (0); - } if (kroute6_remove(kt, kr6) == -1) return (-1); break; @@ -3318,7 +3316,7 @@ kr_fib_change(struct ktable *kt, struct kroute_full *kf, int type, int mpath) case AID_INET: if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { - if (kf->priority != RTP_MINE) { + if (kr->flags & F_KERNEL) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr = kroute_matchgw(kr, &kf->nexthop)) == @@ -3376,8 +3374,6 @@ kr_fib_change(struct ktable *kt, struct kroute_full *kf, int type, int mpath) } if (kr->flags & F_NEXTHOP && changed) knexthop_track(kt, kr); - } else { - kr->flags &= ~F_BGPD_INSERTED; } } else { add4: @@ -3387,7 +3383,7 @@ add4: case AID_INET6: if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { - if (kf->priority != RTP_MINE) { + if (kr6->flags & F_KERNEL) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr6 = kroute6_matchgw(kr6, &kf->nexthop)) @@ -3453,8 +3449,6 @@ add4: if (kr6->flags & F_NEXTHOP && changed) knexthop_track(kt, kr6); - } else { - kr6->flags &= ~F_BGPD_INSERTED; } } else { add6: diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 3c9456c7559..6a7cfdc95dd 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.556 2022/07/22 11:17:48 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.557 2022/07/22 17:26:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -4256,6 +4256,7 @@ network_dump_upcall(struct rib_entry *re, void *ptr) memcpy(&kf.nexthop, &prefix_nexthop(p)->true_nexthop, sizeof(kf.nexthop)); kf.prefixlen = p->pt->prefixlen; + kf.flags = F_KERNEL; if ((asp->flags & F_ANN_DYNAMIC) == 0) kf.flags = F_STATIC; if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NETWORK, 0,