Skip to content

Commit 97dbf55

Browse files
author
David Sommerseth
committed
Improved documentation in the code
Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent e978a1a commit 97dbf55

File tree

4 files changed

+94
-25
lines changed

4 files changed

+94
-25
lines changed

python-ethtool/etherinfo.c

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
* Internal functions for working with struct etherinfo
3636
*
3737
*/
38+
39+
/**
40+
* Simple macro which makes sure the destination string is freed if used earlier.
41+
*
42+
* @param dst Destination pointer
43+
* @param src Source pointer
44+
*
45+
*/
3846
#define SET_STR_VALUE(dst, src) { \
3947
if( dst ) { \
4048
free(dst); \
@@ -43,6 +51,11 @@
4351
}
4452

4553

54+
/**
55+
* Frees the memory used by a struct ipv6address pointer chain. All elements are freed
56+
*
57+
* @param ptr Pointer to a struct ipv6address chain.
58+
*/
4659
void free_ipv6addresses(struct ipv6address *ptr) {
4760
struct ipv6address *ipv6ptr = ptr;
4861

@@ -59,6 +72,11 @@ void free_ipv6addresses(struct ipv6address *ptr) {
5972
}
6073
}
6174

75+
/**
76+
* Frees the memory used by struct etherinfo, including all struct ipv6address children.
77+
*
78+
* @param ptr Pointer to a struct etherninfo element
79+
*/
6280
void free_etherinfo(struct etherinfo *ptr)
6381
{
6482
if( ptr == NULL ) { // Just for safety
@@ -82,6 +100,17 @@ void free_etherinfo(struct etherinfo *ptr)
82100
free(ptr);
83101
}
84102

103+
104+
/**
105+
* Add a new IPv6 address record to a struct ipv6address chain
106+
*
107+
* @param addrptr Pointer to the current IPv6 address chain.
108+
* @param addr IPv6 address, represented as char * string
109+
* @param netmask IPv6 netmask, as returned by libnl rtnl_addr_get_prefixlen()
110+
* @param scope IPV6 address scope, as returned by libnl rtnl_addr_get_scope()
111+
*
112+
* @return Returns a new pointer to the chain containing the new element
113+
*/
85114
struct ipv6address * etherinfo_add_ipv6(struct ipv6address *addrptr, const char *addr, int netmask, int scope) {
86115
struct ipv6address *newaddr = NULL;
87116

@@ -100,11 +129,13 @@ struct ipv6address * etherinfo_add_ipv6(struct ipv6address *addrptr, const char
100129
}
101130

102131

103-
/*
104-
* libnl callback functions
132+
/**
133+
* libnl callback function. Does the real parsing of a record returned by NETLINK. This function
134+
* parses LINK related packets
105135
*
136+
* @param obj Pointer to a struct nl_object response
137+
* @param arg Pointer to a struct etherinfo element where the parse result will be saved
106138
*/
107-
108139
static void callback_nl_link(struct nl_object *obj, void *arg)
109140
{
110141
struct etherinfo *ethi = (struct etherinfo *) arg;
@@ -137,6 +168,13 @@ static void callback_nl_link(struct nl_object *obj, void *arg)
137168
}
138169

139170

171+
/**
172+
* libnl callback function. Does the real parsing of a record returned by NETLINK. This function
173+
* parses ADDRESS related packets
174+
*
175+
* @param obj Pointer to a struct nl_object response
176+
* @param arg Pointer to a struct etherinfo element where the parse result will be saved
177+
*/
140178
static void callback_nl_address(struct nl_object *obj, void *arg)
141179
{
142180
struct etherinfo *ethi = (struct etherinfo *) arg;
@@ -188,6 +226,12 @@ static void callback_nl_address(struct nl_object *obj, void *arg)
188226
*
189227
*/
190228

229+
/**
230+
* Dumps the contents of a struct etherinfo element to file
231+
*
232+
* @param fp FILE pointer where to dump
233+
* @param ptr Pointer to a struct etherinfo element
234+
*/
191235
void dump_etherinfo(FILE *fp, struct etherinfo *ptr)
192236
{
193237

@@ -220,6 +264,16 @@ void dump_etherinfo(FILE *fp, struct etherinfo *ptr)
220264
}
221265

222266

267+
/**
268+
* Query NETLINK for ethernet configuration
269+
*
270+
* @param ethinf Pointer to an available struct etherinfo element. The 'device' member
271+
* must contain a valid string to the device to query for information
272+
* @param nlc Pointer to the libnl handle, which is used for the query against NETLINK
273+
* @param query What to query for. Must be NLQRY_LINK or NLQRY_ADDR.
274+
*
275+
* @return Returns 1 on success, otherwise 0.
276+
*/
223277
int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery query)
224278
{
225279
struct nl_cache *link_cache;

python-ethtool/etherinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <netlink/route/addr.h>
2525
#include <arpa/inet.h>
2626

27-
typedef enum {NLQRY_LINK, NLQRY_ADDR} nlQuery;
27+
typedef enum {NLQRY_LINK, NLQRY_ADDR} nlQuery; /**< Supported query types in the etherinfo code */
2828

2929
int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery query);
3030
void free_etherinfo(struct etherinfo *ptr);

python-ethtool/etherinfo_ipv6_obj.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
/**
19-
* ethtool.etherinfo deallocator - cleans up when a object is deleted
19+
* ethtool.etherinfo_ipv6addr deallocator - cleans up when a object is deleted
2020
*
2121
* @param self etherinfo_ipv6_py object structure
2222
*/
@@ -30,7 +30,7 @@ void _ethtool_etherinfo_ipv6_dealloc(etherinfo_ipv6_py *self)
3030

3131

3232
/**
33-
* ethtool.etherinfo function, creating a new etherinfo object
33+
* ethtool.etherinfo_ipv6addr function, creating a new etherinfo object
3434
*
3535
* @param type
3636
* @param args
@@ -48,7 +48,7 @@ PyObject *_ethtool_etherinfo_ipv6_new(PyTypeObject *type, PyObject *args, PyObje
4848

4949

5050
/**
51-
* ethtool.etherinfo init (constructor) method. Makes sure the object is initialised correctly.
51+
* ethtool.etherinfo_ipv6addr init (constructor) method. Makes sure the object is initialised correctly.
5252
*
5353
* @param self
5454
* @param args
@@ -70,7 +70,7 @@ int _ethtool_etherinfo_ipv6_init(etherinfo_ipv6_py *self, PyObject *args, PyObje
7070
}
7171

7272
/**
73-
* ethtool.etherinfo function for retrieving data from a Python object.
73+
* ethtool.etherinfo_ipv6addr function for retrieving data from a Python object.
7474
*
7575
* @param self
7676
* @param attr_o contains the object member request (which element to return)
@@ -104,7 +104,7 @@ PyObject *_ethtool_etherinfo_ipv6_getter(etherinfo_ipv6_py *self, PyObject *attr
104104

105105

106106
/**
107-
* ethtool.etherinfo function for setting a value to a object member. This feature is
107+
* ethtool.etherinfo_ipv6addr function for setting a value to a object member. This feature is
108108
* disabled by always returning -1, as the values are read-only by the user.
109109
*
110110
* @param self

python-ethtool/etherinfo_struct.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@
1010
#ifndef _ETHERINFO_STRUCT_H
1111
#define _ETHERINFO_STRUCT_H
1212

13-
13+
/**
14+
* Contains IP address information about a particular ethernet device
15+
*
16+
*/
1417
struct etherinfo {
15-
char *device;
16-
int index;
17-
char *hwaddress;
18-
char *ipv4_address;
19-
int ipv4_netmask;
20-
char *ipv4_broadcast;
21-
struct ipv6address *ipv6_addresses;
18+
char *device; /**< Device name */
19+
int index; /**< NETLINK index reference */
20+
char *hwaddress; /**< HW address / MAC address of device */
21+
char *ipv4_address; /**< Configured IPv4 address */
22+
int ipv4_netmask; /**< Configured IPv4 netmask */
23+
char *ipv4_broadcast; /**< Configured IPv4 broadcast address */
24+
struct ipv6address *ipv6_addresses; /**< Configured IPv6 addresses (as a pointer chain) */
2225
};
2326

27+
28+
/**
29+
* Pointer chain with IPv6 addresses associated with a ethernet interface. Used
30+
* by struct etherinfo
31+
*/
2432
struct ipv6address {
25-
char *address;
26-
int netmask;
27-
int scope;
28-
struct ipv6address *next;
33+
char *address; /**< Configured IPv6 address */
34+
int netmask; /**< Configured IPv6 netmask */
35+
int scope; /**< Scope for the IPv6 address */
36+
struct ipv6address *next; /**< Pointer to next configured IPv6 address */
2937
};
3038

31-
/*
39+
/**
3240
* NETLINK connection handle and related information to be shared
3341
* among all the instantiated etherinfo objects.
3442
*/
@@ -46,15 +54,22 @@ struct etherinfo_obj_data {
4654
struct etherinfo *ethinfo; /**< Contains info about our current interface */
4755
};
4856

57+
/**
58+
* A Python object of struct etherinfo_obj_data
59+
*
60+
*/
4961
typedef struct {
5062
PyObject_HEAD
51-
struct etherinfo_obj_data *data;
63+
struct etherinfo_obj_data *data; /* IPv4 and IPv6 address information, only one element used */
5264
} etherinfo_py;
5365

54-
66+
/**
67+
* A Python object of struct ipv6address
68+
*
69+
*/
5570
typedef struct {
5671
PyObject_HEAD
57-
struct ipv6address *addrdata;
72+
struct ipv6address *addrdata; /**< IPv6 address, only one element is used in this case */
5873
} etherinfo_ipv6_py;
5974

6075
/**

0 commit comments

Comments
 (0)