Re: ospf6d: bring ospf6d closer to ospfd

2020-03-28 Thread Denis Fondras
On Sat, Mar 28, 2020 at 05:00:11PM +0100, Remi Locherer wrote:
> On Sat, Mar 21, 2020 at 05:25:45PM +0100, Denis Fondras wrote:
> > Biggest chunk is rework of rde_asext_get()/rde_asext_put().
> > Also change get_net_link() and get_rtr_link() to work like ospfd couterpart.
> 
> Reads good to me and I didn't spot any issues running tests with it.
> 

Thank you Remi.

> One question: why "if 0" the "Dump SPF tree to log"?
> 

Doh! It is not (yet) time to '#if 0' this part. This is from an unpublished diff
that changes how if_find() works. Thus printing the SPF tree needs to be
rewritten.


> > 
> > Index: rde.c
> > ===
> > RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
> > retrieving revision 1.84
> > diff -u -p -r1.84 rde.c
> > --- rde.c   17 Feb 2020 08:12:22 -  1.84
> > +++ rde.c   21 Mar 2020 16:04:47 -
> > @@ -59,8 +59,9 @@ intrde_req_list_exists(struct rde_nbr
> >  voidrde_req_list_del(struct rde_nbr *, struct lsa_hdr *);
> >  voidrde_req_list_free(struct rde_nbr *);
> >  
> > -struct lsa *rde_asext_get(struct kroute *);
> > -struct lsa *rde_asext_put(struct kroute *);
> > +struct iface   *rde_asext_lookup(struct in6_addr, int);
> > +voidrde_asext_get(struct kroute *);
> > +voidrde_asext_put(struct kroute *);
> >  
> >  int comp_asext(struct lsa *, struct lsa *);
> >  struct lsa *orig_asext_lsa(struct kroute *, u_int16_t);
> > @@ -217,6 +218,7 @@ __dead void
> >  rde_shutdown(void)
> >  {
> > struct area *a;
> > +   struct vertex   *v, *nv;
> >  
> > /* close pipes */
> > msgbuf_clear(_ospfe->ibuf.w);
> > @@ -232,6 +234,10 @@ rde_shutdown(void)
> > LIST_REMOVE(a, entry);
> > area_del(a);
> > }
> > +   for (v = RB_MIN(lsa_tree, _tree); v != NULL; v = nv) {
> > +   nv = RB_NEXT(lsa_tree, _tree, v);
> > +   vertex_free(v);
> > +   }
> > rde_nbr_free();
> >  
> > free(iev_ospfe);
> > @@ -643,8 +649,6 @@ rde_dispatch_parent(int fd, short event,
> > struct kroutekr;
> > struct imsgev   *iev = bula;
> > struct imsgbuf  *ibuf = >ibuf;
> > -   struct lsa  *lsa;
> > -   struct vertex   *v;
> > ssize_t  n;
> > int  shut = 0, link_ok, prev_link_ok, orig_lsa;
> > unsigned int ifindex;
> > @@ -676,13 +680,7 @@ rde_dispatch_parent(int fd, short event,
> > break;
> > }
> > memcpy(, imsg.data, sizeof(kr));
> > -
> > -   if ((lsa = rde_asext_get()) != NULL) {
> > -   v = lsa_find(NULL, lsa->hdr.type,
> > -   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
> > -
> > -   lsa_merge(nbrself, lsa, v);
> > -   }
> > +   rde_asext_get();
> > break;
> > case IMSG_NETWORK_DEL:
> > if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(kr)) {
> > @@ -691,20 +689,7 @@ rde_dispatch_parent(int fd, short event,
> > break;
> > }
> > memcpy(, imsg.data, sizeof(kr));
> > -
> > -   if ((lsa = rde_asext_put()) != NULL) {
> > -   v = lsa_find(NULL, lsa->hdr.type,
> > -   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
> > -
> > -   /*
> > -* if v == NULL no LSA is in the table and
> > -* nothing has to be done.
> > -*/
> > -   if (v)
> > -   lsa_merge(nbrself, lsa, v);
> > -   else
> > -   free(lsa);
> > -   }
> > +   rde_asext_put();
> > break;
> > case IMSG_IFINFO:
> > if (imsg.hdr.len != IMSG_HEADER_SIZE +
> > @@ -1202,48 +1187,77 @@ rde_req_list_free(struct rde_nbr *nbr)
> >  /*
> >   * as-external LSA handling
> >   */
> > -struct lsa *
> > -rde_asext_get(struct kroute *kr)
> > +struct iface *
> > +rde_asext_lookup(struct in6_addr prefix, int plen)
> >  {
> > +
> > struct area *area;
> > struct iface*iface;
> > struct iface_addr   *ia;
> > -   struct in6_addr  addr;
> > -
> > -   LIST_FOREACH(area, >area_list, entry)
> > -   LIST_FOREACH(iface, >iface_list, entry)
> > +   struct in6_addr  ina, inb;
> > +   
> > +   LIST_FOREACH(area, >area_list, entry) {
> > +   LIST_FOREACH(iface, >iface_list, entry) {
> > TAILQ_FOREACH(ia, >ifa_list, entry) {
> > if (IN6_IS_ADDR_LINKLOCAL(>addr))
> > 

Re: ospf6d: bring ospf6d closer to ospfd

2020-03-28 Thread Remi Locherer
On Sat, Mar 21, 2020 at 05:25:45PM +0100, Denis Fondras wrote:
> Biggest chunk is rework of rde_asext_get()/rde_asext_put().
> Also change get_net_link() and get_rtr_link() to work like ospfd couterpart.

Reads good to me and I didn't spot any issues running tests with it.

One question: why "if 0" the "Dump SPF tree to log"?

> 
> Index: rde.c
> ===
> RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
> retrieving revision 1.84
> diff -u -p -r1.84 rde.c
> --- rde.c 17 Feb 2020 08:12:22 -  1.84
> +++ rde.c 21 Mar 2020 16:04:47 -
> @@ -59,8 +59,9 @@ int  rde_req_list_exists(struct rde_nbr
>  void  rde_req_list_del(struct rde_nbr *, struct lsa_hdr *);
>  void  rde_req_list_free(struct rde_nbr *);
>  
> -struct lsa   *rde_asext_get(struct kroute *);
> -struct lsa   *rde_asext_put(struct kroute *);
> +struct iface *rde_asext_lookup(struct in6_addr, int);
> +void  rde_asext_get(struct kroute *);
> +void  rde_asext_put(struct kroute *);
>  
>  int   comp_asext(struct lsa *, struct lsa *);
>  struct lsa   *orig_asext_lsa(struct kroute *, u_int16_t);
> @@ -217,6 +218,7 @@ __dead void
>  rde_shutdown(void)
>  {
>   struct area *a;
> + struct vertex   *v, *nv;
>  
>   /* close pipes */
>   msgbuf_clear(_ospfe->ibuf.w);
> @@ -232,6 +234,10 @@ rde_shutdown(void)
>   LIST_REMOVE(a, entry);
>   area_del(a);
>   }
> + for (v = RB_MIN(lsa_tree, _tree); v != NULL; v = nv) {
> + nv = RB_NEXT(lsa_tree, _tree, v);
> + vertex_free(v);
> + }
>   rde_nbr_free();
>  
>   free(iev_ospfe);
> @@ -643,8 +649,6 @@ rde_dispatch_parent(int fd, short event,
>   struct kroutekr;
>   struct imsgev   *iev = bula;
>   struct imsgbuf  *ibuf = >ibuf;
> - struct lsa  *lsa;
> - struct vertex   *v;
>   ssize_t  n;
>   int  shut = 0, link_ok, prev_link_ok, orig_lsa;
>   unsigned int ifindex;
> @@ -676,13 +680,7 @@ rde_dispatch_parent(int fd, short event,
>   break;
>   }
>   memcpy(, imsg.data, sizeof(kr));
> -
> - if ((lsa = rde_asext_get()) != NULL) {
> - v = lsa_find(NULL, lsa->hdr.type,
> - lsa->hdr.ls_id, lsa->hdr.adv_rtr);
> -
> - lsa_merge(nbrself, lsa, v);
> - }
> + rde_asext_get();
>   break;
>   case IMSG_NETWORK_DEL:
>   if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(kr)) {
> @@ -691,20 +689,7 @@ rde_dispatch_parent(int fd, short event,
>   break;
>   }
>   memcpy(, imsg.data, sizeof(kr));
> -
> - if ((lsa = rde_asext_put()) != NULL) {
> - v = lsa_find(NULL, lsa->hdr.type,
> - lsa->hdr.ls_id, lsa->hdr.adv_rtr);
> -
> - /*
> -  * if v == NULL no LSA is in the table and
> -  * nothing has to be done.
> -  */
> - if (v)
> - lsa_merge(nbrself, lsa, v);
> - else
> - free(lsa);
> - }
> + rde_asext_put();
>   break;
>   case IMSG_IFINFO:
>   if (imsg.hdr.len != IMSG_HEADER_SIZE +
> @@ -1202,48 +1187,77 @@ rde_req_list_free(struct rde_nbr *nbr)
>  /*
>   * as-external LSA handling
>   */
> -struct lsa *
> -rde_asext_get(struct kroute *kr)
> +struct iface *
> +rde_asext_lookup(struct in6_addr prefix, int plen)
>  {
> +
>   struct area *area;
>   struct iface*iface;
>   struct iface_addr   *ia;
> - struct in6_addr  addr;
> -
> - LIST_FOREACH(area, >area_list, entry)
> - LIST_FOREACH(iface, >iface_list, entry)
> + struct in6_addr  ina, inb;
> + 
> + LIST_FOREACH(area, >area_list, entry) {
> + LIST_FOREACH(iface, >iface_list, entry) {
>   TAILQ_FOREACH(ia, >ifa_list, entry) {
>   if (IN6_IS_ADDR_LINKLOCAL(>addr))
>   continue;
>  
> - inet6applymask(, >addr,
> - kr->prefixlen);
> - if (!memcmp(, >prefix,
> - sizeof(addr)) && kr->prefixlen ==
> - ia->prefixlen) {
> - /* already announced as Prefix LSA */
> -   

ospf6d: bring ospf6d closer to ospfd

2020-03-21 Thread Denis Fondras
Biggest chunk is rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd couterpart.

Index: rde.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.84
diff -u -p -r1.84 rde.c
--- rde.c   17 Feb 2020 08:12:22 -  1.84
+++ rde.c   21 Mar 2020 16:04:47 -
@@ -59,8 +59,9 @@ intrde_req_list_exists(struct rde_nbr
 voidrde_req_list_del(struct rde_nbr *, struct lsa_hdr *);
 voidrde_req_list_free(struct rde_nbr *);
 
-struct lsa *rde_asext_get(struct kroute *);
-struct lsa *rde_asext_put(struct kroute *);
+struct iface   *rde_asext_lookup(struct in6_addr, int);
+voidrde_asext_get(struct kroute *);
+voidrde_asext_put(struct kroute *);
 
 int comp_asext(struct lsa *, struct lsa *);
 struct lsa *orig_asext_lsa(struct kroute *, u_int16_t);
@@ -217,6 +218,7 @@ __dead void
 rde_shutdown(void)
 {
struct area *a;
+   struct vertex   *v, *nv;
 
/* close pipes */
msgbuf_clear(_ospfe->ibuf.w);
@@ -232,6 +234,10 @@ rde_shutdown(void)
LIST_REMOVE(a, entry);
area_del(a);
}
+   for (v = RB_MIN(lsa_tree, _tree); v != NULL; v = nv) {
+   nv = RB_NEXT(lsa_tree, _tree, v);
+   vertex_free(v);
+   }
rde_nbr_free();
 
free(iev_ospfe);
@@ -643,8 +649,6 @@ rde_dispatch_parent(int fd, short event,
struct kroutekr;
struct imsgev   *iev = bula;
struct imsgbuf  *ibuf = >ibuf;
-   struct lsa  *lsa;
-   struct vertex   *v;
ssize_t  n;
int  shut = 0, link_ok, prev_link_ok, orig_lsa;
unsigned int ifindex;
@@ -676,13 +680,7 @@ rde_dispatch_parent(int fd, short event,
break;
}
memcpy(, imsg.data, sizeof(kr));
-
-   if ((lsa = rde_asext_get()) != NULL) {
-   v = lsa_find(NULL, lsa->hdr.type,
-   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
-
-   lsa_merge(nbrself, lsa, v);
-   }
+   rde_asext_get();
break;
case IMSG_NETWORK_DEL:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(kr)) {
@@ -691,20 +689,7 @@ rde_dispatch_parent(int fd, short event,
break;
}
memcpy(, imsg.data, sizeof(kr));
-
-   if ((lsa = rde_asext_put()) != NULL) {
-   v = lsa_find(NULL, lsa->hdr.type,
-   lsa->hdr.ls_id, lsa->hdr.adv_rtr);
-
-   /*
-* if v == NULL no LSA is in the table and
-* nothing has to be done.
-*/
-   if (v)
-   lsa_merge(nbrself, lsa, v);
-   else
-   free(lsa);
-   }
+   rde_asext_put();
break;
case IMSG_IFINFO:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
@@ -1202,48 +1187,77 @@ rde_req_list_free(struct rde_nbr *nbr)
 /*
  * as-external LSA handling
  */
-struct lsa *
-rde_asext_get(struct kroute *kr)
+struct iface *
+rde_asext_lookup(struct in6_addr prefix, int plen)
 {
+
struct area *area;
struct iface*iface;
struct iface_addr   *ia;
-   struct in6_addr  addr;
-
-   LIST_FOREACH(area, >area_list, entry)
-   LIST_FOREACH(iface, >iface_list, entry)
+   struct in6_addr  ina, inb;
+   
+   LIST_FOREACH(area, >area_list, entry) {
+   LIST_FOREACH(iface, >iface_list, entry) {
TAILQ_FOREACH(ia, >ifa_list, entry) {
if (IN6_IS_ADDR_LINKLOCAL(>addr))
continue;
 
-   inet6applymask(, >addr,
-   kr->prefixlen);
-   if (!memcmp(, >prefix,
-   sizeof(addr)) && kr->prefixlen ==
-   ia->prefixlen) {
-   /* already announced as Prefix LSA */
-   log_debug("rde_asext_get: %s/%d is "
-   "part of prefix LSA",
-   log_in6addr(>prefix),
-   kr->prefixlen);
-