Re: ospf6d: rework redist_list and area

2019-12-14 Thread Denis Fondras
On Sat, Dec 14, 2019 at 10:15:36PM +0100, Remi Locherer wrote:
> On Sat, Dec 14, 2019 at 12:05:57PM +0100, Denis Fondras wrote:
> > Still working towards bringing ospf6d and ospfd closer.
> > 
> > area is now part of struct iface.
> 
> Makes sense to me.
> 
> > redist_list is part of struct area.
> 
> In ospfd the redist_list per area is only used to redistribute a default
> route into a stub area. ospf6d does not have proper support for multiple
> areas yet. I think we should only add support for stub areas once we implement
> multi area support.
> 
> Maybe you can split your diff into smaller parts? E.g. the priority filter
> in kr_init() could be a diff on it's own.
> 

The initial diff was splitted but after an operating error, 3 diffs were mixed.
I will split them again. :)



Re: ospf6d: rework redist_list and area

2019-12-14 Thread Remi Locherer
On Sat, Dec 14, 2019 at 12:05:57PM +0100, Denis Fondras wrote:
> Still working towards bringing ospf6d and ospfd closer.
> 
> area is now part of struct iface.

Makes sense to me.

> redist_list is part of struct area.

In ospfd the redist_list per area is only used to redistribute a default
route into a stub area. ospf6d does not have proper support for multiple
areas yet. I think we should only add support for stub areas once we implement
multi area support.

Maybe you can split your diff into smaller parts? E.g. the priority filter
in kr_init() could be a diff on it's own.

Remi



ospf6d: rework redist_list and area

2019-12-14 Thread Denis Fondras
Still working towards bringing ospf6d and ospfd closer.

area is now part of struct iface.
redist_list is part of struct area.

Some changes, related to reloading, are not in use now but it feels like the
right time to get it in.

Denis

Index: area.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/area.c,v
retrieving revision 1.4
diff -u -p -r1.4 area.c
--- area.c  28 Dec 2008 20:08:31 -  1.4
+++ area.c  13 Dec 2019 22:24:09 -
@@ -39,6 +39,7 @@ area_new(void)
LIST_INIT(>iface_list);
LIST_INIT(>nbr_list);
RB_INIT(>lsa_tree);
+   SIMPLEQ_INIT(>redist_list);
 
return (area);
 }
@@ -46,9 +47,10 @@ area_new(void)
 int
 area_del(struct area *area)
 {
-   struct iface*iface = NULL;
-   struct vertex   *v, *nv;
-   struct rde_nbr  *n;
+   struct iface*iface = NULL;
+   struct vertex   *v, *nv;
+   struct rde_nbr  *n;
+   struct redistribute *r;
 
/* area is removed so neutralize the demotion done by the area */
if (area->active == 0)
@@ -68,6 +70,11 @@ area_del(struct area *area)
vertex_free(v);
}
 
+   while ((r = SIMPLEQ_FIRST(>redist_list)) != NULL) {
+   SIMPLEQ_REMOVE_HEAD(>redist_list, entry);
+   free(r);
+   }
+
free(area);
 
return (0);
@@ -88,19 +95,24 @@ area_find(struct ospfd_conf *conf, struc
 }
 
 void
-area_track(struct area *area, int state)
+area_track(struct area *area)
 {
-   int old = area->active;
+   int  old = area->active;
+   struct iface*iface;
 
-   if (state & NBR_STA_FULL)
-   area->active++;
-   else if (area->active == 0)
-   fatalx("area_track: area already inactive");
-   else
-   area->active--;
+   area->active = 0;
+   LIST_FOREACH(iface, >iface_list, entry) {
+   if (iface->state & IF_STA_DOWN)
+   continue;
+   area->active = 1;
+   break;
+   }
 
-   if (area->active == 0 || old == 0)
+   if (area->active != old) {
+   ospfe_imsg_compose_rde(IMSG_AREA_CHANGE, area->id.s_addr, 0,
+   >active, sizeof(area->active));
ospfe_demote_area(area, old == 0);
+   }
 }
 
 int
@@ -110,7 +122,7 @@ area_border_router(struct ospfd_conf *co
int  active = 0;
 
LIST_FOREACH(area, >area_list, entry)
-   if (area->active > 0)
+   if (area->active)
active++;
 
return (active > 1);
@@ -124,5 +136,5 @@ area_ospf_options(struct area *area)
if (area && !area->stub)
opt |= OSPF_OPTION_E;
 
-   return opt;
+   return (opt);
 }
Index: database.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/database.c,v
retrieving revision 1.17
diff -u -p -r1.17 database.c
--- database.c  11 Dec 2019 21:33:56 -  1.17
+++ database.c  13 Dec 2019 22:24:09 -
@@ -135,7 +135,7 @@ send_db_description(struct nbr *nbr)
}
 
dd_hdr.opts = htonl(area_ospf_options(area_find(oeconf,
-   nbr->iface->area_id)));
+   nbr->iface->area->id)));
dd_hdr.bits = bits;
dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num);
 
Index: hello.c
===
RCS file: /cvs/src/usr.sbin/ospf6d/hello.c,v
retrieving revision 1.19
diff -u -p -r1.19 hello.c
--- hello.c 11 Dec 2019 21:33:56 -  1.19
+++ hello.c 13 Dec 2019 22:24:09 -
@@ -72,7 +72,7 @@ send_hello(struct iface *iface)
/* hello header */
hello.iface_id = htonl(iface->ifindex);
LSA_24_SETHI(hello.opts, iface->priority);
-   opts = area_ospf_options(area_find(oeconf, iface->area_id));
+   opts = area_ospf_options(iface->area);
LSA_24_SETLO(hello.opts, opts);
hello.opts = htonl(hello.opts);
 
@@ -120,7 +120,6 @@ recv_hello(struct iface *iface, struct i
 {
struct hello_hdr hello;
struct nbr  *nbr = NULL, *dr;
-   struct area *area;
u_int32_tnbr_id, opts;
int  nbr_change = 0;
 
@@ -148,12 +147,12 @@ recv_hello(struct iface *iface, struct i
return;
}
 
-   if ((area = area_find(oeconf, iface->area_id)) == NULL)
+   if (iface->area == NULL)
fatalx("interface lost area");
 
opts = LSA_24_GETLO(ntohl(hello.opts));
-   if ((opts & OSPF_OPTION_E && area->stub) ||
-   ((opts & OSPF_OPTION_E) == 0 && !area->stub)) {
+   if ((opts & OSPF_OPTION_E && iface->area->stub) ||
+   ((opts & OSPF_OPTION_E) == 0 && !iface->area->stub)) {
log_warnx("recv_hello: ExternalRoutingCapability mismatch, "