Commit Graph

423 Commits

Author SHA1 Message Date
Lorenzo Colitti
76a6f956dd Add the defaultNetwork element to the netstats.proto.
This is in its own commit because AOSP has diverged from internal
master.

Bug: 35142602
Test: builds, boots
Change-Id: I75fc85b961bc919e3d6c2adce6d6861c6f2c8379
2018-01-20 02:26:58 +09:00
Lorenzo Colitti
b8e79f3312 Add getDefaultNetwork to the NetworkStats public API.
This allows an app using the public API to know whether the
traffic in a particular bucket was on the default network
(i.e., the network was selected by the system), or not (i.e.,
the network was selected by the app).

Bug: 35142602
Test: builds, boots
Test: added coverage to NetworkUsageStatsTest CTS test, still passes
Change-Id: I9f6669908fa119743b9c0aa0c31a03e5ebafa7db
2018-01-20 02:26:58 +09:00
Lorenzo Colitti
d99f4ff71f Merge changes Id8776d14,Ifa291c62,I5ea9d200 am: c48f4cb7f1 am: b36b423230
am: 0d74e0554c

Change-Id: I12108d96e29bfe71406106c2af950a6d6a9f8351
2018-01-19 16:46:11 +00:00
Lorenzo Colitti
ab7807a5bb Track and persist in stats whether traffic is on the default network.
This change adds the defaultNetwork to the ident based on current
system networking state, and persists that value to flash.

Bug: 35142602
Test: runtest frameworks-net
Test: downloaded files using default/non-default networks while watching dumpsys netstats
Change-Id: Id8776d149b2977548a9eb455ad4926af55e25aba
2018-01-19 19:49:16 +09:00
Lorenzo Colitti
3e85855083 Add the default network to NetworkStats and NetworkStatsCollection.
This allows us to maintain NetworkStats entries that track
whether the traffic was on the default network.

At the moment, the stats collection code always passes in
DEFAULT_NETWORK_NO. However, this value is a no-op, since it is
not persisted to disk. Only the ident, the uid/set/tag, and the
packet/byte/operation counters are persisted.

A future change will add defaultNetwork to the ident and start
persisting it.

Bug: 35142602
Test: runtest frameworks-net
Change-Id: Ifa291c62c0fa389b88e5561086a29dcd7cee2253
2018-01-19 19:49:16 +09:00
Lorenzo Colitti
28d1a529d5 Pass all default networks to NetworkStatsService
This will allow NetworkStatsService to treat traffic on these
networks differently from traffic where the app selects a network
that is not the default.

Bug: 35142602
Test: runtest frameworks-net
Change-Id: I5ea9d200d9fb153490c6108bb9390bf152f297da
2018-01-19 16:40:10 +09:00
Di Lu
3fef704896 Add xfrm mark in IpSecConfig
Bug: 63589600
Test: runtest frameworks-net
Change-Id: I2d38d781b8b31d8bf39fd4e9a7e31509f15a9e16
2018-01-18 15:23:56 -08:00
Nathan Harold
67e7673adf Add Tunnel Interface APIs to IpSecManager
Add a new interface and a new management object,
IpSecTunnelInterface to the IpSecManager surface.
This object will be used to control IPsec tunnels.

-Add IpSecTunnelInterface object
-Add methods to create and use an IpSecTunnelInterface
-Update the IpSecTransform builder to create Tunnel
 mode IpSecTransform objects (usable with an IpSecTunnel)

Bug: 36033193
Test: compilation
Change-Id: Ib6948b12c15c93674234dc36288058ae44435b90
2018-01-17 16:14:17 -08:00
nharold
002831b7c0 Merge "IpSec - API Tweak for removeTransportModeTransform" am: 6725ff729b am: d58b237445
am: a2411eb8ee

Change-Id: I479c24d9ac5d4b022ec6310395fdb4274cfd5598
2018-01-17 20:50:14 +00:00
nharold
77af60dd1d Merge "Prevent Closure of Underlying Socket FDs" am: 3cff120fcb am: 31f05d66ca
am: 5a653d2ec7

Change-Id: I3ab796cc17d5ee2e4a2c8838bac2ada4831c755f
2018-01-17 10:14:43 +00:00
Nathan Harold
ff097d9e93 Make Transforms Unidirectional am: 5a19b9500d am: f4fc2714c2
am: ab40c5ac15

Change-Id: I608be255a307891ec3fe2d97cda817d75240c95c
2018-01-17 10:03:31 +00:00
Nathan Harold
0d483b76f3 IpSec - API Tweak for removeTransportModeTransform
Because IpSecTransforms are now unidirectional,
and because the only mechanism for removing Transforms
removes it from both directions, the API can no longer
use the Transform parameter to meaningfully validate
that the caller had applied a transform. Since that
functionality was as-yet unimplemented and is now
infeasible, the transform parameter is removed.

Bug: 72079356
Test: cts - IpSecManagerTest; runtest frameworks-net
Change-Id: If19b0d34bdc6daf31a40d6d62bff326dcbca08c0
2018-01-17 01:11:46 -08:00
Nathan Harold
3167625a15 Prevent Closure of Underlying Socket FDs
The version of applyTransportModeTransform() and
removeTransportModeTransform() that accepted
Socket and DatagramSocket were closing the underlying
FDs upon return. It's unclear whether this is due to
a behavior change elsewhere in ParcelFileDescriptor,
but either way, converting to using getFileDescriptor$
and then calling dup() explicitly rather than relying
on ParcelFileDescriptor seems like a better idea anyway.

Bug: 72047396
Test: CTS - IpSecManagerTest.testCreateTransform()
Change-Id: Ia2f02564e1289f25bf113dbb861fcfd2240537a7
2018-01-16 21:30:20 -08:00
Nathan Harold
5a19b9500d Make Transforms Unidirectional
Convert the IpSecTransform from being a bi-directional
pair of SAs to a unidirectional single SA. This CL
also removes the concept of "direction from SAs meaning
that a IpSecTransform may now be applied to a socket
in either direction.

-Make transforms unidirectional
-Add Convert allocateSpi() to use destination rather
 than direction and remote address
-Remove directionality from builders for IpSecTransform
-Change applyTransportModeTransform() to take a
 direction in which to apply the transform object.
-Additional minor naming updates
-Restrict IpSecConfig to only print keys on eng builds
-Move DIRECTION constants to IpSecManager
-Add sourceAddress parameter to IpSecTransform to provide
 additional guarantees about the source address of data;
 (explicit failure rather than implicit failure).
-Move SPI to the build() method of IpSecTransform

Bug: 71717213
Test: runtest frameworks-net, CTS - IpSecManagerTest
Change-Id: I0824b37f443f4b8c62536d9801238c63ed8f2a1c
2018-01-16 11:08:31 -08:00
Benedict Wong
3de5545763 Merge "Add validation to IpSecConfig algorithm setters" am: 53e5d21924 am: c93df5ca1c
am: c135035ab6

Change-Id: I7ff85771945c68025ce8d66ca85313bac087b3a5
2018-01-09 21:23:35 +00:00
Benedict Wong
53e5d21924 Merge "Add validation to IpSecConfig algorithm setters" 2018-01-09 18:18:28 +00:00
nharold
8dddc0d093 Merge changes from topic "ipsec-resource-id-cleanup" am: 2b36299c73 am: d7319df4d0
am: f81e9dcf6a

Change-Id: Ib96b30bcb1b47c23d0a18cf043dd042409c61322
2018-01-08 20:29:11 +00:00
Jeff Sharkey
a6886af481 Add DataUnit to clarify SI-vs-IEC units.
Mirrors the design of TimeUnit and ChronoUnit which many developers
are already familiar with, making it easy to pick up and use.

Yes, this is an enum.

Bug: 70915728
Test: bit FrameworksCoreTests:android.util.DataUnitTest
Change-Id: Id0cfdac5c81ed89c3c9ece23c964acba4a4f8471
2018-01-07 19:06:01 -07:00
Benedict Wong
70867e55f7 Add validation to IpSecConfig algorithm setters
Adds checks to ensure that users can only set the correct types of
algorithms for the Authentication, Encryption and Authenticated
Encryption algorithms.

Bug: 65223935
Test: Added tests in IpSecConfigTest, and passed on aosp_marlin-eng
Change-Id: I462c77d9eb5710b8d03a48866453649d3b6fc6bf
2018-01-04 16:56:40 -08:00
Nathan Harold
5e8544685d IpSec Invalidate the Resource IDs on close()
To facilitate error checking we should invalidate
the resource IDs of all objects when we close() them.
Today, the resource ID is invalidated on the Transform
object but not on the SPI or Encap Socket. This CL
unifies the behavior.

Bug: 70641274
Test: cts - IpSecManagerTest
Change-Id: I28caec3e913902c748c6a50b4ef742ccef8b1b09
2018-01-04 15:28:29 -08:00
Chenbo Feng
fa05f2bf30 Merge "Use NetworkStatsService to get stats for apps" am: 8469cd614d am: fa7f4015fc
am: 2e6aabced1

Change-Id: I90ce68a72afbf596e28d987e925795709d24dd52
2017-12-21 19:49:25 +00:00
Chenbo Feng
aa7ba31c8e Use NetworkStatsService to get stats for apps
Move the native implementation of TrafficStats to NetworkStatsService
and apps need to get the NetworkStatsService binder interface from
system_server in order to get the network usage stats since boot. This
implementation can hide the detail of retrieving network traffic
information from apps and the NetworkStatsService can choose which
methoed it use to get the data depending on the kernel version of the
device.

Bug: 30950746
Test: CtsNetTestCases -t android.net.cts.TrafficStatsTest
Change-Id: I53bbefd19aa0b783b9b4b42ea4d76db3e9ec07a3
2017-12-19 19:57:44 -08:00
Benedict Wong
0ee0b691f7 Merge "[ipsec-qtaguid] Tag sockets upon creation of encap sockets" am: cd534c6990 am: 8caa274ade
am: 073572a677

Change-Id: I4140f386687c579044f9b5fe59dd7e05f86000fe
2017-12-19 00:41:55 +00:00
Benedict Wong
083faee14a [ipsec-qtaguid] Tag sockets upon creation of encap sockets
Added calls to tag encap sockets to that of the UID for which the encap
socket is being created on behalf of. This ensures that all data
accounting generated for the UDP-encap-ESP socket is correctly billed to
the right UID.

Bug: 62994731
Test: New tests added to IpSecServiceTest.java, passing
Change-Id: I15365ea9c982fd7b4e3cdeff314ddfba2289c86e
2017-12-18 19:46:06 +00:00
Jeff Sharkey
1fb74318cf [CHERRY-PICK] API for apps to tag sockets with their own UID.
This enables app A to create a socket, pass it to app B, and have
app B accept blame for the traffic performed on that socket.

Also adds helpful public APIs for tagging raw FileDescriptor sockets
instead of making developers go through shady SocketImpl wrappers.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AppSecurityTests#testAppFailAccessPrivateData
Bug: 63932076
Change-Id: I08925c843974675fc82e4080cec2eaab9ab7cd41
Merged-In: I08925c843974675fc82e4080cec2eaab9ab7cd41
(cherry picked from commit 4e164f9e94)
2017-12-18 19:44:40 +00:00
nharold
05e99ef743 Merge "Use consistent naming for allocating SPI." am: 816f0ebaab am: 4753ed4b1b
am: 63f6a5625f

Change-Id: Ib6845ab0d7f385fbd1d59c0179771542e12c8be0
2017-12-14 21:48:58 +00:00
Jeff Sharkey
f95fb35f01 Add more IntDef prefixes for auto-documenting.
Test: builds, boots
Bug: 70177949
Exempt-From-Owner-Approval: annotation-only changes
Change-Id: I76dde6054e06f52240bd4b1a0f196dcb74623608
2017-12-13 20:05:36 -07:00
Jonathan Basseri
20e96c55d5 Use consistent naming for allocating SPI.
Throughout the IPsec code (API, system server, netd) we use "reserve"
SPI and "allocate" SPI interchangeably. This renames to use "allocate"
everywhere for self-consistency and consistency with the kernel
(ALLOCSPI).

In javadoc, I am leaving the word "reserve" in several places because it
is still an accurate description of how the method behaves.

Bug: 69128142
Test: TreeHugger should be enough
Change-Id: I8ea603b4612303b0393beef04032671fa53d2106
2017-12-12 13:50:35 -08:00
Jeff Sharkey
c10b61fc54 Merge "API for apps to tag sockets with their own UID." 2017-12-05 05:00:46 +00:00
nharold
97e981cca3 Merge "Validate IpSecAlgorithm Length" am: 68b81299d2 am: f0dd03e114
am: c8347df907

Change-Id: I1a28d860ac7125afc1f82ac17d1834b0121c0e11
2017-12-05 02:46:06 +00:00
nharold
f0dd03e114 Merge "Validate IpSecAlgorithm Length"
am: 68b81299d2

Change-Id: I23f7612c119e67f9a1647568aeefde38a365f8da
2017-12-05 02:28:10 +00:00
Jeff Sharkey
4e164f9e94 API for apps to tag sockets with their own UID.
This enables app A to create a socket, pass it to app B, and have
app B accept blame for the traffic performed on that socket.

Also adds helpful public APIs for tagging raw FileDescriptor sockets
instead of making developers go through shady SocketImpl wrappers.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AppSecurityTests#testAppFailAccessPrivateData
Bug: 63932076
Change-Id: I08925c843974675fc82e4080cec2eaab9ab7cd41
2017-12-04 17:43:40 -07:00
Nathan Harold
eb1d489332 Validate IpSecAlgorithm Length
Improve the Validation of IpSecAlgorithm by
explicitly checking the length in addition to
the truncation length (previously an oversight).
In addition, we now check the lengths during
un-parceling, which will catch someone maliciously
manually building a parcel and passing it, bypassing
the checks in the constructor.

Bug: 68780091
Test: runtest -x IpSecAlgorithmTest.java
Change-Id: I8172762617264d34f47d5144336464510f07a701
2017-12-04 15:12:14 -08:00
Jonathan Basseri
b77b161454 Merge "Javadoc cleanup of IpSecManager API." am: d09d106ec0 am: f96bfee165
am: 3947cda36f

Change-Id: Id10e39da5495f9367332cbc5c754506fc64f3c75
2017-11-22 02:10:32 +00:00
Jonathan Basseri
f96bfee165 Merge "Javadoc cleanup of IpSecManager API."
am: d09d106ec0

Change-Id: Iaf206b0980d3bed14fe6b8318d2073577212b460
2017-11-22 01:51:46 +00:00
Jonathan Basseri
2725a233c9 Javadoc cleanup of IpSecManager API.
This changes only comments and annotations, which results
in minor API changes.

Bug: 63777932
Test: `make update-api` and visually inspect generated HTML.
Change-Id: I7a7a9244eade6cc55aca17a47e0a838cd6f84cc9
2017-11-20 10:49:59 -08:00
Xin Li
47beb1e8a3 Merge commit '98e12851336b7db16e583f9afac63ecc97465980' from
oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master.

Change-Id: Ia7b8da4a00d215160e4a4fa40f6044208d1297b7
Merged-In: I19846d2a3ee27aecbae2367a74ee49082eea154d
2017-11-14 12:31:11 -08:00
Ricky Wai
3e97a6fc40 Hide NetworkStatsFactory class
Test: Able to compile
Change-Id: I37f385c773120405c437643b5de406772a684dcd
2017-11-09 15:22:59 +00:00
nharold
2fd8e1a9e6 Merge "Fix signature for finalize() to resolve API Lint error" am: 28dc8a29a1
am: c09d405e1d

Change-Id: I1f8915547876e0e0045724eb9a1e29123ab4edda
2017-11-08 18:20:06 +00:00
Benedict Wong
d12ea7c331 Merge "Update documentation for AES-GCM-ESP keymat length" am: f27dc03921
am: 6491b03410

Change-Id: I5e61a9c28dac49f2dca554ce2fdf755ab7be0dab
2017-11-08 18:12:25 +00:00
nharold
28dc8a29a1 Merge "Fix signature for finalize() to resolve API Lint error" 2017-11-08 17:56:43 +00:00
Benedict Wong
f27dc03921 Merge "Update documentation for AES-GCM-ESP keymat length" 2017-11-08 17:47:40 +00:00
Nathan Harold
2a30daf3f7 Fix signature for finalize() to resolve API Lint error
The API linter on goog/master noticed that this method is
listed in the public API even though it's protected. The
change is probably related to a signature change from the
internal finalize method which throws a Throwable. Fix the
method in IpSecManager to throw Throwable, which should
fix the current.txt and resolve the lint error.

Bug: 69006767
Test: compilation, make update-api
Change-Id: I173d014baaa505c365b7916fcb52f2a8b4af9373
2017-11-07 17:46:12 -08:00
Benedict Wong
01b1ab4034 Update documentation for AES-GCM-ESP keymat length
Added notes that keymat length must include 32 bits of salt.

Bug: 68672051
Test: Frameworks-net unit tests & IpSecManager CTS tests run
Change-Id: I0ae0c5be8a45b2374783b3bd1fa8bf930f15e687
2017-11-07 17:39:35 -08:00
Jeff Sharkey
0a2582193e Merge "Define NOT_ROAMING network capability." am: 8f380ab29c
am: 3fe1ae29cd

Change-Id: Ib511f7af82c80fd4e95f4da9de1fdce200deb987
2017-11-03 23:07:03 +00:00
Jeff Sharkey
7c19a1abd6 Define NOT_ROAMING network capability.
The "roaming" state of a network really belongs on NetworkCapabilities
instead of being published through NetworkInfo.isRoaming().  One major
reason is to support developers creating NetworkRequests for a
non-roaming network.

Watch for any capability changes that network statistics are
interested in (either metered or roaming) and notify it to perform
an update pass; fixes bug where we previously only triggered on
roaming changes.

Fix bug in VPNs where metered/roaming capabilities of underlying
networks weren't being propagated; this was probably preventing
some jobs from running over unmetered networks, and causing other
jobs to run over roaming networks!  Also passes along link bandwidth
information from underlying networks, and propegates any changes
to underlying networks.

Fix race condition by reading prevNc inside lock.  Utility methods
correctly calculate min/max link bandwidth values.

Test: bit FrameworksNetTests:android.net.,com.android.server.net.,com.android.server.connectivity.,com.android.server.ConnectivityServiceTest
Bug: 68397798, 16207332
Change-Id: I3e1a6544c902bf3a79356b72d3616af1fd2b0f49
2017-11-01 19:05:42 -06:00
Benedict Wong
982cb0db7f Merge "Add support for AES-GCM-ESP as an IPSec algorithm" am: b6df7f0d35 am: cb2c14fc55
am: f92bfc3b77

Change-Id: I49932a5fc048b4a60512fac45a3537f050397168
2017-10-19 17:37:22 +00:00
Benedict Wong
cb2c14fc55 Merge "Add support for AES-GCM-ESP as an IPSec algorithm"
am: b6df7f0d35

Change-Id: Ic099206a28c4f21fa796969c953a8d4e81e8495b
2017-10-19 17:14:53 +00:00
Benedict Wong
53d60a2d24 Add support for AES-GCM-ESP as an IPSec algorithm
Allows native AES-GCM-ESP to be used as an IPSec transport/tunnel mode
algorithm with kernel support

Bug: 63589918
Test: IPsecService tests added, existing ones pass
Change-Id: Ie1a9a902be205f269aa37bf956198f2e5b177c21
2017-10-18 11:22:24 -07:00
nharold
2b71ef1fe2 Merge "Cosmetic Cleanups for IpSecService" am: 87d6fc04b2 am: ffb9ae2323
am: cc51ef0a47

Change-Id: I0a9c52ca26ad1b7e4505f7c9dc32ad9550b62afc
2017-10-05 01:07:53 +00:00