ripd: move 6 auth functions to rip_auth

This change sets up new files, rip_auth.c/.h, and moves existing
authentication-related functions there, leaving the code mostly intact:

extern rip_auth_simple_password()
extern rip_auth_md5()
extern rip_auth_md5_set()
extern rip_auth_header_write()
static rip_auth_simple_write()
static rip_auth_md5_ah_write()
ripd: move some code to rip_auth_check_packet()

Incoming packet authentication code, which used to be a part of long
rip_read(), is now a separate rip_auth_check_packet() function. This
makes it possible to make rip_auth_simple_password() and rip_auth_md5()
static and simpler.
ripd: move some code to rip_auth_dump_ffff_rte()

The code, which dispatched authentication family RTE decoding in
rip_packet_dump(), is moved to a new function in rip_auth.c,
rip_auth_dump_ffff_rte(), and fixed to include 9th byte of a
hash digest in the dump (it used to be missing it).
ripd: move some code to rip_auth_allowed_inet_rtes()

Long rip_output_process() function used to decide directly, how many
inet RTEs a RESPONSE packet may contain. This change introduces a
dedicated function to make this decision and makes rip_output_process()
use it.
ripd: move some code to rip_auth_make_packet()

rip_output_process() implemented RFC2453 3.10.2 (Generating Reponse
Messages) and also a few related things: route-map processing,
offset-list processing, RIP packet setup and authentication. Now the
function is changed to focus on producing a list or inet RTEs to send,
which are converted into a complete (authenticated, where appropriate)
packet with a separate function, rip_auth_make_packet().

rip_auth_header_write() is replaced with the new function, which also
incorporates some of the code formerly belonging to rip_output_process().
rip_auth_md5_set() becomes static.
ripd: "doff" variable is no more required

Since a complete packet layout is known in rip_auth_make_packet(), the
"RIPv2 Packet Length" field can be set right in rip_auth_md5_ah_write(),
which also makes rip_auth_md5_set() simpler.
ripd: auth type 0x0003 stands for hash, not MD5

Keyed-MD5 was the only hash algorithm possible for Authentication Type
0x0003 in RFC2082, but a later spec, RFC4822, adds other options.
Related messages, comments and a macro are updated to reflect this.
ripd: introduce struct rip_auth_rte

There were two structures available for accessing 0xFFFF family RTE(-like)
packet data: rip_md5_info and rip_md5_data. Both are now replaced with a
single rip_auth_rte structure and the following functions updated to use
it:

* rip_auth.c: rip_auth_simple_password(), rip_auth_md5(),
  rip_auth_check_packet(), rip_auth_make_packet()
* ripd.c: rip_packet_dump()
ripd: move some code to rip_auth_write_leading_rte()

The new function incorporates code formerly belonging to
rip_auth_simple_write() and rip_auth_md5_ah_write(). This also makes
rip_auth_make_packet() simpler.
ripd: use LOOKUP() for auth RTE type code

There is a new message array to decode Authentication Type field of a
0xFFFF RTE, which makes rip_auth_simple_password() and
rip_auth_dump_ffff_rte() simpler.
ripd: fortify packet reception

rip_read() performed very basic verification of an incoming packet
sizing and structure, and additional checks were scattered among other
functions, making it hard to tell, how complete the whole process was.
This task is now solved with a new dedicated function,
rip_packet_examin() (written with respective OSPF-2 and OSPF-3 functions
in mind), which also checks packet contents to be semantically valid.

Receiving buffer is now larger and there is a "relaxed_rx" parameter to
deal with packets slightly larger than traditional 512 bytes limit. The
parameter is not yet used and packet size checks remain strict.
ripd: implement "relaxed-recv-size-checks" mode

* doc/ripd.texi: add new mode option description
* ripd/ripd.h: extend "struct rip"
* ripd/ripd.c
  * rip_read(): update  to pass the flag to rip_packet_examin()
  * show_ip_rip_status(): display flag value in output
  * rip_relaxed_recv_size_checks(): new DEFUN
  * no_rip_relaxed_recv_size_checks(): new DEFUN
  * config_write_rip(): update for new config line
  * rip_init(): update for new DEFUNs
ripd: remove duplicate packet checks

Since rip_packet_examin() is now in place, the following functions can
assume clean input and focus on their primary task:

* rip_auth.c: rip_auth_md5(), rip_auth_check_packet()
* ripd.c: rip_response_process()
ripd: split rip_auth_md5()

rip_auth_md5() function implemented both generic RIP hash authentication
and Keyed-MD5 processing in particular. It is now split into two
functions. rip_auth_check_hash() manages authentication key lookup and
comparison of hash digests. rip_auth_make_hash_md5() handles purely
Keyed-MD5 part of the job.
ripd: clean rip_auth_md5_set() up

The function is renamed to rip_auth_write_trailer() and changed to use
existing rip_auth_make_hash_md5() for Keyed-MD5 processing. A length
check, which does not belong there, is removed.
ripd: clean rip_auth_simple_password() up

Excessive check is removed; indentation is made in line with the other
functions in the same file.
ripd: add authentication debug mode

There is a new debug mode introduced in CLI, "debug rip authentication",
which is now used to log all RIP authentication related messages.

* rip_debug.h: add declarations
* rip_debug.c
  * DEFUNs: update show_debugging_rip; add debug_rip_authentication,
    no_debug_rip_authentication
  * update: config_write_debug(), rip_debug_reset(), rip_debug_init()
* ripd.c:rip_read(): log authentication failure once in "debug rip
  packet recv" mode
* rip_auth.c
  * rip_auth_check_packet(): update to log its messages respectively
  * update to log details of what is happening:
    rip_auth_check_password(), rip_auth_make_hash_md5(),
    rip_auth_check_hash(), rip_auth_check_packet(),
    rip_auth_write_trailer(), rip_auth_write_leading_rte(),
    rip_auth_make_packet()
ripd: treat Keyed-MD5 as a particular case of hash

struct rip_interface is extended with "hash_algo" field with the only
possible value now standing for Keyed-MD5. There are two message arrays
started, both consisting of 1 item. Several functions are updated to
allow adding other hash algorithms with different digest sizes:
rip_auth_check_hash(), rip_auth_write_trailer(),
rip_auth_write_leading_rte(), rip_auth_make_packet(),
rip_auth_allowed_inet_rtes().

Hash function can now return an error code (not used in MD5 case).
ripd: add Rx crypto sequence number handling

There is a "Sequence Number" field in an authentication header (0xFFFF
family RTE with Authentication Type 0x0003), which must be processed
during both reception and transmission of a packet. The
reception-specific (RFC4822 2.3.2) SeqNo processing was never
implemented in Quagga ripd. Necessary missing bits are added:
rip_peer.seqno, rip_peer_getseqno(), rip_peer_setseqno(). Appropriate
sequence number processing is added to rip_auth_check_hash().
configure: detect libgcrypt presence on request

The only hash function available in Quagga code so far was MD5. However,
weaknesses discovered in MD5 have been driving a switch of assorted
network protocols to stronger hash functions, namely, SHA-1 and SHA-2.
These are readily available in gcrypt library, in both pure and HMAC
modes.

This change adds build-time libgcrypt detection and a macro to wrap
gcrypt-specific code. Existing MD5 code is left intact.