android: Use make-standalone-toolchain.sh from NDK

This helps avoid having to hardcode internal NDK paths in our build
scripts, making them less fragile.  It also lets us use a combined
sysroot for all dependencies, as the local copy of the toolchain is
guaranteed to be writable.  Net result is that packages can generally
just invoke plain $(CC) without --sysroot, -I, or -L flags.

For background info, see "the easy way" in
$(NDK)/docs/STANDALONE-TOOLCHAIN.html

Also, after openconnect is built, the user is left with a new toolchain
containing many helpful libraries.  It can be used to cross-compile other
programs just by setting $PATH and --host= with appropriate values.

The change was successfully compile-tested with the following NDK releases:
8c, 8d, 8e, 9, 9b, 9c.  For each release, ARM/x86/MIPS targets were built
on Linux using both x86 and x86_64 host binaries.  OSX was not tested.

NDK releases <= 8b were also tested, but they showed a large number of
unrelated build failures due to factors like:

 - Shipping a version of binutils that doesn't recognize the "rrx(s)"
instruction in gmp

 - Calling the x86 binary "i686-android-linux-gcc" instead of
"i686-linux-android-gcc"

 - Using binutils (bfd) ld instead of gold for x86, so the final link
hits the same zlib dependency bug that we see on MIPS

 - Lack of support for the android-14 (4.0/ICS) ABI

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
android: Install stripped binaries under $(TRIPLET)/out

This is a little more user-friendly than making people dig into .libs/
and copy them out.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
dtls: Set rekey_method correctly if the header is missing

ASA gateways do not appear to send the X-DTLS-Rekey-Method: header, so
fall back to the same rekey_method as CSTP rather than assuming
REKEY_NONE.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Sanity-check CSTP and DTLS rekey times

Just set REKEY_NONE if the rekey time is zero or negative, so that we
don't need to test (ka->rekey && ka->rekey_method != REKEY_NONE) in
multiple locations.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
cstp: Rework DTLS master secret (re)generation

Improve handling of the following cases:

 - Server-specified "rekey method none".  In this case, openconnect should
   generate one DTLS master secret on initial connection, and reuse it
   for the lifetime of the VPN session.

 - DTLS key changes.  The DTLS connection needs to be torn down any time
   a new master secret is sent to the server, or else the client and
   server will lose DTLS connectivity (possibly for extended periods of
   time).

   We will assume for now that the server-provided DTLS session ID only
   changes if we send a new DTLS master secret, as that is the behavior
   seen on current ASA firmware releases.

 - CSTP reconnections.  dtls_times.last_rekey should only be updated when
   the key actually gets overwritten by new random data, not every time
   we see an "X-DTLS-Session-ID:" header (which happens on every CSTP
   reconnect).

Note that there is one case in which our master DTLS secret will be
rejected: if it is all zeroes.  I have confirmed that other trivial keys
(00000....01, fffff....) are OK.  So we probably do not have to worry too
much about DTLS failing permanently if we send an unacceptable key in the
"rekey method none" case.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
mainloop: Use consistent logic for rekey timeout check

ka_stalled_action() and keepalive_action() should both use the same test.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
mainloop: Simplify the keepalive functions

Moving the "compare values + update timeout" logic into a helper function
lets us delete several duplicated checks and temporary variables.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>