213 Commits

Author SHA1 Message Date
Joel Scherpelz
d8ea68ddc9 Partially revert "Add blocking and retrying wrappers for INetd uses."
Direct access to Netd from the bluetooth process is disallowed by
SELinux policy. This change reverts to the old behavior where IpManager 
interacts with NetdService indirectly via NetworkManagementService.

Bug: 36492299

This partially reverts commit af39244a34f4449c12a5f925222c9bc8d8049320.

Change-Id: Icf20b1e24abf7dd3123760f8637928bde7afe06b
2017-03-30 01:18:44 +00:00
Erik Kline
af39244a34 Add blocking and retrying wrappers for INetd uses.
Test: as follows
    - built (bullhead)
    - flashed
    - booted
    - runtest frameworks-net passes

Change-Id: I1a8e15149bf9dbedc6a09c0d8ab6abb2ef4f8fee
2017-03-15 16:23:29 +09:00
Lorenzo Colitti
58ebe1c6f1 Rename AvoidBadWifiTracker to MultinetworkPolicyTracker
Rename the class and ensure that all code related to bad wifi
avoidance has names that reflect its purpose.  This will allow us
to reuse most of the the code for other purposes in future CLs.

Test: runtest frameworks-net passes
Bug: 34630278
Change-Id: Ida190e5a79e7a12f4eec07e1a3e4d9d138e83bcd
2017-01-31 15:42:57 +09:00
Hugo Benichi
4456f33a95 ApfTest: fix flaky testApfFilterRa.
testApfFilterRa is failing with probabiliy 1/10 ~ 1/15 on the following
assert: assertDrop(program, packet, lifetime/6), for lifetime values
that are multiple of 6, where 6 is the hardcoded fraction of RA lifetime
to filter in ApfFilter.java.

When the lifetime is not a multiple of 6, the remainder of 1 to 5
seconds gives enough margin so that when the APF program is simulated
the faked lifetime of the program is less than lifetime/6 away and the
packet is dropped.

However for lifetimes which are exact multiples of 6, this margin is
always 0s and that result in nondeterminism in the result. This is
consistent with the obervation that the only failed assert was for a
lifetime of 300s, the only multiple of 6.

This can be observed by detecting the age limit at which the filter
stops dropping packet oscillating between lifetime/6 and lifetime/6 + 1
for lifetimes which are multiple of 6.

This patch fixes the flakyness by freezing the flow of time in tests so
that the expected filter age threshold is consistent and stable.

Test: no failure observed in 1000 runs.
Bug: 32561414
Change-Id: I5251d047039f34b82ce8a5d20ae46563e1e0cce8
2017-01-31 11:13:44 +09:00
Treehugger Robot
e7128b10a8 Merge "Don't loop forever on zero-length ICMPv6 ND options." 2017-01-20 08:47:17 +00:00
Lorenzo Colitti
1eda5b25ce Don't loop forever on zero-length ICMPv6 ND options.
Bug: 33828433

(cherry picked from commit 2f157c421a9fa15660b8f1bc0c64b1ebb45fa64a)

Change-Id: Icc03f0fcbf40d87e0b9c69e1172802ffcc85531b
2017-01-20 15:48:21 +09:00
Erik Kline
fed4194af0 Eschew unspecified IP addresses for DNS servers
Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-wifi passes (though no test covers this code yet)
Bug: 34210527
Change-Id: I2d44445982dfb3221f7b6394daf0479c1fa8a6e1
2017-01-19 17:01:46 +09:00
Erik Kline
ade3a8ccb0 Have IpManager track L2-L4 signaling traffic required for IP connectivity.
Test: as follows
    - built and flashed
    - observed logcat
    - observed "dumpsys wifi ipmanager"
    - runtest BlockingSocketReaderTest passes
    - runtest ConnectivityPacketSummaryTest passes
Bug: 21859053
Bug: 26101306
Bug: 31742572
Bug: 31707128
Bug: 33531488

Change-Id: Ibecaf809dcc1813924b25749e8ba8eb2d4bdf114
2016-12-15 19:09:49 +09:00
Erik Kline
c8585b9742 More correct startup and shutdown procedures.
During IpManager startup, anything sending messages to the state machine
must not begin doing so until after the state machine has been started.
Reorder the constructor accordingly.

During shutdown, AvoidBadWifiTracker needs to unregister the registered
BroadcastReceiver and might as well also unregister the ContentObserver.

Test: backport from internal
Bug: 33388922
Change-Id: I58e07f7ccddaab160c153bcfb69fd45f50bb8710
2016-12-15 10:43:41 +09:00
Erik Kline
511818ffb3 DHCPv4 anonymity profile: support skipping hostname option
Per https://tools.ietf.org/html/rfc7844#section-3.7

   When using the anonymity profile, DHCP clients SHOULD NOT send the
   Host Name option.

Once the net.hostname property is removed and ensured unset via CTS
this option will no longer be sent.

Test: as follows
    - build, flashed
    - connected to v4-only and dualstack networks, verified v4 works
    - android.net.dhcp.DhcpPacketTest passes
    - setprop net.hostname "" and verified no hostname option
Bug: 30979015
Change-Id: Ieab3f04ea38e176d9147bb788742a5397762c2e4
2016-12-13 18:14:44 +09:00
Hugo Benichi
02428988ad DO NOT MERGE: APF: also drop any ICMPv6 RSs
Test: new unit test + $ runtest franeworks-net
Bug: 32833400

(cherry picked from commit f98182ef5e80ede5de7f2c2a5f40fc92a46c9704)

Change-Id: Ifaf6e778c811c7d865c790a293b1fce3f43cad1c
2016-12-09 13:59:19 +09:00
Hugo Benichi
dafc44ea11 DO NOT MERGE: ApfFilter: use elapsedRealTime for RA lifetime
This patch replaces System.currentTimeMillis() with
SystemClock.elapsedRealTime() to make RA lifetime computation more
resilient to various external events inducing jumps in
currentTimeMillis().

Test: ApfTest passes.

(cherry picked from commit 305af8e98a4fce712c1a93daf3b050dac2e8b91a)

Change-Id: If19011fc0c905948f2e42b975cfcc5f8672a95fb
2016-12-08 17:13:33 +09:00
Hugo Benichi
94dcb3c3fd DO NOT MERGE: Do not synchronize boolean reads/writes
This patch removes the synchronization around the private variable
mRunning inside of IpReachabilityMonitor and instead qualifeis the field
as volatile.

Synchronization is not needed for reads/writes on native fields or
object references because they are already guaranteed to be atomic.

Synchronization here was used for enforcing memory visibility across
concurrent threads indirectly through monitor acquire/release.
The volatile keyword achieves this in a more explicit way.

Also, this patch changes the way that probeAll() copies the
IpReachabilityMonitor's mIpWatchList by temporary holding mIpWatchList
keys into an ArrayList instead of a more expensive HashSet. Since Java
HashSet are just degenerated HashMaps, and that key iteration order is
based on key hash, the iteration order over this temporary collection
will be consistent for the same mIpWatchList.

Test: refactoring CL. Existing unit tests still pass.

(cherry picked from commit b0f1186c034c4df9eb54ed29944d16ce6d7ade56)

Change-Id: I48d2b4d837a459150cd431b400ec01b87b48c014
2016-12-08 17:13:32 +09:00
Hugo Benichi
4104ff9220 DO NOT MERGE: ApfFilter: systematically use u8, u16, u32 getters
This patch adds a getUint8 getter for ByteBuffers and changes ApfFilter
to make uses of getUint8/16/32 everywhere.

The return types of getUint16 is also changed from long to int, which
will expand gracefully to long as an unsigned int as it is guaranteed to
be positive after getUint16.

Test: ApfTest passes

(cherry picked from commit 995dd94673005b43d32456e2de5fda0090b23576)

Change-Id: I606ebc5aedfcacde400d27cc6bc37145769b122c
2016-12-08 17:13:32 +09:00
Hugo Benichi
0668a61d82 DO NOT MERGE: Add fuzzing tests to ApfFilter RA processing
Test: added new unit tests

(cherry picked from commit 8acea76a2b7555b3bd5ca1170cca9d09e979fafc)

Change-Id: I847d7e4895766042043c0bba1c9b9a698a705d87
2016-12-08 17:13:31 +09:00
Erik Kline
b406666cf5 Handle IpReachabilityMonitor errors better.
If construction of a new IpReachabilityMonitor throws an IAE then
log it and immediately call onProvisioningFailure().

Test: runtest frameworks-wifi
      passes, except for selectQualifiedNetworkDoesNotChooseDeletedEphemeral()
      which fails with an NPE for unrelated reasons.

Bug: 31038971
Bug: 31742703
Change-Id: Ie91b8bdd509d06ad54d062bf446e74c092eb096c
(cherry picked from commit e4526604664cb66ecdcbeca4d8f64e8c94750c31)
2016-12-07 16:23:26 +09:00
Hugo Benichi
1ade34dd76 Reject DHCP packets with no magic cookie
am: 006e061301

Change-Id: I54a32519d13e8d5463ca86630540722d73ff75cb
2016-10-07 02:29:49 +00:00
Hugo Benichi
c4a13afe92 Catch runtime exceptions when parsing DHCP packets
am: e0ea7fecd6

Change-Id: I1e701bb19b5c062f1527dd3e5b79e2e7860ca025
2016-10-06 21:11:47 +00:00
Hugo Benichi
006e061301 Reject DHCP packets with no magic cookie
This patch adds an explicit check in the DHCP packet parser for
rejecting packets without a magic cookie, instead of relying on the
top-level try-catch-all in the parser.

This allows to add to DHCP error metrics this specific error.

It also allows to add two poor man's fuzzing tests that tries to find
additional gaps in the DHCP packet parser by
 - trying to parse all subslices of a valid offer packet.
 - trying to parse random byte arrays.

Test: covered by previously introduced malformed DHCP packet unit tests
      + additional fuzzing tests.
Bug: 31850211
Change-Id: If53c9ba9df78d7604ec018c9d67c237ae59c4833
2016-10-06 21:22:29 +09:00
Hugo Benichi
e0ea7fecd6 Catch runtime exceptions when parsing DHCP packets
This patch adds a try catch all to DHCP packet parsing so that
DhcpClient does not choke on malformed packets, brinding down with it
the whole framework.

Test: added new unit tests catching the issue fixed in this patch.
Bug: 31850211
Change-Id: I3c50a149fed6b2cbc4f40bb4f0e5bb2b56859b44
2016-10-05 21:58:26 +09:00
Lorenzo Colitti
d2ad8ece53 Ignore loss of IPv6 provisioning when not avoiding bad Wi-Fi.
am: f11ee9f592

Change-Id: I3090ac5fe7dabf2ee19120bd0ab566edaa95ddb6
2016-10-04 07:50:14 +00:00
Lorenzo Colitti
fdac9b608b Slightly simplify IpManager#compareProvisioning.
am: b77b775213

Change-Id: I31ab37d3fc39baf73fa14ef3b54b781b60347b41
2016-10-04 07:49:23 +00:00
Erik Kline
d719d95139 Conditionally accept loss of on-link IPv6 DNS servers
am: 5b437d6ff9

Change-Id: Ie32080d7918dea0ae89bd3e0987cb1c8f121e0bd
2016-10-04 07:48:46 +00:00
Erik Kline
23cdacbec6 Refactor "avoid bad wifi" logic into a utility class
am: 065ab6ee40

Change-Id: I4a6ad3791ac551b0d64b37dd4e2afef1e8e8ee10
2016-10-04 07:47:52 +00:00
Lorenzo Colitti
f11ee9f592 Ignore loss of IPv6 provisioning when not avoiding bad Wi-Fi.
Bug: 31827713
Change-Id: I81471f2f3e6c1c4d7bdfebc9dd321bb9d76ad0b6
2016-10-04 15:07:44 +09:00
Lorenzo Colitti
b77b775213 Slightly simplify IpManager#compareProvisioning.
Bug: 31827713
Change-Id: Icc1c8d98feef14c972891451fd94f855d78de43e
2016-10-04 15:07:44 +09:00
Erik Kline
5b437d6ff9 Conditionally accept loss of on-link IPv6 DNS servers
Permit this if and only if we're not "avoiding bad wifi" in general.

Bug: 31827713
Change-Id: I0874ec2d1d09e913ccdbe9f6e178090400808a04
2016-10-04 15:07:43 +09:00
Erik Kline
065ab6ee40 Refactor "avoid bad wifi" logic into a utility class
Additionally, add this utility class to IpManager for compatibility
verification.  A follow-on CL will make use of IpManager's local
AvoidBadWifiTracker.

Bug: 31827713
Change-Id: If8c56c3f8076d6a5157ea180e361bbdadc2bc1dd
2016-10-04 15:07:42 +09:00
Erik Kline
c3eec4fff9 Support triggering confirmConfiguration() via dumpsys
Tested:
  - flashed to device
  - triggered
  - monitored tcpdump for the expected traffic

Bug: 30869013
Change-Id: I6a4741bdeed2aaa483f8c2281acb74d245a323e8
2016-09-28 15:19:00 +09:00
Erik Kline
8ec1dc8117 Handle more commands in StoppingState
Also, expand the logging of states in which messages are
received and handled.

Bug: 31264287
Change-Id: If633984cb54128716fc9b3fcb27925906d0bd826
2016-09-20 17:20:57 +09:00
Hugo Benichi
7d21eaedad ApfFilter: take into account IPv4 subnet prefix
When IPv4 is provisioned on an interface with Apf capabilities,
ApfFilter will only keep track of the raw ipv4 address, with no
information about the subnet or prefix length.

This patch adds the missing prefix length information to ApfFilter. This
allows to calculate the subnet broadcast ipv4 address for more
precise ipv4 broadcast filtering when the multicast lock is not held.

Bug: 30231088

Change-Id: Iebaec040703647c4ced30bb585be173e97a1fae5
2016-09-13 10:54:47 +09:00
Hugo Benichi
0dc1d31470 ApfFilter: more precise IPv4 broadcast filter
This patch refines the Apf IPv4 filter for interfaces with Apf
capabilities to drop packets when:
  - the multicast lock is not held
  - the packet is an IPv4 packet
  - the packet is not a DHCP packet addressed to us
  - the packet is L2 broadcast, or IPv4 multicast, or IPv4 broadcast
      - caveat: subnet broadcast address is not checked.

This allows to drop IPv4 broadcast packets whose MAC destination
address is not the L2 broadcast address but the current address of the
interface. Such packets can be received on network that rewrite L2
addresses and can put significant pressure on battery by waking up the
phone unnecessarily.

Bug: 30231088

Change-Id: I8b1785fc5ceadaa1f2881765983e502135dcbc46
2016-09-13 10:54:42 +09:00
Hugo Benichi
961ca49fd6 Better IPv4 multicast coverage in ApfTest
This patch improves the test coverage of ApfFilter for IPv4 broadcast and
multicast traffic.

Bug: 30231088
Change-Id: I2e1d5d5a7cbae17f3d5978a4cf5f10666b5c6104
2016-09-08 14:03:46 +09:00
Erik Kline
ee5de9d245 Remove INetd AIDL reference
Change-Id: I29dfee480a4706213b36766724b6211dbc74dbac
2016-08-30 11:40:20 +09:00
Erik Kline
c1bc0be161 Add simple NetdService util class
Hopefully we can avoid a small amount of repeated wrapper code.

Bug: 21859053
Bug: 28135208
Change-Id: I00f404f19c14a1726071e62e558f551dccf8b915
2016-08-25 16:25:39 +09:00
Erik Kline
e845cf22c1 Merge "Ensure known good state when starting." into nyc-mr1-dev 2016-08-22 02:55:41 +00:00
Erik Kline
d1dcbefe06 Fix up some comments in IPv6 tethering code.
Bug: 30298058
Change-Id: Icc99e772898b8303d8f2f8521784e2cb5c2afacc
2016-08-10 10:00:32 +09:00
Erik Kline
fa37b2f613 Handle setting and deprecating local DNS IPv6 addresses
[ IPv6TetheringCoordinator ]

  - Send CMD_IPV6_TETHER_UPDATE to all TetherInterfaceStateMachines.

This results in some spurious noop messages, but currently
the coordinator does not maintain state about which downstream interaces
are serving IPv6 and which are not.  Until it does maintain such state
it does not know to notify only the affected interfaces about a loss of
IPv6 upstream

[ IPv6TetheringInterfaceServices ]

    - De-dup incoming IPv6-only LinkProperties to avoid spurious updates
      to the RA daemon.
    - Keep track of new prefixes/dns and newly deprecated prefixes/dns
      on each update.
        - Set and remove local_network routes based on new and newly
          deprecated prefixes.
        - Set and remove local DNS server IP addresses based on new
          and newly deprecated DNS servers. Update dnsmasq via netd
          accordingly.
    - Pass newly deprecated and new information to the RA daemon.

[ RouterAdvertisementDaemon ]

    - Receive newly deprecated prefixes/DNS and update local tracking
      data structures accordingly.
    - Properly send urgent final deprecation RAs, and then cease all
      transmissions.

Bug: 30298058
Change-Id: Idc821603fa93bff1a821d1180d4135bc70e4a08d
2016-08-09 19:19:43 +09:00
Erik Kline
703b0974e0 Ensure known good state when starting.
Split StartedState into StartedState and RunningState, and ensure
known good state before proceeding from the former to the latter.

Bug: 30290336
Change-Id: I0a93f8fe53c65a0b90c28c3cf708792146a92aab
2016-08-08 15:31:08 +09:00
Erik Kline
354607f2ac Deprecate IPv6 prefixes no longer in use.
Bug: 30298058
Change-Id: I0fa9ece9b2fb07214971a91b77f5b07972d83bb6
2016-08-02 12:51:24 +09:00
Paul Jensen
4e40413c50 Merge "Sanity check ICMP6 router advertisement packets" into nyc-mr1-dev 2016-07-26 14:30:00 +00:00
Paul Jensen
4b545b04f6 Sanity check ICMP6 router advertisement packets
There is a chance a packet can slip by before we install the filter
on our socket listening for RAs, so add some basic sanity checking
to make sure we've recieved an RA.

Change-Id: I14cf84a0814896a41e00f50af376dfc4988d36cb
Fixes: 29586253
2016-07-20 15:01:17 -04:00
Erik Kline
e33daf1295 More correctly close RA daemon socket.
Bug: 9580643
Bug: 30190913
Change-Id: I34e34624da09957d96fee38c3f2005e23eb1bee5
2016-07-19 22:44:21 +09:00
Hugo Benichi
38db976514 APF: filter unwanted ARP replies
This patch adds APF filtering of ARP replies for interfaces with APF.

- when the interface has no IPv4 address, broadcast ARP replies with a
  0.0.0.0 target ip are dropped (GARP), ARP requests with a 0.0.0.0
  target ip are dropped.

- when the interface has an IPv4 address, broadcast ARP replies to a
  different ip are dropped (including GARPs to 0.0.0.0), ARP requests to
  a different ip are dropped.

Bug: 29404209
Bug: 30080487
Change-Id: I82613eb865c7f38b6260997fe2caf2aff382ad78
2016-07-14 23:36:53 +09:00
Erik Kline
a3ca6bd3e0 Basic IPv6 Router Advertisement daemon
Bug: 9580643
Change-Id: Iebd4d1f694699ffd4daf7d71e9b9d8f49e9b632f
2016-07-11 18:37:25 +09:00
Hugo Benichi
42e608527a Merge "IpConn metrics: distinguish NUD_FAILED answers" into nyc-mr1-dev 2016-07-07 13:02:31 +00:00
Hugo Benichi
7643423521 IpConn metrics: add times to DHCP bound state
This patch adds DhcpClientEvent logging for:
 - time from init state to bound state
 - time from bound state to bound state when renewing

Example:
ConnectivityMetricsEvent(12:04:33.353, 0, 0): DhcpClientEvent(wlan0, WaitBeforeStartState, 94ms)
ConnectivityMetricsEvent(12:04:35.772, 0, 0): DhcpClientEvent(wlan0, DhcpInitState, 2417ms)
ConnectivityMetricsEvent(12:04:35.787, 0, 0): DhcpClientEvent(wlan0, DhcpRequestingState, 15ms)
ConnectivityMetricsEvent(12:04:35.793, 0, 0): DhcpClientEvent(wlan0, ConfiguringInterfaceState, 6ms)
ConnectivityMetricsEvent(12:04:35.811, 0, 0): DhcpClientEvent(wlan0, InitialBoundState, 2457ms)
ConnectivityMetricsEvent(12:05:35.791, 0, 0): DhcpClientEvent(wlan0, DhcpBoundState, 59998ms)
ConnectivityMetricsEvent(12:05:35.988, 0, 0): DhcpClientEvent(wlan0, WaitBeforeRenewalState, 196ms)
ConnectivityMetricsEvent(12:05:36.003, 0, 0): DhcpClientEvent(wlan0, DhcpRenewingState, 15ms)
ConnectivityMetricsEvent(12:05:36.010, 0, 0): DhcpClientEvent(wlan0, RenewingBoundState, 219ms)

Change-Id: I2540dd102a6509dff55936e38015265659b20760
2016-07-07 16:10:20 +09:00
Hugo Benichi
0d1c65b221 IpConn metrics: distinguish NUD_FAILED answers
This patch adds in IpReachabilityMonitor a timestamp variable set
everytime that probeAll() send NUD probe requests to RTNETLINK.
This allows to distinguish between:
  1) NUD_FAILED events resulting from such a forced NUD probe
  2) "organic" NUD_FAILED notifications from the kernel

This distinction is added to IpReachabilityEvent as a one-bit flag.

This patch also changes the formatting of ApfProgramEvent flags to use
'|' as a joining character, similarly to other flags formatting.

Bug: 21859053
Change-Id: I24c64a3f17fa283eace5bd0a05c21a90a2305359
2016-07-07 15:58:28 +09:00
Hugo Benichi
54756fdfd9 Merge "IpConn metrics: correctly read RA lifetimes" into nyc-mr1-dev 2016-07-05 12:25:55 +00:00
Hugo Benichi
176ed01a1f IpConn metrics: add dhcp transition times
This patch adds lifetime durations of DhcpClient states to
DhcpClientEvents.

To record the duration of a state, the event is now recorded when the
DhcpClient state machine exits that state.

In addition this patch removes event logging of StoppedState,
DhcpState and DhcpHaveLeaseState.

Change-Id: Ibd37b5e3070f35113b6b45942b1e1ff19c27a90b
2016-07-05 17:32:56 +09:00