diff options
author | David Sommerseth <davids@redhat.com> | 2013-12-20 01:08:46 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2013-12-20 01:11:28 +0100 |
commit | d10055619793bf8ff74814f4126ddb8ba5ee913f (patch) | |
tree | b36082d75bc761782747af536f7c7d998d690832 /python-ethtool/etherinfo.c | |
parent | 52b17fc36d39c32d6e766c18ee8fd4f472f62d39 (diff) | |
download | python-ethtool-d10055619793bf8ff74814f4126ddb8ba5ee913f.tar.gz python-ethtool-d10055619793bf8ff74814f4126ddb8ba5ee913f.tar.xz python-ethtool-d10055619793bf8ff74814f4126ddb8ba5ee913f.zip |
Get rid of the internal IP address lists
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>
Diffstat (limited to 'python-ethtool/etherinfo.c')
-rw-r--r-- | python-ethtool/etherinfo.c | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c index 8e9d0b5..61fe037 100644 --- a/python-ethtool/etherinfo.c +++ b/python-ethtool/etherinfo.c @@ -55,8 +55,6 @@ void free_etherinfo(struct etherinfo *ptr) free(ptr->device); Py_XDECREF(ptr->hwaddress); - Py_XDECREF(ptr->ipv4_addresses); - Py_XDECREF(ptr->ipv6_addresses); free(ptr); } @@ -219,18 +217,17 @@ int get_etherinfo_link(etherinfo_py *self) * @param nlc Pointer to the libnl handle, which is used for the query against NETLINK * @param query What to query for. Must be NLQRY_ADDR4 or NLQRY_ADDR6. * - * @return Returns 1 on success, otherwise 0. + * @return Returns a Python list containing PyNetlinkIPaddress objects on success, otherwise NULL */ -int get_etherinfo_address(etherinfo_py *self, nlQuery query) +PyObject * get_etherinfo_address(etherinfo_py *self, nlQuery query) { struct nl_cache *addr_cache; struct rtnl_addr *addr; struct etherinfo *ethinf = NULL; PyObject *addrlist = NULL; - int ret = 0; if( !self || !self->ethinfo ) { - return 0; + return NULL; } ethinf = self->ethinfo; @@ -239,11 +236,11 @@ int get_etherinfo_address(etherinfo_py *self, nlQuery query) PyErr_Format(PyExc_RuntimeError, "Could not open a NETLINK connection for %s", ethinf->device); - return 0; + return NULL; } if( _set_device_index(ethinf) != 1) { - return 0; + return NULL; } /* Query the for requested info via NETLINK */ @@ -251,7 +248,7 @@ int get_etherinfo_address(etherinfo_py *self, nlQuery query) /* Extract IP address information */ if( rtnl_addr_alloc_cache(get_nlc(), &addr_cache) < 0) { nl_cache_free(addr_cache); - return 0; + return NULL; } addr = rtnl_addr_alloc(); /* FIXME: Error handling? */ @@ -260,46 +257,24 @@ int get_etherinfo_address(etherinfo_py *self, nlQuery query) switch( query ) { case NLQRY_ADDR4: rtnl_addr_set_family(addr, AF_INET); - - /* Make sure we don't have any old IPv4 addresses saved */ - Py_XDECREF(ethinf->ipv4_addresses); - ethinf->ipv4_addresses = PyList_New(0); - if (!ethinf->ipv4_addresses) { - rtnl_addr_put(addr); - nl_cache_free(addr_cache); - return 0; - } - assert(ethinf->ipv4_addresses); - addrlist = ethinf->ipv4_addresses; - ret = 1; break; case NLQRY_ADDR6: rtnl_addr_set_family(addr, AF_INET6); - - /* Likewise for IPv6 addresses: */ - Py_XDECREF(ethinf->ipv6_addresses); - ethinf->ipv6_addresses = PyList_New(0); - if (!ethinf->ipv6_addresses) { - rtnl_addr_put(addr); - nl_cache_free(addr_cache); - return 0; - } - assert(ethinf->ipv6_addresses); - addrlist = ethinf->ipv6_addresses; - ret = 1; break; default: - ret = 0; + return NULL; } - if( ret == 1 ) { - /* Retrieve all address information - common code for NLQRY_ADDR4 and NLQRY_ADDR6*/ - nl_cache_foreach_filter(addr_cache, OBJ_CAST(addr), callback_nl_address, addrlist); - rtnl_addr_put(addr); - nl_cache_free(addr_cache); - } + /* Retrieve all address information */ + addrlist = PyList_New(0); /* The list where to put the address object */ + assert(addrlist); + + /* Loop through all configured addresses */ + nl_cache_foreach_filter(addr_cache, OBJ_CAST(addr), callback_nl_address, addrlist); + rtnl_addr_put(addr); + nl_cache_free(addr_cache); - return ret; + return addrlist; } |