Commit Graph

717 Commits

Author SHA1 Message Date
Christopher Tate
fde4caf456 Be resilient to restoring unintelligible network templates
Some OEMs have introduced incompatible network bookkeeping.  We now
detect and ignore those network definitions at restore time.

In addition, we now

  * log when an undefined network match type is used to construct a
    NetworkTemplate instance, and
  * quietly refuse to match such a NetworkTemplate against any known
    network identifier, rather than crashing the inquiring app.

Bug 38151335
Test: manual

Change-Id: I565b6f6b87df1f13a8c0c01ae6049bda270b1e48
2017-05-17 10:33:01 -07:00
Hugo Benichi
85c377405c Merge "NetworkStatsFactory: no double looping on stats + stacked interfaces" am: b884b37cea am: cd6537edb5 am: b323e61584
am: 1f27dba36f

Change-Id: I175ffaae545d88b7bc39ab01ab3a811af7e03d60
2017-05-10 09:30:01 +00:00
Hugo Benichi
1f27dba36f Merge "NetworkStatsFactory: no double looping on stats + stacked interfaces" am: b884b37cea am: cd6537edb5
am: b323e61584

Change-Id: I0312882bb8885aaa65f99a445fd0554d6ac054b3
2017-05-10 09:20:04 +00:00
Hugo Benichi
b884b37cea Merge "NetworkStatsFactory: no double looping on stats + stacked interfaces" 2017-05-10 08:19:33 +00:00
Hugo Benichi
e8a2ba93eb Merge "Merge "NetworkStatsFactory: fix double accounting on IPv6 only networks" am: ce730270bc am: 76dc14ec88 am: 1697d48faf" into oc-dev-plus-aosp
am: f8dbdba5a2

Change-Id: Ie09f2b4e04749e61923781f4b13e796054108fad
2017-05-10 02:06:06 +00:00
Hugo Benichi
286734b834 Merge "NetworkStatsFactory: fix double accounting on IPv6 only networks" am: ce730270bc am: 76dc14ec88
am: 1697d48faf

Change-Id: I7dbfe3c96678e2325eb533f31523ad10d861ad02
2017-05-10 00:40:28 +00:00
Hugo Benichi
b15ed2c488 NetworkStatsFactory: fix double accounting on IPv6 only networks
For 464xlat scenarios on IPv6 networks, the clatd interface setup
introduces double counting of apps ipv4 traffic. NetworkStatsFactory was
accounting for this on the tx path, but not on the rx path. Also it did
not accounted for the 20 bytes added by the IPv6 header.

This patch subtract correctly the rx and tx traffic from the root uid on
the underlying interface, and also adds correctly the 20 bytes cost per
packet on the stacked interface for 464xlat traffic.

Test: added several new unit tests, based on synthetic data and real
      data also.
Bug: 33681750
Change-Id: I4867fe181938d94b5594b3d88896a3c4e01d895c
Merged-In: I2675643b220acbc6110179fa937d4c313b6f5e32

(cherry picked from commit e1bb3a14d1ee1aba2f92e5bccf659774699eaffe)
2017-05-10 09:19:12 +09:00
Hugo Benichi
5efd907d85 NetworkStatsFactory: no double looping on stats + stacked interfaces
This patch uses the associative structure of the stacked/base interface
collection to avoid the two nested for loops over stacked/base
interfaces and all stats entries when correcting 464xlat traffic stats.

Consequently the list of stats entries is iterated only once.

Test: runtest -x frameworks/base/../NetworkStatsFactoryTest.java
Bug: 33681750
Change-Id: I84ae997fb693b909f431764697627b9957131732
2017-05-10 09:14:14 +09:00
Hugo Benichi
ce730270bc Merge "NetworkStatsFactory: fix double accounting on IPv6 only networks" 2017-05-10 00:07:29 +00:00
Hugo Benichi
6d58a32565 NetworkStatsFactory: fix double accounting on IPv6 only networks
For 464xlat scenarios on IPv6 networks, the clatd interface setup
introduces double counting of apps ipv4 traffic. NetworkStatsFactory was
accounting for this on the tx path, but not on the rx path. Also it did
not accounted for the 20 bytes added by the IPv6 header.

This patch subtract correctly the rx and tx traffic from the root uid on
the underlying interface, and also adds correctly the 20 bytes cost per
packet on the stacked interface for 464xlat traffic.

Test: added several new unit tests, based on synthetic data and real
      data also.
Bug: 33681750
Change-Id: I2675643b220acbc6110179fa937d4c313b6f5e32
2017-05-09 22:46:14 +09:00
Hugo Benichi
20f5ef9065 Merge changes I4872f8ba,I92039f29,Iaad13e13 am: 767ac317e2 am: 717238a614
am: 44e9b81c54

Change-Id: I9c38d1254f82b50f4d1e953e72bf15a46562d3b8
2017-05-09 06:30:48 +00:00
Hugo Benichi
4dd4db7720 NsdService: test coverage for client requests.
Adding coverage for:
  - NsdManager client disconnection
  - in-flight request GC

Test: new test passes
Bug: 37013369, 33298084
Change-Id: I92039f297cf99352bbf4196797933d89c0b819ff
2017-05-09 10:49:33 +09:00
Hugo Benichi
f2c64f8725 NsdManager: remove duplicated argument validation
This patch simplifies argument validation in NsdManager public api and
regroup duplicated validation into common methods.

This makes stack traces more actionable as now specific errors will
cause the api to throw exception from specific methods, whereas before
IllegalArgumentException would be thrown from inside the same api method
for different reasons.

This patch also includes a couple of other small cleanups.

Test: $ runtest -x frameworks/base/tests/net/../NsdManagerTest.java
Bug: 37013369
Change-Id: Iaad13e13976e9bf8f508d7188f823f8184ac414b
2017-05-09 10:49:33 +09:00
Hugo Benichi
284ecaa201 Merge "NsdManager: add test coverage for discoverServices()" am: 3e21b1745c am: 60182dbe4e
am: 27b0eebb4d

Change-Id: I46acfd104ac3457126c3ccef5041788e4146321c
2017-05-02 09:04:59 +00:00
Hugo Benichi
459c68c725 Merge "NsdManager: unit test coverage for servive registration" am: b0e408450c am: bc57faa1ac
am: 9a3e69d9b6

Change-Id: Ideabb1c929ddd4307e66831cddb20e2feac2c6d9
2017-05-02 06:49:52 +00:00
Hugo Benichi
287730e764 NsdManager: add test coverage for discoverServices()
Test: added new tests
Bug: 37013369, 33298084
Change-Id: If6c1113ee1bd4690db90abd5a61c3e229c827aec
2017-05-02 15:26:33 +09:00
Hugo Benichi
3ec710f6f0 NsdManager: unit test coverage for servive registration
This patch adds test coverage for NsdManager#registerService() and
NsdManager#unregisterService(). This test shows a potential defect in
the api: if unregisterService() fails, the associated listener is always
unregistered from NsdManager. If the service initially registered is
still registered, this potentially make it impossible to unregister.

Test: added new unit test
Bug: 37013369, 33298084
Change-Id: Ia089b6d2f2a349907a8b29d9a3acd7f59e177887
2017-05-02 13:31:24 +09:00
nharold
ee588f0304 Merge "Hide IpSecManager, IpSecTransform, and IpSecAlgorithm" am: 01e368f26d am: 939528045a
am: 52dab83f7a

Change-Id: I3bf240b35c3d509c4e016ffe20519c1bda5ab0b3
2017-04-26 17:38:58 +00:00
Nathan Harold
185f2ccd1c Hide IpSecManager, IpSecTransform, and IpSecAlgorithm
These classes, originally planned to be part of the
public API, are not ready for public consumption.
They are planned to be un-hidden in a future release.

Bug: 37681043
Test: make update-api and make
Change-Id: I8caccd3f8455341cb56a2256354eacbadedff047
2017-04-26 06:50:54 +00:00
Nathan Harold
7194bb9bf9 Hide IpSecManager, IpSecTransform, and IpSecAlgorithm
These classes, originally planned to be part of the
public API, are not ready for public consumption.
They are planned to be un-hidden in a future release.

Bug: 37681043
Test: make update-api and make
Merged-In: I8caccd3f8455341cb56a2256354eacbadedff047
Change-Id: I8caccd3f8455341cb56a2256354eacbadedff047
(cherry picked from commit e38565fc74ee19e27175782be3cf2f0dffefd3a6)
2017-04-25 16:53:50 -07:00
Hugo Benichi
3b40687000 Merge "NsdManager: add unit tests" am: dc54ad7fc3 am: 40ab8401b2
am: d2181235b9

Change-Id: I7a5202be0e6a6274f3bd11737f30fee0ef947235
2017-04-22 00:57:48 +00:00
Hugo Benichi
0b1540e40d NsdManager: add unit tests
This prepares some refactoring and the addition of a timeout to
resolveService.

Test: new tests pass
Bug: 37013369, 33298084
Change-Id: Ie8277bd5983278507bfa70495b4ce7d13895b24b
2017-04-21 05:16:37 +00:00
Hugo Benichi
4a786f94c2 Merge changes Ic029cc9f,Id917f3a2 into oc-dev
* changes:
  NsdService: minor cleanups
  Nsdmanager/NsdService: add logging
2017-04-20 04:27:50 +00:00
nharold
d19fe145b9 Merge changes from topic 'ipsec-hide-overloads' am: fe358c6adf am: 8508bc52d2
am: 6eab2ee093

Change-Id: Iaa713ba4b20bab12331bd996288ed2440c349db2
2017-04-18 22:12:54 +00:00
Nathan Harold
31af88727b Consistenly Throw IOExceptions from IpSecManager am: a64b019f94 am: 5db180bbb7
am: 7883c5d460

Change-Id: I04198299d43da4c9c91f705acc5520f734ad9249
2017-04-18 22:11:18 +00:00
Nathan Harold
b2b85df5d6 Hide Socket+DatagramSocket IpSecTransform methods
These methods do not currently work for IPv4 sockets,
so they need to be hidden until the underlying kernel
code can be made to work properly in a dual-stack
environment.

Bug: 36073210
Test: compilation
Merged-In: Idce367f638a42da374a7f1dc5ebb8931c9555e06
Change-Id: Idce367f638a42da374a7f1dc5ebb8931c9555e06
(cherry picked from commit da18b028f85e9a2c969c636aea6abf7f4bac3922)
2017-04-17 20:23:51 -07:00
Nathan Harold
2528c66a66 Consistenly Throw IOExceptions from IpSecManager
Bug: 36073210
Test: api-update
Change-Id: Ia3825e85b09b6330f1326a26cf9e1cadf9dacf71
Merged-In: Ia3825e85b09b6330f1326a26cf9e1cadf9dacf71
(cherry picked from commit c2fd6cfdc9dce33d57a3c2780e0527dd4b1bfeb9)
2017-04-17 20:23:34 -07:00
Nathan Harold
4b909c85f6 Hide Socket+DatagramSocket IpSecTransform methods
These methods do not currently work for IPv4 sockets,
so they need to be hidden until the underlying kernel
code can be made to work properly in a dual-stack
environment.

Bug: 36073210
Test: compilation
Change-Id: Idce367f638a42da374a7f1dc5ebb8931c9555e06
2017-04-17 19:41:08 -07:00
Nathan Harold
a64b019f94 Consistenly Throw IOExceptions from IpSecManager
Bug: 36073210
Test: api-update
Change-Id: Ia3825e85b09b6330f1326a26cf9e1cadf9dacf71
2017-04-17 17:57:41 -07:00
Hugo Benichi
b6389543d4 Nsdmanager/NsdService: add logging
This patch adds basic logging to NsdManager and NsdService, and improves
the facilities for pretty printing the event ids defined in NsdManager.

It also includes a few minor cleanups:
  - adding 'final' on effectively final instance variables of NsdManager
  and NsdService.
  - similarly, adding 'static' on effectively static class fields.
  - regrouping instance variables together.

Test: no functional changes
Bug: 33074219

(cherry picked from commit 2183ba9b5f8eb54c74cd198a7506b21319794e99)

Merged-In: I360d539e73cc8e4b45d4e0d20b2e345455fdb10c
Change-Id: Id917f3a2085d17f277850af36a2cf859e3614a0f
2017-04-17 10:07:05 +09:00
Nathan Harold
0bb49fc68c Add FileDescriptor Versions of applyTransportModeTransform()
Because there is no way using the Java sockets API to actually
get a socket of AF_INET on mode machines, it is necessary to
provide a way to apply transforms to sockets made using the
native wrapper API, which uses POSIX APIs and will create a
socket that is AF_INET.

Bug: 36073210
Test: b/34811227
Change-Id: I28ac7cc4f36045ce523a54111e5be975b0331356
2017-04-13 15:05:13 -07:00
Nathan Harold
ed0fcf1faf IpSecManager and IpSecAlgorithm API Tweaks
-Add a reserveSecurityParamterIndex() function that allows the
 system to select an SPI.
-Disallow INVALID_SECURITY_PARAMETER_INDEX from being passed as
 an explicit SPI request.
-Remove the ALGO_ prefix from constants in IpSecAlgorithm

Bug: 36073210
Test: Updated CTS tests still pass on bullhead
Change-Id: Ic94809996076b0718f153f550b82192fe7048a2e
2017-04-13 15:04:47 -07:00
nharold
acdb1a217c Merge changes from topic 'ipsec-api-tweaks' am: fddf677b8b am: 176bfb58c6
am: a237a34085

Change-Id: Ie868985d20535f35b869730a4ddaa00dc88a352d
2017-04-12 20:53:17 +00:00
Nathan Harold
480aa304dd IpSecManager and IpSecAlgorithm API Tweaks am: 0540679eb4 am: 9c2428ad4d
am: 99c50add4f

Change-Id: I49641308cd0f2ce3e8a7545c8b03108d69287c64
2017-04-12 20:51:41 +00:00
Nathan Harold
0072e19c8e Add FileDescriptor Versions of applyTransportModeTransform()
Because there is no way using the Java sockets API to actually
get a socket of AF_INET on mode machines, it is necessary to
provide a way to apply transforms to sockets made using the
native wrapper API, which uses POSIX APIs and will create a
socket that is AF_INET.

Bug: 36073210
Test: b/34811227
Change-Id: I28ac7cc4f36045ce523a54111e5be975b0331356
2017-04-11 10:14:11 -07:00
Nathan Harold
0540679eb4 IpSecManager and IpSecAlgorithm API Tweaks
-Add a reserveSecurityParamterIndex() function that allows the
 system to select an SPI.
-Disallow INVALID_SECURITY_PARAMETER_INDEX from being passed as
 an explicit SPI request.
-Remove the ALGO_ prefix from constants in IpSecAlgorithm

Bug: 36073210
Test: Updated CTS tests still pass on bullhead
Change-Id: Ic94809996076b0718f153f550b82192fe7048a2e
2017-04-11 10:14:10 -07:00
Hugo Benichi
0a336978a8 Merge changes I9ad4ce81,I360d539e am: f34d09ac30 am: 4062ac81be
am: 84c878ecc8

Change-Id: Ieeb3222246c63292a75ad91e9c867eaedcad8f90
2017-04-06 02:13:07 +00:00
Nathan Harold
7c30d6b8f2 Add Initial IPsec APIs to IpSecService
-Plumb IpSecManager APIs to NetD
-Add Resource Management to IpSecService

Bug: 30984788
Test: b/34812052, b/34811227
Change-Id: Ic43965c6158f28cac53810adbf5cf50d2c54f920
(cherry picked from commit 93962f34ce21f5aac825afbcebf2f3e8c7a30910)
2017-04-05 10:24:45 -07:00
Nathan Harold
8e518b4255 IpSecManager and IpSecTransform API Cleanup
-Remove Int-based SPI usage from the IpSecTransform.Builder
 This is essentially a less-safe method overload, and it is both
 unnecessary and difficult to implement: the cross-validation
 between SPI and Transform is actually useful, and the kernel
 requires two different mechanisms to use an unreserved vs a
 reserved (alloc'd) SPI: CREATESA vs UPDATESA, which makes this
 hard to support. API Council has questioned the value of this,
 and they are right: everything points to "remove this". In the
 future, if we find that SPI reservation is overhead, we can
 always add it back.

-Hiding the TunnelMode builder method and application/remove
 methods. These will not land by the time the next API
 stabilizes, so better to hide them now that this is a
 near-certainty. Expectation is to un-hide them in the subsequent
 API bump.

Bug: 36073210
Test: Compilation, verified nobody is calling these stubs
Change-Id: Ic1a3f2cf7128633318ac175d6b56b45eb8d21cab
(cherry picked from commit 48b566557d5a66d4476008b3c59b815eb78cb373)
2017-04-05 10:24:23 -07:00
Nathan Harold
18fd608286 Change reserveSecurityParameterIndex() to take a remoteAddress
To make the SPI reservation more semantically consistent with the
transform creation API, and to ensure that we always create SPI
reservations relative to a well-known remote, we should take the
SPI request relative to a remote (rather than to a destination).
This necessitates that we now consider direction separately, which
is used for keying the SA-Id.

Bug: 36073210
Test: compilation
Change-Id: I81e955c20128c1f8e04fd68eb26669561f827a78
(cherry picked from commit c4f879925b58b1b5ca9a3cfdc898c20cbf56355a)
2017-04-05 10:24:03 -07:00
Nathan Harold
8ea66052f2 Add a Skeleton IpSecService
-Add IpSecService with the necessary glue to connect to netd
-Add code to retrieve IpSecService from System Server

Bug: 30984788
Test: b/34812052, b/34811227
Change-Id: I4cdcb643421141202f77a0e2f87a37012de0cd92
(cherry picked from commit 28084d89ec136b56f5012be33a0dea147962f9f6)
2017-04-05 10:23:27 -07:00
Hugo Benichi
32be63d083 Nsdmanager/NsdService: add logging
This patch adds basic logging to NsdManager and NsdService, and improves
the facilities for pretty printing the event ids defined in NsdManager.

It also includes a few minor cleanups:
  - adding 'final' on effectively final instance variables of NsdManager
  and NsdService.
  - similarly, adding 'static' on effectively static class fields.
  - regrouping instance variables together.

Test: no functional changes
Bug: 33074219
Change-Id: I360d539e73cc8e4b45d4e0d20b2e345455fdb10c
2017-04-05 15:05:44 +09:00
nharold
6ca64c9dbe Merge changes from topic 'ipsec-transport-impl' am: 464dc5c07e am: 38e47af3ef
am: 8108bef16d

Change-Id: Ie820478fc01f42b5143a63a3422380ce7ec74847
2017-04-02 00:35:08 +00:00
Nathan Harold
426d6f088f IpSecManager and IpSecTransform API Cleanup am: 55e8910aa8 am: 91b516e78b
am: 37f260f5d8

Change-Id: Ie84a720356466000930030de6f7a9182500afadb
2017-04-02 00:33:17 +00:00
Nathan Harold
031acb850f Add Initial IPsec APIs to IpSecService
-Plumb IpSecManager APIs to NetD
-Add Resource Management to IpSecService

Bug: 33695893
Test: CTS verifies nearly all of these paths
Change-Id: Ic43965c6158f28cac53810adbf5cf50d2c54f920
2017-03-31 18:11:27 -07:00
Nathan Harold
55e8910aa8 IpSecManager and IpSecTransform API Cleanup
-Remove Int-based SPI usage from the IpSecTransform.Builder
 This is essentially a less-safe method overload, and it is both
 unnecessary and difficult to implement: the cross-validation
 between SPI and Transform is actually useful, and the kernel
 requires two different mechanisms to use an unreserved vs a
 reserved (alloc'd) SPI: CREATESA vs UPDATESA, which makes this
 hard to support. API Council has questioned the value of this,
 and they are right: everything points to "remove this". In the
 future, if we find that SPI reservation is overhead, we can
 always add it back.

-Hiding the TunnelMode builder method and application/remove
 methods. These will not land by the time the next API
 stabilizes, so better to hide them now that this is a
 near-certainty. Expectation is to un-hide them in the subsequent
 API bump.

Bug: 36073210
Test: Compilation, verified nobody is calling these stubs
Change-Id: Ic1a3f2cf7128633318ac175d6b56b45eb8d21cab
2017-03-31 11:21:10 -07:00
Nathan Harold
abf3bde466 Merge "Change reserveSecurityParameterIndex() to take a remoteAddress" am: d118826971 am: d083810c0b
am: 81d48a99e0

Change-Id: I941ee00099df0afdbce94b73c1bd81c246fac1e8
2017-03-30 03:48:20 +00:00
Nathan Harold
909d66e80a Change reserveSecurityParameterIndex() to take a remoteAddress
To make the SPI reservation more semantically consistent with the
transform creation API, and to ensure that we always create SPI
reservations relative to a well-known remote, we should take the
SPI request relative to a remote (rather than to a destination).
This necessitates that we now consider direction separately, which
is used for keying the SA-Id.

Bug: 36073210
Test: compilation
Change-Id: I81e955c20128c1f8e04fd68eb26669561f827a78
2017-03-29 17:46:47 -07:00
Nathan Harold
7e854f1b82 Merge commit 'e45e328821ba' into oc-dev-plus-aosp
Change-Id: I30ad9038be8faee57e5d6b1391d9e70a966a9a77
2017-03-29 17:05:10 -07:00
Nathan Harold
d2a1dad9a8 Add a Skeleton IpSecService
-Add IpSecService with the necessary glue to connect to netd
-Add code to retrieve IpSecService from System Server

Bug: 34811227
Test: Service boots (and dumpsys works), more via b/34811227
Merged-In: I4cdcb643421141202f77a0e2f87a37012de0cd92
Change-Id: I4cdcb643421141202f77a0e2f87a37012de0cd92
2017-03-29 11:31:27 -07:00