Compute and display SPF execution statistics

Detailed SPF statistics, all around time spent executing various pieces of SPF
such as the SPF algorithm itself, installing routes, pruning unreachable networks
etc.

Reason codes for firing up SPF are:
R - Router LSA, N - Network LSA, S - Summary LSA, ABR - ABR status change,
ASBR - ASBR Status Change, AS - ASBR Summary, M - MaxAge

Signed-off-by: Dinesh G Dutt <ddutt@cumulusnetworks.com>
Reviewed-by: JR Rivers <jrrivers@cumulusnetworks.com>
Reviewed-by: Scott Feldman <sfeldma@cumulusnetworks.com>
Reviewed-by: Ayan Banerjee <ayan@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
ospfd: Some small tweaks to the SPF execution reason patch

* ospf_spf.h: use an enum for the reason, and have it as a new argument to
  ospf_spf_calculate_schedule, no need for additional call, and let compiler
  do the checking.
* ospf_spf.c: format changes - Quagga coding style places function names
  at the start of a new line, for easy grepping for definition.
  (ospf_spf_calculate_timer) Change the log format of SPF execution time to
  avoid ginormous line, and make logging conditional, as is the norm.
Make static IPv6 routes respect non-default routing tables.

Signed-off-by: Nolan Leake <nolan@cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
Added show command to display only the routes in the RIB that does not count ECMPs

Signed-off-by: Ayan Banerjee <ayan@cumulusnetworks.com>
Reviewed-by: JR Rivers <jrrivers@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
Avoid timing out of adjacencies by serving all interfaces in round-robin.

Ensure that all interfaces are served in a round robin fashion during
write. This prevents adjacencies from timing out when you have a lot of LSAs
to be sent out each adjacency. This is essentially a scalability improvement.

Signed-off-by: Ayan Banerjee <ayan@cumulusnetworks.com>
Reviewed-by: Dinesh G Dutt <ddutt@cumulusnetworks.com>
Reviewed-by: Scott Feldman <sfeldma@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
ospfd: Tweak previous iface RR write patch to avoid free/malloc & redundant log

* linklist.{c,h}: (listnode_move_to_tail) new unction to move a
  listnode to tail of list.
* ospf_packet.c: (ospf_write) remove debug that seemed to be mostly covered
  by existing debug.
  Use listnode_move_to_tail to just move the list node to the end of the
  tail, rather than freeing the one to hand and allocing a new one.
OSPFd: Update timestamps when we MaxAge LSAs.

When an LSA is flushed we need to update the timestamps for them. This
allows for the node to give the neighbor sufficient time to send back
an acknowledgement before retransmission kicks in.

Signed-off-by: Dinesh G Dutt <ddutt@cumulusnetworks.com>
Reviewed-by: Scott Feldman <sfeldma@cumulusnetworks.com>
Reviewed-by: James Li <jli@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
Add set ipv6 next-hop peer-address command.

IPv4 has the ability to specify the peer address with the keyword peer-address.
IPv6 mandates the use of a specific global or local address only in setting the
next-hop in routemaps. This makes it cumbersome to configure some large networks
with BGP and IPv6. This patch fixes that deficiency.

Signed-off-by: Dinesh G Dutt <ddutt@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
Fix to take care of ordering between interface and router ospf command.

SYMPTOM:

Interface mode OSPF area configuration is not retained after restarting quagga.

Example -

quagga(config)# interface swp49
quagga(config-if)# ip ospf area 0.0.0.0

quagga# sh run
<snip>
interface swp49
 ip ospf area 0.0.0.0
 ipv6 nd suppress-ra
 link-detect
!

quagga# write memory

* Restart quagga at this point*

quagga# sh run
<snip>
interface swp49
 ipv6 nd suppress-ra
 link-detect
!

ISSUE:

The issue is that the interface mode commands can reach the OSPF process even
before 'router ospf' command that initializes the default OSPF instance, this
is not getting handled properly in OSPF process.

FIX:

Initialize the default OSPF instance during OSPF process initializations, which
is before 'router ospf' command is received in OSPF process. So, when interface
mode command is received, it is guaranteed to have ospf instance to work with.

Other way could be to call ospf_get() instead of ospf_lookup() while processing
the config command callbacks, although OSPF needs to have at least one instance
structure anyways, therefore calling it unconditionally in OSPF initializations
should be fine too.

There could be more elaborate fix(es) possible to handle this, like adding some
ordering mechanism for commands as they are read by a process, or storing the
received command and applying it after the commands its dependent upon are
processed. For the issue at hand, initializing the default instance in main()
serves the purpose well.

Signed-off-by: Vipin Kumar <vipin@cumulusnetworks.com>
Reviewed-by: Dinesh Dutt <ddutt@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
bgpd: remove unused variables
Fix BGP's use of restart bit.

bgpd-restart-bit-fix.patch

ISSUE:

Quagga BGP doesn't send or use the restart-bit via the Graceful-Restart(GR)
capability. GR capability implementation isn't complete as per the RFC.

PATCH:

Patch uses BGP instance creation as the beginning of the startup period,
and 'restart_time' is taken as the startup period. As a result, BGP will
set the restart bit in the GR capability of the OPEN messages during the
startup period.

As an indication of quagga implementation's capability of sending End-Of-RIB,
helping a restarting neighbor, quagga BGP will now send global GR capability
irrespective of the graceful-restart config in BGP and the address-family
specific GR capability will be sent only if the GR config is present.
Forwarding bit is not set assuming its not preserved.

Incorporated feedback from David Lamparter via the quagga-dev mailing list.

Signed-off-by: Vipin Kumar <vipin@cumulusnetworks.com>
Reviewed-by: Pradosh Mohapatra <pmohapat@cumulusnetworks.com>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
bgpd: trivial, remove unneeded extra variable in bgp_capability_restart
bgpd: one more fix for tightening of check for missing well-known attributes

* bgp_attr.c: (bgp_attr_check) The check for missing NEXT_HOP has the right
  spirit, but wrong where it counts, on the logic.  It wouldn't catch a
  missing NEXT_HOP on a v4-only UPDATE.  It would though have incorrectly
  flagged next-hop as missing on multi-protocol-only UPDATEs.

  Caught by Martin Winter with a test-suite.
bgpd: implement route-map set as-path prepend last-as

It picks up the AS to add from the aspath, or uses the peers
AS number. Useful mostly in iBGP setups.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Reviewed-by: Paul Jakma <paul@opensourcerouting.org>
doc: Document 'set as-path prepend' and 'set as-path prepend last-as'
zebra/kernel_socket.c: Use platform alignment

Use the platform-provided RT_ROUNDUP macro to align sockaddrs on the
routing socket, rather than using hard-coded assumptions about
alignment.  Emit a warning if the OS doesn't define alignment macros.

Resolves failure of ripngd on NetBSD 6 i386, which changed alignment
to uint64_t from long.
bgpd: stop startup timer on stopping BGP (fixes dd49eb1)

bgp_delete() really needs to kill t_startup, otherwise after creating
and quickly destroying a BGP instance it may fire on a deallocated
struct bgp, overwriting memory.

Reported-by: Martin Winter <mwinter@netdef.org>
Fixes: dd49eb1 ("Fix BGP's use of restart bit.")
Cc: Vipin Kumar <vipin@cumulusnetworks.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
bgpd: set BGP_ATTR_MP_[UN]REACH_NLRI (fixes 1a211cb)

Unfortunately, the attribute present bits for MP_REACH and MP_UNREACH
which 1a211cb ("bgpd: one more fix"...) tests for are never set in their
corresponding attribute parsing functions.

Reported-by: Martin Winter <mwinter@netdef.org>
Fixes: 1a211cb "bgpd: one more fix for tightening of check for missing well-known attributes"
Cc: Paul Jakma <paul@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Reset routemap set iff a routemap is applied

Otherwise keep it as it. Fixes a bug where external routes
without associated routemap would have their metric(-type)
reset.

Signed-off-by: Olivier Tilmans <otilmans@gmail.com>
Added new external route type -- Fibbing

Signed-off-by: Olivier Tilmans <otilmans@gmail.com>