CHROMIUM: Refactor tcp_nuke_addr() matching logic

This code needs to meet the following requirements:

 - Match both "native" IPv4 sockets and IPv6-mapped-IPv4 sockets
   (currently the latter sockets are ignored, and Android uses them
   extensively).

 - Don't nuke connections on loopback interfaces.  Currently this logic
   is broken, because tcp_is_local() always returns true.  This happens
   because it uses the routing code, which always sends packets destined
   for local interfaces through lo:

        # ip route get 100.107.2.11
        local 100.107.2.11 via ??? ??? dev lo  src 100.107.2.11

   Instead, the code will explicly check whether the local address is in
   the loopback range.

 - As a quirk of how ADB and CTS work under Chrome OS, the ADB port
   (5555/tcp) must be excluded from nuking to avoid failing tests.
   An explicit check is added for this condition, per b/31635190.

BUG=b:30261109
TEST=`nuketest 0.0.0.0` and see whether it resets IPv4, mapped IPv4, or
     IPv6 connections
TEST=`nuketest 0.0.0.1`
TEST=`nuketest ::`
TEST=`nuketest ::1`

Change-Id: I47be2a35a358d9f4e5e79623b639a84c84bb522d
Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/407923
Reviewed-by: Abhishek Bhardwaj <abhishekbh@google.com>
1 file changed