android clat service

This software provides the nat 4->6 translation needed for the "clat" part of
the 464xlat standard.  It is needed for better IPv4 application support while
on an IPv6-only mobile network connection using 464xlat's nat64 (such as
T-Mobile's IPv6 trial).

A general diagram of how 464xlat works:
http://dan.drown.org/android/clat/Clat-Plat.png

Depends-on: I2392f8127dcd90d16b0f20ff31bcc5aa096db464
Change-Id: If2bc6916fc66fd4bca7cc241c83cfae839b82e15
Signed-off-by: Daniel Drown <dan-android@drown.org>
build and include for debug builds.

The builds the clatd and adds the needed conf file.

Change-Id: Idb45a7b8b712ffaedddee9f3ca73d44001eaba81
Don't compile packet dumping code by default.

Bug: 7664960

Change-Id: Ieb56bcc010d0e12264d43e0a0dfcb1beb479d4e2
Ensure netlink messages come from the kernel.

Currently clatd accepts all netlink messages without validating
that they come from the kernel. This could allow another app to
spoof these messages. Fix this by connecting the socket to the
kernel so that no other process can send it messages.

Bug: 7664960
Change-Id: I994641ea13cfd07fb25ccf52fcbbf5d1c9633ec4
Merge "Ensure netlink messages come from the kernel."
Change the IP addresses used by CLAT.

- Change the IPv4 address to 192.0.0.4. This is one of the IPv4
  addresses reserved by IANA for DS-Lite, so it's close enough.
- Change the IPv6 IID to ::464. The current code uses an IID
  in the IANA reserved range.

Change-Id: I6039f13efc7d20c433b03cd322fc82a3a45b84cf
clatd: use correct header file.

Change-Id: I8e7130c1c9b7d6397bc5e705e58667fb7b37b598
Make clatd a bit more robust when started by netd.

1. When started from netd, DNS lookups (used to detect the NAT64
   prefix) fail because ANDROID_DNS_MODE=local. Unset it.
2. Only add the SIGTERM handler just before starting the event
   loop. Otherwise, if clatd hangs before the event loop is
   started (e.g., when #1 happens), it can't be stopped.

While I'm at it, add a couple of logging statements.

Change-Id: Ie24b37e34b729ce6cd3769b5d64348f2c1b9627d
Merge "Make clatd a bit more robust when started by netd." into jb-mr2-dev
Stop setting accept_ra, now that netd does it.

Bug: 8276725
Change-Id: Iedbd34bc94f678afe51429078e6c06ff144e6373
Remove code to copy the default route.

This is no longer necessary now that the kernel removes it for us
when accept_ra = 2.

Bug: 8276725
Change-Id: If16d9fbc63af2829f1ee4c87031f895f15a3b3d7
Remove debug tag, as clatd is now built by default

https://googleplex-android-review.googlesource.com/285000
adds clatd to generic_no_telephony.mk, so clatd will be included
on both user and debug builds.

Bug: 8276725
Change-Id: I4b5292b6c48740f2ee3ac246f8ccd11c6ee3fdd8
Don't add the IPv4 default route in clatd.

The IPv4 default route is now added by ConnectivityService
because the stacked LinkProperties object contains it.

Bug: 8276725
Change-Id: I6513bfa4df29b8663cefd30ed0bae1a80b63447c
Configure the interface before bringing it up

Currently, clatd brings the clat4 interface up before assigning
its IPv4 address. This can cause a race condition, because as
soon as the interface comes up, the framework notices and reads
the interface configuration into the LinkProperties. If this
happens before the IPv4 address is configured, then the framework
ends up thinking clat4's IPv4 address is 0.0.0.0/0.

Fix this by configuring the address before the interface is
brought up.

Currently the framework does not use this address for anything,
so this is purely cosmetic, but it could make debugging more
confusing.

Bug: 8276725
Change-Id: I2bfee586a0d70050c53b10cc3f7eb9a98173e11d
Pass in the length to pseudo checksum functions

Currently, the pseudo-header checksum calculation functions get
the transport layer length from the IP header. This requires that
the length be known at IP header construction time, which
does not allow transport layer translation functions to change
the length of the packet later. Have the transport functions
pass in the size directly.

Bug: 8276725
Change-Id: I76a93f5e66181bec21d68f779c68c54090a77c33
Slightly improve dumping packets

Add a function for dumping iovecs, and make hexdumps clearer by
adding spaces between bytes.

Bug: 8276725
Change-Id: Ifb2f8317613d05fa6bd600700090a6df258cde08
Add liblog

Bug: 8580410
Change-Id: I22d0f0a30e5e42ff0c68805703747dd46ccf4fb6
Merge "Pass in the length to pseudo checksum functions" into jb-mr2-dev
Merge "Slightly improve dumping packets" into jb-mr2-dev
Treat the options as part of the TCP header.

This simplifies the code and makes UDP and TCP look the same. It
will also make it easier to implement nested translation in the
future because there will only be one iovec array entry for the
transport layer header, regardless of whether we are translating
UDP or TCP and regardless of the presence of options.

Also get rid of a couple of memcpy statements by pointing to the
original data instead.

Bug: 8276725
Change-Id: I6a702aefdf3a070eedfc6f7d3ebec21880ecc22b