Thanks toralf! Pattern now supports Gentoo and since your output had IPv6 addresses I was finally able to add basic IPv6 support to get_connections() as well. The later isn't as complete as I'd like in that it simply includes IPv6 addresses if present. No doubt some resolvers need extra arguments to surface them.
Tips welcome to expand our IPv6 support. Also, if you have netstat or lsof output with IPv6 connections I'd love to expand our unit tests.
One last thing - in the example you gave above I don't understand the format of the 'beam' connections (for example ::ffff:5.9.158.75:5222). Seems it's an IPv6 address mashed together with an IPv4 address? At present Stem treats those lines as being malformed.
One last thing - in the example you gave above I don't understand the format of the 'beam' connections (for example ::ffff:5.9.158.75:5222). Seems it's an IPv6 address mashed together with an IPv4 address? At present Stem treats those lines as being malformed.
This is a well-formed IPv6 address, a standard representation produced by inet_ntop(3).
Please see: https://tools.ietf.org/html/rfc2765. (Warning: at least one Wikipedia article refers to the revised RFC —which obsoletes this one— but forgets to update the terminology, resulting in misinformation.)
tl;dr: It's called "IPv4-mapped IPv6 address", in that example the address is 5.9.158.75 written in IPv6 (port 5222). The full IPv6 address is:
0000:0000:0000:0000:0000:ffff:0509:9e4b
This is interesting. Is that the same interface? That doesn't look like "IPv4-mapped", but "IPv4-translated", i.e. ::ffff:0:5.9.158.75. Are we looking at a glibc bug or something? Or is the weird endianness playing tricks with my mind? :/
Is this the same interface ?
Erm, now sure how to achive that, but that server just have 1 ethernet card as LAN, so I'd say yes.
FWIW here's the full picture of a snapshot of IPv6:
The local address looks fine, but the remote is 2001:858:2:2:aabb on port 44811. Am I missing something or it that missing quite a few digits?
You are missing that netstat is a butt-ugly shitty fossil. Seriously, just look at the code if you dare.
And yes it's missing digits. This is because netstat cannot into variable-length columns: it truncates ip:port to 22 chars (actually it truncates "ip" then appends ":port"). facepalm
For quite a while Debian carried a patch that added option "-W!|--wide" (off by default) that prevented the truncation. I believe it was merged upstream at some point. Not sure what the situation was/is on Gentoo; maybe toralf just needs to add "-W" to his command line.
Thanks! Added netstat and proc support. Would you mind double checking that the proc resolution matches what you get from the other resolvers? Think it's right but as the most finicky resolver would be good to double check.
Would you mind double checking that the proc resolution matches what you get from the other resolvers? Think it's right but as the most finicky resolver would be good to double check.
I looked at the patch (did not run your code). It's wrong. Please re-read my comment:9 and check the code I referenced. You need to do the byte reversal word-wise, where word means 32 bits.
Gotcha. teor, please provide your proc contents at the same time as another connection resolver so I have the addresses they should be translating into. Easier to fix that way. :P
toralf, on irc you mentioned that proc was no longer running for you at all. Is that still the case?
yes, tried 88ecc42 - /proc failed completely (no connections at all) the other 3 works
Wouldn't it be better to read just the connection of the tor process instead all, meaning read from "/proc//net" ?
That is a very good point. Results should be the same, but it's quicker and simpler than what we do now (get inodes of the process, then use that to filter down to the process' connections). Wonder why I didn't do this originally - maybe '/proc//net/*' isn't present on some platforms?
88ecc42..e04f453 made it both for pythin2 and for python3.
However the /proc resolver returns all IPv6 connections and not only those related to the Tor process. But this is related to the enhancement request above.
Good news: Resolving connections this way is faster, simpler, and avoids reading /proc//fd which doesn't work unless 'DisableDebuggerAttachment 0' is set.
Bad news: Doesn't work.
Currently proc connection resolution works as follows...
Read where links in /proc//fd/* point to so we can get the inode from anything citing a socket...
% ls -l /proc/26257/fdlrwx------ 1 atagar atagar 64 Jan 27 08:56 0 -> /dev/pts/10lrwx------ 1 atagar atagar 64 Jan 27 08:56 1 -> /dev/pts/10lrwx------ 1 atagar atagar 64 Jan 27 08:56 10 -> socket:[15644314]lrwx------ 1 atagar atagar 64 Jan 27 08:56 11 -> socket:[15645635]
One we have a list of socket inodes for the process we read /proc/net/tcp to get the connection information for them.
Trouble is that /proc//net/tcp isn't restricted to just that process. In fact it's merely a copy of /proc/net/tcp...
I applied 02723814521e891260637764c236c9f9e5f429e2 here on top of the patched 1-4-0 stem - works fine, so is "DisableDebuggerAttachment 0" is no longer needed ?
:-)
For debug purpose I printed out all ipv6 connections I got from "get_connections(resolver, process_pid=pid, process_name='tor')":
Hi toralf. I'm a little confused, you said 'works fine' but also that it includes the beam connections? Again, /proc//net/tcp is identical to /proc/net/tcp so this is simply dumping all connections you have rather than just tor's.
In /proc/net/tcp I can only filter by inode or uid. Clearly uid only works if tor's running under a unique user. If anyone knows how to get a list of inodes owned by a process besides reading /proc//fd then that would be very useful. :)
toralf reports that the master branch is fine as far as he can tell. Gonna resolve this - if anyone has an idea for how to get the inodes then I'm eager to know!
Trac: Resolution: N/Ato fixed Status: reopened to closed