Commit Graph

24 Commits

Author SHA1 Message Date
Maciej Żenczykowski
32b46a4d36 switch to classic bpf macros
Note: this switches
  com_android_networkstack_tethering_util_setupIcmpFilter
over to relative cbpf which in turn is called from:
  com_android_networkstack_tethering_util_setupNaSocket
  com_android_networkstack_tethering_util_setupNsSocket
and tested by p/m/C's:
  TetheringUtilsTest.java - testIcmpSocketFilters()

Test: TreeHugger, atest TetheringUtilsTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I22a5ea8f8e3b879a37fe4acd84f61020661eaa71
2023-04-19 00:06:15 +00:00
Maciej Żenczykowski
a7e496f067 TetheringUtils jni - clazz type is jclass
See: packages/modules/Connectivity/Tethering/src/com/android/networkstack/tethering/util/TetheringUtils.java

public static native void setupNaSocket(FileDescriptor fd) throws SocketException;
public static native void setupNsSocket(FileDescriptor fd) throws SocketException;
public static native void setupRaSocket(FileDescriptor fd, int ifIndex) throws SocketException;

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If406a4e507da916f5691d0ae4bded14dd168bc72
2023-03-27 22:41:09 +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
1686030e6c Improve accept/reject comment readability.
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If4cad0b83d2e62bfbbc0f65e9ffeefc69381c371
2022-09-15 18:46:10 +00:00
Patrick Rohr
a881ba3001 Move BpfUtils -- integrate TcUtils into Tethering module
Bug: 202086915
Bug: 157552970
Test: atest TetheringTests
Change-Id: Ibf9d8d568b9f890a22869e70384848e33a380d4f
2022-01-13 10:09:11 +01:00
Maciej Żenczykowski
23ff703f7a better compatibility for unusual Qualcomm/Mediatek cellular ARPHRD_* values
see kernel/private/wembley/+/refs/heads/tm-4.19/include/uapi/linux/if_arp.h
which has #define ARPHRD_PUREIP 520 (and is a Mediatek based device)

or Qualcomm based Pixel 3 and older kernels (<=4.9) which #define ARPHRD_RAWIP 530
(unlike Pixel 4/5 which are 4.14/4.19 and use the upstream ARPHRD_RAWIP of 519)

We stop supporting 520/530 starting with 5.11+ since those as GKI 2.0 only kernels
cannot be using non-upstream-ed constants (btw. this is probably true for 5.10-S
as well, but let's play it safe).  For pre-5.11 we're lucky because even now
(with 5.15 released) upstream has yet to define an ARPHRD_* for either one of
520 or 530, so there's no harm in 'squatting' on this unused space.

This approach also means there's absolutely no change in behaviour on
pre-launch-T devices, since they all are at most running 5.10 kernels.

We'll be able to get rid of this code in the far future once we stop shipping
mainline tethering updates to pre-5.10 Mediatek or pre-4.14 Qualcomm devices.
This will likely be many years.

Test: TreeHugger
Bug: 207057951
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I767b5fc56bc826e088507aea8ae7a30aa8aa424a
2021-11-25 11:03:58 +00:00
Maciej Żenczykowski
c8c36b9407 isEthernet() - ARPHRD_PPP does not require ethernet headers
(this is required to make ipv6 tethering work with at least S.LSI modems)

Test: TreeHugger
Bug: 207057951
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic178db928ec7f74f69d7d4739b3b8439ff026625
2021-11-18 23:31:56 -08:00
markchien
d02f9af918 Rename tethering util folder and its package name
Move tethering util files from android.net.util into
com.android.networkstack.tethering.util. The goal is move all of
tethering internal files into its own namespace
com.android.networkstack.tethering.util.

Bug: 205088391
Test: atest TetheringTests
      atest CtsTetheringTest
      atest TetheringPrivilegedTests

Change-Id: I6559fb4f873b3cad5b210b10e49df1b6c6914a70
2021-11-09 17:02:47 +08:00
Tyler Wear
e8043ca762 bpfmap: Move to Common Location
Move bpfmap to frameworks/libs/net/common/native.

Bug: 179733303
Change-Id: Id08b216ec6a64968d66d7990f91ea7ce222a1154
2021-10-29 09:05:33 -07:00
Hungming Chen
1257e9bfff Throw an errno exception when open BPF map failed
Needed because an invalid file descriptor should notify the caller to
stop using the object.

Bug: 190523685

Test: atest BpfMaptest
Change-Id: I70fb08b54b1c0caa4be4e3f07b59bf4f2397f39d
2021-08-03 08:38:16 +00:00
markchien
083606292b Replace throwErrnoException with JNIHelp jniThrowException
Rather than adding throwErrnoException local function, using standard
jniThrowException in JNIHelp.h.

Also improve the readability:
1. Use throwIOException for
    jniThrowExceptionFmt(env, "java/io/IOException", ...);
2. Use throwSoecktException for
    jniThrowExceptionFmt(env, "java/net/SocketException", ...);
then the code can fit to one line.

Test: atest TetheringPrivilegedTests (ErrnoException is
test in BpfMapTest)
Change-Id: I396771e2c68e319f510d7a4ea5f263d18d7fad9d
2021-07-20 10:15:01 +00:00
Ye Jiao
86f56a135a Fix memory access violation in NetworkStack
Fix memory access violation in com_android_networkstack_tethering_BpfUtils.cpp
caused by invalid format string in com_android_networkstack_tethering_BpfUtils_isEthernet.
If rv is not valid, jniThrowException will format a string using
"Unknown hardware address type %s on interface %s". However, rv is an int but here
"%s" is used in fmt string, thus causing access violation of memory.

Use "%d" instead of "%s" for int.

Bug: 188757793
Change-Id: I9d8ec0708efd747e24b3b3ffed5336434d4f64a7
2021-05-24 06:12:56 +00:00
Hungming Chen
3c94994650 Fix attaching program failure on kernel 5.10
Attach BPF program may be failed with the netlink error message
"Invalid argument". Per debug kernel trace, it is failed in
comparing the kind name in tc_new_tfilter.

Log:
05-05 19:44:42.329  1073  2332  2332 W tc_new_tfilter:
Specified filter kind does not match existing one

Test: enable usb tethering and check the follows

$ adb shell tc filter show dev <upstream, downstream> ingress
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream6_ether:[*fsobj]
direct-action not_in_hw id 3 tag 94ca9b12972fdea8
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream4_ether:[*fsobj]
direct-action not_in_hw id 9 tag 992aa9bfd0503457
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream6_rawip:[*fsobj]
direct-action not_in_hw id 4 tag 7fb60e556b8f3be7
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream4_rawip:[*fsobj]
direct-action not_in_hw id 6 tag e41426095404fb64

Change-Id: I471a2e34c626a3737cbd2754e4d1b3000bcf6ba6
2021-05-06 02:52:07 +00:00
Hungming Chen
3dbd4a1cc4 [NFCT.TETHER.15] Attach BPF program in the mainline module
Migrate Maze's BPF program attaching and detaching functions from
system/netd/server/OffloadUtils.{c, h} to tethering module.

Test: atest TetheringCoverageTests
Test case #1:
Enable WiFi hotspot and check tc filters are added or removed on both
wlan1 and rmnet_data#.

$ adb shell tc filter show dev wlan1 ingress
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream6_ether:[*fsobj] direct-action
not_in_hw id 2 tag 7cf020cc09a7c982
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream4_ether:[*fsobj] direct-action
not_in_hw id 7 tag 2f87d55b636c082c

$ adb shell tc filter show dev rmnet_data2 ingress;
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream6_rawip:[*fsobj] direct-action
not_in_hw id 3 tag 8b3885b75bd261de
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream4_rawip:[*fsobj] direct-action
not_in_hw id 6 tag b1c9478c91f8df9a

Test case #2:
Enable USB tethering and check tc filters are added or removed on both
rndis0 and rmnet_data#.

Test case #3:
Enable WiFi and USB tethering and check tc filter are added or removed
on rndis0, wlan1 and rmnet_data#.

Change-Id: I3f9a65043271bc8f5bf1b82ae505c471625ca9de
2021-03-11 17:49:42 +08:00
Lorenzo Colitti
4e92da06fa Dump counters in "dumpsys tethering bpf".
This CL adds the counters collected by the tethering programs to
the output of "dumpsys tethering bpf". The counter names are
fetched by JNI code at startup and then read by the debugging
code on demand.

Example from my device:

  Forwarding errors:
    TCP_CONTROL_PACKET: 67
    NON_GLOBAL_SRC: 13
    NON_GLOBAL_DST: 17
    LOCAL_SRC_DST: 7

Test: manual (debug-only code)
Change-Id: I7ec7992612556a4bca5f1b6bb52c655d6d870201
2021-02-10 04:43:03 +00:00
Hungming Chen
400702b6bb Use header module bpf_syscall_wrappers
Use the versioned header library instead of just including
the header files.

Test: atest BpfMapTest
Change-Id: Icf23dcdc051a4ead6a7c6e925159cdc27f49eac2
2021-01-13 14:31:28 +08:00
markchien
7052688dde Provide a easy way to access bpf maps from java
A wrapper for bpf map opening, reading/writing, and iteration.

Bug: 173167302
Test: atest BpfMapTest

Change-Id: I792b41978b322c9e4969cd7b6c35d6978ab86bc4
2021-01-11 17:43:27 +08:00
Orion Hodson
e5bd0dba21 Use libnetjniutils for JNI File Descriptor info
Drops use of deprecated API in libnativehelper and uses a common
helper that will be stable across releases.

Bug: 158749603
Test: m
Change-Id: Ic1a1811ffb9a1c207f562a180417e99df31e3502
2020-12-11 22:48:10 +00:00
Tyler Wear
90e4063fd2 tethering: DAD Proxy Daemon
DAD proxy daemon responsible for forwarding NS/NA between
tethered iface and upstream iface.

Change-Id: I2e58e10e7fa7dba6a6f63ad03b000549f3afc37e
2020-09-22 11:58:49 -07:00
Orion Hodson
0cdccd707f Sync with libnativehelper refactoring
jniGetFDFromFileDescriptor() is now a legacy method and moved to a
separate header.

Bug: 151443957
Bug: 158749603
Test: m
Change-Id: Icd06e9a315680c2251dbb9032a904dd6d66aa359
Merged-In: Icd06e9a315680c2251dbb9032a904dd6d66aa359
Exempt-From-Owner-Approval: cherry pick
(cherry picked from commit a5c4682505)
2020-06-24 14:13:13 +01:00
markchien
547e168540 Move offload config hidl usage from native to java
TetheringUtil JNI is too big that it statically linking hidl and its
dependency library. To remove these static libraries, calling hidl in java
directly instead of using JNI.

Bug: 148984662
Test: -build, flash, boot
      -manually ON/OFF tethering

Change-Id: Id5a9759eb453fddaf0c3b7a31da17224e35e963e
2020-02-10 15:25:19 +08:00
markchien
f87ebdcbb4 Change tetheroffloadjni to tetheringutilsjni
Rename tetheroffloadjni to tetheringutilsjni and move setupRaSocket
jni method from NetUtils into tetheringutilsjni.

Bug: 143195885
Test: -build, flash, boot
      -atest TetheringTests
      -Off/On hotspot with ipv6 upstream

Change-Id: Ib68eb6999bbe2d3ca97e68712f22b105311ef800
2020-01-07 07:42:13 +00:00
markchien
ee6ad37837 [Tether07] Migrate Tethering into module
Now tethering would be run in dedicated service.
TetheringManager is the interface used to communicate with
TetheringService. The new call flow would be: ConnectivityManager
-> ConnectivityService -> TetheringManager -> TetheringService.
Note: the return value of #tether(), #untether() and #setUsbTethering()
APIs would always be no error. Client can use #getLastTetherError()
or #getTetheredIfaces or listen tether state change to check
status of corresponding interface.

Bug: 136040414
Bug: 144742179
Test: -build, flash, boot
      -atest TetheringTests
      -atest FrameworksNetTests

Change-Id: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
Merged-In: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
2019-11-30 10:03:08 +00:00
markchien
6aa388904e [Tether06] Migrate tether offload controller into module
The tether offload JNI library in this patch still have many dependencies
with internal libraries. Will have follow up changes to cut the
dependencies to let it be a unbundled library.

Bug: 136040414
Test: -build, flash, boot
      -atest TetheringTests
      -atest FrameworksNetTests

Change-Id: Iacf8e0b94135e35672de3ee77c474ee39a00c591
2019-11-05 12:49:50 +09:00