-/* $OpenBSD: kroute.c,v 1.276 2022/07/21 10:22:43 claudio Exp $ */
+/* $OpenBSD: kroute.c,v 1.277 2022/07/22 11:17:48 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
#include "bgpd.h"
#include "log.h"
-#define RTP_MINE 0xff
-
struct ktable **krt;
u_int krt_size;
return;
}
- if (!(kf->flags & F_KERNEL))
+ if (kf->priority == RTP_MINE)
return;
switch (kf->prefix.aid) {
krm->next = kr;
}
- if ((kr->flags & (F_KERNEL | F_CONNECTED)) ==
- (F_KERNEL | F_CONNECTED))
+ if (kf->priority != RTP_MINE && kf->flags & F_CONNECTED)
if (kif_kr_insert(kr) == -1)
return (-1);
kr6m->next = kr6;
}
- if ((kr6->flags & (F_KERNEL | F_CONNECTED)) ==
- (F_KERNEL | F_CONNECTED))
+ if (kf->priority != RTP_MINE && kf->flags & F_CONNECTED)
if (kif_kr6_insert(kr6) == -1)
return (-1);
}
/* XXX this is wrong for nexthop validated via BGP */
- if (kf->flags & F_KERNEL) {
+ if (kf->priority != RTP_MINE) {
RB_FOREACH(h, knexthop_tree, KT2KNT(kt))
if (prefix_compare(&kf->prefix, &h->nexthop,
kf->prefixlen) == 0)
if (s->kroute == kr)
knexthop_validate(kt, s);
- if (kr->flags & F_KERNEL && kr == krm && kr->next == NULL)
+ if (kr->priority != RTP_MINE && kr == krm && kr->next == NULL)
/* again remove only once */
kr_redistribute(IMSG_NETWORK_REMOVE, kt, kr_tofull(kr));
if (s->kroute == kr)
knexthop_validate(kt, s);
- if (kr->flags & F_KERNEL && kr == krm && kr->next == NULL)
+ if (kr->priority != RTP_MINE && kr == krm && kr->next == NULL)
/* again remove only once */
kr_redistribute(IMSG_NETWORK_REMOVE, kt, kr6_tofull(kr));
}
memset(kf, 0, sizeof(*kf));
- kf->flags = F_KERNEL;
if (rtm->rtm_flags & RTF_STATIC)
kf->flags |= F_STATIC;
if (rtm->rtm_flags & RTF_REJECT)
kf->flags |= F_REJECT;
- kf->priority = rtm->rtm_priority;
+ /* adjust priority here */
+ if (rtm->rtm_priority == kr_state.fib_prio)
+ kf->priority = RTP_MINE;
+ else
+ 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)) >=
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) {
return (0);
}
}
+ if (kf->priority == RTP_MINE) {
+ kr->flags &= ~F_BGPD_INSERTED;
+ return (0);
+ }
if (kroute_remove(kt, kr) == -1)
return (-1);
break;
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)) ==
return (0);
}
}
+ if (kf->priority == RTP_MINE) {
+ kr6->flags &= ~F_BGPD_INSERTED;
+ return (0);
+ }
if (kroute6_remove(kt, kr6) == -1)
return (-1);
break;
case AID_INET:
if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen,
kf->priority)) != NULL) {
- if (kr->flags & F_KERNEL) {
+ if (kf->priority != RTP_MINE) {
/* get the correct route */
if (mpath && type == RTM_CHANGE &&
(kr = kroute_matchgw(kr, &kf->nexthop)) ==
}
if (kr->flags & F_NEXTHOP && changed)
knexthop_track(kt, kr);
+ } else {
+ kr->flags &= ~F_BGPD_INSERTED;
}
} else {
add4:
case AID_INET6:
if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen,
kf->priority)) != NULL) {
- if (kr6->flags & F_KERNEL) {
+ if (kf->priority != RTP_MINE) {
/* get the correct route */
if (mpath && type == RTM_CHANGE &&
(kr6 = kroute6_matchgw(kr6, &kf->nexthop))
if (kr6->flags & F_NEXTHOP && changed)
knexthop_track(kt, kr6);
+ } else {
+ kr6->flags &= ~F_BGPD_INSERTED;
}
} else {
add6: