74 Commits

Author SHA1 Message Date
Paul Jensen
8514a8131f Merge "Android packet filtering program interpreter test & program generator" into mm-wireless-dev
am: 44307adcf3

* commit '44307adcf371bacad4de6925a9207bdbfdc6f874':
  Android packet filtering program interpreter test & program generator
2016-02-03 17:12:47 +00:00
Paul Jensen
44307adcf3 Merge "Android packet filtering program interpreter test & program generator" into mm-wireless-dev 2016-02-03 16:48:43 +00:00
Paul Jensen
d38fb7662d Android packet filtering program interpreter test & program generator
Change-Id: I17951bd6320b9eb3b6c43f2ae37f62c2025705c1
2016-02-03 10:19:13 -05:00
Erik Kline
3d51d8bacc Ignore link properties updates when nothing actually changed.
am: 6076cb0b85

* commit '6076cb0b859185b075d3a70655afb192d68d0774':
  Ignore link properties updates when nothing actually changed.
2016-02-03 14:37:11 +00:00
Erik Kline
d33e6232fe Partial unification of DHCPv4 and static IPv4 configuration codepaths
am: 8deac7793c

* commit '8deac7793c32be0c3b64b64d48dd9c0e2407e8db':
  Partial unification of DHCPv4 and static IPv4 configuration codepaths
2016-02-03 14:29:32 +00:00
Erik Kline
6076cb0b85 Ignore link properties updates when nothing actually changed.
Change-Id: Ia3c0a652cb3b67707a5c5a0bb40f991ef1e6f777
2016-02-03 22:42:54 +09:00
Erik Kline
8deac7793c Partial unification of DHCPv4 and static IPv4 configuration codepaths
Change-Id: Ic796f9b7bb853a332175c34e0f557588efb6247a
2016-02-03 22:42:53 +09:00
Erik Kline
0c96d715c1 Move DHCPv4 mechanics into IpManager
am: 8afa558c52

* commit '8afa558c527b4be4e0e489b17485577e23148636':
  Move DHCPv4 mechanics into IpManager
2016-02-03 08:44:13 +00:00
Erik Kline
8afa558c52 Move DHCPv4 mechanics into IpManager
Bug: 17345682
Change-Id: I2c3d9d665ff3c38f02084c0cf86cd76035e7b0aa
2016-02-03 17:23:45 +09:00
Erik Kline
59235e66a5 Support static IP configuration internally
am: 1e91e4ebb6

* commit '1e91e4ebb65e63969e6ae45503257852be017aee':
  Support static IP configuration internally
2016-02-02 04:07:58 +00:00
Erik Kline
1e91e4ebb6 Support static IP configuration internally
Also, stop passing around "reason" for IPv4 provision success
or failure.

Bug: 17345682
Change-Id: I4c4b22977a93048e0b291206721d0ccc77cfaaf2
2016-02-01 22:32:21 +09:00
Erik Kline
4cc9ef8c74 Initial refactoring to group IP-related elements into an IpManager
am: a636761bd6

* commit 'a636761bd67963385397ee920dcf76ec7cf113fb':
  Initial refactoring to group IP-related elements into an IpManager
2016-02-01 10:08:40 +00:00
Erik Kline
a636761bd6 Initial refactoring to group IP-related elements into an IpManager
Bug: 17345682
Change-Id: I88f3f4bd32d18cd8d4f1404493648c8bcc1deeec
2016-02-01 17:59:47 +09:00
Erik Kline
7cb501310e DO NOT MERGE Refactor netlink and IpReachabilityMonitor into services/net
- netlink from core to services/net/netlink
    - IpReachabilityMonitor from core to services/net/ip

Cherry-picked from 02cc5a030a6f132e776b754dd5684ae632009f76
Change-Id: I45ac3f591bade45dd5ec441111b02b621234c0e4
2015-12-10 16:06:50 -08:00
Lorenzo Colitti
bda01cc5e3 Fix canceling renew alarms.
1. Entering DhcpBoundState cancels the renew alarm, but at that
   point the renew alarm is guaranteed not to have been scheduled.
   This is harmless, but results in an "unknown listener" message
   in the AlarmManager logs.
2. We don't cancel the renew alarm when exiting DhcpBoundState.
   This is also harmless, because that alarm does nothing except
   in DhcpBoundState, and we cancel it whenever we enter
   DhcpBoundState. But canceling it on exit is more correct.

Change-Id: I60dfcf00f243253b81b8906540e0a6218a7a489c
2015-12-10 12:58:27 +00:00
Lorenzo Colitti
9d3aadb247 Add a new WakeupMessage class and use it in two places.
This is useful when using the new AlarmManager direct callback
interface to wake up the system and request that an object whose
API consists of messages (such as a StateMachine) perform some
action.

In this situation, using AlarmManager.onAlarmListener by itself
will wake up the system to send the message, but does not
guarantee that the system will be awake until the target object
has processed it. This is because as soon as the onAlarmListener
sends the message and returns, the system is free to go to sleep
again.

Bug: 20157436
Bug: 25823676
Change-Id: Idff20029d287f26347441a2523b7fb20eda6a8b0
2015-12-08 23:50:23 +09:00
Lorenzo Colitti
c415f72b66 Merge changes I456984a2,Id4d1031b
* changes:
  Switch the DHCP client to the new AlarmManager callback interface
  Refactor alarm setting code in preparation for switch to callback
2015-11-25 04:37:59 +00:00
Lorenzo Colitti
831204c651 Switch the DHCP client to the new AlarmManager callback interface
Bug: 24224067
Bug: 25823676
Change-Id: I456984a2f6243f92edb63b8599d861627e2de1cf
2015-11-24 13:47:15 +09:00
Lorenzo Colitti
e5f11cd6cc Refactor alarm setting code in preparation for switch to callback
Bug: 25823676
Change-Id: Id4d1031b5bd3a7f041c32ad4ac9384e045b385e8
2015-11-24 13:47:15 +09:00
Lorenzo Colitti
6c7acb6ec7 Add a test that checks the contents of DISCOVER packets.
Change-Id: I571d560cf7032babf7b7867ad748e2a896116ce7
2015-11-17 16:36:18 +09:00
Lorenzo Colitti
8a484fbb8c Merge "Don\'t crash if a DHCP server doesn\'t send the server ID option." into mnc-dr-dev am: a2cc04736d am: e4aacaeec9 am: c52503acf0
am: bce5116b8d

* commit 'bce5116b8d10c91436445cd0a0830bb51702bfd4':
  Don't crash if a DHCP server doesn't send the server ID option.
2015-10-29 18:20:30 +00:00
Lorenzo Colitti
7611f1cdb4 Don't crash if a DHCP server doesn't send the server ID option.
This violates a MUST in RFC2131, but apparently some
implementations don't know or care.

Bug: 25343517
Change-Id: I80459b58ffe231e7ed64e77bafa157a96b745149
2015-10-29 16:09:16 +09:00
Erik Kline
952159f3bc Make all IpReachabilityMonitor log messages have the same tag
Change-Id: I463566a9efc52ea02d431fb859e915a615ad0dc6
2015-10-27 11:40:36 +09:00
Lorenzo Colitti
eda0ea4190 am 3d3f766c: am 871d96b4: am 13c5dd5c: am eb0bbd45: Merge changes Id6a0b0de,I5f03b8b2,I62464b92 into mnc-dr-dev
* commit '3d3f766c8b37dcf495235ca4a500494498712eed':
  Support DHCP replies with multiple default gateways.
  Accept DHCP responses from non-67 server source ports
  Improve logging of DHCP parse errors using exceptions.
2015-10-12 17:12:08 +00:00
Lorenzo Colitti
4e4d59eeef Connect the DHCP UDP socket to the server.
This makes it so that the socket cannot receive datagrams from
anybody except the DHCP server. This does not improve security,
because we never read from the UDP socket anyway, but it does
make ListeningPortsTest pass.

Bug: 23906864
Bug: 23933386
Change-Id: Ib090273a417f7eb2ac1ee3309260249b72fb8345
2015-10-11 16:06:11 +09:00
Lorenzo Colitti
cccaa51f34 Merge "Connect the DHCP UDP socket to the server." 2015-10-09 04:36:02 +00:00
Lorenzo Colitti
577255e1d4 Connect the DHCP UDP socket to the server.
This makes it so that the socket cannot receive datagrams from
anybody except the DHCP server. This does not improve security,
because we never read from the UDP socket anyway, but it does
make ListeningPortsTest pass.

Bug: 23906864
Bug: 23933386
Change-Id: I82fe9d6c6c520536ffd6422bcc60fab664999e6f
2015-10-09 13:27:22 +09:00
Lorenzo Colitti
025f4a5aae Support DHCP replies with multiple default gateways.
Just use the first one for compatibility with the legacy client.

Bug: 23975855
Change-Id: Id6a0b0de32e8947c12c02eb9a3be417e2f82c99a
2015-10-08 16:28:02 +09:00
Erik Kline
b19238c488 Accept DHCP responses from non-67 server source ports
Bug: 24687559
Change-Id: I5f03b8b2780c558281d8a50d0893fd64f2812add
2015-10-08 15:40:41 +09:00
Erik Kline
496906ee70 Improve logging of DHCP parse errors using exceptions.
Bug: 23975855
Change-Id: I62464b92f0bb568e57bf5e1a63bc75f22c75aac1
2015-10-08 15:40:31 +09:00
Erik Kline
1c01e61c90 Only log exceptions if the IpReachabilityMonitor is still running.
It's not terribly interesting to see logged exceptions about reads
on sockets that were deliberately closed due to normal tear down.

Change-Id: Ib6834a98b6f086fc40ce19db60c161414459d758
2015-10-01 20:38:03 +09:00
Erik Kline
41480898f3 Add an explanation of how IpReachabilityMonitor works
Change-Id: Idfc1cf64c867182ffd612b27ba463b97e6c95769
2015-09-28 15:44:12 +09:00
Ian Pedowitz
3a08975000 am cafb3192: am 4c74a02e: am 3af6163a: am 31fe464d: Merge "Give the DhcpClient alarm broadcasts foreground priority." into mnc-dr-dev
* commit 'cafb3192a06e237ae2a7466d051ee66e05cac11d':
  Give the DhcpClient alarm broadcasts foreground priority.
2015-09-25 18:59:37 +00:00
Lorenzo Colitti
9795a1d8b9 Give the DhcpClient alarm broadcasts foreground priority.
Bug: 24265658
Bug: 24224067
Change-Id: I375097e7957643efb4bc0bb81318b13d9b9c82c1
2015-09-25 12:57:39 +09:00
Erik Kline
02cc5a030a Refactor netlink and IpReachabilityMonitor into services/net
- netlink from core to services/net/netlink
    - IpReachabilityMonitor from core to services/net/ip

Change-Id: I45ac3f591bade45dd5ec441111b02b621234c0e4
2015-09-24 12:50:36 +09:00
Ian Pedowitz
7d223aeef8 am 0a76afb9: Merge "Don\'t crash on (invalid) hardware address lengths > 127." into mnc-dev
* commit '0a76afb93e6f303921ab84e2f26747c3ebf19b62':
  Don't crash on (invalid) hardware address lengths > 127.
2015-09-03 17:34:50 +00:00
Lorenzo Colitti
d64144a37c Don't crash on (invalid) hardware address lengths > 127.
These would cause us to crash with a NegativeArraySizeException
when trying to create the clientMac array. Instead, if the length
is > 16 (invalid, because the field is only 16 bytes long), fudge
it to 6 (Ethernet / wifi).  This is a bit less liberal than the
legacy client, which doesn't check the length at all.

Bug: 23725795
Change-Id: I83f47bfc400ffa8ce85dd9d1b8eb96be5afe51a5
2015-09-03 21:28:48 +09:00
Lorenzo Colitti
c7f2030ffc am e022cb08: Merge "Don\'t attempt to stop the receive thread if we never started it." into mnc-dev
* commit 'e022cb085f6ebc2801f843bb47c9fd23f6daa3ea':
  Don't attempt to stop the receive thread if we never started it.
2015-08-12 03:45:30 +00:00
Lorenzo Colitti
31e19f34f5 Don't attempt to stop the receive thread if we never started it.
If socket initialization fails, DhcpState#exit will call
mReceiveThread#stop and crash the system with an NPE. Make sure
we don't do that if mReceiveThread is null, and properly null it
out when exiting.

Bug: 23088314
Change-Id: I4378d8280f9d8588f5eaa8bd7ade61beab1c3ce2
2015-08-11 15:42:59 +09:00
Lorenzo Colitti
8bf977d562 ConnectivityManager API for for packet keepalives.
Bug: 21405946
Change-Id: Ie1f8f8bee684fe2bb1092a9f1bc9f5dc29b1defc
2015-07-18 17:00:13 +00:00
Lorenzo Colitti
b0b3d0bcfb Fix two parsing bugs in new DHCP client.
1. We don't parse PAD options properly, leading in failure to
   parse packets sent by DHCP servers that put the end of options
   marker after pad options and at an odd offset.
2. We get the DhcpResults vendorInfo from the wrong option type
   (60 instead of 43).

Fix these and add unit tests for the offer packets sent by a few
different DHCP servers.

Bug: 21955617
Bug: 22281295
Change-Id: I5d13f1a6a3ff0b53112f18f3db8792fa32ad2da3
2015-07-06 13:50:53 +09:00
Lorenzo Colitti
5bc64b847a Correctly time out CMD_START_DHCP.
WifiStateMachine expects CMD_START_DHCP to time out after 30-40
seconds. Currently, DhcpClient imposes timeouts on DhcpInitState
and on DhcpRequestState, but not on the time it takes to get to
from CMD_START_DHCP to DhcpBoundState. So in theory the client
could oscillate between DhcpInitState and DhcpRequestState and
never time out.

Fix this by introducing a new oneshot timer that is set when DHCP
starts and is cancelled when it succeeds. CMD_RENEW_DHCP does not
need this because it's implemented using only one state, so the
oneshot timeout can be implemented using the state timeout.

Bug: 19704592
Change-Id: I6a5847a3dee23a2692237b8f3b3b0f8049da5140
2015-06-08 19:57:14 +09:00
Lorenzo Colitti
be843e8394 Actually close sockets when stopping the receive thread.
Contrary to the expectations of the code, IoUtils.closeQuietly()
does not unblock system calls. So mReceiveThread.halt() was not
actually stopping the receive thread.

This wasn't actually a problem, because after "stopping" the
receive thread, either the interface would go down (interrupting
the previous receive thread with ENETDOWN), or a packet would
arrive to both the old and new receive threads, stopping the
old one. But the lack of a "stopping receive thread" message at
the expected time was confusing.

While I'm at it, also add the string for CMD_TIMEOUT.

Bug: 19704592
Change-Id: I74732429118af780453028898148519b294fa9d3
2015-06-04 20:07:14 +09:00
Lorenzo Colitti
f68edb1611 Actually fall back from yiaddr to ciaddr.
The initial implementation of toDhcpResults attempted to get the
leased IP address from ciaddr if yiaddr was 0.0.0.0, but it never
actually did so because a) it used == instead of equals(), and b)
the parsing code never populated mClientIp for a DhcpOfferPacket
or DhcpAckPacket.

Fix this and add a test for it.. Technically DHCP does not use
ciaddr (only bootp uses it), but in 5.0 we would use ciaddr if
yiaddr was 0.0.0.0 and a bit more compatibility shouldn't hurt.

Bug: 19704592
Change-Id: I1f58555f0c10b9c576995a6edb759a83d8938ea0
2015-06-04 14:57:11 +09:00
Lorenzo Colitti
3a40b0deab Make RenewingState time out as well.
Bug: 19704592
Change-Id: I0759a98911a8c0059936916db8db459b7d66bc00
2015-06-03 17:23:30 +09:00
Lorenzo Colitti
48f9c731ff Remove the IPv4 address from the interface when DHCP fails.
Bug: 19704592
Change-Id: I9b96cdcfc7c9442b3f8d6797aca63559ed4bdb9b
2015-06-03 12:09:14 +09:00
Lorenzo Colitti
8f602cdd38 Merge "Fix DHCP lease time parsing." into mnc-dev 2015-06-02 07:47:48 +00:00
Erik Kline
d59aa84fda pass a defensive copy of DhcpResults
Also: correct state transition handling in DhcpBoundState#enter().

Bug: 20451261
Change-Id: I3be50f6b1b3fae179d6fff7ca8ae1d687caa3221
2015-06-02 16:22:57 +09:00
Lorenzo Colitti
d973537ee1 Fix DHCP lease time parsing.
Currently we treat a lease time larger than 2**31-1 as a negative
value, which causes DhcpClient to attempt to renew its IP address
constantly. Fix this by properly handling large and infinite
lifetimes, and while we're at it, impose a minimum lease time of
60 seconds.

Bug: 21352084
Change-Id: If62c9efeffad6222e2fe0c110f77d0e4c70de96d
2015-06-02 16:21:17 +09:00
Lorenzo Colitti
82babcd83a Specify more information in DhcpClient PendingIntents.
- Specify the package name. This provides a bit of security, but
  not much since the package is "android".
- Specify the interface name so we can run more than one client
  at a time.

Bug: 21395858
Bug: 19704592
Change-Id: I91c9ea15285b36628b6aef0b975c16a0b08d061e
2015-05-26 12:40:12 +00:00