Skip to content

Commit 64b6c08

Browse files
author
David Sommerseth
committed
Moved etherinfo::ipv6_addresses to etherinfo::get_ipv6_addresses()
This is more appropriate as it is not a static list of IPv6 address objects which are returned. Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent e3e1bef commit 64b6c08

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

python-ethtool/etherinfo_obj.c

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,36 +121,12 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
121121
} else if( strcmp(attr, "ipv4_broadcast") == 0 ) {
122122
get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
123123
ret = RETURN_STRING(self->data->ethinfo->ipv4_broadcast);
124-
} else if( strcmp(attr, "ipv6_addresses") == 0 ) {
125-
struct ipv6address *ipv6 = NULL;
126-
int i = 0;
127-
ret = PyTuple_New(1);
128-
129-
get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
130-
ipv6 = self->data->ethinfo->ipv6_addresses;
131-
while( ipv6 ) {
132-
PyObject *ipv6_pyobj = NULL, *ipv6_pydata = NULL, *args = NULL;
133-
struct ipv6address *next = ipv6->next;
134-
135-
ipv6->next = NULL;
136-
ipv6_pydata = PyCObject_FromVoidPtr(ipv6, NULL);
137-
args = PyTuple_New(1);
138-
PyTuple_SetItem(args, 0, ipv6_pydata);
139-
ipv6_pyobj = PyObject_CallObject((PyObject *)&ethtool_etherinfoIPv6Type, args);
140-
if( ipv6_pyobj ) {
141-
PyTuple_SetItem(ret, i++, ipv6_pyobj);
142-
_PyTuple_Resize(&ret, i+1);
143-
}
144-
ipv6 = next;
145-
}
146-
_PyTuple_Resize(&ret, i);
147124
} else {
148125
ret = PyObject_GenericGetAttr((PyObject *)self, attr_o);
149126
}
150127
return ret;
151128
}
152129

153-
154130
/**
155131
* ethtool.etherinfo function for setting a value to a object member. This feature is
156132
* disabled by always returning -1, as the values are read-only by the user.
@@ -225,12 +201,55 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
225201

226202

227203
/**
228-
* This is required by Python, which lists all accessible methods
229-
* in the object. But no methods are provided.
204+
* Returns a tuple list of ethertool.etherinfo_ipv6addr objects, containing configured
205+
* IPv6 addresses
206+
*
207+
* @param self
208+
* @param notused
209+
*
210+
* @return Returns a Python tuple list of ethertool.etherinfo_ipv6addr objects
211+
*/
212+
PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *notused) {
213+
PyObject *ret;
214+
struct ipv6address *ipv6 = NULL;
215+
int i = 0;
216+
217+
if( !self || !self->data ) {
218+
PyErr_SetString(PyExc_AttributeError, "No data available");
219+
return NULL;
220+
}
221+
222+
get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
223+
ipv6 = self->data->ethinfo->ipv6_addresses;
224+
ret = PyTuple_New(1);
225+
while( ipv6 ) {
226+
PyObject *ipv6_pyobj = NULL, *ipv6_pydata = NULL, *args = NULL;
227+
struct ipv6address *next = ipv6->next;
228+
229+
ipv6->next = NULL;
230+
ipv6_pydata = PyCObject_FromVoidPtr(ipv6, NULL);
231+
args = PyTuple_New(1);
232+
PyTuple_SetItem(args, 0, ipv6_pydata);
233+
ipv6_pyobj = PyObject_CallObject((PyObject *)&ethtool_etherinfoIPv6Type, args);
234+
if( ipv6_pyobj ) {
235+
PyTuple_SetItem(ret, i++, ipv6_pyobj);
236+
_PyTuple_Resize(&ret, i+1);
237+
}
238+
ipv6 = next;
239+
}
240+
_PyTuple_Resize(&ret, i);
241+
return ret;
242+
}
243+
244+
245+
/**
246+
* Defines all available methods in the ethtool.etherinfo class
230247
*
231248
*/
232249
static PyMethodDef _ethtool_etherinfo_methods[] = {
233-
{NULL} /**< No methods defined */
250+
{"get_ipv6_addresses", _ethtool_etherinfo_get_ipv6_addresses, METH_NOARGS,
251+
"Retrieve configured IPv6 addresses. Returns a tuple list of etherinfo_ipv6addr objects"},
252+
{NULL} /**< No methods defined */
234253
};
235254

236255
/**
@@ -248,8 +267,6 @@ static PyMemberDef _ethtool_etherinfo_members[] = {
248267
"IPv4 netmask in bits"},
249268
{"ipv4_broadcast", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
250269
"IPv4 broadcast address"},
251-
{"ipv6_addresses", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
252-
"Returns a list of associated IPv6 addresses"},
253270
{NULL} /* End of member list */
254271
};
255272

0 commit comments

Comments
 (0)