Commit Graph

309 Commits

Author SHA1 Message Date
Motomu Utsumi
f688eeb10a Add flag to test BpfNetMaps refactoring
Following CLs will switch previous codepath (JNI) and new codepath
(Java) for bpf map operations based on this flag.

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: I74f10d5c97390993acea110f6528ef8980bb2aa4
2022-07-28 02:32:41 +00:00
Motomu Utsumi
9be2ea0080 Use java BpfMap in BpfNetMaps#replaceUidChain
Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Ib2a2c2646834110a3eeeb786a4ea7a3f85718be8
2022-07-27 06:01:47 +00:00
Chiachang Wang
b7f81e4a6d Merge "Correct javadoc usage" 2022-07-15 07:41:33 +00:00
chiachangwang
9473c59980 Correct javadoc usage
"{@see" aren't rendered properly. Replace them with "See {@link"
or @see depending on the usage.

Bug: 238753273
Test: make doc-comment-check-docs ; Check the doc result
Change-Id: I70cb2f36e7c5fa8102b5949054df5184d755202c
2022-07-15 03:44:46 +00:00
Paul Hu
6d74747445 Merge "Use common methods to check/enforece mutiple permissions" 2022-07-14 06:19:54 +00:00
Paul Hu
e79157578b Merge "Reword comment for language quality" 2022-07-06 01:52:06 +00:00
Chalard Jean
2ddcf603e2 Reword comment for language quality
This addresses a leftover comment to aosp/1919251

Bug: 238139913
Test: comment-only
Change-Id: Icfd054a1f9a4b928b222fb1a74af066c36c886b0
2022-07-06 01:51:35 +00:00
paulhu
3ffffe71c7 Use common methods to check/enforece mutiple permissions
Use PermissionUtils methods to check/enforece mutiple permissions
to avoid inconsistent behavior and duplicated code.

Bug: 177187957
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I0850a2c8b15e0dfc6d21298c5599ad36bb2056dc
2022-07-04 10:42:06 +00:00
Ken Chen
daf5cb64cc Log BPF programs & maps in bugreport
Currently (T+), BPF program and map status are only dumped on demand.
$ adb shell dumpsys connectivity trafficcontroller

The information can be useful for issue debugging, especially on Data
Usage and NetworkPolicyManagerService. It should be logged in bugreport
dumpsys connectivity section as Android S (which is handled by netd).

Bug: 237954856
Test: adb bugreport
Change-Id: Ic02a58ff2ebdbf375d9df0917e8218ab8faa96da
2022-07-04 11:32:44 +08:00
Motomu Utsumi
25cf86fc95 Refactor BpfNetMaps and getChainEnabled
Address comments from aosp/2117045 and aosp/2131752
Rename USE_NETD to PRE_T
Rename getChainEnabled to isChainEnabled
Remove unnecessary parentheses
Fix comment

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Iaff8c9fc5f74de3fe41a7fb010355b1742fbce90
2022-06-27 14:33:28 +00:00
Motomu Utsumi
be3ff1e923 Add API to get current firewall chain status
This commit adds ConnectivityManager#getFirewallChainEnabled to read the
current firewall chain status

Bug: 208371987
Test: m
Change-Id: I1eadb69f953af5d031cd8dabde3e1f098cf0f4df
2022-06-24 09:11:53 +00:00
Motomu Utsumi
f8bd82cd67 Refactor code and improve tests for VPN filtering
Bug: 206482423
Test: atest ConnectivityServiceTest PermissionMonitorTest

Change-Id: Ic6ff7a3d7695ad6ce96764a9bab2c0a641ba2ba6
2022-06-10 03:18:32 +00:00
Motomu Utsumi
1d9054ba5f Add 3rd deny firewall chain for OEM
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
ConnectivityServiceTest

Change-Id: Ib521fa02f6a19270cb88a3d85321bda822516c78
2022-06-06 07:47:35 +00:00
Motomu Utsumi
d980149817 Add deny firewall chain for OEM
Bug: 207773349
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
--iterations 50 && atest ConnectivityServiceTest --iterations 10

Change-Id: I60d5540821abcced03356f366775f16ee369d7f9
2022-06-03 09:10:57 +00:00
Remi NGUYEN VAN
de9818fb81 Merge "Remove logic from NetworkMonitorManager wrapper" 2022-06-01 01:20:03 +00:00
Remi NGUYEN VAN
9ada184a2b Remove logic from NetworkMonitorManager wrapper
NetworkMonitorManager should just be a passthrough wrapper for
INetworkMonitor. Move logic to choose the notifyNetworkConnected version
to call to its only caller, ConnectivityService.

This allows removing the dependency on modules-utils-build, which makes
the networkstack-client library less portable; for example it would add
duplicate classes if networkstack-client is included into service-wifi,
as service-wifi can already use modules-utils-build from framework-wifi.

Fixes: 227161380
Test: atest ConnectivityServiceTest
Change-Id: Ie50f586c5d1ffe021cb0a96294f13f478fd3a2dd
2022-05-31 18:50:50 +09:00
Chiachang Wang
589bfc1c04 Remove unused variable
Clean up to remove unused variable.

Change-Id: Iad05d6db2fccdaff7419de02b29d74a18b00c3b4
Test: TH
2022-05-27 08:24:19 +00:00
Treehugger Robot
2438b2f5c6 Merge "Clat dump information improvement" 2022-05-19 06:35:16 +00:00
Hungming Chen
c6e00ea74e Clat dump information improvement
This is a followup commit for aosp/2017317.

1. Reorder the NAT464 information in dumpsys connectivity
2. Reword message when clat not started

Bug: 212345928
Test: dumpsys connectivity
Change-Id: I31c7066787dc7db8e5fe225f3918368b25bb7f5e
2022-05-18 14:49:57 +00:00
Treehugger Robot
af7101ff0f Merge changes I03e7cda7,I675c4ef5
* changes:
  Allow ethernet on automotive to set allowed UIDs
  Updating Eth CTS to account for existing ifaces
2022-05-18 02:52:24 +00:00
James Mattis
46491d7546 Allow ethernet on automotive to set allowed UIDs
Allow ethernet factories on automotive devices to set the allowed UIDs
on NetworkCapabilities.

Bug: 229419469
Test: atest FrameworksNetTests
Change-Id: I03e7cda75f1c530e0d0e4a756330bc9847a96668
2022-05-17 15:32:13 -07:00
Treehugger Robot
b6ac308b50 Merge changes I5ffa2faf,Id5f14d6e
* changes:
  add proper minimum bpfloader version annotations for block/clatd/dscp_policy/netd
  move netd maps and progs into /sys/fs/bpf/netd_shared/...
2022-05-17 15:39:02 +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
Motomu Utsumi
b08654ca04 Block incoming packets in VPN Lockdown mode.
Currently, even when VPN Lockdown mode is enabled, incoming packets are
not dropped if VPN is not connected.

This commit fixed this issue.
After this commit, If VPN Lockdown mode is enabled, incoming packets
are dropped regardless of the VPN connectivity.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest PermissionMonitorTest
Change-Id: If52ece613c8aac1073355e43b6fb9cb3fcc87d1d
2022-05-16 10:40:59 +00:00
Motomu Utsumi
77a794868f Refactor VPN interface filtering necessity check
Test: atest ConnectivityServiceTest
Change-Id: Iedf344f6275d4c6b23716eb11e3eecf54c6a2f9a
2022-05-16 10:38:01 +00:00
Junyu Lai
fc938cf026 Merge "Limit data usage request per uid" 2022-05-13 09:06:41 +00:00
Junyu Lai
f3c946278c Limit data usage request per uid
Currently, there is no limtation for an app to request
data usage callback, which is dangerous if the app fire
hundreds of thousands requests and potientially this might
cause OOM if the apps don't free them.

Test: atest NetworkStatsObserversTest#testRegister_limit
Bug: 229103088
Change-Id: I8299f46fd47a82ec9b25ba2e0d3c95db5512c331
2022-05-12 08:53:21 +08:00
Sooraj Sasindran
5ea6f517a6 Merge "Fallback should be evaluated for each preference" 2022-05-11 21:05:18 +00:00
Sooraj Sasindran
b0e283c900 Fallback should be evaluated for each preference
1) alowFallback flag was incorrectly not reset while setting profile
   preference. Corrected it.

2) Threw exception if default preference and enterprise preference are
set together

3) renamed clearUser to withoutUser

Bug: 231670730
Test: ConnectivityServiceTest

Change-Id: Iaf49237bdc791c7e1dd884d069eff64e74757477
2022-05-10 22:11:55 -07:00
Paul Hu
7d180e679a Merge changes I5eaeb415,I236f1550
* changes:
  Check carrier privilege for CBS network requests synchronously
  Allow 3p apps to request restricted networks
2022-05-10 14:38:30 +00:00
junyulai
96bd9fe4de Check carrier privilege for CBS network requests synchronously
Normally if an app calls requestNetwork with capabilities that it
does not have permission to request, it gets a SecurityException,
except if it requests NET_CAPABILITY_CBS, in which case the request
will not throw but the app will get an onUnavailable callback.

Make this codepath throw as well. This simplifies the code and makes
the app-visible behaviour more consistent (and consistent with what
happens in S and below). The reason the code was written this way is because the carrier privilege app should receive a callback if it
loses permission. But onUnavailable is also not the best callback to
send, since it is used very rarely and also releases the app's
request. It seems better to leave the request registered and send
onLost.

Test: atest FrameworksNetTests
Bug: 194332512
Change-Id: I5eaeb415a6654851246e38599a996fbd9366fde0
2022-05-10 10:26:54 +00:00
Paul Hu
8fc2a55a16 Allow 3p apps to request restricted networks
Since 3p apps are allowed to use restricted networks in S, they
should be allowed to request a restricted network reasonably.
Otherwise, the functionalities of 3p apps will break if they rely
on restricted networks. Thus, CS needs to allow 3p apps to
request restricted networks if 3p apps are in the allowed list.

Bug: 230509118
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I236f1550095ee2be29adbc3b28d3ac2561a8b072
2022-05-10 18:10:19 +08:00
Sooraj Sasindran
9cc129f37d Do not remove profile network preference for different uids
Multiple enterprise slice can be setup within single user profile based
on different uids. So do not remove profile network preference with same
user profile but with different uids

Bug: 229644102
Test: manual system test and ConnectivityServciceTest
Change-Id: I897b643e01240958fff575de9e15182069efc698
2022-05-06 00:58:33 -07:00
Prerana Patil
a1c6dbbd53 Merge "Update VPN isolation code for excluded routes" 2022-05-03 17:40:12 +00:00
Sooraj Sasindran
07a20408db Merge "Allow device owner to configure profile network preference" 2022-05-02 07:13:21 +00:00
Sooraj Sasindran
bb65aa8fc2 Allow device owner to configure profile network preference
isMangedProfile returns true for managed profiles.
But enterprise device can be fully managed like device owner.
Hence check specifically if request is coming on fully managed
device.

Bug: 226966328
Bug: 231071836

Test: ran DevicePolicyManager CTS and ConnectivityServiceTest
Change-Id: I7827466bd61e24ba9c36c3a2e25043257e2ed602
2022-05-01 21:20:36 -07:00
Prerana
2b97bbebf4 Update VPN isolation code for excluded routes
Bug: 230058738
Test: atest LinkPropertiesTest

Result: https://paste.googleplex.com/4706859672928256

Change-Id: I970fca6b0e2cd358e9bd77152563d13367867c74
2022-04-29 22:23:02 +00:00
Treehugger Robot
722346dce4 Merge "ClatCoordinator: dump BPF forwarding rules" 2022-04-27 14:54:16 +00:00
Hungming Chen
707675511a ClatCoordinator: dump BPF forwarding rules
This is a preparation for moving clat map dump from netd to
mainline module.

Test: compare dumpsys connectivity and netd

$ adb shell dumpsys connectivity
Nat464Xlat:
  ClatCoordinator:
    Forwarding rules:
      BPF ingress map: iif nat64Prefix v6Addr -> v4Addr oif
        47 /64:ff9b::/96 /2a00:79e1:abc:6f02:4aac:17dd:b40e:8bcc -> /192.0.0.4 52
      BPF egress map: iif v4Addr -> v6Addr nat64Prefix oif
        52 /192.0.0.4 -> /2a00:79e1:abc:6f02:4aac:17dd:b40e:8bcc /64:ff9b::/96 47 ether

$ adb shell dumpsys netd
ClatdController
  BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
    47(wlan0) 64:ff9b::/96 2a00:79e1:abc:6f02:4aac:17dd:b40e:8bcc -> 192.0.0.4 52(v4-wlan0)
  BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)
    52(v4-wlan0) 192.0.0.4 -> 2a00:79e1:abc:6f02:4aac:17dd:b40e:8bcc 64:ff9b::/96 47(wlan0) ether

Change-Id: I597709663477b62005b0bc5cc1bf0fc22743e10b
2022-04-26 06:44:14 +00:00
Maciej Żenczykowski
0736d7bd91 adjust for new T bpfloader net_shared location
(this is safe because on pre-T none of these maps and programs are mainlined
 and thus safe to access from mainline code anyway)

Test: TreeHugger, manual
Bug: 218408035
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I23e565d665247f33e084978890a1ee8ffe0fe568
2022-04-23 09:03:06 +00:00
Lorenzo Colitti
64ac247056 Merge "Remove UserId from UID when checking against BLUETOOTH_UID" 2022-04-22 06:51:41 +00:00
Hungming Chen
eb15a2d816 [CLATJ#27] Use ClatdCoordinator since T+ devices
- For clatd start and stop, use ClatdCoordinator on T+ and Netd on S-
- Fix the unit test for T+ and S- devices
  Note that mokito.verify(.., times(1)) is replaced by verify(..)
  because times(1) is the default and can be omitted.
  See verify in mockito/src/main/java/org/mockito/Mockito.java

Note that this commit needs to be merged with aosp/1956072.

Bug: 212345928
Test: atest FrameworksNetTests
      manual test
      1. Connect to ipv6-only wifi.
      2. Try IPv4 traffic.
         $ ping 8.8.8.8
      3. Check bpf entries are added
      4. Disconnect from ipv6-only wifi.
      5. Check bpf entries are removed
      6. testipv4.com shows 10/10

Change-Id: I7dfda6eec19de94e4258971effcd8a1210542473
2022-04-21 13:24:36 +08:00
Andrew Cheng
2ae5c735b6 Remove UserId from UID when checking against BLUETOOTH_UID
A UID can be a concatenation of a UserID with a 5 digit package UID.
E.g., Bluetooth under User10 would have UID 1001002. This CL removes the
UserID (if any), before checking against BLUETOOTH_UID.

Bug: 228598338
Test: m
Change-Id: I532583345cc9ab474fc848a3ede6be9d8be9c5b0
2022-04-20 18:27:23 +00:00
Junyu Lai
0da479b280 Improve dumpsys logs for NetworkProvider and NetworkOffer
It will look like below:

NetworkProviders for:
  2: WIFI_AWARE_FACTORY
  1: Ethernet

Network Offers:
  NetworkOffer [ Provider Id (1) Score(...) Caps [...] Needed by [1, 2, 3]]
  NetworkOffer [ Provider Id (2) Score(...) Caps [...] Needed by [4, 5, 6]]

Test: manual
Bug: 227408533
Change-Id: I84cb03757877d7127d39c359010c8092a8ca87d9
2022-04-20 15:55:09 +08:00
Tyler Wear
3ad8089d19 Add IPv6 Handling for DSCP Policies and Support Interfaces with MAC Addresses
Add bpf functionality to handle IPv6 packets and apply
DSCP value.
Also support DSCP policy rules on multiple interfaces
simultaneously.

Test: atest DscpPolicyTest

Bug: 217166486
Change-Id: I452a87355fd0382a4c38b84aa3465505951d9bf0
2022-04-15 07:53:51 -07:00
Lorenzo Colitti
d12af7ebfe Allow the bluetooth UID to register network factories.
This ensures that bluetooth can register bluetooth tethering
NetworkAgents without having to make NETWORK_FACTORY a privileged
or role permission.

Test: m
Bug: 221949454
Change-Id: I24a5da444b10dde740c1e449c8630de56946d4e1
2022-04-06 11:15:12 +09:00
Lucas Lin
41ed965e68 Merge "Add @RequiresPermission for setUnderlyingNetworks" 2022-03-29 15:34:17 +00:00
markchien
3c04e66da0 Api review: change updateFirewallRule to setUidFirewallRule
Bug: 218494748
Test: TH

Change-Id: I52a02ebe109b687359f579c16fded4af3c9cd242
Merged-In: I52a02ebe109b687359f579c16fded4af3c9cd242
2022-03-25 18:49:08 +08:00
Lorenzo Colitti
a63e2341d6 Rename destroyAndAwaitReplacement to unregisterAfterReplacement.
Rename requested by API council.

Fix: 224764301
Test: existing CTS tests updated
Change-Id: Ibab9c9cd64bf0dde1e22705e81cff11d356fc719
2022-03-24 01:12:26 +09:00
lucaslin
69e1aa9117 Add @RequiresPermission for setUnderlyingNetworks
setUnderlyingNetworks() is mainly for the NetworkAgents who hold
the NETWORK_FACTORY to set its underlying networks.

And the underlying networks are only visible and useful for the
caller of getNetworkCapabilities() or the receiver of
onCapabilitiesChanged() who hold one of NETWORK_FACTORY,
NETWORK_SETTINGS and MAINLINE_NETWORK_STACK permissions.
Otherwise, the underlying networks field will be cleard before
sending.

Bug: 205738644
Test: atest CtsNetTestCases:ConnectivityManagerTest
      atest CtsHostsideNetworkTests:HostsideVpnTests
      atest FrameworksNetTests
Change-Id: Ife7630d9676a31ee5ab977cb1b87aec3b6fd7080
2022-03-22 18:15:09 +08:00