-/* $OpenBSD: kroute.c,v 1.264 2022/06/22 15:24:58 claudio Exp $ */
+/* $OpenBSD: kroute.c,v 1.265 2022/06/23 07:43:37 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
} kr_state;
struct kroute {
- struct in_addr prefix;
- struct in_addr nexthop;
- uint32_t mplslabel;
- uint16_t flags;
- uint16_t labelid;
- u_short ifindex;
- uint8_t prefixlen;
- uint8_t priority;
+ RB_ENTRY(kroute) entry;
+ struct kroute *next;
+ struct in_addr prefix;
+ struct in_addr nexthop;
+ uint32_t mplslabel;
+ uint16_t flags;
+ uint16_t labelid;
+ u_short ifindex;
+ uint8_t prefixlen;
+ uint8_t priority;
};
struct kroute6 {
- struct in6_addr prefix;
- struct in6_addr nexthop;
- uint32_t mplslabel;
- uint16_t flags;
- uint16_t labelid;
- u_short ifindex;
- uint8_t prefixlen;
- uint8_t priority;
-};
-
-struct kroute_node {
- RB_ENTRY(kroute_node) entry;
- struct kroute r;
- struct kroute_node *next;
-};
-
-struct kroute6_node {
- RB_ENTRY(kroute6_node) entry;
- struct kroute6 r;
- struct kroute6_node *next;
+ RB_ENTRY(kroute6) entry;
+ struct kroute6 *next;
+ struct in6_addr prefix;
+ struct in6_addr nexthop;
+ uint32_t mplslabel;
+ uint16_t flags;
+ uint16_t labelid;
+ u_short ifindex;
+ uint8_t prefixlen;
+ uint8_t priority;
};
-struct knexthop_node {
- RB_ENTRY(knexthop_node) entry;
+struct knexthop {
+ RB_ENTRY(knexthop) entry;
struct bgpd_addr nexthop;
void *kroute;
};
struct kif_kr {
LIST_ENTRY(kif_kr) entry;
- struct kroute_node *kr;
+ struct kroute *kr;
};
struct kif_kr6 {
LIST_ENTRY(kif_kr6) entry;
- struct kroute6_node *kr;
+ struct kroute6 *kr;
};
LIST_HEAD(kif_kr_head, kif_kr);
void kr_redistribute6(int, struct ktable *, struct kroute6 *);
struct kroute_full *kr_tofull(struct kroute *);
struct kroute_full *kr6_tofull(struct kroute6 *);
-int kroute_compare(struct kroute_node *, struct kroute_node *);
-int kroute6_compare(struct kroute6_node *, struct kroute6_node *);
-int knexthop_compare(struct knexthop_node *, struct knexthop_node *);
+int kroute_compare(struct kroute *, struct kroute *);
+int kroute6_compare(struct kroute6 *, struct kroute6 *);
+int knexthop_compare(struct knexthop *, struct knexthop *);
int kredist_compare(struct kredist_node *, struct kredist_node *);
int kif_compare(struct kif_node *, struct kif_node *);
-struct kroute_node *kroute_find(struct ktable *, const struct bgpd_addr *,
+struct kroute *kroute_find(struct ktable *, const struct bgpd_addr *,
uint8_t, uint8_t);
-struct kroute_node *kroute_matchgw(struct kroute_node *,
- struct bgpd_addr *);
-int kroute_insert(struct ktable *, struct kroute_node *);
-int kroute_remove(struct ktable *, struct kroute_node *);
-void kroute_clear(struct ktable *);
+struct kroute *kroute_matchgw(struct kroute *, struct bgpd_addr *);
+int kroute_insert(struct ktable *, struct kroute *);
+int kroute_remove(struct ktable *, struct kroute *);
+void kroute_clear(struct ktable *);
-struct kroute6_node *kroute6_find(struct ktable *, const struct bgpd_addr *,
+struct kroute6 *kroute6_find(struct ktable *, const struct bgpd_addr *,
uint8_t, uint8_t);
-struct kroute6_node *kroute6_matchgw(struct kroute6_node *,
- struct bgpd_addr *);
-int kroute6_insert(struct ktable *, struct kroute6_node *);
-int kroute6_remove(struct ktable *, struct kroute6_node *);
-void kroute6_clear(struct ktable *);
-
-struct knexthop_node *knexthop_find(struct ktable *, struct bgpd_addr *);
-int knexthop_insert(struct ktable *,
- struct knexthop_node *);
-int knexthop_remove(struct ktable *,
- struct knexthop_node *);
-void knexthop_clear(struct ktable *);
-
-struct kif_node *kif_find(int);
-int kif_insert(struct kif_node *);
-int kif_remove(struct kif_node *);
-void kif_clear(void);
-
-int kif_kr_insert(struct kroute_node *);
-int kif_kr_remove(struct kroute_node *);
-
-int kif_kr6_insert(struct kroute6_node *);
-int kif_kr6_remove(struct kroute6_node *);
-
-int kroute_validate(struct kroute *);
-int kroute6_validate(struct kroute6 *);
-void knexthop_validate(struct ktable *,
- struct knexthop_node *);
-void knexthop_track(struct ktable *, void *);
-void knexthop_send_update(struct knexthop_node *);
-struct kroute_node *kroute_match(struct ktable *, struct bgpd_addr *, int);
-struct kroute6_node *kroute6_match(struct ktable *, struct bgpd_addr *,
- int);
-void kroute_detach_nexthop(struct ktable *,
- struct knexthop_node *);
+struct kroute6 *kroute6_matchgw(struct kroute6 *, struct bgpd_addr *);
+int kroute6_insert(struct ktable *, struct kroute6 *);
+int kroute6_remove(struct ktable *, struct kroute6 *);
+void kroute6_clear(struct ktable *);
+
+struct knexthop *knexthop_find(struct ktable *, struct bgpd_addr *);
+int knexthop_insert(struct ktable *, struct knexthop *);
+int knexthop_remove(struct ktable *, struct knexthop *);
+void knexthop_clear(struct ktable *);
+
+struct kif_node *kif_find(int);
+int kif_insert(struct kif_node *);
+int kif_remove(struct kif_node *);
+void kif_clear(void);
+
+int kif_kr_insert(struct kroute *);
+int kif_kr_remove(struct kroute *);
+
+int kif_kr6_insert(struct kroute6 *);
+int kif_kr6_remove(struct kroute6 *);
+
+int kroute_validate(struct kroute *);
+int kroute6_validate(struct kroute6 *);
+void knexthop_validate(struct ktable *, struct knexthop *);
+void knexthop_track(struct ktable *, void *);
+void knexthop_send_update(struct knexthop *);
+struct kroute *kroute_match(struct ktable *, struct bgpd_addr *, int);
+struct kroute6 *kroute6_match(struct ktable *, struct bgpd_addr *, int);
+void kroute_detach_nexthop(struct ktable *, struct knexthop *);
uint8_t prefixlen_classful(in_addr_t);
uint8_t mask2prefixlen(in_addr_t);
int kr_fib_delete(struct ktable *, struct kroute_full *, int);
int kr_fib_change(struct ktable *, struct kroute_full *, int, int);
-RB_PROTOTYPE(kroute_tree, kroute_node, entry, kroute_compare)
-RB_GENERATE(kroute_tree, kroute_node, entry, kroute_compare)
+RB_PROTOTYPE(kroute_tree, kroute, entry, kroute_compare)
+RB_GENERATE(kroute_tree, kroute, entry, kroute_compare)
-RB_PROTOTYPE(kroute6_tree, kroute6_node, entry, kroute6_compare)
-RB_GENERATE(kroute6_tree, kroute6_node, entry, kroute6_compare)
+RB_PROTOTYPE(kroute6_tree, kroute6, entry, kroute6_compare)
+RB_GENERATE(kroute6_tree, kroute6, entry, kroute6_compare)
-RB_PROTOTYPE(knexthop_tree, knexthop_node, entry, knexthop_compare)
-RB_GENERATE(knexthop_tree, knexthop_node, entry, knexthop_compare)
+RB_PROTOTYPE(knexthop_tree, knexthop, entry, knexthop_compare)
+RB_GENERATE(knexthop_tree, knexthop, entry, knexthop_compare)
RB_PROTOTYPE(kredist_tree, kredist_node, entry, kredist_compare)
RB_GENERATE(kredist_tree, kredist_node, entry, kredist_compare)
int
kr4_change(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute_node *kr;
- int action = RTM_ADD;
- uint16_t labelid;
+ struct kroute *kr;
+ int action = RTM_ADD;
+ uint16_t labelid;
/* for blackhole and reject routes nexthop needs to be 127.0.0.1 */
if (kl->flags & (F_BLACKHOLE|F_REJECT))
log_warn("%s", __func__);
return (-1);
}
- kr->r.prefix.s_addr = kl->prefix.v4.s_addr;
- kr->r.prefixlen = kl->prefixlen;
- kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
- kr->r.flags = kl->flags | F_BGPD;
- kr->r.priority = RTP_MINE;
- kr->r.labelid = labelid;
+ kr->prefix.s_addr = kl->prefix.v4.s_addr;
+ kr->prefixlen = kl->prefixlen;
+ kr->nexthop.s_addr = kl->nexthop.v4.s_addr;
+ kr->flags = kl->flags | F_BGPD;
+ kr->priority = RTP_MINE;
+ kr->labelid = labelid;
if (kroute_insert(kt, kr) == -1) {
- rtlabel_unref(kr->r.labelid);
+ rtlabel_unref(kr->labelid);
free(kr);
return (-1);
}
} else {
- kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
- rtlabel_unref(kr->r.labelid);
- kr->r.labelid = labelid;
+ kr->nexthop.s_addr = kl->nexthop.v4.s_addr;
+ rtlabel_unref(kr->labelid);
+ kr->labelid = labelid;
if (kl->flags & F_BLACKHOLE)
- kr->r.flags |= F_BLACKHOLE;
+ kr->flags |= F_BLACKHOLE;
else
- kr->r.flags &= ~F_BLACKHOLE;
+ kr->flags &= ~F_BLACKHOLE;
if (kl->flags & F_REJECT)
- kr->r.flags |= F_REJECT;
+ kr->flags |= F_REJECT;
else
- kr->r.flags &= ~F_REJECT;
+ kr->flags &= ~F_REJECT;
}
- if (send_rtmsg(kr_state.fd, action, kt, &kr->r))
- kr->r.flags |= F_BGPD_INSERTED;
+ if (send_rtmsg(kr_state.fd, action, kt, kr))
+ kr->flags |= F_BGPD_INSERTED;
return (0);
}
int
kr6_change(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute6_node *kr6;
- struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT;
- int action = RTM_ADD;
- uint16_t labelid;
+ struct kroute6 *kr6;
+ struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT;
+ int action = RTM_ADD;
+ uint16_t labelid;
/* for blackhole and reject routes nexthop needs to be ::1 */
if (kl->flags & (F_BLACKHOLE|F_REJECT))
log_warn("%s", __func__);
return (-1);
}
- memcpy(&kr6->r.prefix, &kl->prefix.v6, sizeof(struct in6_addr));
- kr6->r.prefixlen = kl->prefixlen;
- memcpy(&kr6->r.nexthop, &kl->nexthop.v6,
- sizeof(struct in6_addr));
- kr6->r.flags = kl->flags | F_BGPD;
- kr6->r.priority = RTP_MINE;
- kr6->r.labelid = labelid;
+ memcpy(&kr6->prefix, &kl->prefix.v6, sizeof(struct in6_addr));
+ kr6->prefixlen = kl->prefixlen;
+ memcpy(&kr6->nexthop, &kl->nexthop.v6, sizeof(struct in6_addr));
+ kr6->flags = kl->flags | F_BGPD;
+ kr6->priority = RTP_MINE;
+ kr6->labelid = labelid;
if (kroute6_insert(kt, kr6) == -1) {
- rtlabel_unref(kr6->r.labelid);
+ rtlabel_unref(kr6->labelid);
free(kr6);
return (-1);
}
} else {
- memcpy(&kr6->r.nexthop, &kl->nexthop.v6,
- sizeof(struct in6_addr));
- rtlabel_unref(kr6->r.labelid);
- kr6->r.labelid = labelid;
+ memcpy(&kr6->nexthop, &kl->nexthop.v6, sizeof(struct in6_addr));
+ rtlabel_unref(kr6->labelid);
+ kr6->labelid = labelid;
if (kl->flags & F_BLACKHOLE)
- kr6->r.flags |= F_BLACKHOLE;
+ kr6->flags |= F_BLACKHOLE;
else
- kr6->r.flags &= ~F_BLACKHOLE;
+ kr6->flags &= ~F_BLACKHOLE;
if (kl->flags & F_REJECT)
- kr6->r.flags |= F_REJECT;
+ kr6->flags |= F_REJECT;
else
- kr6->r.flags &= ~F_REJECT;
+ kr6->flags &= ~F_REJECT;
}
- if (send_rt6msg(kr_state.fd, action, kt, &kr6->r))
- kr6->r.flags |= F_BGPD_INSERTED;
+ if (send_rt6msg(kr_state.fd, action, kt, kr6))
+ kr6->flags |= F_BGPD_INSERTED;
return (0);
}
int
krVPN4_change(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute_node *kr;
- int action = RTM_ADD;
- uint32_t mplslabel = 0;
- uint16_t labelid;
+ struct kroute *kr;
+ int action = RTM_ADD;
+ uint32_t mplslabel = 0;
+ uint16_t labelid;
/* nexthop within 127/8 -> ignore silently */
if ((kl->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) ==
log_warn("%s", __func__);
return (-1);
}
- kr->r.prefix.s_addr = kl->prefix.v4.s_addr;
- kr->r.prefixlen = kl->prefixlen;
- kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
- kr->r.flags = kl->flags | F_BGPD | F_MPLS;
- kr->r.priority = RTP_MINE;
- kr->r.labelid = labelid;
- kr->r.mplslabel = mplslabel;
- kr->r.ifindex = kl->ifindex;
+ kr->prefix.s_addr = kl->prefix.v4.s_addr;
+ kr->prefixlen = kl->prefixlen;
+ kr->nexthop.s_addr = kl->nexthop.v4.s_addr;
+ kr->flags = kl->flags | F_BGPD | F_MPLS;
+ kr->priority = RTP_MINE;
+ kr->labelid = labelid;
+ kr->mplslabel = mplslabel;
+ kr->ifindex = kl->ifindex;
if (kroute_insert(kt, kr) == -1) {
- rtlabel_unref(kr->r.labelid);
+ rtlabel_unref(kr->labelid);
free(kr);
return (-1);
}
} else {
- kr->r.mplslabel = mplslabel;
- kr->r.ifindex = kl->ifindex;
- kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
- rtlabel_unref(kr->r.labelid);
- kr->r.labelid = labelid;
+ kr->mplslabel = mplslabel;
+ kr->ifindex = kl->ifindex;
+ kr->nexthop.s_addr = kl->nexthop.v4.s_addr;
+ rtlabel_unref(kr->labelid);
+ kr->labelid = labelid;
if (kl->flags & F_BLACKHOLE)
- kr->r.flags |= F_BLACKHOLE;
+ kr->flags |= F_BLACKHOLE;
else
- kr->r.flags &= ~F_BLACKHOLE;
+ kr->flags &= ~F_BLACKHOLE;
if (kl->flags & F_REJECT)
- kr->r.flags |= F_REJECT;
+ kr->flags |= F_REJECT;
else
- kr->r.flags &= ~F_REJECT;
+ kr->flags &= ~F_REJECT;
}
- if (send_rtmsg(kr_state.fd, action, kt, &kr->r))
- kr->r.flags |= F_BGPD_INSERTED;
+ if (send_rtmsg(kr_state.fd, action, kt, kr))
+ kr->flags |= F_BGPD_INSERTED;
return (0);
}
int
krVPN6_change(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute6_node *kr6;
- struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT;
- int action = RTM_ADD;
- uint32_t mplslabel = 0;
- uint16_t labelid;
+ struct kroute6 *kr6;
+ struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT;
+ int action = RTM_ADD;
+ uint32_t mplslabel = 0;
+ uint16_t labelid;
/* nexthop to loopback -> ignore silently */
if (IN6_IS_ADDR_LOOPBACK(&kl->nexthop.v6))
log_warn("%s", __func__);
return (-1);
}
- memcpy(&kr6->r.prefix, &kl->prefix.v6, sizeof(struct in6_addr));
- kr6->r.prefixlen = kl->prefixlen;
- memcpy(&kr6->r.nexthop, &kl->nexthop.v6,
- sizeof(struct in6_addr));
- kr6->r.flags = kl->flags | F_BGPD | F_MPLS;
- kr6->r.priority = RTP_MINE;
- kr6->r.labelid = labelid;
- kr6->r.mplslabel = mplslabel;
- kr6->r.ifindex = kl->ifindex;
+ memcpy(&kr6->prefix, &kl->prefix.v6, sizeof(struct in6_addr));
+ kr6->prefixlen = kl->prefixlen;
+ memcpy(&kr6->nexthop, &kl->nexthop.v6, sizeof(struct in6_addr));
+ kr6->flags = kl->flags | F_BGPD | F_MPLS;
+ kr6->priority = RTP_MINE;
+ kr6->labelid = labelid;
+ kr6->mplslabel = mplslabel;
+ kr6->ifindex = kl->ifindex;
if (kroute6_insert(kt, kr6) == -1) {
- rtlabel_unref(kr6->r.labelid);
+ rtlabel_unref(kr6->labelid);
free(kr6);
return (-1);
}
} else {
- kr6->r.mplslabel = mplslabel;
- kr6->r.ifindex = kl->ifindex;
- memcpy(&kr6->r.nexthop, &kl->nexthop.v6,
- sizeof(struct in6_addr));
- rtlabel_unref(kr6->r.labelid);
- kr6->r.labelid = labelid;
+ kr6->mplslabel = mplslabel;
+ kr6->ifindex = kl->ifindex;
+ memcpy(&kr6->nexthop, &kl->nexthop.v6, sizeof(struct in6_addr));
+ rtlabel_unref(kr6->labelid);
+ kr6->labelid = labelid;
if (kl->flags & F_BLACKHOLE)
- kr6->r.flags |= F_BLACKHOLE;
+ kr6->flags |= F_BLACKHOLE;
else
- kr6->r.flags &= ~F_BLACKHOLE;
+ kr6->flags &= ~F_BLACKHOLE;
if (kl->flags & F_REJECT)
- kr6->r.flags |= F_REJECT;
+ kr6->flags |= F_REJECT;
else
- kr6->r.flags &= ~F_REJECT;
+ kr6->flags &= ~F_REJECT;
}
- if (send_rt6msg(kr_state.fd, action, kt, &kr6->r))
- kr6->r.flags |= F_BGPD_INSERTED;
+ if (send_rt6msg(kr_state.fd, action, kt, kr6))
+ kr6->flags |= F_BGPD_INSERTED;
return (0);
}
int
kr_flush(u_int rtableid)
{
- struct ktable *kt;
- struct kroute_node *kr, *next;
- struct kroute6_node *kr6, *next6;
+ struct ktable *kt;
+ struct kroute *kr, *next;
+ struct kroute6 *kr6, *next6;
if ((kt = ktable_get(rtableid)) == NULL)
/* too noisy during reloads, just ignore */
return (0);
RB_FOREACH_SAFE(kr, kroute_tree, &kt->krt, next)
- if ((kr->r.flags & F_BGPD_INSERTED)) {
+ if ((kr->flags & F_BGPD_INSERTED)) {
if (kt->fib_sync) /* coupled */
- send_rtmsg(kr_state.fd, RTM_DELETE, kt, &kr->r);
+ send_rtmsg(kr_state.fd, RTM_DELETE, kt, kr);
if (kroute_remove(kt, kr) == -1)
return (-1);
}
RB_FOREACH_SAFE(kr6, kroute6_tree, &kt->krt6, next6)
- if ((kr6->r.flags & F_BGPD_INSERTED)) {
+ if ((kr6->flags & F_BGPD_INSERTED)) {
if (kt->fib_sync) /* coupled */
- send_rt6msg(kr_state.fd, RTM_DELETE, kt,
- &kr6->r);
+ send_rt6msg(kr_state.fd, RTM_DELETE, kt, kr6);
if (kroute6_remove(kt, kr6) == -1)
return (-1);
}
int
kr4_delete(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute_node *kr;
+ struct kroute *kr;
if ((kr = kroute_find(kt, &kl->prefix, kl->prefixlen,
RTP_MINE)) == NULL)
return (0);
- if (!(kr->r.flags & F_BGPD_INSERTED))
+ if (!(kr->flags & F_BGPD_INSERTED))
return (0);
- send_rtmsg(kr_state.fd, RTM_DELETE, kt, &kr->r);
+ send_rtmsg(kr_state.fd, RTM_DELETE, kt, kr);
if (kroute_remove(kt, kr) == -1)
return (-1);
int
kr6_delete(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute6_node *kr6;
+ struct kroute6 *kr6;
if ((kr6 = kroute6_find(kt, &kl->prefix, kl->prefixlen,
RTP_MINE)) == NULL)
return (0);
- if (!(kr6->r.flags & F_BGPD_INSERTED))
+ if (!(kr6->flags & F_BGPD_INSERTED))
return (0);
- send_rt6msg(kr_state.fd, RTM_DELETE, kt, &kr6->r);
+ send_rt6msg(kr_state.fd, RTM_DELETE, kt, kr6);
if (kroute6_remove(kt, kr6) == -1)
return (-1);
int
krVPN4_delete(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute_node *kr;
+ struct kroute *kr;
if ((kr = kroute_find(kt, &kl->prefix, kl->prefixlen,
RTP_MINE)) == NULL)
return (0);
- if (!(kr->r.flags & F_BGPD_INSERTED))
+ if (!(kr->flags & F_BGPD_INSERTED))
return (0);
- send_rtmsg(kr_state.fd, RTM_DELETE, kt, &kr->r);
+ send_rtmsg(kr_state.fd, RTM_DELETE, kt, kr);
if (kroute_remove(kt, kr) == -1)
return (-1);
int
krVPN6_delete(struct ktable *kt, struct kroute_full *kl)
{
- struct kroute6_node *kr6;
+ struct kroute6 *kr6;
if ((kr6 = kroute6_find(kt, &kl->prefix, kl->prefixlen,
RTP_MINE)) == NULL)
return (0);
- if (!(kr6->r.flags & F_BGPD_INSERTED))
+ if (!(kr6->flags & F_BGPD_INSERTED))
return (0);
- send_rt6msg(kr_state.fd, RTM_DELETE, kt, &kr6->r);
+ send_rt6msg(kr_state.fd, RTM_DELETE, kt, kr6);
if (kroute6_remove(kt, kr6) == -1)
return (-1);
void
kr_fib_couple(u_int rtableid)
{
- struct ktable *kt;
- struct kroute_node *kr;
- struct kroute6_node *kr6;
+ struct ktable *kt;
+ struct kroute *kr;
+ struct kroute6 *kr6;
if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */
return;
kt->fib_sync = 1;
RB_FOREACH(kr, kroute_tree, &kt->krt)
- if (kr->r.flags & F_BGPD) {
- if (send_rtmsg(kr_state.fd, RTM_ADD, kt, &kr->r))
- kr->r.flags |= F_BGPD_INSERTED;
+ if (kr->flags & F_BGPD) {
+ if (send_rtmsg(kr_state.fd, RTM_ADD, kt, kr))
+ kr->flags |= F_BGPD_INSERTED;
}
RB_FOREACH(kr6, kroute6_tree, &kt->krt6)
- if (kr6->r.flags & F_BGPD) {
- if (send_rt6msg(kr_state.fd, RTM_ADD, kt, &kr6->r))
- kr6->r.flags |= F_BGPD_INSERTED;
+ if (kr6->flags & F_BGPD) {
+ if (send_rt6msg(kr_state.fd, RTM_ADD, kt, kr6))
+ kr6->flags |= F_BGPD_INSERTED;
}
log_info("kernel routing table %u (%s) coupled", kt->rtableid,
kt->descr);
void
kr_fib_decouple(u_int rtableid)
{
- struct ktable *kt;
- struct kroute_node *kr;
- struct kroute6_node *kr6;
+ struct ktable *kt;
+ struct kroute *kr;
+ struct kroute6 *kr6;
if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */
return;
return;
RB_FOREACH(kr, kroute_tree, &kt->krt)
- if ((kr->r.flags & F_BGPD_INSERTED)) {
- if (send_rtmsg(kr_state.fd, RTM_DELETE, kt, &kr->r))
- kr->r.flags &= ~F_BGPD_INSERTED;
+ if ((kr->flags & F_BGPD_INSERTED)) {
+ if (send_rtmsg(kr_state.fd, RTM_DELETE, kt, kr))
+ kr->flags &= ~F_BGPD_INSERTED;
}
RB_FOREACH(kr6, kroute6_tree, &kt->krt6)
- if ((kr6->r.flags & F_BGPD_INSERTED)) {
- if (send_rt6msg(kr_state.fd, RTM_DELETE, kt, &kr6->r))
- kr6->r.flags &= ~F_BGPD_INSERTED;
+ if ((kr6->flags & F_BGPD_INSERTED)) {
+ if (send_rt6msg(kr_state.fd, RTM_DELETE, kt, kr6))
+ kr6->flags &= ~F_BGPD_INSERTED;
}
kt->fib_sync = 0;
int
kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr)
{
- struct ktable *kt;
- struct knexthop_node *h;
+ struct ktable *kt;
+ struct knexthop *h;
if ((kt = ktable_get(rtableid)) == NULL) {
log_warnx("%s: non-existent rtableid %d", __func__, rtableid);
void
kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr)
{
- struct ktable *kt;
- struct knexthop_node *kn;
+ struct ktable *kt;
+ struct knexthop *kn;
if ((kt = ktable_get(rtableid)) == NULL) {
log_warnx("%s: non-existent rtableid %d", __func__,
kr_show_route(struct imsg *imsg)
{
struct ktable *kt;
- struct kroute_node *kr, *kn;
- struct kroute6_node *kr6, *kn6;
+ struct kroute *kr, *kn;
+ struct kroute6 *kr6, *kn6;
struct bgpd_addr *addr;
int flags;
sa_family_t af;
struct ctl_show_nexthop snh;
- struct knexthop_node *h;
+ struct knexthop *h;
struct kif_node *kif;
u_int i;
u_short ifindex = 0;
memcpy(&af, (char *)imsg->data + sizeof(flags), sizeof(af));
if (!af || af == AF_INET)
RB_FOREACH(kr, kroute_tree, &kt->krt) {
- if (flags && (kr->r.flags & flags) == 0)
+ if (flags && (kr->flags & flags) == 0)
continue;
kn = kr;
do {
send_imsg_session(IMSG_CTL_KROUTE,
- imsg->hdr.pid, kr_tofull(&kn->r),
+ imsg->hdr.pid, kr_tofull(kn),
sizeof(struct kroute_full));
} while ((kn = kn->next) != NULL);
}
if (!af || af == AF_INET6)
RB_FOREACH(kr6, kroute6_tree, &kt->krt6) {
- if (flags && (kr6->r.flags & flags) == 0)
+ if (flags && (kr6->flags & flags) == 0)
continue;
kn6 = kr6;
do {
send_imsg_session(IMSG_CTL_KROUTE,
- imsg->hdr.pid, kr6_tofull(&kn6->r),
+ imsg->hdr.pid, kr6_tofull(kn6),
sizeof(struct kroute_full));
} while ((kn6 = kn6->next) != NULL);
}
kr = kroute_match(kt, addr, 1);
if (kr != NULL)
send_imsg_session(IMSG_CTL_KROUTE,
- imsg->hdr.pid, kr_tofull(&kr->r),
+ imsg->hdr.pid, kr_tofull(kr),
sizeof(struct kroute_full));
break;
case AID_INET6:
kr6 = kroute6_match(kt, addr, 1);
if (kr6 != NULL)
send_imsg_session(IMSG_CTL_KROUTE,
- imsg->hdr.pid, kr6_tofull(&kr6->r),
+ imsg->hdr.pid, kr6_tofull(kr6),
sizeof(struct kroute_full));
break;
}
switch (h->nexthop.aid) {
case AID_INET:
kr = h->kroute;
- snh.valid = kroute_validate(&kr->r);
+ snh.valid = kroute_validate(kr);
snh.krvalid = 1;
- snh.kr = *kr_tofull(&kr->r);
- ifindex = kr->r.ifindex;
+ snh.kr = *kr_tofull(kr);
+ ifindex = kr->ifindex;
break;
case AID_INET6:
kr6 = h->kroute;
- snh.valid = kroute6_validate(&kr6->r);
+ snh.valid = kroute6_validate(kr6);
snh.krvalid = 1;
- snh.kr = *kr6_tofull(&kr6->r);
- ifindex = kr6->r.ifindex;
+ snh.kr = *kr6_tofull(kr6);
+ ifindex = kr6->ifindex;
break;
}
if ((kif = kif_find(ifindex)) != NULL)
int
kr_reload(void)
{
- struct ktable *kt;
- struct kroute_node *kr;
- struct kroute6_node *kr6;
- struct knexthop_node *nh;
- struct network *n;
- u_int rid;
- int hasdyn = 0;
+ struct ktable *kt;
+ struct kroute *kr;
+ struct kroute6 *kr6;
+ struct knexthop *nh;
+ struct network *n;
+ u_int rid;
+ int hasdyn = 0;
for (rid = 0; rid < krt_size; rid++) {
if ((kt = ktable_get(rid)) == NULL)
if (hasdyn) {
/* only evaluate the full tree if we need */
RB_FOREACH(kr, kroute_tree, &kt->krt)
- kr_redistribute(IMSG_NETWORK_ADD, kt, &kr->r);
+ kr_redistribute(IMSG_NETWORK_ADD, kt, kr);
RB_FOREACH(kr6, kroute6_tree, &kt->krt6)
- kr_redistribute6(IMSG_NETWORK_ADD, kt, &kr6->r);
+ kr_redistribute6(IMSG_NETWORK_ADD, kt, kr6);
}
}
*/
int
-kroute_compare(struct kroute_node *a, struct kroute_node *b)
+kroute_compare(struct kroute *a, struct kroute *b)
{
- if (ntohl(a->r.prefix.s_addr) < ntohl(b->r.prefix.s_addr))
+ if (ntohl(a->prefix.s_addr) < ntohl(b->prefix.s_addr))
return (-1);
- if (ntohl(a->r.prefix.s_addr) > ntohl(b->r.prefix.s_addr))
+ if (ntohl(a->prefix.s_addr) > ntohl(b->prefix.s_addr))
return (1);
- if (a->r.prefixlen < b->r.prefixlen)
+ if (a->prefixlen < b->prefixlen)
return (-1);
- if (a->r.prefixlen > b->r.prefixlen)
+ if (a->prefixlen > b->prefixlen)
return (1);
/* if the priority is RTP_ANY finish on the first address hit */
- if (a->r.priority == RTP_ANY || b->r.priority == RTP_ANY)
+ if (a->priority == RTP_ANY || b->priority == RTP_ANY)
return (0);
- if (a->r.priority < b->r.priority)
+ if (a->priority < b->priority)
return (-1);
- if (a->r.priority > b->r.priority)
+ if (a->priority > b->priority)
return (1);
return (0);
}
int
-kroute6_compare(struct kroute6_node *a, struct kroute6_node *b)
+kroute6_compare(struct kroute6 *a, struct kroute6 *b)
{
int i;
for (i = 0; i < 16; i++) {
- if (a->r.prefix.s6_addr[i] < b->r.prefix.s6_addr[i])
+ if (a->prefix.s6_addr[i] < b->prefix.s6_addr[i])
return (-1);
- if (a->r.prefix.s6_addr[i] > b->r.prefix.s6_addr[i])
+ if (a->prefix.s6_addr[i] > b->prefix.s6_addr[i])
return (1);
}
- if (a->r.prefixlen < b->r.prefixlen)
+ if (a->prefixlen < b->prefixlen)
return (-1);
- if (a->r.prefixlen > b->r.prefixlen)
+ if (a->prefixlen > b->prefixlen)
return (1);
/* if the priority is RTP_ANY finish on the first address hit */
- if (a->r.priority == RTP_ANY || b->r.priority == RTP_ANY)
+ if (a->priority == RTP_ANY || b->priority == RTP_ANY)
return (0);
- if (a->r.priority < b->r.priority)
+ if (a->priority < b->priority)
return (-1);
- if (a->r.priority > b->r.priority)
+ if (a->priority > b->priority)
return (1);
return (0);
}
int
-knexthop_compare(struct knexthop_node *a, struct knexthop_node *b)
+knexthop_compare(struct knexthop *a, struct knexthop *b)
{
int i;
* tree management functions
*/
-struct kroute_node *
+struct kroute *
kroute_find(struct ktable *kt, const struct bgpd_addr *prefix,
uint8_t prefixlen, uint8_t prio)
{
- struct kroute_node s;
- struct kroute_node *kn, *tmp;
+ struct kroute s;
+ struct kroute *kn, *tmp;
- s.r.prefix = prefix->v4;
- s.r.prefixlen = prefixlen;
- s.r.priority = prio;
+ s.prefix = prefix->v4;
+ s.prefixlen = prefixlen;
+ s.priority = prio;
kn = RB_FIND(kroute_tree, &kt->krt, &s);
if (kn && prio == RTP_ANY) {
return (kn);
}
-struct kroute_node *
-kroute_matchgw(struct kroute_node *kr, struct bgpd_addr *gw)
+struct kroute *
+kroute_matchgw(struct kroute *kr, struct bgpd_addr *gw)
{
in_addr_t nexthop;
nexthop = gw->v4.s_addr;
do {
- if (kr->r.nexthop.s_addr == nexthop)
+ if (kr->nexthop.s_addr == nexthop)
return (kr);
kr = kr->next;
} while (kr);
}
int
-kroute_insert(struct ktable *kt, struct kroute_node *kr)
+kroute_insert(struct ktable *kt, struct kroute *kr)
{
- struct kroute_node *krm;
- struct knexthop_node *h;
- struct in_addr ina, inb;
+ struct kroute *krm;
+ struct knexthop *h;
+ struct in_addr ina, inb;
if ((krm = RB_INSERT(kroute_tree, &kt->krt, kr)) != NULL) {
/* multipath route, add at end of list */
}
/* XXX this is wrong for nexthop validated via BGP */
- if (kr->r.flags & F_KERNEL) {
- inet4applymask(&ina, &kr->r.prefix, kr->r.prefixlen);
+ if (kr->flags & F_KERNEL) {
+ inet4applymask(&ina, &kr->prefix, kr->prefixlen);
RB_FOREACH(h, knexthop_tree, KT2KNT(kt))
if (h->nexthop.aid == AID_INET) {
inet4applymask(&inb, &h->nexthop.v4,
- kr->r.prefixlen);
+ kr->prefixlen);
if (memcmp(&ina, &inb, sizeof(ina)) == 0)
knexthop_validate(kt, h);
}
- if (kr->r.flags & F_CONNECTED)
+ if (kr->flags & F_CONNECTED)
if (kif_kr_insert(kr) == -1)
return (-1);
if (krm == NULL)
/* redistribute multipath routes only once */
- kr_redistribute(IMSG_NETWORK_ADD, kt, &kr->r);
+ kr_redistribute(IMSG_NETWORK_ADD, kt, kr);
}
return (0);
}
int
-kroute_remove(struct ktable *kt, struct kroute_node *kr)
+kroute_remove(struct ktable *kt, struct kroute *kr)
{
- struct kroute_node *krm;
- struct knexthop_node *s;
+ struct kroute *krm;
+ struct knexthop *s;
if ((krm = RB_FIND(kroute_tree, &kt->krt, kr)) == NULL) {
log_warnx("%s: failed to find %s/%u", __func__,
- inet_ntoa(kr->r.prefix), kr->r.prefixlen);
+ inet_ntoa(kr->prefix), kr->prefixlen);
return (-1);
}
/* head element */
if (RB_REMOVE(kroute_tree, &kt->krt, kr) == NULL) {
log_warnx("%s: failed for %s/%u", __func__,
- inet_ntoa(kr->r.prefix), kr->r.prefixlen);
+ inet_ntoa(kr->prefix), kr->prefixlen);
return (-1);
}
if (kr->next != NULL) {
if (RB_INSERT(kroute_tree, &kt->krt, kr->next) !=
NULL) {
log_warnx("%s: failed to add %s/%u", __func__,
- inet_ntoa(kr->r.prefix), kr->r.prefixlen);
+ inet_ntoa(kr->prefix), kr->prefixlen);
return (-1);
}
}
while (krm->next != kr && krm->next != NULL)
krm = krm->next;
if (krm->next == NULL) {
- log_warnx("%s: multipath list corrupted "
- "for %s/%u", inet_ntoa(kr->r.prefix), __func__,
- kr->r.prefixlen);
+ log_warnx("%s: multipath list corrupted for %s/%u",
+ __func__, inet_ntoa(kr->prefix), kr->prefixlen);
return (-1);
}
krm->next = kr->next;
}
/* check whether a nexthop depends on this kroute */
- if (kr->r.flags & F_NEXTHOP)
+ if (kr->flags & F_NEXTHOP)
RB_FOREACH(s, knexthop_tree, KT2KNT(kt))
if (s->kroute == kr)
knexthop_validate(kt, s);
- if (kr->r.flags & F_KERNEL && 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->r);
+ kr_redistribute(IMSG_NETWORK_REMOVE, kt, kr);
- if (kr->r.flags & F_CONNECTED)
+ if (kr->flags & F_CONNECTED)
if (kif_kr_remove(kr) == -1) {
- rtlabel_unref(kr->r.labelid);
+ rtlabel_unref(kr->labelid);
free(kr);
return (-1);
}
- rtlabel_unref(kr->r.labelid);
+ rtlabel_unref(kr->labelid);
free(kr);
return (0);
void
kroute_clear(struct ktable *kt)
{
- struct kroute_node *kr;
+ struct kroute *kr;
while ((kr = RB_MIN(kroute_tree, &kt->krt)) != NULL)
kroute_remove(kt, kr);
}
-struct kroute6_node *
+struct kroute6 *
kroute6_find(struct ktable *kt, const struct bgpd_addr *prefix,
uint8_t prefixlen, uint8_t prio)
{
- struct kroute6_node s;
- struct kroute6_node *kn6, *tmp;
+ struct kroute6 s;
+ struct kroute6 *kn6, *tmp;
- s.r.prefix = prefix->v6;
- s.r.prefixlen = prefixlen;
- s.r.priority = prio;
+ s.prefix = prefix->v6;
+ s.prefixlen = prefixlen;
+ s.priority = prio;
kn6 = RB_FIND(kroute6_tree, &kt->krt6, &s);
if (kn6 && prio == RTP_ANY) {
return (kn6);
}
-struct kroute6_node *
-kroute6_matchgw(struct kroute6_node *kr, struct bgpd_addr *gw)
+struct kroute6 *
+kroute6_matchgw(struct kroute6 *kr, struct bgpd_addr *gw)
{
struct in6_addr nexthop;
nexthop = gw->v6;
do {
- if (memcmp(&kr->r.nexthop, &nexthop, sizeof(nexthop)) == 0)
+ if (memcmp(&kr->nexthop, &nexthop, sizeof(nexthop)) == 0)
return (kr);
kr = kr->next;
} while (kr);
}
int
-kroute6_insert(struct ktable *kt, struct kroute6_node *kr)
+kroute6_insert(struct ktable *kt, struct kroute6 *kr)
{
- struct kroute6_node *krm;
- struct knexthop_node *h;
- struct in6_addr ina, inb;
+ struct kroute6 *krm;
+ struct knexthop *h;
+ struct in6_addr ina, inb;
if ((krm = RB_INSERT(kroute6_tree, &kt->krt6, kr)) != NULL) {
/* multipath route, add at end of list */
}
/* XXX this is wrong for nexthop validated via BGP */
- if (kr->r.flags & F_KERNEL) {
- inet6applymask(&ina, &kr->r.prefix, kr->r.prefixlen);
+ if (kr->flags & F_KERNEL) {
+ inet6applymask(&ina, &kr->prefix, kr->prefixlen);
RB_FOREACH(h, knexthop_tree, KT2KNT(kt))
if (h->nexthop.aid == AID_INET6) {
inet6applymask(&inb, &h->nexthop.v6,
- kr->r.prefixlen);
+ kr->prefixlen);
if (memcmp(&ina, &inb, sizeof(ina)) == 0)
knexthop_validate(kt, h);
}
- if (kr->r.flags & F_CONNECTED)
+ if (kr->flags & F_CONNECTED)
if (kif_kr6_insert(kr) == -1)
return (-1);
if (krm == NULL)
/* redistribute multipath routes only once */
- kr_redistribute6(IMSG_NETWORK_ADD, kt, &kr->r);
+ kr_redistribute6(IMSG_NETWORK_ADD, kt, kr);
}
return (0);
}
int
-kroute6_remove(struct ktable *kt, struct kroute6_node *kr)
+kroute6_remove(struct ktable *kt, struct kroute6 *kr)
{
- struct kroute6_node *krm;
- struct knexthop_node *s;
+ struct kroute6 *krm;
+ struct knexthop *s;
if ((krm = RB_FIND(kroute6_tree, &kt->krt6, kr)) == NULL) {
log_warnx("%s: failed for %s/%u", __func__,
- log_in6addr(&kr->r.prefix), kr->r.prefixlen);
+ log_in6addr(&kr->prefix), kr->prefixlen);
return (-1);
}
/* head element */
if (RB_REMOVE(kroute6_tree, &kt->krt6, kr) == NULL) {
log_warnx("%s: failed for %s/%u", __func__,
- log_in6addr(&kr->r.prefix), kr->r.prefixlen);
+ log_in6addr(&kr->prefix), kr->prefixlen);
return (-1);
}
if (kr->next != NULL) {
if (RB_INSERT(kroute6_tree, &kt->krt6, kr->next) !=
NULL) {
log_warnx("%s: failed to add %s/%u", __func__,
- log_in6addr(&kr->r.prefix),
- kr->r.prefixlen);
+ log_in6addr(&kr->prefix), kr->prefixlen);
return (-1);
}
}
while (krm->next != kr && krm->next != NULL)
krm = krm->next;
if (krm->next == NULL) {
- log_warnx("%s: multipath list corrupted "
- "for %s/%u", __func__, log_in6addr(&kr->r.prefix),
- kr->r.prefixlen);
+ log_warnx("%s: multipath list corrupted for %s/%u",
+ __func__, log_in6addr(&kr->prefix), kr->prefixlen);
return (-1);
}
krm->next = kr->next;
}
/* check whether a nexthop depends on this kroute */
- if (kr->r.flags & F_NEXTHOP)
+ if (kr->flags & F_NEXTHOP)
RB_FOREACH(s, knexthop_tree, KT2KNT(kt))
if (s->kroute == kr)
knexthop_validate(kt, s);
- if (kr->r.flags & F_KERNEL && kr == krm && kr->next == NULL)
+ if (kr->flags & F_KERNEL && kr == krm && kr->next == NULL)
/* again remove only once */
- kr_redistribute6(IMSG_NETWORK_REMOVE, kt, &kr->r);
+ kr_redistribute6(IMSG_NETWORK_REMOVE, kt, kr);
- if (kr->r.flags & F_CONNECTED)
+ if (kr->flags & F_CONNECTED)
if (kif_kr6_remove(kr) == -1) {
- rtlabel_unref(kr->r.labelid);
+ rtlabel_unref(kr->labelid);
free(kr);
return (-1);
}
- rtlabel_unref(kr->r.labelid);
+ rtlabel_unref(kr->labelid);
free(kr);
return (0);
void
kroute6_clear(struct ktable *kt)
{
- struct kroute6_node *kr;
+ struct kroute6 *kr;
while ((kr = RB_MIN(kroute6_tree, &kt->krt6)) != NULL)
kroute6_remove(kt, kr);
}
-struct knexthop_node *
+struct knexthop *
knexthop_find(struct ktable *kt, struct bgpd_addr *addr)
{
- struct knexthop_node s;
+ struct knexthop s;
bzero(&s, sizeof(s));
memcpy(&s.nexthop, addr, sizeof(s.nexthop));
}
int
-knexthop_insert(struct ktable *kt, struct knexthop_node *kn)
+knexthop_insert(struct ktable *kt, struct knexthop *kn)
{
if (RB_INSERT(knexthop_tree, KT2KNT(kt), kn) != NULL) {
log_warnx("%s: failed for %s", __func__,
}
int
-knexthop_remove(struct ktable *kt, struct knexthop_node *kn)
+knexthop_remove(struct ktable *kt, struct knexthop *kn)
{
kroute_detach_nexthop(kt, kn);
void
knexthop_clear(struct ktable *kt)
{
- struct knexthop_node *kn;
+ struct knexthop *kn;
while ((kn = RB_MIN(knexthop_tree, KT2KNT(kt))) != NULL)
knexthop_remove(kt, kn);
while ((kkr = LIST_FIRST(&kif->kroute_l)) != NULL) {
LIST_REMOVE(kkr, entry);
- kkr->kr->r.flags &= ~F_NEXTHOP;
+ kkr->kr->flags &= ~F_NEXTHOP;
kroute_remove(kt, kkr->kr);
free(kkr);
}
while ((kkr6 = LIST_FIRST(&kif->kroute6_l)) != NULL) {
LIST_REMOVE(kkr6, entry);
- kkr6->kr->r.flags &= ~F_NEXTHOP;
+ kkr6->kr->flags &= ~F_NEXTHOP;
kroute6_remove(kt, kkr6->kr);
free(kkr6);
}
}
int
-kif_kr_insert(struct kroute_node *kr)
+kif_kr_insert(struct kroute *kr)
{
struct kif_node *kif;
struct kif_kr *kkr;
- if ((kif = kif_find(kr->r.ifindex)) == NULL) {
- if (kr->r.ifindex)
+ if ((kif = kif_find(kr->ifindex)) == NULL) {
+ if (kr->ifindex)
log_warnx("%s: interface with index %u not found",
- __func__, kr->r.ifindex);
+ __func__, kr->ifindex);
return (0);
}
if (kif->k.nh_reachable)
- kr->r.flags &= ~F_DOWN;
+ kr->flags &= ~F_DOWN;
else
- kr->r.flags |= F_DOWN;
+ kr->flags |= F_DOWN;
if ((kkr = calloc(1, sizeof(*kkr))) == NULL) {
log_warn("%s", __func__);
}
int
-kif_kr_remove(struct kroute_node *kr)
+kif_kr_remove(struct kroute *kr)
{
struct kif_node *kif;
struct kif_kr *kkr;
- if ((kif = kif_find(kr->r.ifindex)) == NULL) {
- if (kr->r.ifindex)
+ if ((kif = kif_find(kr->ifindex)) == NULL) {
+ if (kr->ifindex)
log_warnx("%s: interface with index %u not found",
- __func__, kr->r.ifindex);
+ __func__, kr->ifindex);
return (0);
}
if (kkr == NULL) {
log_warnx("%s: can't remove connected route from interface "
- "with index %u: not found", __func__, kr->r.ifindex);
+ "with index %u: not found", __func__, kr->ifindex);
return (-1);
}
}
int
-kif_kr6_insert(struct kroute6_node *kr)
+kif_kr6_insert(struct kroute6 *kr)
{
struct kif_node *kif;
struct kif_kr6 *kkr6;
- if ((kif = kif_find(kr->r.ifindex)) == NULL) {
- if (kr->r.ifindex)
+ if ((kif = kif_find(kr->ifindex)) == NULL) {
+ if (kr->ifindex)
log_warnx("%s: interface with index %u not found",
- __func__, kr->r.ifindex);
+ __func__, kr->ifindex);
return (0);
}
if (kif->k.nh_reachable)
- kr->r.flags &= ~F_DOWN;
+ kr->flags &= ~F_DOWN;
else
- kr->r.flags |= F_DOWN;
+ kr->flags |= F_DOWN;
if ((kkr6 = calloc(1, sizeof(*kkr6))) == NULL) {
log_warn("%s", __func__);
}
int
-kif_kr6_remove(struct kroute6_node *kr)
+kif_kr6_remove(struct kroute6 *kr)
{
struct kif_node *kif;
struct kif_kr6 *kkr6;
- if ((kif = kif_find(kr->r.ifindex)) == NULL) {
- if (kr->r.ifindex)
+ if ((kif = kif_find(kr->ifindex)) == NULL) {
+ if (kr->ifindex)
log_warnx("%s: interface with index %u not found",
- __func__, kr->r.ifindex);
+ __func__, kr->ifindex);
return (0);
}
if (kkr6 == NULL) {
log_warnx("%s: can't remove connected route from interface "
- "with index %u: not found", __func__, kr->r.ifindex);
+ "with index %u: not found", __func__, kr->ifindex);
return (-1);
}
}
void
-knexthop_validate(struct ktable *kt, struct knexthop_node *kn)
+knexthop_validate(struct ktable *kt, struct knexthop *kn)
{
- void *oldk;
- struct kroute_node *kr;
- struct kroute6_node *kr6;
+ void *oldk;
+ struct kroute *kr;
+ struct kroute6 *kr6;
oldk = kn->kroute;
kroute_detach_nexthop(kt, kn);
if (kr) {
kn->kroute = kr;
- kr->r.flags |= F_NEXTHOP;
+ kr->flags |= F_NEXTHOP;
}
/*
if (kr6) {
kn->kroute = kr6;
- kr6->r.flags |= F_NEXTHOP;
+ kr6->flags |= F_NEXTHOP;
}
if (kr6 != oldk)
void
knexthop_track(struct ktable *kt, void *krp)
{
- struct knexthop_node *kn;
+ struct knexthop *kn;
RB_FOREACH(kn, knexthop_tree, KT2KNT(kt))
if (kn->kroute == krp)
}
void
-knexthop_send_update(struct knexthop_node *kn)
+knexthop_send_update(struct knexthop *kn)
{
struct kroute_nexthop n;
- struct kroute_node *kr;
- struct kroute6_node *kr6;
+ struct kroute *kr;
+ struct kroute6 *kr6;
bzero(&n, sizeof(n));
memcpy(&n.nexthop, &kn->nexthop, sizeof(n.nexthop));
switch (kn->nexthop.aid) {
case AID_INET:
kr = kn->kroute;
- n.valid = kroute_validate(&kr->r);
- n.connected = kr->r.flags & F_CONNECTED;
- if (kr->r.nexthop.s_addr != 0) {
+ n.valid = kroute_validate(kr);
+ n.connected = kr->flags & F_CONNECTED;
+ if (kr->nexthop.s_addr != 0) {
n.gateway.aid = AID_INET;
- n.gateway.v4.s_addr = kr->r.nexthop.s_addr;
+ n.gateway.v4.s_addr = kr->nexthop.s_addr;
}
if (n.connected) {
n.net.aid = AID_INET;
- n.net.v4.s_addr = kr->r.prefix.s_addr;
- n.netlen = kr->r.prefixlen;
+ n.net.v4.s_addr = kr->prefix.s_addr;
+ n.netlen = kr->prefixlen;
}
break;
case AID_INET6:
kr6 = kn->kroute;
- n.valid = kroute6_validate(&kr6->r);
- n.connected = kr6->r.flags & F_CONNECTED;
- if (memcmp(&kr6->r.nexthop, &in6addr_any,
+ n.valid = kroute6_validate(kr6);
+ n.connected = kr6->flags & F_CONNECTED;
+ if (memcmp(&kr6->nexthop, &in6addr_any,
sizeof(struct in6_addr)) != 0) {
n.gateway.aid = AID_INET6;
- memcpy(&n.gateway.v6, &kr6->r.nexthop,
+ memcpy(&n.gateway.v6, &kr6->nexthop,
sizeof(struct in6_addr));
}
if (n.connected) {
n.net.aid = AID_INET6;
- memcpy(&n.net.v6, &kr6->r.prefix,
+ memcpy(&n.net.v6, &kr6->prefix,
sizeof(struct in6_addr));
- n.netlen = kr6->r.prefixlen;
+ n.netlen = kr6->prefixlen;
}
break;
}
send_nexthop_update(&n);
}
-struct kroute_node *
+struct kroute *
kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
{
int i;
- struct kroute_node *kr;
+ struct kroute *kr;
struct bgpd_addr masked;
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->r)) == 0)
+ bgpd_filternexthop(kr_tofull(kr)) == 0)
return (kr);
}
return (NULL);
}
-struct kroute6_node *
+struct kroute6 *
kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchall)
{
int i;
- struct kroute6_node *kr6;
+ struct kroute6 *kr6;
struct bgpd_addr masked;
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->r)) == 0)
+ bgpd_filternexthop(kr6_tofull(kr6)) == 0)
return (kr6);
}
}
void
-kroute_detach_nexthop(struct ktable *kt, struct knexthop_node *kn)
+kroute_detach_nexthop(struct ktable *kt, struct knexthop *kn)
{
- struct knexthop_node *s;
- struct kroute_node *k;
- struct kroute6_node *k6;
+ struct knexthop *s;
+ struct kroute *k;
+ struct kroute6 *k6;
if (kn->kroute == NULL)
return;
switch (kn->nexthop.aid) {
case AID_INET:
k = kn->kroute;
- k->r.flags &= ~F_NEXTHOP;
+ k->flags &= ~F_NEXTHOP;
break;
case AID_INET6:
k6 = kn->kroute;
- k6->r.flags &= ~F_NEXTHOP;
+ k6->flags &= ~F_NEXTHOP;
break;
}
}
LIST_FOREACH(kkr, &kif->kroute_l, entry) {
if (reachable)
- kkr->kr->r.flags &= ~F_DOWN;
+ kkr->kr->flags &= ~F_DOWN;
else
- kkr->kr->r.flags |= F_DOWN;
+ kkr->kr->flags |= F_DOWN;
if (kt == NULL)
continue;
}
LIST_FOREACH(kkr6, &kif->kroute6_l, entry) {
if (reachable)
- kkr6->kr->r.flags &= ~F_DOWN;
+ kkr6->kr->flags &= ~F_DOWN;
else
- kkr6->kr->r.flags |= F_DOWN;
+ kkr6->kr->flags |= F_DOWN;
if (kt == NULL)
continue;
char *buf = NULL, *next, *lim;
struct rt_msghdr *rtm;
struct kroute_full kl;
- struct kroute_node *kr;
- struct kroute6_node *kr6;
+ struct kroute *kr;
+ struct kroute6 *kr6;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
log_warn("%s", __func__);
return (-1);
}
- kr->r.prefix.s_addr = kl.prefix.v4.s_addr;
- kr->r.prefixlen = kl.prefixlen;
+ kr->prefix.s_addr = kl.prefix.v4.s_addr;
+ kr->prefixlen = kl.prefixlen;
if (kl.nexthop.aid == AID_INET)
- kr->r.nexthop.s_addr = kl.nexthop.v4.s_addr;
- kr->r.flags = kl.flags;
- kr->r.ifindex = kl.ifindex;
- kr->r.priority = kl.priority;
- kr->r.labelid = rtlabel_name2id(kl.label);
+ kr->nexthop.s_addr = kl.nexthop.v4.s_addr;
+ kr->flags = kl.flags;
+ kr->ifindex = kl.ifindex;
+ kr->priority = kl.priority;
+ kr->labelid = rtlabel_name2id(kl.label);
if (kl.priority == kr_state.fib_prio) {
- send_rtmsg(kr_state.fd, RTM_DELETE, kt, &kr->r);
- rtlabel_unref(kr->r.labelid);
+ send_rtmsg(kr_state.fd, RTM_DELETE, kt, kr);
+ rtlabel_unref(kr->labelid);
free(kr);
} else
kroute_insert(kt, kr);
log_warn("%s", __func__);
return (-1);
}
- kr6->r.prefix = kl.prefix.v6;
- kr6->r.prefixlen = kl.prefixlen;
+ kr6->prefix = kl.prefix.v6;
+ kr6->prefixlen = kl.prefixlen;
if (kl.nexthop.aid == AID_INET6)
- kr6->r.nexthop = kl.nexthop.v6;
+ kr6->nexthop = kl.nexthop.v6;
else
- kr6->r.nexthop = in6addr_any;
- kr6->r.flags = kl.flags;
- kr6->r.ifindex = kl.ifindex;
- kr6->r.priority = kl.priority;
- kr6->r.labelid = rtlabel_name2id(kl.label);
+ kr6->nexthop = in6addr_any;
+ kr6->flags = kl.flags;
+ kr6->ifindex = kl.ifindex;
+ kr6->priority = kl.priority;
+ kr6->labelid = rtlabel_name2id(kl.label);
if (kl.priority == kr_state.fib_prio) {
- send_rt6msg(kr_state.fd, RTM_DELETE, kt,
- &kr6->r);
- rtlabel_unref(kr6->r.labelid);
+ send_rt6msg(kr_state.fd, RTM_DELETE, kt, kr6);
+ rtlabel_unref(kr6->labelid);
free(kr6);
} else
kroute6_insert(kt, kr6);
int
kr_fib_delete(struct ktable *kt, struct kroute_full *kl, int mpath)
{
- struct kroute_node *kr;
- struct kroute6_node *kr6;
+ struct kroute *kr;
+ struct kroute6 *kr6;
switch (kl->prefix.aid) {
case AID_INET:
if ((kr = kroute_find(kt, &kl->prefix, kl->prefixlen,
kl->priority)) == NULL)
return (0);
- if (!(kr->r.flags & F_KERNEL))
+ if (!(kr->flags & F_KERNEL))
return (0);
if (mpath) {
if ((kr6 = kroute6_find(kt, &kl->prefix, kl->prefixlen,
kl->priority)) == NULL)
return (0);
- if (!(kr6->r.flags & F_KERNEL))
+ if (!(kr6->flags & F_KERNEL))
return (0);
if (mpath) {
int
kr_fib_change(struct ktable *kt, struct kroute_full *kl, int type, int mpath)
{
- struct kroute_node *kr;
- struct kroute6_node *kr6;
- int flags, oflags;
- int changed = 0, rtlabel_changed = 0;
- uint16_t new_labelid;
+ struct kroute *kr;
+ struct kroute6 *kr6;
+ int flags, oflags;
+ int changed = 0, rtlabel_changed = 0;
+ uint16_t new_labelid;
flags = kl->flags;
switch (kl->prefix.aid) {
case AID_INET:
if ((kr = kroute_find(kt, &kl->prefix, kl->prefixlen,
kl->priority)) != NULL) {
- if (kr->r.flags & F_KERNEL) {
+ if (kr->flags & F_KERNEL) {
/* get the correct route */
if (mpath && type == RTM_CHANGE &&
(kr = kroute_matchgw(kr, &kl->nexthop)) ==
goto add4;
if (kl->nexthop.aid == AID_INET) {
- if (kr->r.nexthop.s_addr !=
+ if (kr->nexthop.s_addr !=
kl->nexthop.v4.s_addr)
changed = 1;
- kr->r.nexthop.s_addr =
+ kr->nexthop.s_addr =
kl->nexthop.v4.s_addr;
- kr->r.ifindex = kl->ifindex;
+ kr->ifindex = kl->ifindex;
} else {
- if (kr->r.nexthop.s_addr != 0)
+ if (kr->nexthop.s_addr != 0)
changed = 1;
- kr->r.nexthop.s_addr = 0;
- kr->r.ifindex = kl->ifindex;
+ kr->nexthop.s_addr = 0;
+ kr->ifindex = kl->ifindex;
}
- if (kr->r.flags & F_NEXTHOP)
+ if (kr->flags & F_NEXTHOP)
flags |= F_NEXTHOP;
new_labelid = rtlabel_name2id(kl->label);
- if (kr->r.labelid != new_labelid) {
- rtlabel_unref(kr->r.labelid);
- kr->r.labelid = new_labelid;
+ if (kr->labelid != new_labelid) {
+ rtlabel_unref(kr->labelid);
+ kr->labelid = new_labelid;
rtlabel_changed = 1;
}
- oflags = kr->r.flags;
+ oflags = kr->flags;
if (flags != oflags)
changed = 1;
- kr->r.flags = flags;
+ kr->flags = flags;
if (rtlabel_changed)
kr_redistribute(IMSG_NETWORK_ADD,
- kt, &kr->r);
+ kt, kr);
if ((oflags & F_CONNECTED) &&
!(flags & F_CONNECTED)) {
kif_kr_remove(kr);
kr_redistribute(IMSG_NETWORK_ADD,
- kt, &kr->r);
+ kt, kr);
}
if ((flags & F_CONNECTED) &&
!(oflags & F_CONNECTED)) {
kif_kr_insert(kr);
kr_redistribute(IMSG_NETWORK_ADD,
- kt, &kr->r);
+ kt, kr);
}
- if (kr->r.flags & F_NEXTHOP && changed)
+ if (kr->flags & F_NEXTHOP && changed)
knexthop_track(kt, kr);
}
} else {
log_warn("%s", __func__);
return (-1);
}
- kr->r.prefix.s_addr = kl->prefix.v4.s_addr;
- kr->r.prefixlen = kl->prefixlen;
+ kr->prefix.s_addr = kl->prefix.v4.s_addr;
+ kr->prefixlen = kl->prefixlen;
if (kl->nexthop.aid == AID_INET)
- kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
- kr->r.flags = flags;
- kr->r.ifindex = kl->ifindex;
- kr->r.priority = kl->priority;
- kr->r.labelid = rtlabel_name2id(kl->label);
+ kr->nexthop.s_addr = kl->nexthop.v4.s_addr;
+ kr->flags = flags;
+ kr->ifindex = kl->ifindex;
+ kr->priority = kl->priority;
+ kr->labelid = rtlabel_name2id(kl->label);
kroute_insert(kt, kr);
}
case AID_INET6:
if ((kr6 = kroute6_find(kt, &kl->prefix, kl->prefixlen,
kl->priority)) != NULL) {
- if (kr6->r.flags & F_KERNEL) {
+ if (kr6->flags & F_KERNEL) {
/* get the correct route */
if (mpath && type == RTM_CHANGE &&
(kr6 = kroute6_matchgw(kr6, &kl->nexthop))
goto add6;
if (kl->nexthop.aid == AID_INET6) {
- if (memcmp(&kr6->r.nexthop,
+ if (memcmp(&kr6->nexthop,
&kl->nexthop.v6,
sizeof(struct in6_addr)))
changed = 1;
- kr6->r.nexthop = kl->nexthop.v6;
- kr6->r.ifindex = kl->ifindex;
+ kr6->nexthop = kl->nexthop.v6;
+ kr6->ifindex = kl->ifindex;
} else {
- if (memcmp(&kr6->r.nexthop,
+ if (memcmp(&kr6->nexthop,
&in6addr_any,
sizeof(struct in6_addr)))
changed = 1;
- kr6->r.nexthop = in6addr_any;
- kr6->r.ifindex = kl->ifindex;
+ kr6->nexthop = in6addr_any;
+ kr6->ifindex = kl->ifindex;
}
- if (kr6->r.flags & F_NEXTHOP)
+ if (kr6->flags & F_NEXTHOP)
flags |= F_NEXTHOP;
new_labelid = rtlabel_name2id(kl->label);
- if (kr6->r.labelid != new_labelid) {
- rtlabel_unref(kr6->r.labelid);
- kr6->r.labelid = new_labelid;
+ if (kr6->labelid != new_labelid) {
+ rtlabel_unref(kr6->labelid);
+ kr6->labelid = new_labelid;
rtlabel_changed = 1;
}
- oflags = kr6->r.flags;
+ oflags = kr6->flags;
if (flags != oflags)
changed = 1;
- kr6->r.flags = flags;
+ kr6->flags = flags;
if (rtlabel_changed)
kr_redistribute6(IMSG_NETWORK_ADD,
- kt, &kr6->r);
+ kt, kr6);
if ((oflags & F_CONNECTED) &&
!(flags & F_CONNECTED)) {
kif_kr6_remove(kr6);
kr_redistribute6(IMSG_NETWORK_ADD,
- kt, &kr6->r);
+ kt, kr6);
}
if ((flags & F_CONNECTED) &&
!(oflags & F_CONNECTED)) {
kif_kr6_insert(kr6);
kr_redistribute6(IMSG_NETWORK_ADD,
- kt, &kr6->r);
+ kt, kr6);
}
- if (kr6->r.flags & F_NEXTHOP && changed)
+ if (kr6->flags & F_NEXTHOP && changed)
knexthop_track(kt, kr6);
}
} else {
log_warn("%s", __func__);
return (-1);
}
- kr6->r.prefix = kl->prefix.v6;
- kr6->r.prefixlen = kl->prefixlen;
+ kr6->prefix = kl->prefix.v6;
+ kr6->prefixlen = kl->prefixlen;
if (kl->nexthop.aid == AID_INET6)
- kr6->r.nexthop = kl->nexthop.v6;
+ kr6->nexthop = kl->nexthop.v6;
else
- kr6->r.nexthop = in6addr_any;
- kr6->r.flags = flags;
- kr6->r.ifindex = kl->ifindex;
- kr6->r.priority = kl->priority;
- kr6->r.labelid = rtlabel_name2id(kl->label);
+ kr6->nexthop = in6addr_any;
+ kr6->flags = flags;
+ kr6->ifindex = kl->ifindex;
+ kr6->priority = kl->priority;
+ kr6->labelid = rtlabel_name2id(kl->label);
kroute6_insert(kt, kr6);
}