Commit Graph

126 Commits

Author SHA1 Message Date
Maciej Żenczykowski
8e4a794519 netd bpf - no-op code hygiene fix for DROP_UNLESS_DNS
We only ever return DROP_UNLESS_DNS on ingress,
so the ordering doesn't actually matter.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I742b85748433f5319d518bebc05d976d630b72e7
2023-03-02 00:12:08 +00:00
Ryan Zuklie
9419d25fe2 Add packet tracing bpf implementation
This adds the core BPF implementation of Android network packet tracing.
The new code looks into the skb to pull out various bits of information.
Both the program and the ring buffer are restricted to 5.8+ kernels and
userdebug or eng builds.

With the packet_info_config map defaulting to zero, userdebug and eng
builds won't run any of the tracing today. The only effect will be 32k
memory increase for the ringbuf and the check on the config array.

Bug: 246985031
Test: build & flash both userdebug and user
Change-Id: I144da2971c0738b565ad58abc17e456209f13bde
2023-01-23 09:51:31 -08:00
Ryan Zuklie
1db34f3b91 Add BPF helpers for ipv4/ipv6 and tcp/udp offsets.
Test: build & install connectivity module
Change-Id: I869810d05ad8266b6a4107a5276864fdbcdbd9b0
2023-01-23 09:50:31 -08:00
Ryan Zuklie
0c57d8567c Update BPF EXT maps with new ignore_on fields.
These all default to false, never ignoring the maps.

Bug: 246985031
Test: build connectivity module
Change-Id: I404d56dcb311b34587d56dd6edc292029c4ad83f
2023-01-19 16:16:02 -08:00
Ryan Zuklie
cc72fa8f9d Update bpf helpers to support new ignore_on fields
This change updates callers to include the new ignore_on and bpfloader
arguments as per the change in aosp/2374598.

Bug: 246985031
Test: tethering build & install, full platform build & install
Change-Id: Id940a6003ae4cb0bbfc65db8ff96590c4f3c847b
2023-01-05 13:26:30 -08: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
0966bbee1a netd.c - switch from is_4_19 to simply passing KVER(4, 19, 0) around
will make it easier to extend this for 5.4+ behaviour as well
without having to introduce another is_5_4 boolean

Bug: 263884894
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id4f6512d813dd460cb2b9a7ccb6a5f7b7e937575
2022-12-30 18:59:49 +00:00
Maciej Żenczykowski
28b9a29e04 netd.c - simplify, if not map A then by definition map B
easier on bpf verifier with no third case

Bug: 263884894
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5076de6f83ba522ed4783bca0a9d7fca4024986a
2022-12-29 12:06:49 +00:00
Maciej Żenczykowski
2de5957a88 bpf_connectivity_headers - remove visibility from //system/netd/tests
depends on at least:
  https://android-review.git.corp.google.com/c/platform/system/netd/+/2363881
  'cleanup a bunch of bpf related things (header files mostly)'

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifaf20267f791af09f8c76dda5dfbc38ebc75c4ba
2022-12-20 00:35:05 +00:00
Maciej Żenczykowski
513474c1a7 rename bpf_shared.h to netd.h
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2e1569c8d70e98f9a3fdbab41fd2ba7f7b84dd37
2022-12-18 20:02:52 +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
4e3321ed3b bpf_tethering.h -> offload.h
match header file with bpf program

Locations to change found via:
  https://source.corp.google.com/search?q=p:aosp-master%20(%5E%7C%5B%5E_%5D)bpf_tethering.h

Core reasoning for this will be to match the .h naming
that we'll have for netd.c and clatd.c once we get rid of bpf_shared.h

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4154659c7fb23a37f5316a5c804fb2606d842e9c
2022-12-08 13:04:45 +00:00
Maciej Żenczykowski
f932a8df0e offload.c - fix a mistake in a comment
The comment added by:
  https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2261966
  'offload.c - make tether_error_map read only.'

mentions offload.o loading on T when it should talk about S+.

Tethering offload bpf code was mainlined in S.
(T mainlined all the other bpf code)

Bug: 254543135
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I10b89691082e451115e61dedbdc0dac7a58e499c
2022-12-03 10:31:23 +00:00
Maciej Żenczykowski
5cee8817af Merge "bpf clatd.c - refix RFC6145 - really use low 16 bits of IPv6 frag id" 2022-11-24 15:25:59 +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
d0c03cf20f Merge "bpf netd.c - switch from 'int direction' to 'bool egress'" 2022-11-21 20:29:40 +00:00
Maciej Żenczykowski
55474984e8 bpf netd.c - switch from 'int direction' to 'bool egress'
and get rid of some macros while we're at it.

This is just slightly easier to read.

(side note: this is all resolved at compile time!)

Bug: 259199087
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7b38afd4b6f9d73b4f34a90040639f0780544ac8
2022-11-21 16:53:38 +00:00
Maciej Żenczykowski
1b7c1f1c97 bpf netd.c - add a TODO
Bug: 259889995
Test: N/A, comment only
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0511433663738550b556208c140b08f76ca7898b
2022-11-21 09:41:33 +00:00
Maciej Żenczykowski
0adec97ca7 Merge "bpf clatd.c - per RFC 6145 simply use bottom 16 bits of IPv6 frag id." 2022-11-21 09:16:08 +00:00
Maciej Żenczykowski
3621cbddf1 bpf netd.c - refactor skip_owner_match() tcp flag processing
(no-op simplification)

Bug: 259199087
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib9e126f1ca84f60b4057ccbbd0071f9684b20b92
2022-11-20 13:48:24 +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
879839a1d8 netd.c: on 4.19+ bpf_skb_load_bytes -> bpf_skb_load_bytes_relative
Bug: 145166494
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5fd18deee1c12386bdb8b554a33ac2845f881cc0
2022-10-28 01:40:41 +00:00
Lorenzo Colitti
3505b584d3 Un-drop support for pre-4.14 kernels.
This effectively reverts commit 6ed2ab9b57,
while ensuring that the program has the right permissions as
defined in r.android.com/2130014 :

oriole:/ # ls -lZ /sys/fs/bpf/netd_shared/prog_netd_cgroupsock_inet_create
-r--r----- 1 root root u:object_r:fs_bpf_netd_readonly:s0  0 2022-10-27 20:05 /sys/fs/bpf/netd_shared/prog_netd_cgroupsock_inet_create

Reason for revert: need to support 4.9 devices upgrading to T.

The only thing that cannot currently be supported on those
devices is the inet_create program which implements the
INTERNET permission.

Also, update bpf_existence_test so it does not check for the
existence of the program on pre-4.14 devices.

Bug: 254001921
Test: atest bpf_existence_test
Change-Id: I14f26cee5feeaae93b4d9710a7b9a2f835ff405f
2022-10-27 20:06:16 +09: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
Treehugger Robot
a32628c98d Merge "remove prog_clatd_schedcls_egress4_clat_ether" 2022-10-25 02:54:07 +00:00
Maciej Żenczykowski
9b9e2911bc Merge "Firewall: Support a greater number of apps/uids" 2022-10-25 00:47:58 +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
c8e40c149f flag test.o bpf program as being test only
Bug: 254543135
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8ee7b0a552510baabb7c29d94521291b8b526692
2022-10-21 00:02:35 +00:00
Maciej Żenczykowski
be25f96390 offload.c - make tether_error_map read only.
Bug: 254543135
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5d4c9cad66f59bd7eed54323ba72ea5a54ddf5e1
2022-10-20 04:08:03 +00:00
t-m-w
56b32223ed Firewall: Support a greater number of apps/uids
Devices with a large number of app uids, particularly those with
multiple work profiles or secondary users, may quietly experience
failures making adjustments to firewall rules, resulting in apps being
blocked from accessing the network when they should be allowed, and
becoming a noticeable problem when using Battery Saver mode.

The misleading "Argument list too long" error in logs signifies that
a BPF map (uid_owner_map in this case) has reached its maximum entries.
This patch doubles that to 4000. uid_permission_map is also affected,
and because uid_counterset_map involves uids too, we do the same there.

bpf_shared.h contains comments urging caution with regard to potential
kernel memory limits. Fortunately, BPF maps have been consolidated
since the comments were written, leaving enough room to easily make
this change without cause for concern. This patch effectively increases
the total size of BPF maps from 3643K to 4077K, which remains beneath
the 4930K used by the maps' pre-consolidation implementation.

Change-Id: I293f99ec498e4ccac98c39f298ba01ba554f2e33
2022-10-18 19:04:10 -04:00
Maciej Żenczykowski
242af39425 dscpPolicy.c - old/new_first_u32 is actually be32
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I10b19a010000f1f49c2a48448f413376045bfe1f
2022-08-22 09:12:26 +00:00
Maciej Żenczykowski
0dd2bb31b6 split TCP control packet error into IPv4 vs IPv6
Bug: 241887405
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia155dbf7780b7bcff87e8fa6752d620ccbcae4a4
2022-08-10 19:34:35 +00:00
Maciej Żenczykowski
b82bf6502a split IP version mismatch error into IPv4 vs IPv6
Bug: 241887405
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6ff121ebaec26c9fe14ec8f4f7daebeff77eb7d1
2022-08-10 19:28:48 +00:00
Maciej Żenczykowski
640752bc4c dscpPolicy - sport is network endian, dport is host endian
be more consistent, and thus also less htons() calls

Test: TreeHugger, atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia331a33a615a598e061db53ae180fffaef7a4342
2022-08-09 23:03:20 +00:00
Treehugger Robot
f39f7f83b0 Merge "dscpPolicy - remove bpf byteswap in favour of userspace" 2022-08-09 21:24:26 +00:00
Maciej Żenczykowski
285f705ced resolve nit from 'netd.c - update some permission related comments'
Test: TreeHugger
Bug: 236672779
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5dcf6c32ef9bfd067afbfbbbd90e67ff678691f4
2022-08-09 17:50:46 +00:00
Treehugger Robot
2e922c3de4 Merge "netd.c - update some permission related comments" 2022-08-09 17:49:06 +00:00
Maciej Żenczykowski
a44510ba0c dscpPolicy - remove bpf byteswap in favour of userspace
Test: atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7a008434d58fc0fba5b503eb6fcfbca15bb2015c
2022-08-09 14:59:46 +00:00
Maciej Żenczykowski
1feaa43cbb dscpPolicy - further improvements
Bug: 237485762
Test: atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia88b14609cad4604523e3fc41860c980ee11abe0
2022-08-09 14:48:20 +00:00
Maciej Żenczykowski
06085b0425 netd.c - update some permission related comments
Test: TreeHugger
Bug: 236672779
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I66187d61ccdd3d625a9873090ab8c0dff18ac6a3
2022-08-09 14:15:59 +00:00
Maciej Żenczykowski
869c4ad452 Merge "update CRITICAL annotations for mainline" 2022-08-08 17:40:52 +00:00
Treehugger Robot
7623d8c799 Merge "No need for special case programs for [4.14, 5.4) kernels." 2022-08-05 22:52:17 +00:00
Maciej Żenczykowski
efe862e102 No need for special case programs for [4.14, 5.4) kernels.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I428ea522b618e27eb65e8578f80f04232600af9a
2022-08-05 11:27:47 +00: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
c907fc73e9 Merge "Add libconnectivity_native_test_utils" 2022-08-01 18:24:33 +00:00
Ken Chen
f6d6b7e7de Merge "Move connectivity_native_test to a sub folder" 2022-07-29 01:55:30 +00:00