summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2013-09-13 18:46:15 +0200
committerDavid Sommerseth <davids@redhat.com>2013-09-13 18:49:10 +0200
commit052d432d9be11a0b6b69826b540b03d1b80904a4 (patch)
tree32a44b8c6b40c62e3be372141796987b34328804 /python-ethtool/etherinfo.c
parentabab733a87025960acee7dd0a2c029e679a502a8 (diff)
downloadpython-ethtool-052d432d9be11a0b6b69826b540b03d1b80904a4.tar.gz
python-ethtool-052d432d9be11a0b6b69826b540b03d1b80904a4.tar.xz
python-ethtool-052d432d9be11a0b6b69826b540b03d1b80904a4.zip
Re-implement the IPv6 support
This uses the same approach as IPv4 uses. Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'python-ethtool/etherinfo.c')
-rw-r--r--python-ethtool/etherinfo.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c
index 538bcb5..c8bbb0f 100644
--- a/python-ethtool/etherinfo.c
+++ b/python-ethtool/etherinfo.c
@@ -78,6 +78,7 @@ void free_etherinfo(struct etherinfo *ptr)
free(ptr->hwaddress);
}
Py_XDECREF(ptr->ipv4_addresses);
+ Py_XDECREF(ptr->ipv6_addresses);
free(ptr);
}
@@ -117,6 +118,7 @@ append_object_for_netlink_address(struct etherinfo *ethi,
assert(ethi);
assert(ethi->ipv4_addresses);
+ assert(ethi->ipv6_addresses);
assert(addr);
addr_obj = make_python_address_from_rtnl_addr(addr);
@@ -124,11 +126,24 @@ append_object_for_netlink_address(struct etherinfo *ethi,
return -1;
}
- if (-1 == PyList_Append(ethi->ipv4_addresses, addr_obj)) {
- Py_DECREF(addr_obj);
- return -1;
- }
+ switch (rtnl_addr_get_family(addr)) {
+ case AF_INET:
+ if (-1 == PyList_Append(ethi->ipv4_addresses, addr_obj)) {
+ Py_DECREF(addr_obj);
+ return -1;
+ }
+ break;
+
+ case AF_INET6:
+ if (-1 == PyList_Append(ethi->ipv6_addresses, addr_obj)) {
+ Py_DECREF(addr_obj);
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ }
Py_DECREF(addr_obj);
/* Success */
@@ -153,6 +168,7 @@ static void callback_nl_address(struct nl_object *obj, void *arg)
switch( rtnl_addr_get_family(rtaddr) ) {
case AF_INET:
+ case AF_INET6:
append_object_for_netlink_address(ethi, rtaddr);
return;
default:
@@ -168,7 +184,6 @@ static void callback_nl_address(struct nl_object *obj, void *arg)
*
*/
-
/**
* Query NETLINK for ethernet configuration
*
@@ -252,6 +267,13 @@ int get_etherinfo(struct etherinfo_obj_data *data, nlQuery query)
return 0;
}
+ /* Likewise for IPv6 addresses: */
+ Py_XDECREF(ethinf->ipv6_addresses);
+ ethinf->ipv6_addresses = PyList_New(0);
+ if (!ethinf->ipv6_addresses) {
+ return 0;
+ }
+
/* Retrieve all address information */
nl_cache_foreach_filter(addr_cache, OBJ_CAST(addr), callback_nl_address, ethinf);
rtnl_addr_put(addr);