On Fri, Feb 25, 2022 at 11:55:08AM +0100, Theo Buehler wrote:
> On Fri, Feb 25, 2022 at 11:15:49AM +0100, Claudio Jeker wrote:
> > For add-path send the Adj-RIB-Out needs to handle multiple paths per
> > prefix. The Adj-RIB-Out stores the prefixes on RB trees and so extend
> > the lookup function to include the path_id (which will be path_id_tx).
> > 
> > For now the path_id_tx in the Adj-RIB-Out is forced to 0 since
> > up_generate_updates() is not ready to handle more than one path per prefix.
> > 
> > This mainly adjusts the bgpctl interface and the internals. Some functions
> > are renamed to start with prefix_adjout_ like all other prefix functions
> > opertating on the Adj-RIB-Out.
> 
> ok
> 
> > +/*
> > + * Lookup a prefix without considering path_id in the peer prefix_index.
> > + * Returns NULL if not found.
> > + */
> > +struct prefix *
> > +prefix_adjout_lookup(struct rde_peer *peer, struct bgpd_addr *prefix,
> > +    int prefixlen)
> > +{
> > +   struct prefix xp, *np;
> > +   struct pt_entry *pte;
> > +
> > +   memset(&xp, 0, sizeof(xp));
> > +   pte = pt_fill(prefix, prefixlen);
> > +   xp.pt = pte;
> 
> I don't understand the benefit of the pte variable, but other lookup
> functions do the same, so I guess it's better to be consistent.

How about this diff that removes this extra variable?
pt_fill() is a nasty function since it returns a pointer to some static
memory.

-- 
:wq Claudio

? obj
Index: rde_prefix.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_prefix.c,v
retrieving revision 1.40
diff -u -p -r1.40 rde_prefix.c
--- rde_prefix.c        18 Jan 2021 12:15:36 -0000      1.40
+++ rde_prefix.c        25 Feb 2022 11:39:52 -0000
@@ -171,8 +171,7 @@ pt_add(struct bgpd_addr *prefix, int pre
 {
        struct pt_entry         *p = NULL;
 
-       p = pt_fill(prefix, prefixlen);
-       p = pt_alloc(p);
+       p = pt_alloc(pt_fill(prefix, prefixlen));
 
        if (RB_INSERT(pt_tree, &pttable, p) != NULL)
                fatalx("pt_add: insert failed");
Index: rde_rib.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
retrieving revision 1.226
diff -u -p -r1.226 rde_rib.c
--- rde_rib.c   25 Feb 2022 11:36:54 -0000      1.226
+++ rde_rib.c   25 Feb 2022 11:39:52 -0000
@@ -297,11 +297,9 @@ struct rib_entry *
 rib_get(struct rib *rib, struct bgpd_addr *prefix, int prefixlen)
 {
        struct rib_entry xre, *re;
-       struct pt_entry *pte;
 
-       pte = pt_fill(prefix, prefixlen);
        memset(&xre, 0, sizeof(xre));
-       xre.prefix = pte;
+       xre.prefix = pt_fill(prefix, prefixlen);
 
        re = RB_FIND(rib_tree, rib_tree(rib), &xre);
        if (re && re->rib_id != rib->id)
@@ -921,11 +919,9 @@ prefix_adjout_get(struct rde_peer *peer,
     struct bgpd_addr *prefix, int prefixlen)
 {
        struct prefix xp;
-       struct pt_entry *pte;
 
        memset(&xp, 0, sizeof(xp));
-       pte = pt_fill(prefix, prefixlen);
-       xp.pt = pte;
+       xp.pt = pt_fill(prefix, prefixlen);
        xp.path_id_tx = path_id;
 
        return RB_FIND(prefix_index, &peer->adj_rib_out, &xp);
@@ -940,11 +936,9 @@ prefix_adjout_lookup(struct rde_peer *pe
     int prefixlen)
 {
        struct prefix xp, *np;
-       struct pt_entry *pte;
 
        memset(&xp, 0, sizeof(xp));
-       pte = pt_fill(prefix, prefixlen);
-       xp.pt = pte;
+       xp.pt = pt_fill(prefix, prefixlen);
 
        np = RB_NFIND(prefix_index, &peer->adj_rib_out, &xp);
        if (np != NULL && pt_prefix_cmp(np->pt, xp.pt) != 0)

Reply via email to