summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo.c
Commit message (Collapse)AuthorAgeFilesLines
* Improve error handling even moreDavid Sommerseth2014-04-011-14/+18
| | | | | | Ensure that a Python exception is set on more places errors can occur. Signed-off-by: David Sommerseth <davids@redhat.com>
* Report invalid/non-existing devices as ENODEVDavid Sommerseth2014-02-211-0/+10
| | | | | | | | | | Without this patch py-ethtool will just report with a very generic system error exception if trying to query a non-existing network interface. This patch will change this to report the error using ENODEV instead. Signed-off-by: David Sommerseth <davids@redhat.com> Reviewed-by: Antoni S. Puimedon <asegurap@redhat.com>
* Added some extra error checks with libnl callsDavid Sommerseth2014-01-101-2/+6
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* cleanup: Rename etherinfo_py and ethtool_etherinfo_TypeDavid Sommerseth2014-01-091-8/+8
| | | | | | | | | Use PyEtherInfo and PyEtherInfoType the base names, to more easily see their relation, and more clearly indicate they are Python objects. Also remove an initialisation of PyEtherInfo/etherinfo_py not needed any more. Signed-off-by: David Sommerseth <davids@redhat.com>
* Merge struct etherinfo and etherinfo_pyDavid Sommerseth2013-12-201-42/+28
| | | | | | | | | | | | | Make things more "pythonic" and avoid another layer of wrapping by removing the struct etherinfo. Move that information to the main Python object instead. This simplifies the object creation and handling too, as now all strings are python objects. Also update some of the documentation blocks along the way. Signed-off-by: David Sommerseth <davids@redhat.com>
* Make the device string a python object as wellDavid Sommerseth2013-12-201-5/+4
| | | | | | This will simplify to "pythonize" struct etherinfo further. Signed-off-by: David Sommerseth <davids@redhat.com>
* Get rid of the internal IP address listsDavid Sommerseth2013-12-201-41/+16
| | | | | | | | With the new structure, these pointers are of no use. Kick them out. The result of this is that get_etherinfo_address() now returns a Python object which contains a list of IP address objects. Signed-off-by: David Sommerseth <davids@redhat.com>
* Clean-up get_etherinfo() and move it to get_etherinfo_address()David Sommerseth2013-12-201-41/+47
| | | | | | | This follows the previous commit. Just cleaning up and making things a bit more clearer. Signed-off-by: David Sommerseth <davids@redhat.com>
* Split out the link info from get_etherinfo()David Sommerseth2013-12-201-42/+84
| | | | | | | This is a needed step for the next move, where we'll query the interfaces for IP address at as late as possible. Signed-off-by: David Sommerseth <davids@redhat.com>
* Kick out struct etherinfo_obj_dataDavid Sommerseth2013-12-171-2/+2
| | | | | | This simplifies and clarifies the object/struct relations a bit better. Signed-off-by: David Sommerseth <davids@redhat.com>
* Reduce the NETLINK pointer complexityDavid Sommerseth2013-12-171-7/+7
| | | | | | | | | | | | Make the NETLINK connection pointer and user counter local global variables inside netlink.c only. Where NETLINK calls via libnl is required, rather use get_nlc() to get a NETLINK connection. This also prepares the next step, to get rid of the struct etherinfo_obj_data wrapper. Signed-off-by: David Sommerseth <davids@redhat.com>
* Splitting up get_etherinfo() callsDavid Sommerseth2013-12-161-26/+35
| | | | | | | Make the calls to retrieve IPv4 and IPv6 addresses individual. This is the the beginning of the rewrite of the whole etherinfo main class. Signed-off-by: David Sommerseth <davids@redhat.com>
* Make the internal MAC address a Python string objectDavid Sommerseth2013-12-161-18/+5
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* Fix a memleak which would happen if querying for a non-existing devicev0.9David Sommerseth2013-12-111-0/+8
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* Merge append_object_for_netlink_address() and callback_nl_address()David Sommerseth2013-12-101-49/+19
| | | | | | | This is to simplify and clearify the code furhter. Simply reduce the call chain. Signed-off-by: David Sommerseth <davids@redhat.com>
* Split out generic NETLINK functions from etherinfo.c to netlink.cDavid Sommerseth2013-12-101-86/+0
| | | | | | Primarily just to clean up the code Signed-off-by: David Sommerseth <davids@redhat.com>
* Remove a memory leakDavid Sommerseth2013-09-131-0/+1
| | | | | | | This happened each time it was needed to look up the 'ifindex' of an interface via the get_interfaces_info() API. Signed-off-by: David Sommerseth <davids@redhat.com>
* Re-implement the IPv6 supportDavid Sommerseth2013-09-131-5/+27
| | | | | | This uses the same approach as IPv4 uses. Signed-off-by: David Sommerseth <davids@redhat.com>
* Rip out the old IPv6 implementation completelyDavid Sommerseth2013-09-131-116/+2
| | | | | | | The whole IPv6 support will be re-implemented using a simliar strategy as the newer IPv4 support uses. Signed-off-by: David Sommerseth <davids@redhat.com>
* Migrated from libnl-1 to libnl-3David Sommerseth2013-09-121-52/+52
| | | | | | | | This ports the current functionality from libnl-1 to libnl-3.0. At the current stage, it should be functional but more patches cleaning up the code will come. Signed-off-by: David Sommerseth <davids@redhat.com>
* Support devices with multiple IPv4 addressesDavid Malcolm2013-01-301-24/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a get_ipv4_addresses() method to ethtool.etherinfo to support devices with multiple IPv4 addresses (rhbz#759150) Previously, get_etherinfo() made queries to NETLINK with NLQRY_ADDR, and callback_nl_address handled responses of family AF_INET (IPv4) by writing to fields within a struct etherinfo. If multiple AF_INET responses come back, each overwrote the last, and the last one won. This patch generalizes things by moving the relevant fields: char *ipv4_address; /**< Configured IPv4 address */ int ipv4_netmask; /**< Configured IPv4 netmask */ char *ipv4_broadcast; from (struct etherinfo) into a new Python class, currently named PyNetlinkIPv4Address. This object has a sane repr(): >>> ethtool.get_interfaces_info('eth1')[0].get_ipv4_addresses() [ethtool.NetlinkIPv4Address(address='192.168.1.10', netmask=24, broadcast='192.168.1.255')] and attributes: >>> print [iface.address for iface in ethtool.get_interfaces_info('eth1')[0].get_ipv4_addresses()] ['192.168.1.10'] >>> print [iface.netmask for iface in ethtool.get_interfaces_info('eth1')[0].get_ipv4_addresses()] [24] >>> print [iface.broadcast for iface in ethtool.get_interfaces_info('eth1')[0].get_ipv4_addresses()] ['192.168.1.255'] The (struct etherinfo) then gains a new field: PyObject *ipv4_addresses; /**< list of PyNetlinkIPv4Address instances */ which is created before starting the query, and populated by the callback as responses come in. All direct usage of the old fields (which assumed a single IPv4 address) are changed to use the last entry in the list (if any), to mimic the old behavior. dump_etherinfo() and _ethtool_etherinfo_str() are changed to loop over all of the IPv4 addresses when outputting, rather than just outputting one. Caveats: * the exact terminology is probably incorrect: I'm not a networking specialist * the relationship between each of devices, get_interfaces_info() results, and addresses seems both unclear and messy to me: how changable is the API? >>> ethtool.get_interfaces_info('eth1')[0].get_ipv4_addresses() [ethtool.NetlinkIPv4Address(address='192.168.1.10', netmask=24, broadcast='192.168.1.255')] It seems that an etherinfo object relates to a device: perhaps it should be named as such? But it may be too late to make this change. Notes: The _ethtool_etherinfo_members array within python-ethtool/etherinfo_obj.c was broken: it defined 4 attributes of type PyObject*, to be extracted from etherinfo_py->data, which is of a completed different type. If these PyMemberDef fields were ever used, Python would segfault. Thankfully _ethtool_etherinfo_getter() has handlers for these attributes, and gets called first. This is a modified version of the patch applied downstream in RHEL 6.4 within python-ethtool-0.6-3.el6: python-ethtool-0.6-add-get_ipv4_addresses-method.patch ported to take account of 508ffffbb3c48eeeb11eeab2bf971180fe4e1940
* Force O_CLOEXEC on the NETLINK socketv0.7David Sommerseth2011-04-121-0/+8
| | | | | | | | | | | To avoid that the NETLINK socket is available to forked children, set the FD_CLOEXEC flag on the NETLINK socket. This also avoids SELinux from complaining on Fedora 14. For more information: https://bugzilla.redhat.com/show_bug.cgi?id=689843 Signed-off-by: David Sommerseth <davids@redhat.com>
* Only open the NETLINK interface when neededDavid Sommerseth2011-04-111-6/+91
| | | | | | | | | Do not open a NETLINK connection when loading the module, but rahter open it when needed. In a case where multiple users needs the connection, it will be shared and only closed when the last active user is done. Signed-off-by: David Sommerseth <davids@redhat.com>
* Fixed several memory leaksDavid Sommerseth2011-04-111-4/+2
| | | | | | | | | | | Several places python-ethtool leaked memory, mostly due to missing Py_DECREF() calls on objects being put in to python lists (via PyList_Append() calls). This revealed an issue in addition where the IPv6 addresses pointers in some cases could freed more times. This is fixed as well. Signed-off-by: David Sommerseth <davids@redhat.com>
* Avoid duplicating IPv6 address informationDavid Sommerseth2011-01-191-0/+8
| | | | | | | | | In commit c52ed2cbdc5b851ebc7bc19d7c682b14a4a16ba4 a free_ipv6addresses() call was removed, which lead to duplicated IPv6 address information in some cases. Re-add this freeing, to be sure we don't add existing information to an already existing pointer chain. Signed-off-by: David Sommerseth <davids@redhat.com>
* Don't segfault if we don't receive any address from rtnl_link_get_addr()David Sommerseth2010-12-211-1/+1
| | | | | | | The callback function for device link information was lacking a simple check to avoid a SEGV in these situations. Signed-off-by: David Sommerseth <davids@redhat.com>
* Python reference counter was not properly set for etherinfo_ipv6addr objectsDavid Sommerseth2010-08-091-5/+3
| | | | | | | | | This caused a double free situation, when Python tried to free the object if the etherinfo::get_ipv6_addresses() method was called several times. In addition the ethtool::get_interfaces_info() would also free the structures uses by etherinfo_ipv6addr objects. Signed-off-by: David Sommerseth <davids@redhat.com>
* Get rid of not needed struct wrappingDavid Sommerseth2010-08-031-4/+4
| | | | | | | | | | The struct nl_handle was wrapped inside struct _nlconnection. This is really not needed if open_netlink() and close_netlink() functions uses "pointer's pointer" (struct nl_handle **) instead. Removes also the need to declare a static struct _nlconnection, as the global nlconnection variable can now be a pointer as well. Signed-off-by: David Sommerseth <davids@redhat.com>
* Added missing copyright notifications and updated where neededDavid Sommerseth2010-08-031-1/+1
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* Improved documentation in the codeDavid Sommerseth2010-08-021-3/+57
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* Improved IPv6 supportDavid Sommerseth2010-07-301-14/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | As the IPv6 protocol allows a single device to have more than one IPv6 address, the previous implementation did not provide all IPv6 information. It would reject all except the last parsed IPv6 address. NOTE: This implementation will break the previous API. This change removes the ethtool.etherinfo.ipv6_address and ethtool.etherinfo.ipv6_netmask members. A new member is added, ethtool.etherinfo.ipv6_addresses (in plural). This contains a tupple list containing of ethtool.etherinfo_ipv6addr objects, one object for each configured IPv6 address on the device. These objects have the following members available: .address - The IPv6 address .netmask - The IPv6 netmask (in bit notation) .scope - A string with the IPv6 address scope Example code: import ethtool devs = ethtool.get_interfaces_info('eth0') for ip6 in devs[0].ipv6_addresses: print "[%s] %s/%i" % (ip6.scope, ip6.address, ip6.netmask) Signed-off-by: David Sommerseth <davids@redhat.com>
* Updated to fetch the interface information when the "getter" function triggersDavid Sommerseth2010-04-281-82/+59
|
* Rewritten ethtool to make use of libnl instead of accessing NETLINK directlyDavid Sommerseth2010-04-261-392/+118
|
* Even more clean up. Improved more error messagesDavid Sommerseth2009-08-241-15/+32
|
* Fixed typos, more clean upDavid Sommerseth2009-08-241-6/+7
|
* Give some creditDavid Sommerseth2009-08-241-0/+1
|
* Improved error handling, clean upDavid Sommerseth2009-08-241-7/+14
|
* Imported functions for retrieving ethernet device info via AF_NETLINKDavid Sommerseth2009-08-241-0/+503