-/* $OpenBSD: rde.c,v 1.599 2023/04/03 10:48:00 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.600 2023/04/07 13:49:03 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
return peer->path_id_tx;
/* peer uses add-path, therefore new path_ids need to be assigned */
- re = rib_get(rib_byid(RIB_ADJ_IN), prefix, prefixlen);
+ re = rib_get_addr(rib_byid(RIB_ADJ_IN), prefix, prefixlen);
if (re != NULL) {
struct prefix *p;
if (req->flags & F_SHORTER) {
for (plen = 0; plen <= req->prefixlen; plen++) {
- re = rib_get(rib_byid(rid), &req->prefix, plen);
+ re = rib_get_addr(rib_byid(rid), &req->prefix,
+ plen);
rde_dump_upcall(re, ctx);
}
} else if (req->prefixlen == hostplen) {
re = rib_match(rib_byid(rid), &req->prefix);
rde_dump_upcall(re, ctx);
} else {
- re = rib_get(rib_byid(rid), &req->prefix,
+ re = rib_get_addr(rib_byid(rid), &req->prefix,
req->prefixlen);
rde_dump_upcall(re, ctx);
}
-/* $OpenBSD: rde.h,v 1.290 2023/03/30 12:11:18 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.291 2023/04/07 13:49:03 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
uint16_t rib_find(char *);
void rib_free(struct rib *);
void rib_shutdown(void);
-struct rib_entry *rib_get(struct rib *, struct bgpd_addr *, int);
+struct rib_entry *rib_get(struct rib *, struct pt_entry *);
+struct rib_entry *rib_get_addr(struct rib *, struct bgpd_addr *, int);
struct rib_entry *rib_match(struct rib *, struct bgpd_addr *);
int rib_dump_pending(void);
void rib_dump_runner(void);
-/* $OpenBSD: rde_rib.c,v 1.257 2023/03/29 10:46:11 claudio Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.258 2023/04/07 13:49:03 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
uint16_t rib_size;
struct rib **ribs;
-struct rib_entry *rib_add(struct rib *, struct bgpd_addr *, int);
+struct rib_entry *rib_add(struct rib *, struct pt_entry *);
static inline int rib_compare(const struct rib_entry *,
const struct rib_entry *);
void rib_remove(struct rib_entry *);
}
struct rib_entry *
-rib_get(struct rib *rib, struct bgpd_addr *prefix, int prefixlen)
+rib_get(struct rib *rib, struct pt_entry *pte)
{
struct rib_entry xre, *re;
memset(&xre, 0, sizeof(xre));
- xre.prefix = pt_fill(prefix, prefixlen);
+ xre.prefix = pte;
re = RB_FIND(rib_tree, rib_tree(rib), &xre);
if (re && re->rib_id != rib->id)
return re;
}
+struct rib_entry *
+rib_get_addr(struct rib *rib, struct bgpd_addr *prefix, int prefixlen)
+{
+ return rib_get(rib, pt_fill(prefix, prefixlen));
+}
+
struct rib_entry *
rib_match(struct rib *rib, struct bgpd_addr *addr)
{
case AID_INET:
case AID_VPN_IPv4:
for (i = 32; i >= 0; i--) {
- re = rib_get(rib, addr, i);
+ re = rib_get_addr(rib, addr, i);
if (re != NULL)
return (re);
}
case AID_INET6:
case AID_VPN_IPv6:
for (i = 128; i >= 0; i--) {
- re = rib_get(rib, addr, i);
+ re = rib_get_addr(rib, addr, i);
if (re != NULL)
return (re);
}
struct rib_entry *
-rib_add(struct rib *rib, struct bgpd_addr *prefix, int prefixlen)
+rib_add(struct rib *rib, struct pt_entry *pte)
{
- struct pt_entry *pte;
struct rib_entry *re;
- pte = pt_get(prefix, prefixlen);
- if (pte == NULL)
- pte = pt_add(prefix, prefixlen);
-
if ((re = calloc(1, sizeof(*re))) == NULL)
fatal("rib_add");
{
struct rib_entry *re;
- re = rib_get(rib, prefix, prefixlen);
+ re = rib_get_addr(rib, prefix, prefixlen);
if (re == NULL)
return (NULL);
return (prefix_bypeer(re, peer, path_id));
struct rde_aspath *asp, struct rde_community *comm,
struct nexthop *nexthop, uint8_t nhflags, uint8_t vstate)
{
+ struct pt_entry *pte;
struct prefix *p;
struct rib_entry *re;
- re = rib_get(rib, prefix, prefixlen);
+ pte = pt_get(prefix, prefixlen);
+ if (pte == NULL)
+ pte = pt_add(prefix, prefixlen);
+ re = rib_get(rib, pte);
if (re == NULL)
- re = rib_add(rib, prefix, prefixlen);
+ re = rib_add(rib, pte);
p = prefix_alloc();
prefix_link(p, re, re->prefix, peer, path_id, path_id_tx, asp, comm,