Skip to content

Commit 8156c88

Browse files
author
David Sommerseth
committed
cleanup: Rename etherinfo_py and ethtool_etherinfo_Type
Use PyEtherInfo and PyEtherInfoType the base names, to more easily see their relation, and more clearly indicate they are Python objects. Also remove an initialisation of PyEtherInfo/etherinfo_py not needed any more. Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent a5308a1 commit 8156c88

File tree

7 files changed

+39
-41
lines changed

7 files changed

+39
-41
lines changed

python-ethtool/etherinfo.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
static void callback_nl_link(struct nl_object *obj, void *arg)
5353
{
54-
etherinfo_py *ethi = (etherinfo_py *) arg;
54+
PyEtherInfo *ethi = (PyEtherInfo *) arg;
5555
struct rtnl_link *link = (struct rtnl_link *) obj;
5656
char hwaddr[130];
5757

@@ -108,12 +108,12 @@ static void callback_nl_address(struct nl_object *obj, void *arg)
108108
/**
109109
* Sets the etherinfo.index member to the corresponding device set in etherinfo.device
110110
*
111-
* @param self A pointer the current etherinfo_py Python object which contains the device name
111+
* @param self A pointer the current PyEtherInfo Python object which contains the device name
112112
* and the place where to save the corresponding index value.
113113
*
114114
* @return Returns 1 on success, otherwise 0.
115115
*/
116-
static int _set_device_index(etherinfo_py *self)
116+
static int _set_device_index(PyEtherInfo *self)
117117
{
118118
struct nl_cache *link_cache;
119119
struct rtnl_link *link;
@@ -153,13 +153,13 @@ static int _set_device_index(etherinfo_py *self)
153153
*/
154154

155155
/**
156-
* Populate the etherinfo_py Python object with link information for the current device
156+
* Populate the PyEtherInfo Python object with link information for the current device
157157
*
158-
* @param self Pointer to the device object, a etherinfo_py Python object
158+
* @param self Pointer to the device object, a PyEtherInfo Python object
159159
*
160160
* @return Returns 1 on success, otherwise 0
161161
*/
162-
int get_etherinfo_link(etherinfo_py *self)
162+
int get_etherinfo_link(PyEtherInfo *self)
163163
{
164164
struct nl_cache *link_cache;
165165
struct rtnl_link *link;
@@ -199,14 +199,14 @@ int get_etherinfo_link(etherinfo_py *self)
199199
/**
200200
* Query NETLINK for device IP address configuration
201201
*
202-
* @param self A etherinfo_py Python object for the current device to retrieve IP address
202+
* @param self A PyEtherInfo Python object for the current device to retrieve IP address
203203
* configuration data from
204204
* @param query What to query for. Must be NLQRY_ADDR4 for IPv4 addresses or NLQRY_ADDR6
205205
* for IPv6 addresses.
206206
*
207207
* @return Returns a Python list containing PyNetlinkIPaddress objects on success, otherwise NULL
208208
*/
209-
PyObject * get_etherinfo_address(etherinfo_py *self, nlQuery query)
209+
PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
210210
{
211211
struct nl_cache *addr_cache;
212212
struct rtnl_addr *addr;

python-ethtool/etherinfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
typedef enum {NLQRY_ADDR4, NLQRY_ADDR6} nlQuery; /**< Supported query types in the etherinfo code */
2121

22-
int get_etherinfo_link(etherinfo_py *data);
23-
PyObject * get_etherinfo_address(etherinfo_py *self, nlQuery query);
22+
int get_etherinfo_link(PyEtherInfo *data);
23+
PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query);
2424

25-
int open_netlink(etherinfo_py *);
25+
int open_netlink(PyEtherInfo *);
2626
struct nl_sock * get_nlc();
27-
void close_netlink(etherinfo_py *);
27+
void close_netlink(PyEtherInfo *);
2828

2929
#endif

python-ethtool/etherinfo_obj.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
/**
3535
* ethtool.etherinfo deallocator - cleans up when a object is deleted
3636
*
37-
* @param self etherinfo_py Python object to deallocate
37+
* @param self PyEtherInfo Python object to deallocate
3838
*/
39-
static void _ethtool_etherinfo_dealloc(etherinfo_py *self)
39+
static void _ethtool_etherinfo_dealloc(PyEtherInfo *self)
4040
{
4141
close_netlink(self);
4242
Py_XDECREF(self->device); self->device = NULL;
@@ -79,12 +79,12 @@ static PyNetlinkIPaddress * get_last_ipv4_address(PyObject *addrlist)
7979
/**
8080
* ethtool.etherinfo function for retrieving data from a Python object.
8181
*
82-
* @param self Pointer to the current etherinfo_py device object
82+
* @param self Pointer to the current PyEtherInfo device object
8383
* @param attr_o contains the object member request (which element to return)
8484
*
8585
* @return Returns a PyObject with the value requested on success, otherwise NULL
8686
*/
87-
PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
87+
PyObject *_ethtool_etherinfo_getter(PyEtherInfo *self, PyObject *attr_o)
8888
{
8989
char *attr = PyString_AsString(attr_o);
9090
PyNetlinkIPaddress *py_addr;
@@ -149,7 +149,7 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
149149
*
150150
* @return Returns always -1 (failure).
151151
*/
152-
int _ethtool_etherinfo_setter(etherinfo_py *self, PyObject *attr_o, PyObject *val_o)
152+
int _ethtool_etherinfo_setter(PyEtherInfo *self, PyObject *attr_o, PyObject *val_o)
153153
{
154154
PyErr_SetString(PyExc_AttributeError, "etherinfo member values are read-only.");
155155
return -1;
@@ -159,11 +159,11 @@ int _ethtool_etherinfo_setter(etherinfo_py *self, PyObject *attr_o, PyObject *va
159159
/**
160160
* Creates a human readable format of the information when object is being treated as a string
161161
*
162-
* @param self Pointer to the current etherinfo_py device object
162+
* @param self Pointer to the current PyEtherInfo device object
163163
*
164164
* @return Returns a PyObject with a string with all of the information
165165
*/
166-
PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
166+
PyObject *_ethtool_etherinfo_str(PyEtherInfo *self)
167167
{
168168
PyObject *ret = NULL;
169169
PyObject *ipv4addrs = NULL, *ipv6addrs = NULL;
@@ -224,12 +224,12 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
224224
/**
225225
* Returns a tuple list of configured IPv4 addresses
226226
*
227-
* @param self Pointer to the current etherinfo_py device object to extract IPv4 info from
227+
* @param self Pointer to the current PyEtherInfo device object to extract IPv4 info from
228228
* @param notused
229229
*
230230
* @return Returns a Python tuple list of NetlinkIP4Address objects
231231
*/
232-
static PyObject *_ethtool_etherinfo_get_ipv4_addresses(etherinfo_py *self, PyObject *notused) {
232+
static PyObject *_ethtool_etherinfo_get_ipv4_addresses(PyEtherInfo *self, PyObject *notused) {
233233
if( !self ) {
234234
PyErr_SetString(PyExc_AttributeError, "No data available");
235235
return NULL;
@@ -242,12 +242,12 @@ static PyObject *_ethtool_etherinfo_get_ipv4_addresses(etherinfo_py *self, PyObj
242242
/**
243243
* Returns a tuple list of configured IPv6 addresses
244244
*
245-
* @param self Pointer to the current etherinfo_py device object to extract IPv6 info from
245+
* @param self Pointer to the current PyEtherInfo device object to extract IPv6 info from
246246
* @param notused
247247
*
248248
* @return Returns a Python tuple list of NetlinkIP6Address objects
249249
*/
250-
static PyObject *_ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *notused) {
250+
static PyObject *_ethtool_etherinfo_get_ipv6_addresses(PyEtherInfo *self, PyObject *notused) {
251251
if( !self ) {
252252
PyErr_SetString(PyExc_AttributeError, "No data available");
253253
return NULL;
@@ -273,10 +273,10 @@ static PyMethodDef _ethtool_etherinfo_methods[] = {
273273
* Definition of the functions a Python class/object requires.
274274
*
275275
*/
276-
PyTypeObject ethtool_etherinfoType = {
276+
PyTypeObject PyEtherInfo_Type = {
277277
PyObject_HEAD_INIT(NULL)
278278
.tp_name = "ethtool.etherinfo",
279-
.tp_basicsize = sizeof(etherinfo_py),
279+
.tp_basicsize = sizeof(PyEtherInfo),
280280
.tp_flags = Py_TPFLAGS_HAVE_CLASS,
281281
.tp_dealloc = (destructor)_ethtool_etherinfo_dealloc,
282282
.tp_str = (reprfunc)_ethtool_etherinfo_str,

python-ethtool/etherinfo_obj.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
#include <Python.h>
2929
#include "etherinfo_struct.h"
3030

31-
void _ethtool_etherinfo_dealloc(etherinfo_py *);
31+
void _ethtool_etherinfo_dealloc(PyEtherInfo *);
3232
PyObject *_ethtool_etherinfo_new(PyTypeObject *, PyObject *, PyObject *);
33-
int _ethtool_etherinfo_init(etherinfo_py *, PyObject *, PyObject *);
34-
PyObject *_ethtool_etherinfo_getter(etherinfo_py *, PyObject *);
35-
int _ethtool_etherinfo_setter(etherinfo_py *, PyObject *, PyObject *);
36-
PyObject *_ethtool_etherinfo_str(etherinfo_py *self);
33+
int _ethtool_etherinfo_init(PyEtherInfo *, PyObject *, PyObject *);
34+
PyObject *_ethtool_etherinfo_getter(PyEtherInfo *, PyObject *);
35+
int _ethtool_etherinfo_setter(PyEtherInfo *, PyObject *, PyObject *);
36+
PyObject *_ethtool_etherinfo_str(PyEtherInfo *self);
3737

3838
#endif

python-ethtool/etherinfo_struct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct {
5050
int index; /**< NETLINK index reference */
5151
PyObject *hwaddress; /**< string: HW address / MAC address of device */
5252
unsigned short nlc_active; /**< Is this instance using NETLINK? */
53-
} etherinfo_py;
53+
} PyEtherInfo;
5454

5555

5656

python-ethtool/ethtool.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "etherinfo_obj.h"
3333
#include "etherinfo.h"
3434

35-
extern PyTypeObject ethtool_etherinfoType;
35+
extern PyTypeObject PyEtherInfo_Type;
3636

3737
#ifndef IFF_DYNAMIC
3838
#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
@@ -268,13 +268,13 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
268268

269269
devlist = PyList_New(0);
270270
for( i = 0; i < fetch_devs_len; i++ ) {
271-
etherinfo_py *dev = NULL;
271+
PyEtherInfo *dev = NULL;
272272

273273
/* Store the device name and a reference to the NETLINK connection for
274274
* objects to use when quering for device info
275275
*/
276276

277-
dev = PyObject_New(etherinfo_py, &ethtool_etherinfoType);
277+
dev = PyObject_New(PyEtherInfo, &PyEtherInfo_Type);
278278
if( !dev ) {
279279
PyErr_SetString(PyExc_OSError, strerror(errno));
280280
free(fetch_devs);
@@ -939,10 +939,8 @@ PyMODINIT_FUNC initethtool(void)
939939
m = Py_InitModule3("ethtool", PyEthModuleMethods, "Python ethtool module");
940940

941941
// Prepare the ethtool.etherinfo class
942-
if (PyType_Ready(&ethtool_etherinfoType) < 0)
942+
if (PyType_Ready(&PyEtherInfo_Type) < 0)
943943
return;
944-
Py_INCREF(&ethtool_etherinfoType);
945-
PyModule_AddObject(m, "etherinfo", (PyObject *)&ethtool_etherinfoType);
946944

947945
// Prepare the ethtool IPv6 and IPv4 address types
948946
if (PyType_Ready(&ethtool_netlink_ip_address_Type))

python-ethtool/netlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ static unsigned int nlconnection_users = 0; /* How many NETLINK users are activ
3333
* for each etherinfo object being generated, and it will
3434
* keep a separate file descriptor open for each object
3535
*
36-
* @param ethi etherinfo_py structure (basically the "self" object)
36+
* @param ethi PyEtherInfo structure (basically the "self" object)
3737
*
3838
* @return Returns 1 on success, otherwise 0.
3939
*/
40-
int open_netlink(etherinfo_py *ethi)
40+
int open_netlink(PyEtherInfo *ethi)
4141
{
4242
if( !ethi ) {
4343
return 0;
@@ -93,9 +93,9 @@ struct nl_sock * get_nlc()
9393
* Closes the NETLINK connection. This should be called automatically whenever
9494
* the corresponding etherinfo object is deleted.
9595
*
96-
* @param ethi etherinfo_py structure (basically the "self" object)
96+
* @param ethi PyEtherInfo structure (basically the "self" object)
9797
*/
98-
void close_netlink(etherinfo_py *ethi)
98+
void close_netlink(PyEtherInfo *ethi)
9999
{
100100
if( !ethi || !nlconnection ) {
101101
return;

0 commit comments

Comments
 (0)