From 4c301d903dfc3d011e673a8772d4ac75e99bbd2a Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 17 Dec 2013 21:07:36 +0100 Subject: Reduce the NETLINK pointer complexity 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 --- python-ethtool/etherinfo_obj.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'python-ethtool/etherinfo_obj.c') diff --git a/python-ethtool/etherinfo_obj.c b/python-ethtool/etherinfo_obj.c index 55a42db..97a06be 100644 --- a/python-ethtool/etherinfo_obj.c +++ b/python-ethtool/etherinfo_obj.c @@ -41,7 +41,7 @@ extern PyTypeObject ethtool_etherinfoIPv6Type; void _ethtool_etherinfo_dealloc(etherinfo_py *self) { if( self->data ) { - close_netlink(self->data); + close_netlink(self); if( self->data->ethinfo ) { free_etherinfo(self->data->ethinfo); @@ -151,11 +151,11 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o) return Py_INCREF(Py_None), Py_None; } } else if( strcmp(attr, "mac_address") == 0 ) { - get_etherinfo(self->data, NLQRY_LINK); + get_etherinfo(self, NLQRY_LINK); Py_INCREF(self->data->ethinfo->hwaddress); return self->data->ethinfo->hwaddress; } else if( strcmp(attr, "ipv4_address") == 0 ) { - get_etherinfo(self->data, NLQRY_ADDR4); + get_etherinfo(self, NLQRY_ADDR4); /* For compatiblity with old approach, return last IPv4 address: */ py_addr = get_last_ipv4_address(self); if (py_addr) { @@ -166,14 +166,14 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o) } Py_RETURN_NONE; } else if( strcmp(attr, "ipv4_netmask") == 0 ) { - get_etherinfo(self->data, NLQRY_ADDR4); + get_etherinfo(self, NLQRY_ADDR4); py_addr = get_last_ipv4_address(self); if (py_addr) { return PyInt_FromLong(py_addr->prefixlen); } return PyInt_FromLong(0); } else if( strcmp(attr, "ipv4_broadcast") == 0 ) { - get_etherinfo(self->data, NLQRY_ADDR4); + get_etherinfo(self, NLQRY_ADDR4); py_addr = get_last_ipv4_address(self); if (py_addr) { if (py_addr->ipv4_broadcast) { @@ -215,14 +215,14 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self) { PyObject *ret = NULL; - if( !self || !self->data || !self->data->nlc || !self->data->ethinfo ) { + if( !self || !self->data || !self->data->ethinfo ) { PyErr_SetString(PyExc_AttributeError, "No data available"); return NULL; } - get_etherinfo(self->data, NLQRY_LINK); - get_etherinfo(self->data, NLQRY_ADDR4); - get_etherinfo(self->data, NLQRY_ADDR6); + get_etherinfo(self, NLQRY_LINK); + get_etherinfo(self, NLQRY_ADDR4); + get_etherinfo(self, NLQRY_ADDR6); ret = PyString_FromFormat("Device %s:\n", self->data->ethinfo->device); if( self->data->ethinfo->hwaddress ) { @@ -281,7 +281,7 @@ static PyObject *_ethtool_etherinfo_get_ipv4_addresses(etherinfo_py *self, PyObj return NULL; } - get_etherinfo(self->data, NLQRY_ADDR4); + get_etherinfo(self, NLQRY_ADDR4); /* Transfer ownership of reference: */ ret = self->data->ethinfo->ipv4_addresses; @@ -307,7 +307,7 @@ static PyObject *_ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObj return NULL; } - get_etherinfo(self->data, NLQRY_ADDR6); + get_etherinfo(self, NLQRY_ADDR6); /* Transfer ownership of reference: */ ret = self->data->ethinfo->ipv6_addresses; -- cgit