From 508ffffbb3c48eeeb11eeab2bf971180fe4e1940 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Mon, 11 Apr 2011 16:36:56 +0200 Subject: 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 --- python-ethtool/etherinfo_obj.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'python-ethtool/etherinfo_obj.c') 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 * @@ -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 ) { -- cgit