History log of /openbsd-current/usr.sbin/ospf6d/rde.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.91 08-Mar-2023 guenther

Delete obsolete /* ARGSUSED */ lint comments.

ok miod@ millert@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.90 20-Jan-2022 naddy

ospf6d: fix -Wunused-but-set-variable warnings

ospf6d.c: sync a missing bit of (disabled) code with ospfd
rde.c: ifdef out some more incomplete code

ok denis@ claudio@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.89 19-Jan-2021 claudio

Make the struct imsgev static. With this ospf6d compiles with -fno-common


Revision tags: OPENBSD_6_8_BASE
# 1.88 16-May-2020 denis

When IMSG_IFADD is removed, IMSG_IFDELETE becomes useless

OK remi@


# 1.87 16-May-2020 denis

IMSG_IFADD is never used, wipe it

OK remi@


Revision tags: OPENBSD_6_7_BASE
# 1.86 05-Apr-2020 denis

Handle connected routes as ospfd(8) does.

OK remi@


# 1.85 29-Mar-2020 denis

Rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd(8)
couterpart.

OK remi@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.90 20-Jan-2022 naddy

ospf6d: fix -Wunused-but-set-variable warnings

ospf6d.c: sync a missing bit of (disabled) code with ospfd
rde.c: ifdef out some more incomplete code

ok denis@ claudio@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.89 19-Jan-2021 claudio

Make the struct imsgev static. With this ospf6d compiles with -fno-common


Revision tags: OPENBSD_6_8_BASE
# 1.88 16-May-2020 denis

When IMSG_IFADD is removed, IMSG_IFDELETE becomes useless

OK remi@


# 1.87 16-May-2020 denis

IMSG_IFADD is never used, wipe it

OK remi@


Revision tags: OPENBSD_6_7_BASE
# 1.86 05-Apr-2020 denis

Handle connected routes as ospfd(8) does.

OK remi@


# 1.85 29-Mar-2020 denis

Rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd(8)
couterpart.

OK remi@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.89 19-Jan-2021 claudio

Make the struct imsgev static. With this ospf6d compiles with -fno-common


Revision tags: OPENBSD_6_8_BASE
# 1.88 16-May-2020 denis

When IMSG_IFADD is removed, IMSG_IFDELETE becomes useless

OK remi@


# 1.87 16-May-2020 denis

IMSG_IFADD is never used, wipe it

OK remi@


Revision tags: OPENBSD_6_7_BASE
# 1.86 05-Apr-2020 denis

Handle connected routes as ospfd(8) does.

OK remi@


# 1.85 29-Mar-2020 denis

Rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd(8)
couterpart.

OK remi@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.88 16-May-2020 denis

When IMSG_IFADD is removed, IMSG_IFDELETE becomes useless

OK remi@


# 1.87 16-May-2020 denis

IMSG_IFADD is never used, wipe it

OK remi@


Revision tags: OPENBSD_6_7_BASE
# 1.86 05-Apr-2020 denis

Handle connected routes as ospfd(8) does.

OK remi@


# 1.85 29-Mar-2020 denis

Rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd(8)
couterpart.

OK remi@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.86 05-Apr-2020 denis

Handle connected routes as ospfd(8) does.

OK remi@


# 1.85 29-Mar-2020 denis

Rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd(8)
couterpart.

OK remi@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.85 29-Mar-2020 denis

Rework of rde_asext_get()/rde_asext_put().
Also change get_net_link() and get_rtr_link() to work like ospfd(8)
couterpart.

OK remi@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.84 17-Feb-2020 denis

Bring ospf6d closer to ospfd

- update debug messages to be more precise
- simplify call to lsa_self()
- drop lsa_find_lsid() redondant parameters

OK remi@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.83 21-Jan-2020 denis

No need to pass peerid to lsa_snap()

OK remi@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.82 02-Jan-2020 denis

Rename orig_rtr_lsa_area() to orig_rtr_lsa()

Now that area is part of iface, original orig_rtr_lsa() is useless. Also
verifying that area != NULL is not needed in some cases (these are
leftovers of the previous diff).

OK remi@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.81 23-Dec-2019 denis

Area is now part of struct iface

OK remi@


Revision tags: OPENBSD_6_6_BASE
# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.80 11-Jun-2019 remi

Introduce conf_clear_redist_list() (from ospfd) and use it in all 3 procs.

ok benno@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.79 12-Jul-2018 remi

Add support for rdomains.

small quirk from tb@
ok phessler@


# 1.78 12-Jul-2018 remi

With the "depend on" option routes are sent out with a metric of 65535 if
the referenced interface is down or in state backup. This is especially
useful on a carp cluster to ensure all traffic goes to the carp master.

ok friehm@ jca@


# 1.77 10-Jul-2018 friehm

pledge(2)

Looks great! deraadt@
OK florian
OK remi@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


# 1.76 12-Jun-2018 remi

Send LSAs with MAX_METRIC for carp interfaces in state backup.
This is similar to what ospfd does.

ok jca@


# 1.75 12-Jun-2018 remi

Fix resending intra area prefix LSAs on link state or if flag change.

ok jca@


# 1.74 10-Jun-2018 remi

memory leak spotted by claudio@

go ahead jca@
OK claudio@


# 1.73 10-Jun-2018 remi

The value for metric of intra area prefix LSAs should be set to:
- 0 when referencing Network LSAs
- 0 for loopback interfaces
- interface output cost for other cases

go ahead jca@
OK claudio@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@


Revision tags: OPENBSD_6_2_BASE
# 1.72 12-Aug-2017 benno

bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@


# 1.71 19-Jun-2017 friehm

Import route priority support from ospfd to ospf6d.
Also remove the RTF_UP flag from hdr.rtm_flags in send_rtmsg() since
ospfd and bgpd don't set the flag.

OK bluhm@ claudio@


# 1.70 30-May-2017 friehm

Adding multipath route support to ospf6d. Almost copied from ospfd.

OK bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.69 27-Dec-2016 jca

Replace struct rroute with struct kroute, as done in ospfd

ok claudio@


# 1.68 03-Sep-2016 renato

Simplify shutdown process.

On shutdown, there's no need to use kill(2) to kill the child
processes. Just closing the IPC sockets will make the children receive
an EOF, break out from the event loop and then exit.

Tha advantages of this "pipe teardown" are:
* simpler code;
* no need to pledge "proc" in the parent process;
* removal of a (hard to trigger) PID reuse race condition.

ok benno@ claudio@


# 1.67 02-Sep-2016 benno

work on making log.c similar in all daemons:

move daemon-local functions into new logmsg.c, and reduce
the (mostly whitespace) differences so that log.c's can be diffed easily.

ok claudio@, feedback from henning@, deraadt@, reyk@


Revision tags: OPENBSD_6_0_BASE
# 1.66 06-Jun-2016 benno

add format attributes to the proper functions and then fix the
warning in rde.c


Revision tags: OPENBSD_5_9_BASE
# 1.65 05-Dec-2015 claudio

EAGAIN handling for imsg_read. OK henning@ benno@


# 1.64 27-Sep-2015 stsp

As done for bgpd recently, rename if_mediatype to if_type in ospfd/ospf6d.
And some ifmedia64 fixes.
"move forward" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.63 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.62 12-Jul-2014 krw

Close connections when msgbuf_write() returns 0.

ok claudio@


Revision tags: OPENBSD_5_5_BASE
# 1.61 13-Nov-2013 benno

handle msgbuf_write() returning EAGAIN,
taken from claudios previous fix to ospfd.

"do it" deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 17-Sep-2012 bluhm

Fix trailing whitespaces.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.59 06-Nov-2011 guenther

Add a #include that's currently picked up via another header that's
violating namespace rules

ok claudio@


Revision tags: OPENBSD_5_0_BASE
# 1.58 07-Jul-2011 claudio

Rework the distribution of link state and iface FSM state changes.
Link state changes are sent from the parent to both childs and
iface FSM state changes are sent from the ospfe to the rde.


# 1.57 07-Jul-2011 claudio

Just use if_find() to find an interface by ifindex.


# 1.56 07-Jul-2011 claudio

correct/change some debug and fatal messages.


# 1.55 07-Jul-2011 claudio

Kill nh_reachable. Link state checking is so easy now that it does not
matter anymore to cache this value for ospf6d.


# 1.54 04-Jul-2011 claudio

LINK_STATE_IS_UP() cleanup userland part. There is no need to special
case carp(4) interfaces anymore. LINK_STATE_IS_UP() almost always does
the right job.
OK deraadt@ henning@

This needs a -current kernel or link state may be not reported correctly.


# 1.53 04-Jul-2011 claudio

Make sure that passive interfaces (like carp) are added to the
intra-area rtr LSA. Diff initialy made by Patrick Coleman but
simplified by myself. Tested and OK dlg@


# 1.52 05-May-2011 claudio

KNF


# 1.51 02-May-2011 claudio

Don't include sys/param.h and reformat some lines.


Revision tags: OPENBSD_4_9_BASE
# 1.50 22-Aug-2010 bluhm

When removing an announced prefix, inherit the metric and ext_tag
from the LSA that is currently in the tree. Based on claudio@'s
diff and his fix for ospfd. Additionally originate an LSA with
external route tag correctly by writing the AS-external-LSA's bit
T into the correct field.
ok claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.49 09-Jul-2010 bluhm

Do not try to originate an intra-area-prefix-lsa if an interface
address changes that does not belong to any area. This fixes an
ospf6d crash. To not search for the area in orig_intra_lsa_net(),
just pass the area as function parameter.
ok claudio@


# 1.48 06-Jul-2010 bluhm

Update the interfaces changes from kroute to rde via imsg. This
is needed to orginate correct intra-area-prefix-lsas.
ok claudio@ stsp@


# 1.47 06-Jul-2010 bluhm

Use the static variable narea only where needed for config reload.
The other imessages use the stack variables area and iface.
ok claudio@


# 1.46 05-Jul-2010 bluhm

During network intra-area-prefix-lsa origination, the designated
router's prefixes were ignored if all other routers on that link
had no prefixes. Advertise a intra-area-prefix-lsa with all prefixes
for the network if there are any adjacent neighbors on link.
ok stsp@


# 1.45 01-Jul-2010 bluhm

Fix memory leak by adding a missing free(lsa).
ok claudio@


# 1.44 01-Jul-2010 bluhm

Fix all white space bugs in ospf6d at once. No binary change.
ok claudio@


# 1.43 01-Jul-2010 bluhm

The prefixes of interface addresses of an ospf link have to be
advertised as link-lsa and intra-area-prefix-lsa when they change
dynamically. Handle RTM_NEWADDR and RTM_DELADDR in kroute by sending
an imsg to ospfe. Upon this event, originate a new link-lsa in
ospfe. In rde a new intra-area-prefix-lsa is generated when a
link-lsa appears or goes away.
ok claudio@; ok and test stsp@


# 1.42 28-Jun-2010 bluhm

Store the ifindex into the kroute change imsg. This way we can use
the interface index for writing routes into the kernel.
ok claudio@


# 1.41 12-Jun-2010 bluhm

Fix an obvious use after free. From ospfd.
ok claudio@


# 1.40 01-Jun-2010 bluhm

Add NULL pointer check after calloc.
ok claudio@ stsp@


# 1.39 01-Jun-2010 bluhm

Fix error message.
ok claudio@ stsp@


# 1.38 16-Apr-2010 claudio

Move a function to a place that is a bit more logical. No functional change.


Revision tags: OPENBSD_4_7_BASE
# 1.37 01-Mar-2010 claudio

Support for redistributing AS-ext LSA (redistribute static/connected).
Appart from multi-area support this is the last big missing piece in
ospf6d. ospf6d should now work correctly in single area setups.
So please test.
"it's always nice to see those #if 0 being killed" stsp@


# 1.36 24-Jan-2010 stsp

In orig_intra_lsa_rtr(), don't allocate and free a temporary buffer
which easily fits on the stack.

OK claudio@


# 1.35 22-Dec-2009 claudio

Add interface index aka. scope id to struct kroute so that the rde can pass
this information to kroute and kroute can use that information to fill in
the various sin6_scope_id fields.


# 1.34 02-Nov-2009 claudio

Add IMSG_CTL_LOG_VERBOSE similar to ospfd it allows to toggle debug logging.
henning, sthen, michele like the idea


# 1.33 28-Jul-2009 claudio

More fallout from the r1.31 commit. This time PID and the fd got swapped.
Again from stsp@


# 1.32 28-Jul-2009 claudio

Running 'ospf6ctl show' twice caused ospf6d to fatal. Cause was a missing -
when passing -1 as fd to the imsg call. No frogs for eric@ and pyr@
From stsp@


Revision tags: OPENBSD_4_6_BASE
# 1.31 06-Jun-2009 eric

make ospf6ctl/ospf6d imsg-in-a-lib ready too.

ospf6ctl is already broken in tree (not connected to build).

ok pyr@


# 1.30 31-May-2009 jacekm

Remove redundant imsg_event_add calls; ok claudio@


# 1.29 31-May-2009 claudio

libevent handler fix to allow EV_READ and EV_WRITE to be set at the same
time in the callback. Same diff that went into ospfd applied with some
fuzz.


# 1.28 09-Apr-2009 stsp

Fix a naming inconsistency in struct lsa_intra_prefix (lsid -> ls_id).

"consistency is a good thing" jsing@, ok claudio@


# 1.27 29-Mar-2009 stsp

As a first step towards SPF tree calculation, prepare for proper
next-hop calculation.

In OSPFv3, next-hop IP addresses are always link-local.
The kernel will want to know which interface the link-local
address belongs to, so we need an ifindex in struct v_nexthop
in addition to the IP address.

Because we cannot determine a link-local next hop IP address
for transit networks, only the outgoing interface will be recorded.

Update calc_nexthop_add() according to the above.

Also add new helpers calc_nexthop_lladdr() and calc_nexthop_transit_nbr(),
to figure out link-local addresses of nexthop neighbours.

ok claudio@


# 1.26 12-Mar-2009 stsp

lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on.

So split it up as follows:
lsa_self() Check whether an LSA is self-originated.
lsa_flush() Flush an LSA from the LSDB.
lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently
requires sending an imsg which must be done by the caller).

ok claudio@


# 1.25 07-Mar-2009 stsp

Add lsa_find_tree() to allow searching for LSAs in a specific LSA tree.
We had code marked XXX searching an LSA tree manually using RB_FIND(),
switch it over to lsa_find_tree().
Make lsa_find() use the new function, too, to avoid code duplication.
ok claudio@


Revision tags: OPENBSD_4_5_BASE
# 1.24 19-Feb-2009 stsp

Use rde_router_id() instead of directly accessing rdeconf->rtr_id.s_addr.

"For sure!" claudio@


# 1.23 19-Feb-2009 stsp

Enable origination of Intra-Area-Prefix LSAs in rde.

New Intra-Area-Prefix LSAs are originated when a neighbour
becomes adjacent, or when a neighbour loses adjacency,
or when an interface changes state.

ok claudio@


# 1.22 19-Feb-2009 stsp

Virtually re-implement origination of Intra-Area-Prefix LSAs.
We now comply with RFC5340 and move prefixes between the two
ref-types of Intra-Area-Prefix LSAs (router and network).

In case an LSA ends up having all of its prefixes moved to another
one, the LSA is flushed from the LSDB by re-originating with MAX_AGE.
(This does not yet work reliably. We end up having LSAs with zero
prefixes in the LSDB in some cases. Should not affect SPF calculation,
so not much harm done, but will need to be fixed.)

This commit just adds the necessary code to do origination,
but it is not being called yet. This will be done in a separate
commit.

"Looks good." claudio@


# 1.21 19-Feb-2009 stsp

Sync iface fsm state from ospfe to rde.

Also syncs other fields the ospfe is syncing to when getting
iface updates from parent process.
None of these fields are used by the rde yet, but state will be
important soon, for proper origination of Intra-Area-Prefix LSAs.

ok claudio@


# 1.20 10-Feb-2009 stsp

Fix two obvious copy-paste errors in fatal error messages. We were
printing IFINFO while we are actually handling an IFDELETE imsg.


# 1.19 03-Feb-2009 stsp

Formatting fixes.


# 1.18 29-Jan-2009 stsp

Hard-code the Link State ID of Intra-Area-Prefix LSAs referencing Network
LSAs to zero. We were using the interface index, which is not quite right
for this type of LSA.

This is part of a greater scheme:
Intra-Area-Prefix LSAs referencing Router LSAs (not yet implemented)
will initially have their Link State ID hard-coded to one.
Then, as soon as we implement fragmentation of Intra-Area-Prefix LSAs,
Link State IDs for both types of Intra-Area-Prefix LSA will have to be
generated dynamically in a non-overlapping fashion.

discussed with claudio@


# 1.17 29-Jan-2009 stsp

Improve debugging message in orig_intra_lsa_net().
Print not just the area, but also the interface to the link the LSA
is generated for.
ok claudio@


# 1.16 28-Jan-2009 stsp

Teach ospf6d to originate Intra-Area-Prefix LSAs, which associate a list
of IPv6 prefixes with a Network LSA (there's another type of this LSA which
associates prefixes with a Router LSA -- this remains to be done).
Add what is necessary to allow ospf6ctl to read the new LSA type via IMSG.
ok claudio@


# 1.15 27-Jan-2009 michele

Again, no need to double check if neighbor exists.

ok stsp@


# 1.14 03-Jan-2009 stsp

Since link LSAs live in iface->lsa_tree and not in area->lsa_tree,
we had better include LSAs from iface->lsa_tree when sending
DB summaries. Fixes initial flood of link LSAs.
ok claudio@


# 1.13 30-Dec-2008 claudio

First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself


# 1.12 28-Dec-2008 claudio

No need to byteswap req_hdr.type as lsa_find() will do that for us.
From Stefan Sperling


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Feb-2008 norby

Correct the output of several error and debug messages.


# 1.10 13-Dec-2007 claudio

Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related.
This removes unneeded data redundancy which makes the code more complex.
* adds the link local prefix to struct iface and attaches a list with
the other prefixes to the struct iface. This is needed to generate the
link LSA.
* disconnects struct iface from struct area (the backpointer is gone)
this will make the reload code a bit easier.
norby@ agrees with the direction we're heading with this


# 1.9 27-Nov-2007 claudio

Make lsa_find() find link local LSA by passing the interface instead of the
area as lookup point. Additionally make lsa_dump or actually the code around
it pass all LSA to ospf6ctl. The rde_spf.c are not final.


# 1.8 27-Nov-2007 claudio

Monster diff to bring us a bit on track again.
a) implement all (or at least most) lsa_check() cases.
b) classify the LSA scope correctly and add a per interface lsa_tree for
the link local stuff.
c) implement a function to parse a prefix.

There is still a lot missing currently link local LSA are added to the
interface tree but nothing can access them (lsa_find() and a few friends
need some changes).
OK norby@


# 1.7 17-Oct-2007 claudio

lsa_snap() should work so enable it.


# 1.6 16-Oct-2007 claudio

Enable the IMSG_DD related code. This code starts to work.


# 1.5 16-Oct-2007 norby

In OSPFv3 the LSA type is a 16 bit value, furthermore it uses different
values than the v2 counterpart.

Change to u_int16_t and define new LSA types.

ok claudio@


# 1.4 16-Oct-2007 claudio

First step at making kroute IPv6 aware. This resulted in many additional
changes -- some are so hairy that I left them out for later by commenting out
larger blocks of code (just grep for XXX if you like to help).
Get it in early so that we can work on.
OK norby@


# 1.3 11-Oct-2007 claudio

Disable some code that is currently far from working and results in frequent
session resets because of bad packets. With this it seems we survive the
hello and database exchange phases. A closer look at the DR and BDR calculation
is still needed.


# 1.2 11-Oct-2007 claudio

From ospfd:
Bye bye global ospf options. OSPF options are per area (at least the one
flag that we set). So introduce a area_ospf_options() function that will
return the correct flags for each area. This makes stub area support a lot
easier.
Don't check for OSPF_OPTION_E in the parent. OSPF_OPTION_E is per area and
so the parent process has no way to know if it should redistribute or not.


# 1.1 08-Oct-2007 norby

Welcome ospf6d

The new ospf6d daemon will support OSPFv3, basically OSPF for IPv6 networks.

It is heavily based on ospfd(8), it is more or less a copy and paste of it.
Currently some unneeded stuff has been removed and the trasition from
IPv4 to IPv6 has begun.

ospf6d is not very usefull at the moment, it is being imported to allow more
people to work on it concurrently.

Not yet connected to the builds.

ok claudio@ dlg@