Commit graph android_packages_modules_Co.../staticlibs/device
Message SHA1
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
Merge "Move #nativeWaitForService into CommonConnectivityJni" into main
Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-08-06 11:12:41 -07:00
2e342c6d9b
Move #nativeWaitForService into CommonConnectivityJni
AServiceManager_waitForService sytem APIs currently only callable
via dlsym(): b/376759605. When built with sdk_version current,
the NDK stubs for "sdk" variants only include NDK APIs,
excluding #systemapi APIs.

Flag: EXEMPT Mechanical refactors
Test: atest ServiceManagerWrapperIntegrationTest
Change-Id: I48f690d771c7905e79e463617ded772f753cc854

Mark Chien   authored and   Patrick Rohr   commited 2025-08-06 10:44:39 -07:00
f250ade6fa
Merge "Make callers of RoutingCoordinatorService pass in RouteInfoParcel" into main
Sarup Dalwani   authored and   Android (Google) Code Review   commited 2025-08-06 07:45:24 -07:00
a4f34a8836
Make callers of RoutingCoordinatorService pass in RouteInfoParcel
RoutingCoordinatorService's {add,remove,update}Route methods
all end up calling netd's *RouteParcel methods.

Make callers explicitly generate and pass in the parcel to the
manager class instead of having them pass in a RouteInfo and
having the service class convert the RouteInfo to a parcel.

Also remove the {add,remove,update}Route methods from
RoutingCoordinatorManager since they are unused.

This is a no-op refactor that simplifies upcoming changes.

RoutingCoordinator is not a stable interface and is not used
across the platform/mainline boundary, so there are no version
skew considerations.

Bug: 394308861
Test: atest ConnectivityCoverageTests
Flag: EXEMPT no-op refactor
Change-Id: Iedf4c9bc28c3fc8c289db421857acddc8c694990

Lorenzo Colitti   commited 2025-08-06 15:57:36 +09:00
8f8e59abf7
Merge "Make Dhcp6AddrRegInformPacket constructor public" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-05 12:46:34 -07:00
24c7ddf8c8
Make Dhcp6AddrRegInformPacket constructor public
Test: TH
Flag: EXEMPT mainline
Change-Id: I20455f9fab089c85de44e5f815c1c5df6f6c0f21

Patrick Rohr   commited 2025-08-05 10:39:23 -07:00
97891a2cfe
Merge "make Struct expose a new parse method that takes a raw byte array" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-01 19:59:09 -07:00
eb7d854d5f
Merge "Fix missing '/' for retrieving interface MTU from ProcfsUtils" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-07-30 02:07:08 -07:00
9bbdbc56b4
Merge changes I74c24016,I3b2b533e into main
* changes:
  NetBpfLoad: remove foo@1.o support
  Tweak: Throw exception for oversized BpfMap keys/values

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-07-30 00:09:14 -07:00
2b9447dcf6
Tweak: Throw exception for oversized BpfMap keys/values
Throw an IllegalArgumentException if the key or value sizes exceed the
limits supported by the BpfMap implementation. This prevents potential
file descriptor cache collisions and makes errors explicit.

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

Maciej Żenczykowski   commited 2025-07-29 19:52:55 -07:00
2a2ee0af44
make Struct expose a new parse method that takes a raw byte array
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifdfc93e0c35df58a983beb30da546db7a0876398

Maciej Żenczykowski   commited 2025-07-29 13:54:39 -07:00
724b2d27d4
Merge "Introduce LegacyStruct to expose writeToBytes(ByteOrder)" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-07-29 13:14:53 -07:00
bd78be51a5
Fix missing '/' for retrieving interface MTU from ProcfsUtils
The `SYS_CLASS_NET_PATH` constant lacked a trailing slash, which
hindered the correct construction of paths for interface-specific
files (e.g., `/sys/class/net/<interface>/mtu`).

This change adds the missing trailing slash, enabling `ProcfsUtils`
to correctly retrieve interface MTU values and other interface-specific
details from `/sys/class/net`.

Flag: EXEMPT mainline
Bug: 429012888
Test: TH
Change-Id: Ib562061d7aa29ed3a7786cca91d79068d4101766

Jimi Chen   commited 2025-07-29 15:26:44 +00:00
b22b23e2ad
Merge "Addressing feedback on IpStructure" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-07-28 18:39:49 -07:00
a383882f7c
Introduce LegacyStruct to expose writeToBytes(ByteOrder)
The ByteOrder should be encoded by the field, not by the writeToBytes()
method. To fix this, a LegacyStruct is introduced which continues to
expose writeToBytes(ByteOrder) during the transition. This approach
helpfully creates a compile error when converting a Struct class back to
inheriting from Struct for all call sites of writeToBytes(ByteOrder).

Test: TH
Flag: EXEMPT mainline
Change-Id: I3b28c53ce3e884e59760744838b3518596de5c75

Patrick Rohr   commited 2025-07-28 15:58:48 -07:00
62d51d1bcd
Merge "Create CommonConnectivityJni to share between modules" into main
Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-07-24 09:56:39 -07:00
0e5defc1e9
Create CommonConnectivityJni to share between modules
Flag: EXEMPT mainline
Test: TH
Change-Id: Ia85dfd3d979803baca9e971d1083f54dff46de53

Jimi Chen   commited 2025-07-23 05:47:12 +00:00
e5a4e6b0ba
Use Log.e for procfs file read errors
Log.wtf implies a catastrophic, unrecoverable failure. Failures to read
procfs files (e.g., due to permissions or non-existence) are better
represented by Log.e as they are often recoverable or expected under
certain conditions, and not always indicative of a fatal application state.

Flag: EXEMPT mainline
Bug: 429012888
Test: TH
Change-Id: I717d46d4c3802ac478e80d2a9dd28c79a9ebc5f7

Jimi Chen   commited 2025-07-18 06:11:15 +00:00
83298a7b5d
Ignore RtNetlinkMessage with null or empty interface names
This patch checks if interface name is null or empty for
RtNetlinkMessage and ignores the message if it is.

Bug: 429497348
Test: build
Flag: EXEMPT bugfix
Change-Id: I6000f5442f341f152b7fbd235affded0fa56fe50

Chuwei He   commited 2025-07-15 18:43:07 -07:00
16c8fd1166
Merge "Pass bluetoothUseRandomAddress via RoutingCoordinator constructor" into main
Motomu Utsumi   authored and   Android (Google) Code Review   commited 2025-07-14 22:47:19 -07:00
1cdb0a5609
Pass bluetoothUseRandomAddress via RoutingCoordinator constructor
This refactoring changes how the bluetoothUseRandomAddress flag is
accessed.

PrivateAddressCoordinator is in a library used by multiple mainline
modules(Tethering, NetworkStack, CaptivePortal, WiFi) and cannot
directly read a Tethering mainline beta flag.

To fix this, the flag's value is now passed down through constructors.

An alternative solution would be to split the Java library for each module,
but with this solution, a single utility class cannot be shared.

This commit is a no-op as the passed value is hardcoded to false.

Test: TH
Flag: EXEMPT refactor
Bug: 287177081
Change-Id: I5f2174ee94b55e7a7298b9742221d6e6c3c5cac5

Motomu Utsumi   commited 2025-07-15 11:20:01 +09:00
323d22a497
Remove wrong comment
Test: TH
Flag: EXEMPT comment only change
Change-Id: Ifba2528aaa9bfb1ecdd982462f451d92bbd85cf2

Yuyang Huang   commited 2025-07-14 08:56:35 -07:00
75cf08972f
Merge "Optionally remove legacy bluetooth tethering address cache on T+" into main
Lorenzo Colitti   authored and   Android (Google) Code Review   commited 2025-06-26 03:33:56 -07:00
5eaf3aab02
Optionally remove legacy bluetooth tethering address cache on T+
After T, Bluetooth tethering could use a random address. But if we keep
putting the legacy Bluetooth address in the cache, the coordinator will
always assign the legacy address first until it runs into a conflict.

This change in itself does not do anything. Once we have a
trunk-stable namespace for mainline beta, we will add a flag for
this change, and check the flag in PrivateAddressCoordinator.

Bug: 287177081
Test: new unit tests
Flag: EXEMPT no behaviour changes
Change-Id: I56810b5b0e1098a5f89cbb1ad665d2b8652e860c

Yuyang Huang   authored and   Lorenzo Colitti   commited 2025-06-26 15:14:47 +09:00
acd7366b65
DHCPv6 addr reg: remove the mAddrRegEnable member.
For the current implementation we don't use the addr reg option yet, so
remove it.

Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I91a6a81010f11ad2e7db48ed10e777bc42d002d5

Xiao Ma   commited 2025-06-19 11:16:49 +09:00
a915249504
DHCPv6 addr reg: get the DHCPv6 message type.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: If072a5bce0c8516af3fa4f7f9b63137de86b7500

Xiao Ma   commited 2025-06-19 11:15:29 +09:00
307112f889
DHCPv6 addr reg: add a function helper to create ADDR_REG_REPLY message.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I1c48ebba71bd49d0164442929d3c5eb9fa96ac90

Xiao Ma   commited 2025-06-19 11:15:29 +09:00
cfa1f11bad
DHCPv6 addr reg: add ADDR_REG_REPLY packet class.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I389fe6c54da3d4443d85b6fa87f915aa6809d21e

Xiao Ma   commited 2025-06-19 11:15:24 +09:00
64baf9aba5
DHCPv6 addr reg: add a function helper to create ADDR_REG_INFORM message.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I6699b1479eec0958610b533af135f163681438df

Xiao Ma   commited 2025-06-19 11:12:59 +09:00
270672310e
DHCPv6 addr reg: build an IA Address option inside Dhcp6AddrRegInform.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: Ia16ba2b5ca9af3810506548085c995eed172b772

Xiao Ma   commited 2025-06-19 11:12:46 +09:00
8b1f9c1772
Addressing feedback on IpStructure
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.StructTest
Flag: EXEMPT refactor
Bug: 392509494
Change-Id: Iaa301f7b4fadd2aaeac326bf07fbcc4ee32fa4d7

Sarup Dalwani   commited 2025-06-17 00:01:47 +00:00
73d2d4948c
Merge "Remove the unused param id from the IaAddressOption#build API." into main
Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-06-12 17:05:50 -07:00
b75ee7c26a
Remove the unused param id from the IaAddressOption#build API.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I524011cafd2bd97c0064b09d2bb80cb59b709bb1

Xiao Ma   commited 2025-06-12 11:47:53 +09:00
4e68970347
Merge "Add getInterfaceMtu method in ProcfsParsingUtils" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-06-10 00:31:57 -07:00
b91b3afcd0
Merge "Replace String.split() with precompiled regex" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-09 21:15:55 -07:00
8f93c27ff9
Add getInterfaceMtu method in ProcfsParsingUtils
Flag: EXEMPT mainline
Bug: 406085682
Test: atest NetworkStackTests:com.android.networkstack.util.ProcfsParsingUtilsTest
Change-Id: I62e129c3903e0c432f4a4d84c7024cfb4e140dd5

Jimi Chen   commited 2025-06-10 03:07:10 +00:00
991a628dfe
Add native call to retrieve driver name via ethtool API
This adds a JNI function to retrieve an interface's driver name via
ethtool API, which will be used to identify USB NCM interfaces.

Unfortunately, SIOCETHTOOL (ETHTOOL_GDRVINFO in particular) does not
allow passing in the interface index, meaning that this operation is
racy, i.e. the interface might have been replaced when
getDriverNameForInterface() is called.

SICOETHTOOL is slowly being replaced by a netlink alternative that
allows querying by interface index but, unfortunately, does not support
ETHTOOL_GDRVINFO yet.

Test: verified manually; automated test will be added shortly.
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I8bec47e36a607e7d8fe2fac2eebcd8dff0360a02

Patrick Rohr   commited 2025-06-09 14:54:38 -07:00
0eaec731ec
Replace String.split() with precompiled regex
String.split() will allocate and compile the given regex on every call.
The networkstack process spends 2.8% of cycles doing this.

https://pprof.corp.google.com/?id=%2Fcns%2Fpf-d%2Fhome%2Fandroid-telemetry-pitot-pprof-prod-data-owner%2Fstack_sampling_pprof%2F2025-06-07%2Fstack-sampling-pprof-6187fab4-56da-4842-b9c3-9d8db45801d1.pb.gz&metric=samples&filter=hide:%255Enterp_helper%2524,focus:regex%257Csplit&pivot=com.android.networkstack.com.android.net.module.util.ProcfsParsingUtils

I randomly noticed this while looking at CPU profiles.

Flag: EXEMPT refactor
Test: ApfFilterTest and any others that may be exercising the code
Change-Id: I811c0e8982a87d10fedcda93379b08e8ab38a11b

Shai Barack   commited 2025-06-07 19:46:06 -07:00
7c0faeeb68
DHCPv6 addr reg: parse IA Address option.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I29d201a69af220af00deb9e1b1d0c1253faa6200

Xiao Ma   commited 2025-06-06 14:37:50 +09:00
a129f4c5cd
Merge "DHCPv6 addr reg: add ADDR_REG_INFORM packet class." into main
Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-06-04 19:56:10 -07:00
d5bb7759e4
Merge changes I5405d71d,I0d3173a6,I1e6e17fa,I94540b6e,I635031bb into main
* changes:
  Pass EthernetPort into maybeTrackInterface
  Move trackAvailableInterfaces into EthernetNetlinkMonitor
  Change trackAvailable to trigger GETLINK dump
  Remove tests which are covered by EthernetManagerTest
  Test EthernetTracker#trackAvailableInterfaces

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-04 13:35:09 -07:00
8ca981193d
Change trackAvailable to trigger GETLINK dump
Instead of calling NetworkInterface#getNetworkInterfaces() (which calls
getifaddrs() and triggers an RTM_GETLINK dump request), trigger the
RTM_GETLINK dump request in EthernetTracker directly. The resulting
RTM_NEWLINK messages will be processed by the NetlinkMonitor callback.

This means that there will be a single entry point for link tracking
which contains all required information (ifindex, ifname, mac).

This change also makes the behavior of EthernetTracker more correct.
Previously, the interface list was retrieved out-of-band from
EthernetNetlinkMonitor. This means that it was possible for an
RTM_NEWLINK to be queued at the same time as #getNetworkInterfaces() was
called. In that case, #getNetworkInterfaces() returns up-to-date
information and is processed before the queued RTM_NEWLINK event with
the now outdated information.

The new code retrieves all information on a single netlink socket and
processes them in order on the same handler thread.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I1e6e17fa4eb3dd8fe308fd54c2bb16a8ad36dc43

Patrick Rohr   commited 2025-06-04 11:17:10 -07:00
5fd68b6785
DHCPv6 addr reg: add ADDR_REG_INFORM packet class.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I74c3412238377454d914c1b550f000621be411e7

Xiao Ma   commited 2025-06-04 11:43:26 +09:00
e3ac6c4c95
DHCPv6 addr reg: add IA Address option id (5).
ADDR_REG_INFORM and ADDR_REG_REPLY message will take this option to
represent the IPv6 address to be registered.

Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: Ib4b86069dfb504cee948ef3880ccf1ee8ea5d5b9

Xiao Ma   commited 2025-06-04 11:36:25 +09:00
816ad97d61
Merge "DHCPv6 addr reg: add ADDR_REG_INFORM and ADDR_REG_REPLY message types." into main
Xiao Ma   authored and   Android (Google) Code Review   commited 2025-06-01 17:23:12 -07:00
bb47bc9433
DHCPv6 addr reg: add ADDR_REG_INFORM and ADDR_REG_REPLY message types.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: If2b30265c45e3a57c867fd7ba1df5f4245a37b35

Xiao Ma   commited 2025-05-30 16:51:55 +09:00
eb1cc9441c
Add socket destroying methods to InetDiagMessage.
Add socket destroying methods by address and permission to InetDiagMessage
to move that functions to ConnectivityService from Netd.

Bug: 373280981
Bug: 331139818
Flag: android.net.platform.flags.connectivity_service_destroy_socket
Test: atest NetworkStaticLibTests
Test: device test
Change-Id: I3c2136df5dfd618d1c757c07bce2b4211b807237

Sewook Seo   commited 2025-05-27 01:35:49 +00:00
45163857b2
NetlinkUtils: bump dump socket recv buffer size to 1MiB
Bump up buffer to 1M to avoid overflow.

Bug: 409212357
Test: TreeHugger
Flag: EXEMPT mainline/trivial
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6ccca6c577fda080067a9cf8a8efae064ed6df51

Maciej Żenczykowski   commited 2025-05-19 10:49:03 -07:00
d9b2cf9be0
Merge "DHCPv6 addr reg: parse OPTION_ADDR_REG_ENABLE option." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-14 19:16:54 -07:00
1b2f537953