| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
| |
Ensure that a Python exception is set on more places errors can occur.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
Errnos are missing from some exceptions and in others the code could
be simplified by just using the convenience method PyErr_FromErrno.
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Acked-by: David Sommerseth <davids@redhat.com>
Message-Id: 1389997662-8460-1-git-send-email-asegurap@redhat.com
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
|
|
| |
The current code is only setting the errno string but doesn't set
the first argument to the IOError exception, i.e., errno.
This patch builds a tuple (errno, strerror(errno)) so that the
Exception has the errno properly set.
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
| |
This is more like a test release, to get these last changes out in the field.
And it will help debugging issues later on too, if there are some issues with
this rewrite.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
Use a more modern way to set the needed struct members, avoiding
to fill out the blanks manually.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
| |
This will simplify to "pythonize" struct etherinfo further.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
| |
make_python_address_from_rtnl_addr() referenced an undefined struct
without netlink/route/addr.h included.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
This follows the previous commit. Just cleaning up and
making things a bit more clearer.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
| |
This simplifies and clarifies the object/struct relations a bit better.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
|
| |
pythonn-ethtool/etherinfo_ipv6_obj.c was removed in
commit abab733a87025960a. The MANIFEST file needs to
reflect that as well.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
| |
Needed for 'make rpmdev'
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
| |
This is to simplify and clearify the code furhter. Simply reduce the
call chain.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
| |
Primarily just to clean up the code
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
| |
Simplify the overall implementation by reusing code more efficiently.
The differences between the IPv4 and IPv6 implementation in libnl is
minimal and can more easily be differentiated those few places its
needed instead.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
| |
This uses the same approach as IPv4 uses.
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
| |
The old ioctl() calls will only return active interaces which is
configured with IPv4 addresses. Thus an interface with only IPv6
configured will not be returned.
This modifies get_active_devices() to use a newer API to retrieve
the needed information.
Bugzilla: RH#855920
Signed-off-by: David Sommerseth <davids@redhat.com>
|
| |
|
| |
|
| |
|
|
|
|
|
| |
This is based on a suite I wrote internally at Red Hat for python-ethtool,
later modified by Braňo Náter <bnater@redhat.com>.
|
|
|
|
|
| |
It's not clear to me that we need a handcoded MANIFEST file, but
if we're going to have it, it ought to be complete.
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
| |
This variable was confusing cppcheck and potentially could
introduce a read of an uninitialized variable if the code
were carelessly modified - simplify it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
Commit d3fd6b84f461a4d7ffbf3f3eae37381150b69e82 introduced an ext_modules
keyword argument to the setup invocation in setup.py, making the
exttool = Extension(...)
code at the top of setup.py redundant. Remove the redundant code.
|
|
|
|
| |
Signed-off-by: David Sommerseth <davids@redhat.com>
|