netlink-based ifconfig() routine replacement

Peter V. Saveliev peet at altlinux.org
Sat Jul 23 07:37:29 UTC 2011


On 22.07.2011 19:29, Federico Simoncelli wrote:
> I didn't check the code, but I believe we should use something
> more standard that is already shipped in rhel: ethtool.
> 
>>>> import ethtool
>>>> ethtool.get_interfaces_info('lo')[0].ipv4_address
> '127.0.0.1'
>>>> ethtool.get_interfaces_info('eth0')[0].ipv4_broadcast
> '192.168.123.255'

I didn't know about this module, so, didn't take it into account, my
mistake. Now I found and tested python-ethtool here:

http://git.kernel.org/?p=linux/kernel/git/acme/python-ethtool.git


> 
> Are there missing features in ethtool?

I see that python-ethtool uses ioctl() (which are deprecated, though),
so it can not get secondary addresses from interfaces that are added
without 'labels'. But VDSM anyway does not recognize them internally
('cause it uses ifconfig, that also uses ioctl()), and I think it is not
a problem.

The big problem is that python-ethtool uses /proc/net/dev to determine
interface names. So it can not get even secondary addresses _with_
labels (alias interfaces as it says ifconfig).

> Did you check the performances?
> 

100 repeats with timeit on

$ /sbin/ip -o link | wc -l
925

(vlan) interfaces:

$ ./ifconfig.py
using ifconfig: 30.629761219
using netlink: 14.31011796
using python-ethtool: 2.88704490662

testing code:
http://projects.radlinux.org/cx/browser/cx/utils/ifconfig.py

Just as expected.

ifconfig() routine uses external process' stdout parsing, so it takes
long time to run the process and some time to parse output.

netlink protocol parser is written in pure Python and though it works
faster, but not so fast as C programs.

python-ethtool is fastest, 'cause it is a module written in C, but it
has significant restrictions (see above).

…

If you mean other python-ethtool, please, provide a link so I can use it
in testing.

…

Thanks!
-- 
Peter V. Saveliev


More information about the vdsm-patches mailing list