[tor-bugs] #12377 [Tor]: get_interface_address6() behaviour iff all interface addresses are internal

Tor Bug Tracker & Wiki blackhole at torproject.org
Tue Feb 24 18:43:56 UTC 2015


#12377: get_interface_address6() behaviour iff all interface addresses are internal
-------------------------+-------------------------------------------------
     Reporter:  rl1987   |      Owner:
         Type:  defect   |     Status:  new
     Priority:  normal   |  Milestone:  Tor: 0.2.7.x-final
    Component:  Tor      |    Version:  Tor: unspecified
   Resolution:           |   Keywords:  tor-relay 026-triaged-1
Actual Points:           |  026-deferrable
       Points:           |  Parent ID:
-------------------------+-------------------------------------------------

Comment (by yawning):

 Replying to [comment:4 dgoulet]:
 > Lots of pieces here, I might be missing a check thus need review :). If
 it's true, maybe the solution is to keep a list of all valid IPs of any
 usable interface and validate our state that way.

 So if the purpose of the routine is "get the address used to reach the
 internet", then keeping a list like that isn't a great solution.  The
 "correct" way to do this is non-portable, but there's "correct" ways for
 all the platforms we care about (and can fall back to the hack as
 needed...).

 Under Linux, you want a rtnetlink(7) socket.
 Under *BSD, this information is available from sysctl
 (`net.route.0.0.dump`)
 Under Windows, you want `GetIpForwardTable()` (https://msdn.microsoft.com
 /en-us/library/aa365953%28v=vs.85%29.aspx).

 The high level "right" way is to use platform specific calls to dump the
 routing table, find the default route and the associated interface, and
 return the interface IP address.

 A brief description of how the linux solution would work:
  1. Open a `RT_NETLINK` socket (AF_NETLINK, PF_ROUTE).
  2. Query the entire routing table with `RTM_GETROUTE`, and find the
 default route and it's associated interface index (RTA_IIF, RTA_OIF).
  3. Query the list of interfaces to get the address `RTM_GETADDR`.  You
 may be able to get away with looking at the RTA_SRC attribute in the
 response from 2, it's been a while so I don't remember off the top of my
 head.
  4. Profit!

 It's a decent chunk of code, especially if you do all platforms, but it
 should be fun to write.

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/12377#comment:8>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list