From: claudio Date: Fri, 7 Apr 2023 13:49:03 +0000 (+0000) Subject: Pass a pt_entry pointer to rib_get() and rib_add(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5bb860535d9d79cdd7a6cc3abe4fe232c8dac051;p=openbsd Pass a pt_entry pointer to rib_get() and rib_add(). Add rib_get_addr() to behave like rib_get() did before. OK tb@ --- diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 9a7ff401427..6327dd2d5f7 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $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 @@ -1734,7 +1734,7 @@ pathid_assign(struct rde_peer *peer, uint32_t path_id, 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; @@ -3052,14 +3052,15 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, 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); } diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 8999272df78..f244749d068 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $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 and @@ -548,7 +548,8 @@ struct rib *rib_byid(uint16_t); 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); diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 99c7119f7a3..3aa355bfc23 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $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 @@ -38,7 +38,7 @@ 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 *); @@ -297,12 +297,12 @@ rib_shutdown(void) } 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) @@ -311,6 +311,12 @@ rib_get(struct rib *rib, struct bgpd_addr *prefix, int prefixlen) 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) { @@ -321,7 +327,7 @@ 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); } @@ -329,7 +335,7 @@ rib_match(struct rib *rib, struct bgpd_addr *addr) 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); } @@ -342,15 +348,10 @@ rib_match(struct rib *rib, struct bgpd_addr *addr) 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"); @@ -861,7 +862,7 @@ prefix_get(struct rib *rib, struct rde_peer *peer, uint32_t path_id, { 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)); @@ -1024,12 +1025,16 @@ prefix_add(struct bgpd_addr *prefix, int prefixlen, struct rib *rib, 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,