Commit graph

111,983 commits

Message SHA1
Merge changes I40b29d98,I6b498579 into main
* changes:
  BpfNetworkStats: use bulk api on 5.10+
  BpfMap.h: on 5.10+ use bulk bpf map api

Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-15 00:53:05 -07:00
80ee0dbbcf
Merge "BpfSyscallWrappers: add helpers for BPF_MAP_LOOKUP{,_AND_DELETE}_BATCH" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-15 00:42:03 -07:00
2445570543
Merge "Allow app-specific network creation with a new permission" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-14 23:04:19 -07:00
6f57c71c68
Allow app-specific network creation with a new permission
If an app registers a network agent and doesn't have NETWORK_FACTORY or
PERMISSION_MAINLINE_NETWORK_STACK, but does have
CREATE_APP_SPECIFIC_NETWORK, ConnectivityService will:
- Allow it to create a network
- Force the capabilities to contain only the app's UID
- Force the network to be restricted
- Ignore attempts to change the UID or make the network non-restricted

Test: TH
Flag: android.net.platform.flags.create_app_specific_network_permission
Bug: 435313135
Change-Id: I5a9517515e64f799c88aca4a51636b1a08e15817

Motomu Utsumi   commited 2025-08-15 12:54:49 +09:00
72d4b516c9
BpfNetworkStats: use bulk api on 5.10+
Most spots autoconverted, but this one needs special love.

Test: TreeHugger
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I40b29d989c5a51082ac8e9ab09b7644eee46d7cb

Maciej Żenczykowski   commited 2025-08-14 20:10:43 -07:00
1ad3d7f43d
BpfSyscallWrappers: add helpers for BPF_MAP_LOOKUP{,_AND_DELETE}_BATCH
Test: TreeHugger
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie7019b7c830c11f0886de990d03f22ec43f30e06

Maciej Żenczykowski   commited 2025-08-14 20:10:43 -07:00
a943e2bdde
BpfMap.h: on 5.10+ use bulk bpf map api
for:
  forAll(f(K))
  forAll(f(K,V))
  consume(f(K,V))

Test: TreeHugger
  ct_m_boot && a_test BpfBitmapTest libnetworkstats_test libbpf_android_test netd_updatable_unit_test bpf_existence_test
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6b4985796db0aa48ad16c153179cfd37682bb1c2

Maciej Żenczykowski   commited 2025-08-14 20:10:43 -07:00
7bfdb000c6
Merge "Mdns: Skip networks with NET_CAPABILITY_LOCAL_NETWORK" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-08-14 18:43:19 -07:00
a1400694b3
Tethering: allow ipv6 1500 mtu again
but still fallback to 1400 if we don't know any better

Bug: 432676104
Test: TreeHugger, mm in p/m/C
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7e1d70e73d2fd24d1f79dc40f3b18a6d82d235ef

Maciej Żenczykowski   commited 2025-08-14 09:37:48 -07:00
39de84ab4c
Merge "Add OffloadCallback interface" into main
Paul Hu   authored and   Android (Google) Code Review   commited 2025-08-14 09:03:46 -07:00
c37f3cf83d
Mdns: Skip networks with NET_CAPABILITY_LOCAL_NETWORK
MdnsSocketProvider expects no overlap between NetworkCallbacks,
Tethering, and Wifi P2P. However, local NetworkAgents can cause
overlap, leading to duplicate sockets. This commit fixes the issue by
skipping networks with NET_CAPABILITY_LOCAL_NETWORK.

Alternatively, the NetworkRequest should addForbiddenCapability
for local networks. However, since this is a module API, it is
not visible to standalone applications.

Flag: EXEMPT bug fix
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.mdns.MdnsSocketProviderTest \
      --update-device
Test: m service-connectivity-mdns-standalone-build-test
Test: atest CtsNetTestCases:android.net.cts.NsdManagerTest \
      CtsNetTestCases:android.net.cts.NsdManagerDownstreamTetheringTest
Bug: 437038495
Change-Id: I78dd7d98ad80147ca26ec6130b6081ef4efb2ecc

Junyu Lai   commited 2025-08-14 20:44:36 +08:00
eb80e8ad9f
Merge "Use imported flag alias for readability" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-14 04:11:21 -07:00
d2b8f3fec2
Merge "Tethering: pass the mtu we announce via RA into updateIpv6UpstreamInterface()" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-14 03:56:49 -07:00
db6b206a16
Use imported flag alias for readability
Import `FLAG_QUEUE_NETWORK_AGENT_EVENTS_IN_SYSTEM_SERVER` and use
its alias in Connectivity Service tests.

Flag: com.android.tethering.mainline.beta.queue_network_agent_events_in_system_server
Fix: 428098184
Test: m
Change-Id: Ic4b5a144c00919defbd7a29048957f028c80bf4a

Junyu Lai   commited 2025-08-14 16:30:32 +08:00
25bd5eaf24
Merge "Use mainline beta flag for NetworkAgent event queueing" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-08-14 01:19:15 -07:00
0c6b14587b
Merge changes I69ad789f,I5954b196 into main
* changes:
  Fix mobile data preferred on multi-user devices.
  Support multi-user SettingsObservers in ConnectivityService

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-14 00:33:06 -07:00
4c516ffd67
Use mainline beta flag for NetworkAgent event queueing
Add `queue_network_agent_events_in_system_server` as a mainline beta
flag. This flag replaces the previous check for
`mQueueNetworkAgentEventsInSystemServer`, allowing the feature to be
controlled and enabled on all Android versions via mainline beta program.

Flag: com.android.tethering.mainline.beta.queue_network_agent_events_in_system_server
Test: atest ConnectivityCoverageTests --update-device \
      --test-filter '.*NetworkAgent.*'
Test: atest ConnectivityCoverageTests --update-device \
      --test-filter '.*Connectivity.*'
Fix: 428098184
Change-Id: I96b0443bd4c55c28d482349738bbdc4798f0c7f9

Junyu Lai   commited 2025-08-14 14:53:06 +08:00
c9890408bf
Tethering: pass the mtu we announce via RA into updateIpv6UpstreamInterface()
Bug: 432676104
Test: TreeHugger, mm in p/m/C
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie6d9d351be178085fa3d07947f1269058e18e376

Maciej Żenczykowski   commited 2025-08-13 23:43:00 -07:00
e92c190c38
Add ethertype constant for Wake-on-LAN
Bug: 408247593
Test: atest NetworkStackTests
Flag: EXEMPT mainline
Change-Id: I5ff868ee66c2941c496db1fdfa02f0322e48d243

Marc Lepage   commited 2025-08-13 14:48:18 -04:00
6498be751c
Merge "Tethering: pass pmtu into updateIpv6UpstreamInterface()" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-13 00:35:13 -07:00
9fdb003b6f
Merge "BpfNetworkStats: introduce poor man's ifindex2name() cache" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-12 23:40:07 -07:00
19f64c9ef7
Merge "Revert "Ignore null or empty interface names in EthernetTracker."" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-12 22:37:39 -07:00
2e367c63f4
Add OffloadCallback interface
This commit adds the OffloadCallback, which is a common interface
to notify the offload service of info updates from MdnsAdvertiser.

Bug: 410734687
Test: atest ConnectivityCoverageTests NsdManagerTest
Flag: EXEMPT legacy refactor
Change-Id: I6bb7fe2b0e4ced4aff9062566d9bcf075893e6fc

Paul Hu   commited 2025-08-13 05:25:42 +00:00
dc188b57d8
Merge changes I7cc9c612,I04e91260 into main
* changes:
  Tethering: pass pmtu into updateAllIpv6Rules()
  Tethering: pass pmtu into Ipv6UpstreamRule()

Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-12 21:18:12 -07:00
8570899fff
Revert "Ignore null or empty interface names in EthernetTracker."
This reverts commit 28961f7464.

Reason for revert: ag/34381937 fixed this one layer up.

Change-Id: I07f0080d137ec59375d001efb6183af108f87dfb

Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-08-12 21:13:10 -07:00
399977a9da
Merge "Tethering: consider route MTUs when calculating IPv6 RA MTU." into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-12 21:07:21 -07:00
d32dafb06f
BpfNetworkStats: introduce poor man's ifindex2name() cache
Uses 16KiB ram, only caches ifindex < 1024, but in practice
that should usually be the case, as these are assigned
in sequential order by the kernel.

Note that in progs/netd.c:86 we have:
  DEFINE_BPF_MAP_NO_NETD(iface_index_name_map, HASH, uint32_t, IfaceValue, 1000)
so stuff doesn't really work right once we go past 1000-ish
tracked interfaces...

(and worst case we're no worse off then we are now...)

Benefit should be significant as all our bpf map stats
dumping logic has to convert from ifindex to ifname
in order to strcmp against the interface we're trying to match,
ie. that's the first thing 3 of the 4 cases we support
do at the very top of their innermost loop.

This effectively eliminates 1 bpf() lookup systemcall, thus
getting us down to 2 (getNextKey + readValue/readValueAndDelete)

Note: the tests work because they're consistent in how they
map ifindex/ifname so they do not require cache clearing.

I believe we don't have to worry about threading, as
we're being called while traversing/consuming maps.
Thus I believe there must be locking external to us.

Also writes should be *super* uncommon, so even if this
were to run multithreaded, races should happen very rarely.
If they did, we'd just write in the same value twice (since
the mapping from ifindex->ifname should rarely if ever change)

Worst case once in a blue moon we'd fail to match an interface
that had *just* shown up (because of reading only half the name),
and we'd lose some stats...

(and since the entire value fits in 16 bytes, and thus in a single
cache line, in practice most cpus will probably write combine
and thus avoid a half write/read anyway, both x86-64 and aarch64
can potentially even do a 16-byte read/write in 1 instruction...
although unclear if that will happen, but worst case should be 2)

Test: TreeHugger, atest libnetworkstats_test
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0d3ea6c5f1f2945adccd479af6c65008bf7d7c51

Maciej Żenczykowski   commited 2025-08-12 20:39:20 -07:00
6bd25b5fd4
Tethering: pass pmtu into updateIpv6UpstreamInterface()
Bug: 432676104
Test: TreeHugger, mm in p/m/C
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie8f12d010798e8066b25334f9a12c333c50331bc

Maciej Żenczykowski   commited 2025-08-12 19:54:50 -07:00
af574432b7
Tethering: pass pmtu into updateAllIpv6Rules()
Bug: 432676104
Test: TreeHugger, mm in p/m/C
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7cc9c612434c269cf2d13462f784d1f7e92d5219

Maciej Żenczykowski   commited 2025-08-12 19:54:50 -07:00
4451a61097
Tethering: pass pmtu into Ipv6UpstreamRule()
Bug: 432676104
Test: TreeHugger, mm in p/m/C
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I04e912604110f7b80ae31468b4f0a8938d127290

Maciej Żenczykowski   commited 2025-08-12 19:54:50 -07:00
897600d37b
Merge "BpfBitmap: some minor optimizations" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-12 19:38:13 -07:00
c0b0105b87
Merge "bpf: Adding AccECN receiver support to TCP connections" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-12 18:44:48 -07:00
c125d064f0
bpf: Adding AccECN receiver support to TCP connections
To support L4S receiver functionality on TCP connections, AccECN
is implemented using eBPF programs. Eth and rawip packets are
handled by separate pairs of ingress and egress programs.
(cherry picked from https://partner-android-review.googlesource.com/q/commit:075c29658a91da2b0e9d36d871bd2403b74a4f69)

Flag: EXEMPT tcpAccECN is not used
Change-Id: Ib0a11880b3f2b1ea04e188fe33366cae9eabe898

k1.reddy   authored and   Maciej Żenczykowski   commited 2025-08-12 18:44:01 -07:00
1191b84fb4
BpfBitmap: some minor optimizations
Test: TreeHugger, atest BpfBitmapTest
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5acf5bcb31777e503e58cef733d617a53006d2b9

Maciej Żenczykowski   commited 2025-08-12 16:02:23 -07:00
d2d26c661a
Optimize BpfMap JNI calls with FastNative/CriticalNative annotations
Convert BpfMap native methods to use @FastNative to reduce JNI overhead.

Refactor synchronizeKernelRCU() to be @CriticalNative for maximum
performance by changing its error handling to return an error code
instead of throwing directly from native code.
(In practice we don't expect it to *ever* fail)

FYI:

@FastNative and @CriticalNative are Android-specific annotations
that signal to the ART runtime to use a lower-overhead JNI transition,
resulting in better performance.

A standard JNI call tells the Garbage Collector (GC) that the thread
is transitioning to a 'Native' state. This is a signal to the GC that
the thread might be busy for a while and shouldn't be suspended arbitrarily.

@FastNative is for short, quick functions:
  This provides a moderately faster JNI call (thread is still 'Runnable').
  The native function signature remains the same as a standard JNI method,
  and it can still access the JNIEnv* to interact with Java objects
  or throw exceptions.

@CriticalNative is for short, quick & trivial functions:
  This provides the fastest possible JNI transition and is intended
  for simple, performance-critical leaf functions.
  It comes with strict requirements:
    - The native method cannot throw exceptions, create Java objects,
      or make any other JNI calls.
    - All arguments and the return type must be primitive, ie:
        jboolean [bool]
        jbyte [s8]
        jchar [u16]
        jshort [s16]
        jint [s32]
        jlong [s64]
        jfloat [32-bit]
        jdouble [64-bit]
        void
      Java objects like String or byte[] are not allowed.
  Because of these restrictions, the native C++ function signature
  must not include JNIEnv* or jobject/jclass parameters.
  (This likely also means it must be 'static')

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9b6107b26086df2e87218ff9274593e9f2eb6b0b

Maciej Żenczykowski   commited 2025-08-12 15:28:05 -07:00
2afef5070a
Tethering: consider route MTUs when calculating IPv6 RA MTU.
The IPv6 Router Advertisement (RA) MTU is now derived from
the minimum of the interface MTU and the MTUs of all IPv6 routes
on the upstream interface, before being clamped to the 1280-1400 range.

This ensures the advertised MTU respects any smaller
MTUs specified by individual routes.

Bug: 432676104
Test: Treehugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If371825bd8f773ae23d1122211caa42ebf5c1f2a

Maciej Żenczykowski   commited 2025-08-12 14:06:05 -07:00
a697b2b8c8
BpfInterfaceMapHelper - flag map use as readonly.
This is the case (by code inspection): this map is read/written
by C++ jni code, but only read from java.

Getting rid of the java read (used in test/dump code only afaict)
would be annoying due to needing to return a java String from jni.

As such lets just flag it as R/O, this will allow write-through
caching in jni.

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iadf0a96f3100d32ea4ffd423b5293c6f2de706cb

Maciej Żenczykowski   commited 2025-08-11 23:44:42 -07:00
52535e446f
KernelUtils: make failure to call & parse uname abort
In practice this is already the case... If uname() execution
fails, or we fail to parse the result, we won't pass the
4.9+ required check in NetBpfLoad, which is required on S+,
and mainline no longer supports anything <S anyway.

We don't require subversion as technically "4.9" (ie. 4.9.0)
is enough for almost all usecases, although in practice I would
expect there will always be an LTS subversion present.

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I66a5eba5c7bcf9bd51997db93c0fefc8104945eb

Maciej Żenczykowski   commited 2025-08-11 21:27:04 -07:00
e9517aedd3
KernelUtils: mark kernelVer const
(this was basically an oversight, nothing should be setting this)

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6e36d9cb7522272e4a725e77b630b43cb6a1494d

Maciej Żenczykowski   commited 2025-08-11 20:58:15 -07:00
168c6c90ab
BpfMap.h: consume() on 5.4+ use 'lookup & delete' kernel api
Reduces consume() from 3 (getNextKey, readValue, deleteValue)
to 2 (getNextKey, readAndDeleteValue) system calls per item.

Test: TreeHugger, atest libnetworkstats_test
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1fee5d85918a5da62b4890dba81f19be4c7a60da

Maciej Żenczykowski   commited 2025-08-11 15:12:52 -07:00
69513313aa
KernelUtils: early init kernel version
(unfortunately need to keep kernelVersion() around for some uses outside of p/m/C)

The goal of this is to make isAtLeastKernelVersion() checks
cheaper.  Currently they all have to check that we've already
parsed uname...

We use that all over the place, even at runtime in BpfMap.h.

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iaf53fc1e36eb9f88df20c39643cbd53f420ded4e

Maciej Żenczykowski   commited 2025-08-11 15:12:52 -07:00
1ede04f16c
BpfMap: readValue() - pass key by reference
clear oversight...

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1455aba2c41e91840afe7bdcc128a709e2ecf7d5

Maciej Żenczykowski   commited 2025-08-11 15:12:52 -07:00
43b0ef8235
BpfNetworkStats: merge forAll(f(K,V)) + clear() -> consume(f(K,V))
(in the future consume() can be changed to use kernel bpf map bulk api)

Test: TreeHugger, atest libnetworkstats_test
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I43c3e7139cf38058da4c187d1cfeec4bf7fb0ca1

Maciej Żenczykowski   commited 2025-08-11 12:45:51 -07:00
85b1b23872
Merge "service-t/jni/com_android_server_net_NetworkStats{Factory,Service}: improve jni" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-11 10:10:56 -07:00
2a7cccfe52
Merge "BpfNetworkStats: optimize bpfGetIfaceStatsInternal() NULL/wildcard iface case" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-11 10:10:44 -07:00
7ff7137c9e
Merge "bpf: iterate() -> forAll() where possible" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-08-11 10:10:20 -07:00
9df6c1fa7b
Merge "BpfMap.h: add consume()" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-11 06:35:18 -07:00
6a2684da25
Merge "Add CDD annotation to APFv6 multi-device tests" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-08-10 18:40:25 -07:00
cee0bf0a8c
Merge "Add CDD annotation to APFv4 multi-device tests" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-08-10 18:40:07 -07:00
e6d8f3c4c5
service-t/jni/com_android_server_net_NetworkStats{Factory,Service}: improve jni
Note that we no longer need the (void*) casts, this is because:
  MAKE_JNI_NATIVE_METHOD() checks function args match
  MAKE_JNI_NATIVE_METHOD_AUTOSIG() autogenerates the signature

Additionally:
  nativeGetTotalStat()
  nativeGetIfaceStat()
  nativeGetUidStat()
should be faster now, by virtue of caching a bunch of calls.

This more-or-less mirrors what was already done in the other file.

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5a715d15ca5c01b625b8b7a62bc0e10bc0cc213f

Maciej Żenczykowski   commited 2025-08-10 10:34:13 -07:00
3e2a811ecf