Commit graph android_packages_modules_Co.../clatd_test.cpp
Message SHA1
Fix duplicate symbols error in external/android-clat
Symbol Global_Clatd_Config is duplicated when switch -fcommon to -fno-common

Bug: b/151457797
Test: mm
Change-Id: Ic6beb25cbc370d5bb085a3c569e66bae87446a49

zijunzhao   commited 2023-07-10 22:33:09 +00:00
3591f72de5
clatd: remove ipv6 address monitoring
This code/logic is spurious, because the majority of packets
are translated by eBPF, so whether the daemon runs or not,
usually just doesn't matter - bpf will handle them anyway.

As such what we actually care about is that the daemon
is terminated at the same time as the bpf map configuration
is removed.  This is done by jni native code stopClatdProcess()
which is called from ClatCoordinator java code immediately
after maybeStopBpf().

Additionally on ipv6 address change we don't even terminate
the daemon - we simply stop the event loop, but still block
in main() until we receive SIGTERM/SIGKILL.

(This was done a while ago to fix a bunch of issues with
daemon dieing and being killed racing with each other)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I86d203a244838166ed1fbec1bc48a680e433f9fa

Maciej Żenczykowski   commited 2023-03-16 09:36:10 +00:00
ca9466c768
[RFCLAT#9] refactor getinterface_ip() to stop using libnl
The interface address query doesn't use libnl anymore.
Needed for reducing the library dependency. Once the last libnl user
del_anycast_address() is removed, clatd can remove libnl. Less
dependency helps moving clatd to mainline.

parse_ifaddrmsg() is used to replaced with getaddr_cb() which updates
struct target variable until walking through all messages.
parse_ifaddrmsg() keeps the same behavior as getaddr_cb().

Bug: 212345928
Test: atest clatd_test and manual test
1. Connect to ipv6-only wifi.
2. Try IPv4 traffic.
   $ ping 8.8.8.8

Change-Id: I56591ec851d3202e18cce9fce3995d658d9f07e2

Hungming Chen   commited 2021-12-30 22:55:26 +08:00
208b2a1a0c
[RFCLAT#8] clatd_test: remove or refactor tests for configure_clat_ipv6_address
1. Delete the test because it has been moved to netd.
- ConfigureIpv6Address

2. Refactor the existing test.
Assign IPv6 address directly because the address is applied by
cli argument now because configure_clat_ipv6_address() is
removed.
- Ipv6AddressChanged

Bug: 212345928
Test: atest clatd_test

Change-Id: I673327a36727e22f4ab23c191ee389fc1914016c

Hungming Chen   commited 2021-12-30 22:55:19 +08:00
049cbd87b3
[RFCLAT#7] clatd_test: remove dead test for configure_tun_ip
Delete the test because it has been moved to netd.
- ConfigureTunIpManual

Bug: 212345928
Test: atest clatd_test
Change-Id: I6b997aa0eb383aad04fd85618b64796f11c79cbf

Hungming Chen   commited 2021-12-30 22:55:14 +08:00
45b2f7c3c5
[RFCLAT#6] clatd_test: remove dead test for detect_mtu
Delete the test because it has been moved to netd.
- DetectMtu

Bug: 212345928
Test: atest clatd_test
Change-Id: I9b9d178ae6c2f93699697a46477414ea3c66d9a9

Hungming Chen   commited 2021-12-30 22:55:03 +08:00
ed36b4b664
Clatd changes for move of libipchecksum.
libipchecksum is becoming its own library in
frameworks/libs/net and its include files are no longer under
netutils/. Adjust clatd code accordingly.

Also reorder some include files as suggested by clang-format.

Test: m
Test: atest clatd_test
Test: connects to IPv6-only wifi, testipv4.com shows 10/10
Change-Id: I5e4c73065ce828123aef7e8851227f9bdf444ff9

Lorenzo Colitti   authored and   Maciej Żenczykowski   commited 2021-12-14 03:19:12 +00:00
0cd5aa5403
switch from using packet ring to normal read
With clat ebpf offload of the receive path on 4.9+ P+ devices
this just doesn't matter any more.

Additionally:
- this is *much* simpler,
- reduces memory consumption,
- eliminates the need for memory locking privs,
- and allows us to increment max supported packet size,
  which fixes a long outstanding terrible bug wrt. GRO'ed
  packets being oversize and simply dropped.

So, win, win, win.

Test:
  git grep '(^|[^t])ring[.][ch]'
  git grep 'TP_FRAME_SIZE|TP_BLOCK_SIZE|TP_FRAMES|TP_FRAME_GAP|TP_NUM_BLOCKS|packet_ring|ring_create|ring_read'
  come up empty

  Verified ipv4 ping works on a flame device on an ipv6 only wireless network.

Bug: 130253220
Test: atest clatd_test netd_integration_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I676dfd16ffd2961f14a4e8fcd707c6f9f484e024

Maciej Żenczykowski   commited 2021-11-09 19:32:33 +00:00
50303534ce
cleanup - remove tun.h
Longer term we should probably just merge the clat_config
and tun_data structs, but not just yet.

Test:
  git grep '(^|[^_])tun[.]h'
  comes up empty

Bug: 144730808
Test: atest clatd_test netd_integration_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7c3a986584aa3d02519545fb928457b61247ed14

Maciej Żenczykowski   commited 2020-06-02 15:56:53 -07:00
6fafed183b
cleanup - read_config() and ipv4_local_prefixlen
Test:
  git grep 'read_config|ipv4_local_prefixlen|default_pdp_interface'
  comes up empty

Bug: 144730808
Test: atest clatd_test netd_integration_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I67b70fe298f69ac51dfbc5daf4078b842fb62808

Maciej Żenczykowski   commited 2020-06-02 15:56:28 -07:00
ba667df1c1
cleanup - ipv6_host_id and is_dynamic_iid
Test:
  git grep 'ipv6_host_id|is_dynamic_iid'
  comes up empty

Bug: 144730808
Test: atest clatd_test netd_integration_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie3ed4583a95f15165a05412a556bae99dc07706b

Maciej Żenczykowski   commited 2020-06-02 01:48:50 -07:00
6b759e57d9
Delete the clatd code that assigns IPv4 and IPv6 addresses.
The IPv4 and IPv6 address assignment code, and its tests, were
migrated to ClatdController in Q, and this code has been unused
since then.

This code is not only unused, it also *should* never be used,
because if it were, many parts of 464xlat on Android would not
work as expected. This includes 464xlat BPF offload and data
usage accounting, both of which require netd to know exactly
which IPv4 and IPv6 addresses are used by clatd at any given
time.

Most of the code is deleted, but the function to generate random
checksum-neutral IIDs was moved to the tests instead.

This change does not delete the configuration file parsing code.
That will be done in a follow-up CL.

Bug: 144730808
Bug: 150738490
Test: atest clatd_test
Test: atest netd_integration_test
Test: IPv6-only wifi continues to work
Change-Id: I8265e9bb04d44ed1dda445fa91881fcd1601dc47

Lorenzo Colitti   authored and   Maciej Żenczykowski   commited 2020-06-01 20:24:44 -07:00
baa3c6aefa
remove ClatdTest.ConfigureIpv6Address
This test isn't useful, because we always select the ipv6 address
within netd and pass it in via cli.

(and then we rename ClatdTest.ConfigureIpv6AddressCommandLine to
ClatdTest.ConfigureIpv6Address)

Test: builds
Bug: 144730808
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5dbf1cd2a253a48de187faafa7c259ceab7dba67

Maciej Żenczykowski   commited 2020-01-30 10:05:17 +00:00
5e5d29d88b
Derive mtu from ipv6 route to ipv4 /96 prefix instead of device
Test: builds, atest, still needs testing on real network
  x86 clatd_test
  --------------
  clatd_test (19 Tests)
  ...
  [6/19] ClatdTest#DetectMtu: PASSED (0ms)
  ...
Bug: 147935930
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3d11ba082dabf70089867146acd84f6436953663

Maciej Żenczykowski   commited 2020-01-20 20:36:43 -08:00
b00113f49a
external: android-clat: fix -Wreorder-init-list
C++20 will require members in a designated initializer to be in order
unlike C99.

Bug: 139945549
Test: mm
Change-Id: I5d94739894a5882f571c1e0ddf069725f0c246e8
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Nick Desaulniers   commited 2019-11-19 09:37:42 -08:00
75f4dc6ec7
make clat checksum tests more reliable
This is to allow increasing pseudochecksum returned by 0xFFFF,
which is another form of 16-bit 1's complement 0 and thus irrelevant.

Test: builds, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8cfa04ed1c0bdde2a605cff258a12690748f3bd5

Maciej Żenczykowski   commited 2019-11-10 23:48:37 -08:00
f037e77296
Move checksum code from clatd to libnetutils.
This allows us to use it elsewhere, for example, in netd.

Bug: 65674744
Test: builds, boots
Test: atest clatd_test clatd_microbenchmark
Change-Id: Ic2cea1cd658ffd23ba9fbe45cb6b28e3b5312005

Lorenzo Colitti   commited 2019-01-20 12:08:33 +09:00
98de5958cf
Allow passing in the IPv4 and IPv6 addresses on the command line.
This allows the address to be determined by netd and passed in,
which makes it possible for the rest of the OS to know what the
clatd IPv6 address is.

Bug: 65674744
Test: atest clatd_test
Test: IPv4 on IPv6-only networks continues to work
Test: clatd continues to avoid existing IPv4 addresses in 192.0.0.0/29
Test: passing NAT64 prefix, IPv4/IPv6 addresses on command line works
Change-Id: I8519c2f01b44022ef036c80aa0df32cd76003055

Lorenzo Colitti   commited 2019-01-15 13:33:36 +09:00
f0fac8631a
Drop support for updating IPv6 addresses in clatd.
Currently, when clatd detects that the IPv6 address on its
interface has changed, it updates its configuration accordingly.
This complicates the code, and it prevents us from determining
the IPv6 address in netd instead of clatd.

Stop doing this, and simply exit instead. The framework will
notice that the interface is gone and restart clatd, which will
then have the correct configuration (and, unlike current code,
the correct NAT64 prefix, if that has changed as well).

This change also allows us to drop CAP_NET_ADMIN and run clatd
as an unprivileged user with no capabilities.

Test: atest clatd_test
Test: changing IPv6 address on interface causes clatd to exit
Test: "adb shell cat /proc/$(adb shell pidof clatd)/status | grep Cap"
Change-Id: I296dcb185f603f685223b24ffefdf7a5c22b66e6

Lorenzo Colitti   commited 2019-01-06 11:22:16 +09:00
66deecd38f
Test clatd methods that affect interface IP addresses.
Depend on tun_interface so we can add tests to clatd_test that
use a real interface instead of mocking everything out. Add a
simple test for determining the clat IPv6 address.

Test: atest clatd_test
Change-Id: I1f10c372388a7c663bebab3c45b206036a264673

Lorenzo Colitti   commited 2019-01-06 11:22:16 +09:00
72f770c4ad
Re-indent clatd code with clang-format
clang-format --style file -i *.{c,h,cpp}

Bug: 118848635
Test: 1. browse over ipv6-only network
      2. atest clatd_test
      3. clang-format --style file -i *.{c,h,cpp}

Change-Id: I7389426101df7745370d0ac5c55176cd8fe2b08b

junyulai   commited 2018-12-11 10:12:47 +08:00
c4e591aa04
Convert a few instances of sprintf to snprintf.
Change-Id: Ib3cdf8c3c817adc0eea0095ca4ef5fd66c8456b0

George Burgess IV   authored and   Elliott Hughes   commited 2016-02-24 20:59:20 -08:00
2dcca6feb9
am fee9afb1: Android-Clatd: Remove unused variable
* commit 'fee9afb1a5':
  Android-Clatd: Remove unused variable

Andreas Gampe   authored and   Android Git Automerger   commited 2014-11-25 19:58:09 +00:00
fe2403cbe3
Android-Clatd: Remove unused variable
For build-system CFLAGS clean-up, fix unused-but-set variables.

Change-Id: I3fc6b0d9bec87cd54d7b5199108cff576b4be677

Andreas Gampe   commited 2014-11-24 18:43:39 -08:00
fee9afb1a5
am 2596f42a: Never use a statically-configured IID on wifi.
* commit '2596f42a4f':
  Never use a statically-configured IID on wifi.

Lorenzo Colitti   authored and   Android Git Automerger   commited 2014-11-18 02:08:17 +00:00
7a7cfd6b4e
Never use a statically-configured IID on wifi.
Bug: 12111730
Change-Id: I062d81f2b65e6e89baae0f840cbd673f8051d523

Lorenzo Colitti   commited 2014-11-10 16:06:44 -10:00
2596f42a4f
am 798f9934: Use different IPv4 addresses on different clat interfaces.
* commit '798f9934fc':
  Use different IPv4 addresses on different clat interfaces.

Lorenzo Colitti   authored and   Android Git Automerger   commited 2014-11-03 09:25:06 +00:00
5ba6d23b61
Use different IPv4 addresses on different clat interfaces.
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

Lorenzo Colitti   commited 2014-11-01 01:17:22 +09:00
798f9934fc
am 9808952b: Generate a random IID if one is not specified.
* commit '9808952bdf':
  Generate a random IID if one is not specified.

Lorenzo Colitti   authored and   Android Git Automerger   commited 2014-10-30 23:40:34 +00:00
9d0a1335b0
Generate a random IID if one is not specified.
- 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

Lorenzo Colitti   commited 2014-10-28 15:30:45 +09:00
9808952bdf
Remove unused variables.
BUG: 17281763
Change-Id: Ia9cbda2897e46ca757910d59d0cbb6de07d55482

Chih-Hung Hsieh   commited 2014-08-26 12:41:52 -07:00
05ff508a79
Use a raw socket to send IPv6 packets instead of a tun.
This will allow us to bind the socket to a particular network.

(cherry picked from commit 10e8827d63)

Bug: 15340961
Change-Id: I0b62ef96364a90b9c0a9e3ac3ba97b5c19c89b69

Lorenzo Colitti   commited 2014-06-13 11:47:50 +09:00
ce14088b80
Make translate_packet take a fd instead of a tun header.
This will make it easier to use separate fds for reading and
writing in a future change.

(cherry picked from commit 91d0f1bc6d)

Bug: 15340961
Change-Id: I374b85f28ae570dc82d21e1ea82a2f072fd7fba3

Lorenzo Colitti   commited 2014-06-13 11:47:42 +09:00
e24982ea3a
Use a raw socket to send IPv6 packets instead of a tun.
This will allow us to bind the socket to a particular network.

Bug: 15340961
Change-Id: I50857d372955f2b6f7035157c2968cda72c32585

Lorenzo Colitti   commited 2014-06-11 12:42:20 +09:00
10e8827d63
Make translate_packet take a fd instead of a tun header.
This will make it easier to use separate fds for reading and
writing in a future change.

Bug: 15340961
Change-Id: I5b081b05765cae0488ac599be5738ce9737cae41

Lorenzo Colitti   commited 2014-06-10 21:32:52 +09:00
91d0f1bc6d
Minor code clean-up for GCC 4.9.
- Tidy up "signed vs unsigned" comparison
- Unconditionally initialize the "protocol" variable. This is a
  false-positive warning as protocol is indeed initialized when used,
  but GCC failed to detect the dependency between protocol and ip6.

Change-Id: I8146898d91d45531c3de73403e0df3330c0a2043

Ben Cheng   commited 2014-04-03 09:31:30 -07:00
932614ee5e
Use uint8_t not char for binary data to avoid -Wall -Werror issues on x86 builds
Change-Id: Ib61e67f15360c27c3ebf61f870a9482217c52357

Brian Carlstrom   commited 2014-02-24 21:14:51 -08:00
fcac410fa1
Add a unit test for 464xlat translation code.
Bug: 11542311
Change-Id: Ibc7f156a6abb96c9bf4983ecd63b052fe308e422

Lorenzo Colitti   commited 2014-02-22 13:19:36 +09:00
f3beefc96a