summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo_obj.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2011-04-11 16:36:56 +0200
committerDavid Sommerseth <davids@redhat.com>2011-04-11 16:36:56 +0200
commit508ffffbb3c48eeeb11eeab2bf971180fe4e1940 (patch)
tree2b8133c62a904fd400f0cef0a3e2abb12048149a /python-ethtool/etherinfo_obj.c
parentabc7f912f66d41dd734a10900429d4cad9377da5 (diff)
downloadpython-ethtool-508ffffbb3c48eeeb11eeab2bf971180fe4e1940.tar.gz
python-ethtool-508ffffbb3c48eeeb11eeab2bf971180fe4e1940.tar.xz
python-ethtool-508ffffbb3c48eeeb11eeab2bf971180fe4e1940.zip
Only open the NETLINK interface when needed
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>
Diffstat (limited to 'python-ethtool/etherinfo_obj.c')
-rw-r--r--python-ethtool/etherinfo_obj.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/python-ethtool/etherinfo_obj.c b/python-ethtool/etherinfo_obj.c
index e1e03fe..cf90601 100644
--- a/python-ethtool/etherinfo_obj.c
+++ b/python-ethtool/etherinfo_obj.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 Red Hat Inc.
+ * Copyright (C) 2009-2011 Red Hat Inc.
*
* David Sommerseth <davids@redhat.com>
*
@@ -40,6 +40,8 @@ extern PyTypeObject ethtool_etherinfoIPv6Type;
void _ethtool_etherinfo_dealloc(etherinfo_py *self)
{
if( self->data ) {
+ close_netlink(self->data);
+
if( self->data->ethinfo ) {
free_etherinfo(self->data->ethinfo);
}
@@ -110,20 +112,21 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
if( strcmp(attr, "device") == 0 ) {
ret = RETURN_STRING(self->data->ethinfo->device);
} else if( strcmp(attr, "mac_address") == 0 ) {
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_LINK);
+ get_etherinfo(self->data, NLQRY_LINK);
ret = RETURN_STRING(self->data->ethinfo->hwaddress);
} else if( strcmp(attr, "ipv4_address") == 0 ) {
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
+ get_etherinfo(self->data, NLQRY_ADDR);
ret = RETURN_STRING(self->data->ethinfo->ipv4_address);
} else if( strcmp(attr, "ipv4_netmask") == 0 ) {
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
+ get_etherinfo(self->data, NLQRY_ADDR);
ret = PyInt_FromLong(self->data->ethinfo->ipv4_netmask);
} else if( strcmp(attr, "ipv4_broadcast") == 0 ) {
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
+ get_etherinfo(self->data, NLQRY_ADDR);
ret = RETURN_STRING(self->data->ethinfo->ipv4_broadcast);
} else {
ret = PyObject_GenericGetAttr((PyObject *)self, attr_o);
}
+
return ret;
}
@@ -160,8 +163,8 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
return NULL;
}
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_LINK);
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
+ get_etherinfo(self->data, NLQRY_LINK);
+ get_etherinfo(self->data, NLQRY_ADDR);
ret = PyString_FromFormat("Device %s:\n", self->data->ethinfo->device);
if( self->data->ethinfo->hwaddress ) {
@@ -223,7 +226,7 @@ PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *n
return NULL;
}
- get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
+ get_etherinfo(self->data, NLQRY_ADDR);
ipv6 = self->data->ethinfo->ipv6_addresses;
ret = PyTuple_New(1);
if( !ret ) {