summaryrefslogtreecommitdiffstats
path: root/python-ethtool/ethtool.c
Commit message (Collapse)AuthorAgeFilesLines
* "char *devname" -> "const char *devname" throughoutDavid Malcolm2013-02-011-12/+12
| | | | | | | | | | | | Calling PyArg_ParseTuple(args, "s", &devname) populates devname with a pointer to the internal storage of an (supposedly) immutable string. Make sure the buffer doesn't get mutated by making these pointers be "const char *", rather than just "char *". Found using cpychecker
* Support devices with multiple IPv4 addressesDavid Malcolm2013-01-301-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix memory leaks in get_interfaces_info()David Malcolm2013-01-151-4/+5
| | | | | | | | | | | | | | | | | | | | | The first half of get_interfaces_info() potentially allocates fetch_devs using calloc, setting fetch_devs_len to a value which may or may not be non-zero. In particular, given a tuple argument containing all non-strings, allocation occurs, but fetch_devs_len is set to zero, so it's not correct to use (fetch_devs_len > 0) as the condition for freeing the memory on the primary exit path, as this would leak fetch_devs (introduced in bfdcac6b16806416a6c0295fcfad5d820595d88c) There are also two error-handling paths that fail to free it (introduced in 4f0295fca2cfd933f4b9b539d5505cb24e4d420c) Instead of this logic, simply initialize it to NULL, and pass it to free on every exit route of the second half of the function: free(NULL) is guaranteed to be a no-op. Found by Braňo Náter using the "cppcheck" static analyzer.
* Fix bad loop condition within get_devices()David Malcolm2013-01-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | get_devices() includes this loop: char buffer[256]; ...snip... char *end = buffer; ...snip... while (end && *end != ':') end++; The condition "end" within the while guard will always be true, given that buffer is on the stack and thus will never be near the zero value. It should be *end instead, to check for the NUL terminator byte: this code will likely crash if the string does not contain a colon character. This appears to have been present in the initial commit of the code (8d6ad996f5d60d569532cdba4febb19c69bdf488) Found by Braňo Náter using the "cppcheck" static analyzer.
* Fix buffer overflow in get_module()David Malcolm2013-01-151-1/+1
| | | | | | | | | | | | | | | | | | get_module() includes this scanf call: if (sscanf(buf, "%*d\t%*s\t%100s\t%*d\t%100s\n", driver, dev) > 0) { i.e. "%100s" for each of driver and dev. i.e. a maximum field width of 100 for each. However, this field width does not include the NUL terminator. Increase the size of driver and dev from 100 to 101 to allow for the NUL byte. This appears to have been present in the initial commit of the code (8d6ad996f5d60d569532cdba4febb19c69bdf488) Found by Braňo Náter using the "cppcheck" static analyzer.
* Only open the NETLINK interface when neededDavid Sommerseth2011-04-111-54/+4
| | | | | | | | | 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-3/+12
| | | | | | | | | | | 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>
* Added ethtool.version string constantDavid Sommerseth2011-01-191-0/+1
| | | | | | This is useful to identify the python-ethtool version at runtime. Signed-off-by: David Sommerseth <davids@redhat.com>
* Get rid of not needed struct wrappingDavid Sommerseth2010-08-031-19/+19
| | | | | | | | | | 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/+2
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* Improved IPv6 supportDavid Sommerseth2010-07-301-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Renamed get_interface_info() to get_interfaces_info() and updated help stringDavid Sommerseth2010-05-041-3/+5
| | | | | This is to make it a bit clearer that the result type of this function always will be a list of ethtool.etherinfo objects.
* Clean up - avoid static variables in etherinfo_obj.hDavid Sommerseth2010-04-281-0/+1
|
* Updated to fetch the interface information when the "getter" function triggersDavid Sommerseth2010-04-281-10/+79
|
* Rewritten ethtool to make use of libnl instead of accessing NETLINK directlyDavid Sommerseth2010-04-261-38/+14
|
* Added parameter to get_interface_inf()David Sommerseth2009-09-161-2/+66
| | | | | | | | | | It can handle a string with a device name or a list or a tuple list with more devices. dev = ethtool.get_interface_info(['lo','eth0','pan0']) dev = ethtool.get_interface_info(('eth0','virbr0')) dev = ethtool.get_interface_info('lo') dev = ethtool.get_interface_info()
* Removed the previous "attempt" of IPv6 support, get_ipaddresses()David Sommerseth2009-09-071-34/+0
|
* Completed implementing the new Python get_interface_info() function.David Sommerseth2009-09-071-6/+58
| | | | | | | | | | | | | | | | | | It will return a list of Python etherinfo objects. These objects have the following properties: .device - Device name .mac_address - Hardware address .ipv4_address .ipv4_netmask .ipv4_broadcast .ipv6_address .ipv6_netmask In addition, it will produce a human readable output if these objects are treated as strings. It will not be possible to modify any of the properties in these objects.
* First cut at a python etherinfo class in C. Does nothing useful yet.David Sommerseth2009-09-041-3/+16
|
* Added new function: get_ipaddresses() - retrieves IPv4 and IPv6 addresses ↵David Sommerseth2009-08-241-1/+39
| | | | for all devices
* ethtool: Older kernels don't have IFF_DYNAMICArnaldo Carvalho de Melo2009-05-281-0/+4
| | | | Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: Add a function to get the interface flagsRuben Kerkhof2008-08-251-15/+65
| | | | | Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: Add licenseArnaldo Carvalho de Melo2008-08-201-0/+16
| | | | | | Part of the fedora review process. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: initialize some variables to shut up gccArnaldo Carvalho de Melo2008-08-191-4/+4
| | | | | | | python-ethtool/ethtool.c: In function 'get_tso': python-ethtool/ethtool.c:480: warning: 'value' may be used uninitialized in this function Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: bindings for binding for ETHTOOL_[GS]RINGPARAMArnaldo Carvalho de Melo2008-07-181-0/+50
| | | | Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: remove unused variables from set_tsoArnaldo Carvalho de Melo2008-07-151-3/+0
| | | | Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: binding for ETHTOOL_SCOALESCEArnaldo Carvalho de Melo2008-07-151-0/+62
| | | | | | | | | | | | | | And support in pethtool (aka ethtool-cmd.py) for setting all the coalesce parameters, providing, as usual, an interface that mimics the one provided by the ethtool command. This cset also introduces struct_desc_from_dict, that will help with other dict based python bindings, not just in python-ethtool. Please let me know if I'm reinventing the wheel, i.e. if there are other Python dict to C struct facilities out there (I bet there is, but heck, this one was easy enough to implement and doesn't requires external support to get this done 8)). Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: implement binding for get_coalesceArnaldo Carvalho de Melo2008-07-141-8/+107
| | | | Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: implement set_tsoArnaldo Carvalho de Melo2008-06-301-12/+48
| | | | Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* ethtool: Make get_dev_int_value genericArnaldo Carvalho de Melo2008-06-301-2/+7
| | | | | | Will be used for ETHTOOL_GCOALESCE and others that retrieve a struct. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
* [PYTHON-ETHTOOL]: Create repositoryArnaldo Carvalho de Melo2007-12-181-0/+554
From code in fedora's rhpl. Code indented, offload methods (tso, etc) added. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>