156 Commits

Author SHA1 Message Date
Lorenzo Colitti
8995d85b94 Don't loop forever on 0-length options.
A malformed RA could cause the Ra constructor in ApfFilter to
enter an infinite loop while holding the class lock. This blocks
IpManager until reboot and drains the battery.

Bug: 29586253
Change-Id: Idaa46b3bc50371db076630881883807c2fa21674
2016-06-23 15:43:34 +09:00
TreeHugger Robot
83e50327fc Merge "Don't drop IPv4 broadcast packets when WiFi multicast lock is held" into nyc-dev 2016-05-27 14:58:48 +00:00
Paul Jensen
f8a01e8431 Don't drop IPv4 broadcast packets when WiFi multicast lock is held
IPv4 broadcast packets can be very common (e.g. every 2s) so they
need to be dropped in the general case.  They also may be critical
for certain discovery protocols, so allow them through with APF
when the WiFi multicast lock is held.

Bug: 26238573
Change-Id: I03e09a2b9c779da5da775e78b95e9e0339720eaf
2016-05-27 09:18:56 -04:00
Lorenzo Colitti
e67ec4eb01 Restore DHCP client logging.
Bug: 28955598
Change-Id: I2e2684a787061612471830e4d840ce422091bafb
2016-05-27 14:14:03 +09:00
Lorenzo Colitti
d954c6368f Merge "Support IPv6 multicast filtering in APF." into nyc-dev 2016-05-24 03:14:38 +00:00
Lorenzo Colitti
11e13e2175 Support IPv6 multicast filtering in APF.
For now this just drops all non-ICMPv6 packets to ff00::/8 when
mMulticastFilter is true. Multicast ICMPv6 is already mostly
dealt with by other filters - the L2 multicast filter, the RA
filter, the multicast NA filter, and ND offload.

Bug: 28393601
Change-Id: Ia7b0d4f00fac6710093befe6a726b46677a5f20b
2016-05-24 00:02:07 +09:00
Erik Kline
d8e1592e64 Support DHCPv4 rebinding state
Bug: 24837343
Change-Id: Id49e1c12ec3b11fedba42bb28348a00cb0b11169
2016-05-23 23:56:46 +09:00
Erik Kline
acda32c35f DHCPv4: lease expiration is fatal, renew failures are not
Bug: 24837343

Change-Id: Ib330864f8376b0907390d581b48cff5446b3392b
2016-05-18 16:17:03 +09:00
Paul Jensen
90ba8cf379 Merge "Use APF program to drop non-IP non-ARP broadcasts" into nyc-dev 2016-05-13 17:14:47 +00:00
Paul Jensen
b742495cf5 Merge "ApfFilter unit test" into nyc-dev 2016-05-13 14:33:25 +00:00
Erik Kline
2ec229a0ed Support IPv4-only and IPv6-only provisioning
Bug: 28437662
Change-Id: I95b2d6eeb48cc526c8e6e015c5130ff9141fb898
2016-05-13 13:21:25 +09:00
Paul Jensen
9132f34976 ApfFilter unit test
Bug: 26238573

Change-Id: I5171038228782bd54e91f5bcc663cc529d2c1150
2016-05-10 11:54:42 -04:00
Paul Jensen
dd7bee8772 Use APF program to drop non-IP non-ARP broadcasts
This used to be done by some WiFi firmwares but should now be done by APF
for consistency across the board.

Bug: 28304368
Change-Id: Ic75f408affc1f56e1ecf4d347d0c287aa72250bf
2016-05-10 11:33:30 -04:00
Erik Kline
fc2e5b6703 IpManager: add distinct DhcpActionTimeoutAlarm
Track provisioning timeouts separately from "DHCP action" timeouts.

Bug: 17733693
Bug: 24837343
Change-Id: I6071699692e7d375155a4c4fe61c7ec0d89396c0
2016-04-28 16:52:10 +09:00
Lorenzo Colitti
adacedb1a8 Notify success before configuring the IP address.
This ensures that IpManager has a complete copy of DHCP state
before configuring the IPv4 address. That way, when the netlink
notification of the IPv4 address arrives, we are guaranteed to
have all DHCP information (including DNS servers and routes)
available and we will never send the IPv4 address before the DNS
servers.

Bug: 27605330
Change-Id: I732424dfe2408be9e40028563e99d610b541e12d
2016-04-28 13:56:50 +09:00
Erik Kline
9c51583daf Merge "IpManager: add a provisioning timeout option" into nyc-dev 2016-04-27 09:40:08 +00:00
Erik Kline
741b15dc75 IpManager: add a provisioning timeout option
Relatedly: remove the provisioning timeout from DhcpClient.

Bug: 17733693
Bug: 24837343
Change-Id: I6d5b835b4ca70ba6fd06df359fc2128a0df46252
2016-04-27 16:27:44 +09:00
TreeHugger Robot
24b6e2bcc8 Merge changes I8de95add,Ia6f4ccfd into nyc-dev
* changes:
  Remove unused event tags of IpConnectivityEvent
  Better ConnectivityMetricsEvent printing
2016-04-27 01:49:53 +00:00
Hugo Benichi
5df9d729f6 Better ConnectivityMetricsEvent printing
This patch adds more information printing for IpConnectivity event
classes in android.net.metrics.

example:

ConnectivityMetricsEvent(14:36:35.799, 0, 1026): DhcpClientEvent(wlan0, DhcpRequestingState)
ConnectivityMetricsEvent(14:36:35.805, 0, 1026): DhcpClientEvent(wlan0, DhcpHaveAddressState)
ConnectivityMetricsEvent(14:36:35.809, 0, 4096): IpManagerEvent(wlan0, PROVISIONING_OK, 155ms)
ConnectivityMetricsEvent(14:36:35.810, 0, 1026): DhcpClientEvent(wlan0, DhcpBoundState)
ConnectivityMetricsEvent(14:36:35.871, 0, 2048): NetworkEvent(101, NETWORK_CONNECTED, 0ms)
ConnectivityMetricsEvent(14:36:35.874, 0, 2051): ValidationProbeEvent(101, PROBE_HTTP:599, 3ms)
ConnectivityMetricsEvent(14:36:35.874, 0, 2048): NetworkEvent(101, NETWORK_VALIDATION_FAILED, 0ms)
ConnectivityMetricsEvent(14:36:35.928, 0, 3072): DefaultNetworkEvent(0 -> 101, [WIFI], IPv4: false, IPv6: false)
ConnectivityMetricsEvent(14:36:37.008, 0, 2051): ValidationProbeEvent(101, PROBE_HTTP:204, 134ms)
ConnectivityMetricsEvent(14:36:37.008, 0, 2050): NetworkEvent(101, NETWORK_VALIDATED, 1137ms)

Also fixes a couple of event logging issues:
  - do no record spurious receive DhcpErrorEvent when a network goes down.
  - add an eventType field to IpManagerEvent instead of using the
    loggger component tag.

Bug: 28204408
Change-Id: Ia6f4ccfd7a0c63a5ccec18825f226c0b5781217b
2016-04-27 09:11:29 +09:00
Erik Kline
5b76623a0e Move IPv4 address setting to IpManager
Bug: 24837343
Bug: 27605330
Change-Id: I19ac80e45b3e9200f81d1166ac6094fd19aee963
2016-04-26 17:19:44 +09:00
Erik Kline
b2ff48bd71 IpManager: delete dead getLinkProperties() code
Now that it's long since been unused also delete the locking that was
introduced to make it possible.

Bug: 17733693
Bug: 24837343
Change-Id: Iee817a7c2e1d1dc9c080d3124d5986232dcda00f
2016-04-26 15:54:12 +09:00
Erik Kline
a84572b503 Add state and callback logs for IpManager dump
Bug: 27605330
Change-Id: I2e659d08fa9acd57a71901f28c85a92c0876c663
2016-04-25 13:11:58 +09:00
Erik Kline
c2827857aa IpManager,DhcpClient: catch some errors and better logging
Bug: 28196843
Change-Id: Ia91e926da569bf9c503ea00e1e0f767d196547da
2016-04-21 21:13:59 +09:00
TreeHugger Robot
b99d6af3ab Merge "Expand NetworkMonitor metrics" into nyc-dev 2016-04-21 05:24:40 +00:00
Erik Kline
a488c23dd5 Expand NetworkMonitor metrics
- add netid to CaptivePortalStateChangeEvent
    - add NetworkMonitorEvent for simple duration measurements

Bug: 28204408
Change-Id: I62035e07d64013878a0bce30c67c929c2c7e7a85
2016-04-21 13:02:55 +09:00
Hugo Benichi
25bf8f5d56 Various fixes in IpReachability event logging
- fold IpReachabilityMonitor* classes into a single IpReachabilityEvent.
- only log an event for NUD_FAILED Netlink answers.
- distinguish between NUD_FAILED with or without lost of provisioning.
- do not record host ip addresses.
- record interface name instead of interface index when losing
  provisioning.

- also return an error code when probeNeighbor fails, and log this error
  code in IpReachability events.

Bug: 28204408
Change-Id: I5f0def0ab1ace7e467a0c69b3b82d07ef2252307
2016-04-21 09:18:50 +09:00
Paul Jensen
520ae86666 Merge "Avoid APF JNEBS instruction with R1 as it doesn't work" into nyc-dev 2016-04-18 10:56:14 +00:00
Hugo Benichi
2677b1957b Fix spurious DHCP parse error logging.
This patch moves the event logging of DHCP response packet parse errors
to DHCPClient in a single place. It also logs receive IO errors as
DHCPErrors instead of DHCPClientEvents.

BUG=28197345

Change-Id: I7ad666cff4d8b97915880477347fbb3f588fdb2a
2016-04-18 11:27:35 +09:00
Paul Jensen
91723d7f7e Avoid APF JNEBS instruction with R1 as it doesn't work
APF version 2 and prior versions fail to execute JNEBS with R1 argument.
The APF interpreter tries to use R1's value as the number of bytes to
compare, as well as the offset within the packet to compare at.
This change makes ApfFilter avoid using this and makes the APF generator
throw if this is used.  This was limiting the IPv4 filter, causing it to
only drop multicast (when multicast filtering was enabled), rather than
a wider range of broadcast packets.

Bug: 28206777

Change-Id: I8d116e024e8bd641b21053c6b1defc734d744467
2016-04-15 13:18:19 +00:00
Hugo Benichi
fc18b6f360 Merge "Add DHCP error event class and record DHCP errors." into nyc-dev 2016-04-14 08:01:31 +00:00
Hugo Benichi
6241874355 Add DHCP error event class and record DHCP errors.
This patch adds an event class derived from IpConnectivityEvent that
records parsing errors of DHCP response packets.

Change-Id: I19516cf05e3419c4262e3236899e52987e5f2264
2016-04-14 15:40:10 +09:00
Hugo Benichi
fbd47caf40 Merge "Add volatile qualifier to boolean variable" into nyc-dev 2016-04-14 04:19:50 +00:00
Erik Kline
5b25a0f796 Add some more metrics: IpManager, IpReachabilityMonitor
Change-Id: Ibb7150c849715a42fc2c879589eaaf86e8a007e7
2016-04-14 10:53:30 +09:00
Erik Kline
0a0e1dcdc6 Also consider loss of IPv6 default route to be fatal
Bug: 27962810
Change-Id: I735d71ddc71da701eebbb9969f6e1cbffd7e1a1c
2016-04-13 19:47:26 +09:00
Hugo Benichi
67530d6585 Add volatile qualifier to boolean variable
DHCP receive thread was spinning on a boolean variable to know when to
stop. That variable had no volatile qualifier, potentially preventing
the thread from stopping at all. Without a volatile qualifier, the reads
and writes in halt() could be reordered in such a way that the running
thread is interrupted before mStopped is set t true. Also, the optimizer
could decide to hoist mStopped in a register inside the running thread,
preventing the loop from exiting.

Change-Id: I5b30c1247808114f0e5b46e230978ee7ea18ab8e
2016-04-13 11:16:51 +09:00
Erik Kline
071b6dfdee Trigger enabling of NDO when startProvisioning() is called.
Bug: 26238390
Bug: 27598285
Change-Id: I1f63bdd27defd43f994d259d07a943872df4f47c
2016-04-12 23:01:23 +09:00
Lorenzo Colitti
059e2bb376 More APF debuggability.
1. Decode RDNSS options.
2. Keep track of how many times the program was updated.
3. Remove the leading / from the IPv4 address.

Change-Id: Ida0518a94ea7d952c82c8181b09044eff907b714
2016-04-08 23:09:25 +09:00
Lorenzo Colitti
19e84f7b75 Merge changes Ibb63f6b4,Ib64559a5 into nyc-dev
* changes:
  Clean up netd state when tethering fails.
  Clear LinkProperties on interface removed.
2016-04-05 13:35:09 +00:00
Lorenzo Colitti
a3d5948c37 Clear LinkProperties on interface removed.
When an interface is removed, all netlink events for that
interface are lost, because netd will no longer be able to
resolve the ifindex in the netlink event to an interface name,
and it only communicates to the framework events that include an
interface name.

This can cause us to end up with stale IP addresses if, for
example, wlan0 is removed because we switch wifi back from AP
mode to STA mode when exiting tethering. The presence of stale
IPv4 addresses can in turn lead us to miss a provisioning
notification because we already think we have an IPv4 address.

Change-Id: Ib64559a5a4fa261f483760b69fa7996314e7cc17
2016-04-05 20:28:57 +09:00
Erik Kline
5db3f10e9a Merge "Move from on464XlatChange() to setNeighborDiscoveryOffload()" into nyc-dev 2016-04-05 03:55:42 +00:00
Lorenzo Colitti
cd404a2fc3 Merge "Add APF code to drop ARP IPv4 requests not for us" into nyc-dev 2016-04-05 02:46:39 +00:00
Erik Kline
5c2e9224a7 Move from on464XlatChange() to setNeighborDiscoveryOffload()
Bug: 26238390
Change-Id: I0f971fbf04e44cb61017653f944d71e1f6d128b4
2016-04-05 11:39:14 +09:00
Paul Jensen
a8458c0363 Add APF code to drop ARP IPv4 requests not for us
The WiFi chipset's ARP offload may handle this when the
AP is asleep, but when the AP is awake and the chipset is in
wake-on-wifi mode use APF to filter these packets.

Bug: 27477163
Change-Id: I180c08bd7301a1af9c3f728ff3cba06ca4e1022d
2016-04-05 01:42:34 +00:00
Paul Jensen
10d70bff61 Merge "Fix potential ApfFilter bugs by careful ByteBuffer use" into nyc-dev 2016-04-05 00:23:37 +00:00
Paul Jensen
10594942c6 Merge "Plumb WiFi multicast filter through to ApfFilter" into nyc-dev 2016-04-05 00:22:22 +00:00
Lorenzo Colitti
77fdf23d6f Honour the DHCP MTU option.
Bug: 25590369
Bug: 27719279
Change-Id: I473b5ec9c13f0d74e1ddd55e9d4abcff374a83ef
2016-03-31 23:51:32 +09:00
Paul Jensen
2e074db972 Plumb WiFi multicast filter through to ApfFilter
Use APF to implement WifiManager.MulticastLock, if APF isn't available
fallback to the present behavior of using DRIVER RXFILTER. Since we
don't know whether APF is supported until we're connected, postpone
enabling/disabling the multicast filter until then; this should be
fine as there isn't much need to filter packets if there aren't any
packets going by since we're not connected.

Bug: 26238573
Change-Id: I862c053f1c8c3a41de50c2951cf14b3ca6923a2a
2016-03-30 11:12:51 +00:00
Pierre Imai
bc786b7475 Merge "Move connectivity events to frameworks/base." into nyc-dev 2016-03-30 01:16:59 +00:00
Paul Jensen
1c71cb3e72 Fix potential ApfFilter bugs by careful ByteBuffer use
Avoid adjusting ApfFilter.Ra.mPacket's postion() and limit()
in matches(). This avoids potential bugs in other parts of
the code that previously relied on limit() being reset.
Also for good measure change some limit() calls to capacity()
as it's more final.

Change-Id: I466e87ce6838f68654b24f2c9543a6cd547d3f87
2016-03-29 12:03:34 -04:00
Pierre Imai
bc9cc50947 Move connectivity events to frameworks/base.
Fixes a crash in bluetooth' DhcpClient due to Class(not)Loader.

Change-Id: I318c033aa8782c27a243104f85950adbf07d03a6
BUG: 27885860
BUG: 25691077
2016-03-29 22:07:09 +09:00