summaryrefslogtreecommitdiffstats
path: root/clatd.c
Commit message (Collapse)AuthorAgeFilesLines
* Process packets in bursts.HEADreplicant-6.0-0004-transitionreplicant-6.0-0004-rc6replicant-6.0-0004-rc5-transitionreplicant-6.0-0004-rc5replicant-6.0-0004-rc4replicant-6.0-0004-rc3replicant-6.0-0004-rc2replicant-6.0-0004-rc1replicant-6.0-0004replicant-6.0-0003replicant-6.0-0002replicant-6.0-0001stable/cm-13.0-ZNH5Ycm-13.0Lorenzo Colitti2016-06-081-26/+29
| | | | | | | | | | | | Add a "packet_burst" config option that will cause clatd to read (and write) in bursts of up to that number of packets, instead of always only reading one packet at a time. This reduces poll overhead and improves performance. The variable is initially set to 10. Bug: 24113287 Change-Id: I7feba4127538c5a89f92e0ebea1fb75971d6b901
* Run the receive path in its own thread.Lorenzo Colitti2016-06-081-8/+38
| | | | | Bug: 24113287 Change-Id: I3e77f5d5e9fcc47819f2a9fe60cff4aa7f97a8bd
* clatd: Relay checksum information from packet socket to TUN interfaceSubash Abhinov Kasiviswanathan2015-11-151-1/+1
| | | | | | | | | | | | | | | | | | With this change, we can notify network stack to disable checksum validation for GRO packets as well as other packets which have checksum validation completed earlier in a driver. GRO packets have the ip_summed field set to CHECKSUM_PARTIAL while checksum offloaded packets have the ip_summed field as CHECKSUM_UNNECESSARY. Kernel copies this ip_summed field to the status field in the tpacket filter. The information from the status field is then passed as part of the TUN header to the TUN interface. Any other packet will have the complete checksum validation done in the network stack. Note that this only applies to packets which are captured in packet sockets and passed onto the TUN interface. Change-Id: I536c0356cbbf30fed7ecda5fdd0d38fa0dfd7bf3
* Revert "clatd: Use the TUN_NOCHECKSUM flag for the tun device"Subash Abhinov Kasiviswanathan2015-11-151-3/+0
| | | | | | | | | | | | | | This reverts commit 7efed4e30259da5348c4a7c2c77a0d0d4b13834d. This change may bypass checksum validation for all packets even if they have not been validated earlier. Hardware supports checksum offload for IPv4 / IPv6 UDP and TCP packets only. ICMPv4 / ICMPv6 / fragmented packet checksum offload is not supported and as a result the checksum will not be validated even once before these packet are delivered to the application. Change-Id: I28152b63bb432c3dc37fe7a713c3b225a662f678
* clatd: Use the TUN_NOCHECKSUM flag for the tun deviceSubash Abhinov Kasiviswanathan2015-10-121-0/+3
| | | | | | | | | This is needed to handle cases when the packet socket receives a GRO coalesced packet which will not have a valid TCP checksum. TUN_NOCHECKSUM is used only when the checksum has already been verified prior to this and GRO is being used. Change-Id: I1409967523152bb7620b4881526e78e8c222cc72
* am 49454814: Make the raw socket and the tun fd nonblocking.Lorenzo Colitti2015-02-201-2/+10
|\ | | | | | | | | * commit '49454814a0a714189916cb2aea1922bc8784b13b': Make the raw socket and the tun fd nonblocking.
| * Make the raw socket and the tun fd nonblocking.Lorenzo Colitti2015-02-031-2/+10
| | | | | | | | Change-Id: I29a3d510ba0b766488bbd66d57829d9aaf70d21d
* | am 9353be2a: Switch the receive path to memory-mapped I/O with PACKET_RX_RING.Lorenzo Colitti2015-02-201-46/+35
|\| | | | | | | | | * commit '9353be2a5f1b4fd00b04e4c826f7f3c3ec6c5d46': Switch the receive path to memory-mapped I/O with PACKET_RX_RING.
| * Switch the receive path to memory-mapped I/O with PACKET_RX_RING.Lorenzo Colitti2015-02-031-46/+35
| | | | | | | | Change-Id: I93231de8f108db782eaa43aceb6cc5281d3739c4
* | am 290b8427: Merge "Move tun functions to a new tun.c."Lorenzo Colitti2014-12-081-38/+1
|\| | | | | | | | | * commit '290b84274989c82393a72f97f7c009094e74c651': Move tun functions to a new tun.c.
| * Move tun functions to a new tun.c.Lorenzo Colitti2014-12-081-38/+1
| | | | | | | | Change-Id: I4910b6cfca0bbf6bde2d1348f43d3131a1212399
* | Use different IPv4 addresses on different clat interfaces.Lorenzo Colitti2014-11-011-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously the code would use 192.0.0.4 on all clat interfaces. This works, but it has the problem when a clat interface goes down, we do not reset TCP connections on its IP address if there is another clat interface up. Fix this by assigning every clat interface its own IP address in 192.0.0.0/29. Bug: 12111730 Change-Id: I28c831acd93b0980efea8e90c1cdf8b607beac68
* | Support 464xlat on broadcast interfaces such as wifi.Lorenzo Colitti2014-10-291-0/+4
| | | | | | | | | | | | | | | | This works by generating a random IID and then using the IPV6_JOIN_ANYCAST socket option on the write-only raw socket to configure an address on the interface. Change-Id: Ieb885b7c54454988e2e4254a14b4213cba3bd791
* | Unduplicate IPv6 address setting code.Lorenzo Colitti2014-10-291-41/+54
| | | | | | | | | | | | | | | | | | Currently, the IPv6 address gets set in two different codepaths depending on whether it's being configured on startup or happens because the interface changed its prefix. Refactor the two into a common function. Change-Id: I37035401bef7a57ff40540bd0f2aed0f6863269d
* | Support more than one clatd at a time.Lorenzo Colitti2014-10-281-6/+11
| | | | | | | | | | | | | | | | | | The only change necessary is to stop calling the clat interface "clat4" and instead name it based on the upstream interface (specifically, "v4-<interface>". Bug: 12111730 Change-Id: I489ebb0e3b1408ace8b64ca09ec20366fefe8d83
* | Generate a random IID if one is not specified.Lorenzo Colitti2014-10-281-4/+4
|/ | | | | | | | | | | | | - Add code to generate a random IPv6 address that's checksum-neutral with the NAT64 prefix and clat IPv4 address. - Only calculate the IP address after the NAT64 prefix is known. - Because the clat IPv6 address is no longer determinisitic, modify interface_poll so it checks whether the prefix has changed instead of checking whether the IPv6 address has changed. - Add/update unit tests. Change-Id: Ia53716ca5315ebdd0eaa3ad3a07552bf18e9dd5c
* Call read on any event, not just on POLLIN.Lorenzo Colitti2014-08-251-11/+12
| | | | | | | | | | | | | | The main clatd event loop calls poll() in a loop, but reads only from FDs that have POLLIN set. This causes it to get into an infinite loop if one of the fds has POLLERR set. Instead, read from all fds that have reported events. The read causes the kernel to return the error to userspace and clear the socket error flag, and poll starts working correctly after that. Bug: 17183471 Bug: 17186694 Change-Id: Ie25853e0d60c077d2478b3e5154946e201f96dca
* Remove unused #include.Elliott Hughes2014-07-181-1/+0
| | | | | | (cherry picked from commit 18921713780edb45ceef327d5fcf3387818300f3) Change-Id: I132f7a4ea1a73073fe22ca5f3d89644f2a302db3
* Fix implicit declaration of function 'prctl' in clatd.Elliott Hughes2014-07-181-0/+1
| | | | | | (cherry picked from commit 787ea96922dc3942946fd4ad1e0495d4e06e0c2f) Change-Id: I4582222c8576353b800cc7d30f16c5dbe5f2e8a9
* Create the tun device after dropping root privileges.Lorenzo Colitti2014-06-131-7/+8
| | | | | | | | | | Currently, clatd creates the clat4 interface as root using root's dac_override abilities. Instead, change the drop_root code to acquire membership in the AID_VPN group, and use that membership to create the interface. This removes the need for dac_override. Change-Id: I1f824254f52a441f21c5b7963d9993be88cea2db
* Log unexpected arguments.Lorenzo Colitti2014-06-131-4/+7
| | | | | | | (cherry picked from commit 3e7b1d8f783320d38382089a3c9a790ba13772dc) Bug: 15340961 Change-Id: Iff172b066aa468f9ee36aab661a8b51cb03db95b
* Mark the raw socket used by clatd.Lorenzo Colitti2014-06-131-16/+40
| | | | | | | | | This is required to use clatd on a non-default network. (cherry picked from commit 10c1adce5e85b429bf45bf7f0208c6c37245fbfb) Bug: 15340961 Change-Id: I779c83644727227a109bfeec1565364336b5ac2b
* Use a packet socket to receive packets.Lorenzo Colitti2014-06-131-109/+96
| | | | | | | | | | | Combined with the previous change to send on a raw socket instead of a tunnel interface, this allows us to get rid of the clat interface and remove all the routing configuration code. (cherry picked from commit d44fac888a441cf21111358f43384f3942399d5d) Bug: 15340961 Change-Id: I2147dbfc07321bbd64d3fb9762b1120487712133
* Use a raw socket to send IPv6 packets instead of a tun.Lorenzo Colitti2014-06-131-5/+25
| | | | | | | | | This will allow us to bind the socket to a particular network. (cherry picked from commit 10e8827d636a72a7bcdfd52d15bad9342ae2a0a6) Bug: 15340961 Change-Id: I0b62ef96364a90b9c0a9e3ac3ba97b5c19c89b69
* Make translate_packet take a fd instead of a tun header.Lorenzo Colitti2014-06-131-2/+19
| | | | | | | | | | This will make it easier to use separate fds for reading and writing in a future change. (cherry picked from commit 91d0f1bc6dd24e54ed3caef9b08525b332ab0adf) Bug: 15340961 Change-Id: I374b85f28ae570dc82d21e1ea82a2f072fd7fba3
* Fix build. Remove superfluous check triggering compiler error.Paul Jensen2014-06-131-1/+1
| | | | | | (cherry picked from commit fc0f94a75c7a6d16ea9e327092f132a0d2c9175e) Change-Id: I0366eb3882948d77a8be2d5d32169a13f412ad4e
* Make DNS request for plat prefix detection network specific.Paul Jensen2014-06-131-5/+20
| | | | | | | | | | | When plat prefix detection is done on a non-default network it must use the network specific version of getaddrinfo() so the plat prefix corresponds to the particular network. The network is specified to clatd via a NetID command line argument. (cherry picked from commit a1c871c8efad6c0b69e27d3b85e82a27e282b8be) Change-Id: I270c5afc4b445cf20e95fd3e58eada6bc24b16ef
* Use uint8_t not char for binary data to avoid -Wall -Werror issues on x86 buildsBrian Carlstrom2014-02-241-1/+1
| | | | Change-Id: Ib61e67f15360c27c3ebf61f870a9482217c52357
* Support translating fragmented packets.Lorenzo Colitti2014-02-221-2/+6
| | | | | Bug: 11542311 Change-Id: I14a20b9ac669cdb5927f6ac26147bb0109099497
* Move translation entry point into translate.c.Lorenzo Colitti2014-02-141-65/+1
| | | | | | | | | | | The entry point to the translation code is currently called packet_handler and lives in clatd.c. Move it into translate.c and rename it to translate_packet, since that's what it does. Also get rid of some redundant includes. Bug: 11542311 Change-Id: I8529fb87f3a86ee6724fad54787c33a5e86c56ab
* Remove unused variablesBernhard Rosenkränzer2014-01-021-2/+0
| | | | | | | | Remove unused variables -- they cause warnings (and errors with -Werror) when building with clang 3.4. Change-Id: I03fff9b1b9d620763f41c8b31a19c4724726739c Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org>
* Add ip6 dummy address to keep data usage stats consistent.JP Abgrall2013-12-261-1/+8
| | | | | | | | | | | Because of the way the tunnel pumps packets into the networking stack, the netfilter xt_qtaguid module can't track stats accurately: the totals don't add up. With "clat" having an ip address, qtaguid will track stats against it, which then can be deducted from the external iface. Bug: 11687690 Change-Id: I22ebf26dd9249e821da87665d2bfb0e54d3cdf64
* Fix compiler warnings and enable -Wall -WerrorLorenzo Colitti2013-11-181-1/+1
| | | | Change-Id: I24847fa35644d92bff0fe31ccfc5c4b3e8705779
* Remove two almost-unused include files.Lorenzo Colitti2013-11-181-2/+0
| | | | | | This fixes a compiler warning. Change-Id: I14b5d3c871e9b2fdc8400d999e76e494ad510328
* Support translating ICMP errors.Lorenzo Colitti2013-04-121-0/+4
| | | | | | | | | When receiving ICMPv6 messages from IPv6-only nodes, use 255.0.0.<ttl> as a fake IPv4 source address. It's better than nothing. Bug: 8276725 Change-Id: Iae93f75764cb9cd875af9bb5f1862a0dce2c2fa7
* Improve checksum calculation and address checkingLorenzo Colitti2013-04-121-2/+2
| | | | | | | | | | | | | 1. Add a function that calculates the checksum of all the packet components starting from the specified position. This simplifies the code a bit and makes it easier to translate nested packets like ICMP error messages. 2. Don't hardcode IP source and destination addresses. This is required to translate ICMP error messages. Bug: 8276725 Change-Id: I2cae45683ae3943e508608fd0a140180dbc60823
* Pass around packet data instead of fdsLorenzo Colitti2013-04-121-14/+38
| | | | | | | | | | | | | | | | | The current code calls all the translation functions one after another, accumulating the translated packet into local variables on the stack and calling writev() at the end. This does not allow calling the translation functions re-entrantly, which is needed, for example, to translate ICMP errors (which contain the packet that caused them). Define a clat_packet type to wrap the array of iovecs and an enum of packet positions. Also clean up the code a bit: get rid of a fair bit of duplicated code (though there is still some left), get rid of some redundant memcpy statements, fix style issues, etc. Bug: 8276725 Change-Id: Ib58d2348894e82275234fc67dbdb1f82753f204f
* Configure the interface before bringing it upLorenzo Colitti2013-03-271-8/+9
| | | | | | | | | | | | | | | | | | | 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
* Don't add the IPv4 default route in clatd.Lorenzo Colitti2013-03-191-7/+0
| | | | | | | | The IPv4 default route is now added by ConnectivityService because the stacked LinkProperties object contains it. Bug: 8276725 Change-Id: I6513bfa4df29b8663cefd30ed0bae1a80b63447c
* Remove code to copy the default route.Lorenzo Colitti2013-03-071-3/+0
| | | | | | | | This is no longer necessary now that the kernel removes it for us when accept_ra = 2. Bug: 8276725 Change-Id: If16d9fbc63af2829f1ee4c87031f895f15a3b3d7
* Stop setting accept_ra, now that netd does it.Lorenzo Colitti2013-03-051-34/+0
| | | | | Bug: 8276725 Change-Id: Iedbd34bc94f678afe51429078e6c06ff144e6373
* Merge "Make clatd a bit more robust when started by netd." into jb-mr2-devLorenzo Colitti2013-03-041-8/+14
|\
| * Make clatd a bit more robust when started by netd.Lorenzo Colitti2013-03-021-8/+14
| | | | | | | | | | | | | | | | | | | | | | | | 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
* | clatd: use correct header file.Nick Kralevich2013-02-281-1/+1
|/ | | | Change-Id: I8e7130c1c9b7d6397bc5e705e58667fb7b37b598
* android clat serviceDaniel Drown2012-11-121-0/+522
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>