Commit Graph

29 Commits

Author SHA1 Message Date
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
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
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
Ken Chen
c52cbe0cf8 Add libconnectivity_native_test_utils
The utility currently contains a firewall class that is used by DNS
resolver tests to block DNS packets.

Bug: 227159929
Test: atest resolv_integration_test
Change-Id: I5c5bc0b263a677f57cd63f002057ff0812f15e64
2022-07-29 03:53:24 +08:00
Ken Chen
ef50ab1473 Move connectivity_native_test to a sub folder
Move sources of connectivity_native_test to a dedicated folder so that
other native tests or utilities can be added to p/m/c/tests/native/ as
well.

Bug: 227159929
Test: atest connectivity_native_test
Change-Id: I97217fbb03b26ed79f1f34932b92c4227a1ece4d
2022-07-28 14:41:23 +08:00
Ken Chen
74ff3ee501 Rename dscp_policy.o to dscpPolicy.o
Underscore character may cause bpf prog/map naming collision. For
example, x.o with map y_z and x_y.o with map z both result in x_y_z
prog/map name, which should be prevented during compile-time.

aosp/2147825 will prohibit underscore character in bpf source name
(source name derives the obj name). Existing bpf modules with underscore
characters in source name need to be updated accordingly.

Bug: 236706995
Test: atest bpf_existence_test
Test: adb root; adb shell ls -l sys/fs/bpf/net_shared | grep dscpPolicy
Change-Id: Ibe98944d09d42bd11b78b5e9ae35ded48c70416d
2022-07-21 21:00:09 +08: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
200d372dc9 move XtBpfProgLocations.h into a new header library
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia5e3c72e65cee17ef67907008d8fe6d4e47050de
2022-06-15 03:17:40 -07:00
Maciej Żenczykowski
b909d8af55 bpf_progs - eliminate netd.c dependency on UidConstants.h
Per Lorenzo's request on:
  https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2123888

Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id464fc2418efcb3764fae2a25c11fdda4439f411
2022-06-15 00:59:20 -07:00
Maciej Żenczykowski
1205737641 assert that xt_bpf programs match Android T netd's expectations
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic0029063e4dbbf1b2cce7d7ca86a017a1c56f072
2022-06-14 20:33:54 -07:00
Maciej Żenczykowski
5f5d2e2c10 remove no longer needed bpf_connectivity headers visibility
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3829ba49e453918bfcbae2e07dd2aea2b81e12bf
2022-06-14 06:03:15 +00:00
Maciej Żenczykowski
6d116d0f38 move netd maps and progs into /sys/fs/bpf/netd_shared/...
(out of current /sys/fs/bpf/net_shared/...)

This will allow genfscon regexp changes in a followup selinux commit.

Note that this has a hard dependency on system/bpf change
  'bpfloader: add support for netd_shared and net_private subdirs'
which also bumps bpfloader to v0.13.

This was merged May 12, 2022 (into both aosp/master and tm-dev)
and it is in Android T starting with Beta 3 release.

This isn't really an issue since amusingly T Beta 2 is already
incompatible with current mainline releases due to the snap
reverting a previous required bpfloader system/bpf change:
  move net_shared bpf programs into net_shared subdirectory
See: http://b/232050459#comment14

So this doesn't break T Beta1/2, since they already don't work,
and Beta3 will work.

Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id5f14d6e3f11cfe35d9d8a9496548a2bc4d022ec
2022-05-16 23:24:37 +00:00
Maciej Żenczykowski
9b2faeb81e enable btf = true for block/clatd/dscp_policy/netd bpf programs
(we avoid offload - for now - due to that being shipped to <T devices)

Before:
  $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o
  -rw-r--r-- 1 system system  2848 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o
  -rw-r--r-- 1 system system 10240 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o
  -rw-r--r-- 1 system system 16144 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o
  -rw-r--r-- 1 system system 18840 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o

After:
  $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o
  -rw-r--r-- 1 system system  6192 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o
  -rw-r--r-- 1 system system 19008 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o
  -rw-r--r-- 1 system system 23960 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o
  -rw-r--r-- 1 system system 27112 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o

So there is a minor increase in .o size, but this allows:

$ adbz shell cat /sys/fs/bpf/net_shared/map_netd_iface_index_name_map
  # WARNING!! The output is for debug purpose only
  # WARNING!! The output format will change
  8: {['e','r','s','p','a','n','0',],}
  1: {['l','o',],}
  4: {['i','f','b','1',],}
  2: {['d','u','m','m','y','0',],}
  16: {['e','t','h','1',],}
  5: {['t','u','n','l','0',],}
  14: {['h','w','s','i','m','0',],}
  17: {['w','l','a','n','0',],}
  12: {['i','p','6','t','n','l','0',],}
  18: {['w','l','a','n','1',],}
  13: {['i','p','6','g','r','e','0',],}
  3: {['i','f','b','0',],}
  15: {['b','u','r','i','e','d','_','e','t','h','0',],}
  9: {['i','p','_','v','t','i','0',],}
  11: {['s','i','t','0',],}
  10: {['i','p','6','_','v','t','i','0',],}
  6: {['g','r','e','0',],}
  7: {['g','r','e','t','a','p','0',],}

This is safe as the net_shared bpf programs are not loaded on pre-T devices,
and the T bpfloader is btf enabled.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2d480391b6d1a6e2ba99b0445281684d4a51d74b
2022-05-03 09:51:23 +00:00
Maciej Żenczykowski
d72a5a7a70 remove _mainline suffix from {clatd,netd}.o_mainline targets
this hack is no longer needed now that duplicate target in system/netd
is no longer an issue due to automerger to sc-mainline-prod being
turned off

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id2c1dfac3bc4e6a8f5376a41ca2d1432b838da38
2022-05-02 14:49:13 -07:00
Tyler Wear
b37f551287 Vendor AIDL interface for port blocking via eBPF
New Connectivity Service exposed to vendor for
restricting certain ports for use only in vendor.

Bug: 179733303

Change-Id: Iad9aff6924498ede5a08cfa5482082f094c0a90b
2022-03-25 09:14:48 -07:00
Ken Chen
1647f60d66 [NETD-BPF#19] Mainline part of bpf code from netd
1. Add libnetd_updatable.so in com.android.tethering. The library is
loaded by netd. Currently, it mainly targets on a few functions which
access BPF maps. The functionality may extend in the future.

2. Attach gcroup progs from libnetd_updatable.so.

3. Move (privileged)TagSocket and untagSocket implementation to mainline
module. Combine privilegedTagSocket and untagSocket into a single
function.

4. Split related unit tests from netd_unit_test to
libnetd_updatable_unit_test as well.

Bug: 202086915
Test: cd system/netd; atest
Test: atest TrafficStatsTest NetworkUsageStatsTest

Change-Id: Ib556458103a4cbb643c1342d9b689ac692160de0
2022-01-30 09:51:25 +08:00
Tyler Wear
723882126a Process DSCP QoS events for policies
New events to handle adding and removing of DSCP QoS policies.
Async indication sends status back to client if the policy
has been added, failed, or if the policy limit has been
reached.

Bug: 202871011
Change-Id: I7988d22ae625ad0dd415927d2943de4a749e6fb8
2022-01-27 10:19:27 +00:00
Maciej Żenczykowski
e1f8ad4d59 Merge changes from topic "libnetworkstats"
* changes:
  Rename libnetdbpf to libnetworkstats
  Copy libnetdbpf from system/net to tethering module
2022-01-25 23:52:06 +00:00
Maciej Żenczykowski
f807ec7da7 Merge changes from topic "configure_bpf_for_clat"
* changes:
  [CLATJ#20] ClatdCoordinator: stop bpf for clat
  [CLATJ#19] ClatdCoordinator: configure bpf for clat
  [CLATJ#18] libclat: move clat tc and bpf utilis from netd
  [CLATJ#17] bpf_connectivity_headers visible to libclat
2022-01-24 19:14:35 +00:00
Ken Chen
f426b2b287 Rename libnetdbpf to libnetworkstats
Two reason for renaming:
1. Avoid module name collision in sc-mainline-prod branch.
2. The libnetdbpf was misnamed before.

Bug: 202086915
Test: atest libnetworkstats_test FrameworksNetTests
      ConnectivityCoverageTests FrameworksNetSmokeTests
      CtsAppOpsTestCases
Change-Id: I87fcf4b1a9d58780a45743a9aa91b9b936e54266
2022-01-24 11:53:59 +08:00
Hungming Chen
99b9ae3787 [CLATJ#17] bpf_connectivity_headers visible to libclat
Needed because ClatdController and clatd binary are moved
into apex. libclat is used for accessing BPF map.

Bug: 212345928
Test: build
Change-Id: I1be5d4c9cc2c9865ac99f2595443e54e7334c843
2022-01-22 20:06:55 +08:00
Wayne Ma
a9716ffcb8 [NETD-TC#11] Make TrafficController as libtraffic_controller into
Tethering module.

Delete tagSocket(), privilegedTagSocket() and untagSocket() since
they are moved out of TrafficController in aosp/1849156.

Bug: 202086915
Test: m; flash; boot;
Change-Id: Ifeaeb060fbf1add9f06748e7846b9e11e0345bda
2022-01-22 12:33:49 +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
Ken Chen
587d4231fc Move netd.c to Tethering module
This is a clean move. The content of netd.c is not changed. The object
name is still netd.o. But the module name is renamed to netd.o_mainline
to avoid name collision in sc-mainline-prod branch.

Modified Android.bp according to the file location. The sub_dir is
newly specified. The object file will be compiled to:
- apex/com.android.tethering/etc/bpf/net_shared/netd.o

The extracted programs and maps will be in:
- sys/fs/bpf/net_shared/

The netd.o will not be loaded in pre-T because the bpfloader before T
does not load objects from paths other than:
- apex/com.android.tethering/etc/bpf/
- /system/etc/bpf/

Bug: 202086915
Test: cd system/netd; atest
Test: atest TrafficStatsTest NetworkUsageStatsTest
Change-Id: I5281c851341f9258a37d8aad6da4196c06342940
2022-01-21 07:40:33 +08:00
Maciej Żenczykowski
4d491bb86e bpf_connectivity_headers -> bpf_headers -> bpf_syscall_wrappers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5db6285add895edf9354e98d9dffc8343ee4b259
2021-12-28 17:58:20 -08:00
Ken Chen
335c0d4249 [NETD-BPF#4] Move bpf_shared.h from netd to module
The header file is referenced by the part going to be mainlined in Netd.
Note that some platform visibility is required with this commit, since
users of bpf_shared.h is currently located in platform. The visibility
can be removed when all users are moved out of platform.

Bug: 202086915
Test: m; flash; boot
Test: cd system/netd && atest
Test: cd packages/modules/Connectivity && atest
Test: atest FrameworksNetTests
Change-Id: I5c16511b6a2d4eb80dfd93157cbc98d5030bd5ac
2021-11-23 11:53:46 +08: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