Commit Graph

31 Commits

Author SHA1 Message Date
KH Shi
3f738fcd3d Pass upstream prefixes to bpf tethering offload
BPF needs upstream prefixes information to filter spoofing IPv6 source
addresses carried in downstream traffic.

We retrieve prefixes from upstream interface's LinkProperties and pass
it to the BpfCoordinator. Forwarding rules will also be updated when
upstream interface's IPv6 link addresses change.

Test: atest TetheringTests
Bug: 261923493
Change-Id: If8cfc3b191e520ca838654d1b5211ab9e9ec021d
2023-10-26 13:13:38 +00:00
Maciej Żenczykowski
e1a615ad83 type safety for 'bool downstream'
funky naming 'stream.down', because downstream.downstream is just too long...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id234654fa8960e7430fc33119f36fd94b858d242
2023-10-10 03:37:14 -07:00
Maciej Żenczykowski
8a6c6d50c0 type safety for 'bool updatetime'
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I99d51524ba913c46bad64b89778c01164639c85e
2023-10-10 03:37:14 -07:00
Maciej Żenczykowski
8d3bde7949 type safety for is_ethernet
(reversing logic, as 'rawip.rawip' is much shorter then 'ethernet.ethernet')

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib48cc2b889e8b587e14edbe89606f887a884af87
2023-10-08 20:16:59 -07:00
Maciej Żenczykowski
901c71051e bpf_progs: use macros for kernel version
Generated via:
  for f in bpf_progs/{block,dscpPolicy,netd,offload,test}.c; do
    sed -i -r 's@KVER[(]([45]), ([0-9]+), 0[)]@KVER_\1_\2@g' "${f}"
  done

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8f211e47bf259fc75aa1caaaf82f41c1929ceab2
2023-10-06 15:54:39 -07:00
Maciej Żenczykowski
3a64568abb type safety for kernel version
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If05c0c5383dceeb65964143f5574d2ee1a484907
2023-10-06 15:54:38 -07:00
KH Shi
c8fb1a2530 bpf tethering offload - add src subnet to upstream ipv6 direction
This patch is based on aosp/2535559 from maze@.

Add source prefix into the upstream key such that only packets which
source IPv6 address matches it will be forwarded to the upstream
interface.

In this patch, the source prefix is set to zero so there is no
behavior changes. Next CL in patch series will use the real source
prefixes retrieved from upstream interface.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I43d068a29b937c7dfeb6fab632a8effb47ee2263
2023-08-10 16:01:21 +08:00
Maciej Żenczykowski
de1342a033 bpf_progs: disable BTF on <=U && user builds
This is to cut down bpfloader boot time.
Potential savings might be on the order of 30+% (300ms).

Loading BTF requires fork-execing the btfloader,
and currently BTF is only used to facilitate debugging.

Bug: 286369326
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifa5f0052135b9dc826b18ca4622784615ed9c3c8
2023-06-09 05:58:57 +00:00
Maciej Żenczykowski
7a03c187f5 remove inprocess tethering
It is just a constant source of bugs, with no real tests,
let's stop pretending this is a supported configuration.

The only tested configuration is out-of-process tethering
updatable apex.

Test: TreeHugger
Bug: 279942846
Change-Id: I4b659a3cd32b89a65549b56006b926a5ac755f7b
2023-04-28 20:11:14 +00:00
Maciej Żenczykowski
58c6337906 sed -i -r 's@/[*] updatetime [*]/ false@NO_UPDATETIME@g' offload.c
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I69947ef2bfc330d38c56b64e9d43dbea1b78cf69
2023-04-20 04:05:06 +00:00
Maciej Żenczykowski
653bb006b7 sed -i -r 's@/[*] updatetime [*]/ true@UPDATETIME@g' offload.c
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie62454bee2c7c0a23cc6827ee626640281527f19
2023-04-20 04:04:58 +00:00
Maciej Żenczykowski
66f52f4ea7 sed -i -r 's@/[*] is_ethernet [*]/ false@RAWIP@g' offload.c
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id488301a50e28e2636936340c78bf8ac5ed2f34e
2023-04-20 04:04:04 +00:00
Maciej Żenczykowski
63fadd1c67 sed -i -r 's@/[*] is_ethernet [*]/ true@ETHER@g' offload.c
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib3967f1768820e92011eee78f589cc54ee3677fc
2023-04-20 04:03:55 +00:00
Maciej Żenczykowski
cad569fef5 sed -i -r 's@/[*] downstream [*]/ true@DOWNSTREAM@g' offload.c
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia1eeca7e8cda672562f3da5b28b52cc25cae2f2a
2023-04-20 04:03:48 +00:00
Maciej Żenczykowski
941ea039db sed -i -r 's@/[*] downstream [*]/ false@UPSTREAM@g' offload.c
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ieaf2cb8d93b4b62fba1be9893ed7e2510b5ed4b7
2023-04-20 04:03:41 +00:00
Maciej Żenczykowski
2541a1924e offload.c - feed kver in to bpf progs
Bug: 263884894
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1ad6df9e4cf4e39b4fe785ca9d8ff0eaa31d33c5
2023-04-19 20:51:18 +00:00
Maciej Żenczykowski
bab0c1ad95 offload.c - adjust bytes for l2 header
Bug: 263884894
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5c7bca4e005302a91368d22b9683db5b16d73b3a
2023-04-04 06:18:28 +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
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
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
869c4ad452 Merge "update CRITICAL annotations for mainline" 2022-08-08 17:40:52 +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
ccce4a3382 offload/test bpf: support InProcessTethering
InProcessTethering runs as system_server (uid/gid AID_SYSTEM)
instead of as the network_stack (uid/gid AID_NETWORK_STACK).

Additionally only the network_stack has access to the default
selinux context of /sys/fs/bpf/tethering, which is fs_bpf_tethering,
so we need to use 'fs_bpf_net_shared' instead.

Bug: 190523685
Bug: 236925089
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibb6ae255dcd8a8e8049be112055f60c3b2cf7df0
2022-07-18 09:05:32 -07:00
Maciej Żenczykowski
07d3013b0d enable btf for offload.o & test.o
The objdump -x visible changes between old and new versions of the
mainline shipped .o files are really very minimal: just the inclusion
of a new .BTF section and changes/removals of some 'l' entries from
the symbol table.  However, it turns out a change to symbol ordering
is incompatible with BpfLoader <v0.10 which doesn't know to skip
non-function symbols, and as such enabling btf requires a little
bit of gymnastics.

After:
  $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/*.o
  -rw-r--r-- 1 system system 118352 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload.o
  -rw-r--r-- 1 system system 123424 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload@btf.o
  -rw-r--r-- 1 system system   2232 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test.o
  -rw-r--r-- 1 system system   6376 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test@btf.o

$ adbz shell logcat -d | egrep offload.*[.]o
07-15 13:10:43.358     0     0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload.o with license Apache 2.0
07-15 13:10:43.359     0     0 I LibBpfLoader: BpfLoader version 0x00019 ignoring ELF object /apex/com.android.tethering/etc/bpf/offload.o with max ver 0x00019
07-15 13:10:43.359     0     0 I bpfloader: Loaded object: /apex/com.android.tethering/etc/bpf/offload.o
07-15 13:10:43.374     0     0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with license Apache 2.0
07-15 13:10:43.375     0     0 I LibBpfLoader: BpfLoader version 0x00019 processing ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with ver [0x00019,0x10000)
07-15 13:10:43.452     0     0 D LibBpfLoader: map_fd found at 0 is 6 in /apex/com.android.tethering/etc/bpf/offload@btf.o
...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id658818d1d42763358747523615b7918d312588e
2022-07-16 05:35:15 +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
f72c8aa5c3 funky workaround to make things load on 4.14 bpf verifier
Mostly this is cut-and-paste of bottom half of do_forward4
function into a seperate function to force the compiler to
emit two differently optimized versions of the code based on
whether is_tcp is true or false.

Bug: 230359047
Test: TreeHugger, manually on flame
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9e3e195ba601daaac2e0c9a70fad170a8fb4d921
2022-05-05 09:46:33 +00: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
Ken Chen
bb57fa9eec [NETD-BPF#3] Relocate Tethering/bpf_progs and rename bpf_tethering_headers
The folder is currently used by tether offload only. Because we will
move netd.c and clatd.c to it, the folder should be moved to the upper
tier.

Also, rename bpf_tethering_headers to bpf_connectivity_headers so that
other connectivity code besides to tethering are justified to use it.

Bug: 202086915
Test: atest FrameworksNetTests
Change-Id: I95943c6e909f1fdca12604ef0c55d67c39ca686b
2021-11-20 18:31:08 +08:00