Commit Graph

21 Commits

Author SHA1 Message Date
Maciej Żenczykowski
c5af9f2084 Drop support for beta versions of Android T.
Android T beta3/4 haven't been tested in ages,
and were really only tested for the transition to final T
nearly a year ago.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I520e60026179c078859572231b86184796182142
2023-04-25 15:08:28 -07:00
Maciej Żenczykowski
4c33f5c958 bpf_net_helpers: define some boolean constants
This will make the code more legibble once we switch to using these.

Also moving them out of the .c files so we can share the same
constants across multiple files.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5cc9058cee8d1ea10d2f9e62a38313d0728f07d3
2023-04-20 04:03:26 +00:00
Maciej Żenczykowski
bdcb8968b8 clatd: update a comment about ipv6 frag handling
Test: N/A, comment only
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id41148e01f5ea8e924bd7bdd09216178081a44c5
2023-03-17 18:29:04 +00:00
Maciej Żenczykowski
9b239528e3 clatd - ipv6 fragment to ipv4 translation support (try 2)
This is a repeat of:
  https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2266447

which was reverted in:
  https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2372509

This time with kver >= 4.14 protections of the bpf_skb_adjust_room()
bpf helper which isn't present on 4.9 T devices.

Original change comments:

Tested manually on a flame device connected to an ipv6-only wifi
network (GoogleGuest).

On server:
  nc -4 -l -u -p 443

On client (phone):
  adb shell nc -4 -u my.server 443

On client (phone):
  adb shell tcpdump -l -ee -vv -s 1600 -i v4-wlan0

On client send something to server "Hi."
On server send something to client "Hey!"

You should see normal unfragmented IP packets.

Then on server send something really long (I used 57 copies of the 26 letter English alphabet).  This should be long enough that fragmentation is required.

You should see tcpdump show 2 ipv4 fragments, and netcat
show the packet being delivered correctly.

(and previous versions of the code were buggy and were
resulting in corrupt packets and things not working)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6758e63d8133215edd26b4cd2d73a5b5f261ffd1
2023-01-04 11:35:50 +00:00
Maciej Żenczykowski
2aaa7b6c67 Revert "clatd - ipv6 fragment to ipv4 translation support"
This reverts commit be9685c35c.

Reason for revert:
  fails on 4.9 due to bpf_skb_adjust_room requiring a later kernel,
  will need an alternative approach

Bug: 261818177
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I26535a96de80febc2fd54dcb564cde4f9ed7b3c9
2023-01-03 11:30:54 +00:00
Maciej Żenczykowski
7b452a1186 bpf_shared.h - split clatd portion out into clatd.h
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib068ffc927d031dfb979d86957fcf5818474831d
2022-12-08 15:39:01 +00:00
Maciej Żenczykowski
f7d2393ded bpf clatd.c - refix RFC6145 - really use low 16 bits of IPv6 frag id
To quote: https://www.rfc-editor.org/rfc/rfc6145

4.1 Identification:
The low-order 16 bits copied from the Identification field in
the IPv4 header.  The high-order 16 bits set to zero.

5.1.1 Identification:
Copied from the low-order 16 bits in the Identification field in
the Fragment Header.

The RFC does not mention endianness.  But I'm assuming it thinks
of things as network, ie. big, endian.

This matches userspace external/android-clat/translate.c:214

  ip_targ->id       = htons(ntohl(frag_hdr->ip6f_ident) & 0xffff);

This takes the 3rd and 4th byte of the 32-bit ipv6 frag ident field:

see also line 195:

  frag_hdr->ip6f_ident = htonl(ntohs(old_header->id));

and

packages/modules/Connectivity/bpf_progs/bpf_net_helpers.h

// Android only supports little endian architectures
#define htons(x) (__builtin_constant_p(x) ? ___constant_swab16(x) : __builtin_bswap16(x))
#define htonl(x) (__builtin_constant_p(x) ? ___constant_swab32(x) : __builtin_bswap32(x))
#define ntohs(x) htons(x)
#define ntohl(x) htonl(x)


Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie4eed30cfd0e3e3e4dfa6c1a54751dcae1f9972b
2022-11-24 09:15:57 +00:00
Maciej Żenczykowski
e6b4ec5b29 bpf clatd.c - per RFC 6145 simply use bottom 16 bits of IPv6 frag id.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifac9ae3702b0fc54a02fcfcf05efb36c1299e8ec
2022-11-18 15:00:03 +00:00
Maciej Żenczykowski
be9685c35c clatd - ipv6 fragment to ipv4 translation support
Tested manually on a flame device connected to an ipv6-only wifi
network (GoogleGuest).

On server:
  nc -4 -l -u -p 443

On client (phone):
  adb shell nc -4 -u my.server 443

On client (phone):
  adb shell tcpdump -l -ee -vv -s 1600 -i v4-wlan0

On client send something to server "Hi."
On server send something to client "Hey!"

You should see normal unfragmented IP packets.

Then on server send something really long (I used 57 copies of the 26 letter English alphabet).  This should be long enough that fragmentation is required.

You should see tcpdump show 2 ipv4 fragments, and netcat
show the packet being delivered correctly.

(and previous versions of the code were buggy and were
resulting in corrupt packets and things not working)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iafbe718f7d6427b3e318c8f3f1ecfe2a13d47540
2022-10-25 22:38:32 +00:00
Maciej Żenczykowski
3b3d9c5dac Merge changes I67ba0379,Iced00bb4
* changes:
  clatd - preparation for ipv6 to ipv4 fragmentation translation
  clatd - pull in more fragmentation related stuff from kernel headers
2022-10-25 03:08:59 +00:00
Maciej Żenczykowski
321321c7b1 clatd - preparation for ipv6 to ipv4 fragmentation translation
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I67ba03796ab93844c93f2b142880b6de6de75f7f
2022-10-24 05:57:42 -07:00
Maciej Żenczykowski
e0ddc47540 clatd - pull in more fragmentation related stuff from kernel headers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iced00bb4341497e14c8feb3bb1d4fbed287fd29d
2022-10-24 05:57:42 -07:00
Maciej Żenczykowski
59234fd785 remove prog_clatd_schedcls_egress4_clat_ether
This is not used, and cannot be used: clat v4-* interfaces
are - by virtue of method of creation - always rawip.
This is because they are tun (not tap) devices.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iaafdd6e471c63668d7fe79b62257255bf98c4fb8
2022-10-24 02:16:18 -07:00
Maciej Żenczykowski
c41e35d830 update CRITICAL annotations for mainline
(these only affect boot time logging)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3f315c5eabe73d3378e6ca0059f05221df7bab5e
2022-08-04 13:59:24 +00:00
Maciej Żenczykowski
ce9108f01a verify CLAT_MARK matches aidl constant.
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ife3ad35b2e5451727a3795a0e78dd820293c0eae
2022-06-16 21:39:32 +00:00
Maciej Żenczykowski
f769952212 bpf programs: switch from integers to #define'd bpfloader versions
(per request from Lorenzo)

We do bump block/clatd/dscp_policy requirements from 0.12 to 0.13,
but this effectively doesn't matter:

- Beta2 is too old either way (pre-0.12)
- Beta3 is new enough (0.13)
- versions in between are simply obsolete / unused / not important
- bpfloader 0.12 won't boot right anyway due to lack of netd maps/programs
  (which cause a netd startup failure)

This allows us to have one less #define in the header files,
with a hard to write explanation about what exactly v0.12 is (or was).

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1ecf15f9d7abbb82ec6bd49848255fab6a41aed4
2022-05-24 16:11:09 -07:00
Maciej Żenczykowski
acebffb966 add proper minimum bpfloader version annotations for block/clatd/dscp_policy/netd
In practice this doesn't actually really matter, since older versions
of the bpfloader won't even look in the relevant directories:

BpfLoader v0.9 is the first one that looks into
  '/apex/com.android.tethering/etc/bpf/net_shared',
but it is only v0.12 that pins the resulting programs and maps
correctly into
  /sys/fs/bpf/net_shared/
hence the annotations for block/clatd/dscp_policy.

BpfLoader v0.13 is the first one that looks into
  '/apex/com.android.tethering/etc/bpf/netd_shared'
subdirectory and pins into
  /sys/fs/bpf/netd_shared/
hence the annotation for netd.

But it's best to explicitly document the intent.

Note that in practice the mainline module will fail spectacularly
on a T OS if it can't find the programs and maps
(presumably due to the bpfloader being too old)
but will work on S even though the bpfloader there is much older,
because these programs/maps are not required on pre-T OS.

This change is thus really only documentation.

Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5ffa2faf83ca337b84e34b01df84436629989c58
2022-05-16 17:09:58 -07:00
Maciej Żenczykowski
824fb294ee rename try_make_readable() to try_make_writable()
In practice this function makes things readable and writable,
so use a less confusing name.

Test: TreeHugger, 'git grep try_make_readable' comes up empty
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I32faad148cc5714cf0ec7246620376ed4dd3d6d2
2022-04-11 23:58:36 -07:00
Maciej Żenczykowski
4b1e0f8bcf clatd bpf - add try_make_readable() of the ethernet/ip header
We now rely on the skb->mark = 0xDeadC1a7 setting side effect
for non offloadable packets, but for this to work reliably,
we *must* be able to read the ip header.

Test: TreeHugger, and on a gs101-based pixel
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic2b15335099404047d136a92ce7aeeb1f11ccfa3
2022-04-07 18:00:42 -07:00
Hungming Chen
6c0b1e85e9 Set mark on non-offloaded ingress clat traffic
As Maze@'s advice, we add a clat mark to clat packet in ingress bpf
and drop the duplicate packets in iptables via mark match.

Bug: 218407445
Test: manual test with unmerged aosp/1951099

0. Connect to IPv6-only wifi

1. Clatd test: ping 5 times and check that iptables drop 5 packets by
   mark 0xdeadc1a7.

$ adb shell ping 8.8.8.8
..
64 bytes from 8.8.8.8: icmp_seq=4 ttl=120 time=14.3 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=120 time=67.4 ms

$ adb shell ip6tables -t raw -L bw_raw_PREROUTING -v
Chain bw_raw_PREROUTING (1 references)
 pkts bytes target     prot opt in     out     source               destination
    5   520 DROP       all      any    any     anywhere             anywhere             mark match 0xdeadc1a7
    0     0 RETURN     all      ipsec+ any     anywhere             anywhere
    0     0 RETURN     all      any    any     anywhere             anywhere             policy match dir in pol ipsec
 1661 1239K            all      any    any     anywhere             anywhere            match bpf pinned /sys/fs/bpf/prog_netd_skfilter_ingress_xtbpf

2. Bpf test: run iperf to an IPv4 server and iptables doesn't see
   offloaded packet with mark 0xdeadc1a7. Drop packet count (5) is
   unchanged.

$ adb shell iperf3 -4 -c 117.102.109.186 -t1
Connecting to host 117.102.109.186, port 5201
[  5] local 192.0.0.4 port 56242 connected to 117.102.109.186 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec   622 KBytes  5.09 Mbits/sec    0   44.0 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-1.00   sec   622 KBytes  5.09 Mbits/sec    0             sender
[  5]   0.00-1.00   sec   201 KBytes  1.64 Mbits/sec                  receiver

$ adb shell ip6tables -t raw -L bw_raw_PREROUTING -v
Chain bw_raw_PREROUTING (1 references)
 pkts bytes target     prot opt in     out     source               destination
    5   520 DROP       all      any    any     anywhere             anywhere             mark match 0xdeadc1a7
    0     0 RETURN     all      ipsec+ any     anywhere             anywhere
    0     0 RETURN     all      any    any     anywhere             anywhere             policy match dir in pol ipsec
 1804 1280K            all      any    any     anywhere             anywhere            match bpf pinned /sys/fs/bpf/prog_netd_skfilter_ingress_xtbpf

3. Enable USB tethering. Do ping and iperf on tethered client.

4. Clatd test: ping 5 times and check that iptables drop 5 packets
   (count from 5 to 10) by mark 0xdeadc1a7.

$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
..
64 bytes from 8.8.8.8: icmp_seq=4 ttl=119 time=13.7 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=119 time=15.9 ms

$ adb shell ip6tables -t raw -L bw_raw_PREROUTING -v
Chain bw_raw_PREROUTING (1 references)
 pkts bytes target     prot opt in     out     source               destination
   10  1040 DROP       all      any    any     anywhere             anywhere             mark match 0xdeadc1a7
    0     0 RETURN     all      ipsec+ any     anywhere             anywhere
    0     0 RETURN     all      any    any     anywhere             anywhere             policy match dir in pol ipsec
 1900 1298K            all      any    any     anywhere             anywhere            match bpf pinned /sys/fs/bpf/prog_netd_skfilter_ingress_xtbpf

5. Bpf test: run iperf to an IPv4 server and iptables doesn't see
   offloaded packet with mark 0xdeadc1a7. Drop packet count (10) is
   unchanged.

$ iperf3 -4 -c 117.102.109.186 -t1
Connecting to host 117.102.109.186, port 5201
[  5] local 192.168.235.233 port 41602 connected to 117.102.109.186 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  3.19 MBytes  26.8 Mbits/sec    0    369 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-1.00   sec  3.19 MBytes  26.8 Mbits/sec    0             sender
[  5]   0.00-1.00   sec  2.58 MBytes  21.7 Mbits/sec                  receiver

$ adb shell ip6tables -t raw -L bw_raw_PREROUTING -v
Chain bw_raw_PREROUTING (1 references)
 pkts bytes target     prot opt in     out     source               destination
   10  1040 DROP       all      any    any     anywhere             anywhere             mark match 0xdeadc1a7
    0     0 RETURN     all      ipsec+ any     anywhere             anywhere
    0     0 RETURN     all      any    any     anywhere             anywhere             policy match dir in pol ipsec
 1978 1320K            all      any    any     anywhere             anywhere            match bpf pinned /sys/fs/bpf/prog_netd_skfilter_ingress_xtbpf

Change-Id: I180206bb15a1362c678f42fb980b60dfed6ce1ab
2022-04-07 11:49:59 +08:00
Maciej Żenczykowski
849b3aadc4 move clatd.c bpf program to mainline
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7e88fcc34c21695e844d607836df4661790cba03
2022-01-20 21:00:22 -08:00