Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil don't make difference between broadcast and point to point interfaces #663

Closed
mffrench opened this issue Aug 4, 2015 · 5 comments

Comments

@mffrench
Copy link

mffrench commented Aug 4, 2015

Hello,

just found this little issue on snic tuple returned by psutil.net_if_addrs().

I've currently a tun0 interfaces linked to a VPN :

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet adr:10.8.0.10  P-t-P:10.8.0.9  Masque:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:20358 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21988 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:100 
          RX bytes:7265126 (6.9 MiB)  TX bytes:6695863 (6.3 MiB)

As you can see the P-t-P target address is considered as the broadcast address on the psutil snic tuple :

snic(family=<AddressFamily.AF_INET: 2>, address='10.8.0.10', netmask='255.255.255.255', broadcast='10.8.0.9')

I guess best way to make the diff and keep retro compatibility would be to add a ptp field with '10.8.0.9' and leave the broadcast field with None.

Cheers,

Mathilde

@giampaolo
Copy link
Owner

Mmm interesting. I took a look at netifaces lib and it seems it has the same problem because the only fields it provides are broadcast, netmask and addr, similarly as psutil.
In order to retrieve NIC info we use getifaddrs: http://man7.org/linux/man-pages/man3/getifaddrs.3.html I suppose the returned structure must have some flag to identify when the broadcast refers to a P2P address but that opens a pandora's box: what other flags should we take into account and are they portable across UNIX platforms? For this reason adding a new ptp field looks like a bad a idea to me.
What is your use case exactly? Identifying NICs linked to a VPN? And why do you need to do that?

@giampaolo
Copy link
Owner

Nevermind. I should read man pages before assuming anything too soon. =)
According to man getifaddrs it seems ptp is the only exception:

       Depending on whether the bit IFF_BROADCAST or IFF_POINTOPOINT is set
       in ifa_flags (only one can be set at a time), either ifa_broadaddr
       will contain the broadcast address associated with ifa_addr (if
       applicable for the address family) or ifa_dstaddr will contain the
       destination address of the point-to-point interface.

...so after all it looks like adding a separate 'ptp' field could make sense.

@giampaolo
Copy link
Owner

giampaolo added a commit that referenced this issue Aug 5, 2015
giampaolo added a commit that referenced this issue Aug 5, 2015
@giampaolo
Copy link
Owner

This is now implemented as of https://github.com/giampaolo/psutil/pull/668/files

@mffrench
Copy link
Author

mffrench commented Aug 5, 2015

Hello Giampalo,

very quick reaction and implementation ! thank you :)

to answer your question (why I need to identify NIC identified on VPN). I'm currently working on an OS mapping plugin linked to the Ariane project. Our target is ability to map all processes and their connections in the OS. https://github.com/echinopsii/net.echinopsii.ariane.community.plugin.procos

You can get more information here : http://ariane.echinopsii.net/

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants