summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2010-08-03 10:30:23 +0200
committerDavid Sommerseth <davids@redhat.com>2010-08-03 10:30:23 +0200
commitb80e65903258d71ac7be0f0775db15aa096a4b54 (patch)
treeb21b10b5a86f96b98312b7d8daf3ab3dd5c0cce2
parent19be403f729d3064259ca17e57ef24a1cc2ff81b (diff)
downloadpython-ethtool-b80e65903258d71ac7be0f0775db15aa096a4b54.tar.gz
python-ethtool-b80e65903258d71ac7be0f0775db15aa096a4b54.tar.xz
python-ethtool-b80e65903258d71ac7be0f0775db15aa096a4b54.zip
Get rid of not needed struct wrapping
The struct nl_handle was wrapped inside struct _nlconnection. This is really not needed if open_netlink() and close_netlink() functions uses "pointer's pointer" (struct nl_handle **) instead. Removes also the need to declare a static struct _nlconnection, as the global nlconnection variable can now be a pointer as well. Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r--python-ethtool/etherinfo.c8
-rw-r--r--python-ethtool/etherinfo.h2
-rw-r--r--python-ethtool/etherinfo_struct.h9
-rw-r--r--python-ethtool/ethtool.c38
4 files changed, 25 insertions, 32 deletions
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c
index 4cb5bc1..2091a3c 100644
--- a/python-ethtool/etherinfo.c
+++ b/python-ethtool/etherinfo.c
@@ -274,7 +274,7 @@ void dump_etherinfo(FILE *fp, struct etherinfo *ptr)
*
* @return Returns 1 on success, otherwise 0.
*/
-int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery query)
+int get_etherinfo(struct etherinfo *ethinf, struct nl_handle *nlc, nlQuery query)
{
struct nl_cache *link_cache;
struct nl_cache *addr_cache;
@@ -291,7 +291,7 @@ int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery q
* interface index if we have that
*/
if( ethinf->index < 0 ) {
- link_cache = rtnl_link_alloc_cache(nlc->nlrt_handle);
+ link_cache = rtnl_link_alloc_cache(nlc);
ethinf->index = rtnl_link_name2i(link_cache, ethinf->device);
if( ethinf->index < 0 ) {
return 0;
@@ -303,7 +303,7 @@ int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery q
switch( query ) {
case NLQRY_LINK:
/* Extract MAC/hardware address of the interface */
- link_cache = rtnl_link_alloc_cache(nlc->nlrt_handle);
+ link_cache = rtnl_link_alloc_cache(nlc);
link = rtnl_link_alloc();
rtnl_link_set_ifindex(link, ethinf->index);
nl_cache_foreach_filter(link_cache, (struct nl_object *)link, callback_nl_link, ethinf);
@@ -318,7 +318,7 @@ int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery q
ethinf->ipv6_addresses = NULL;
/* Extract IP address information */
- addr_cache = rtnl_addr_alloc_cache(nlc->nlrt_handle);
+ addr_cache = rtnl_addr_alloc_cache(nlc);
addr = rtnl_addr_alloc();
rtnl_addr_set_ifindex(addr, ethinf->index);
nl_cache_foreach_filter(addr_cache, (struct nl_object *)addr, callback_nl_address, ethinf);
diff --git a/python-ethtool/etherinfo.h b/python-ethtool/etherinfo.h
index 833e4e8..db368db 100644
--- a/python-ethtool/etherinfo.h
+++ b/python-ethtool/etherinfo.h
@@ -26,7 +26,7 @@
typedef enum {NLQRY_LINK, NLQRY_ADDR} nlQuery; /**< Supported query types in the etherinfo code */
-int get_etherinfo(struct etherinfo *ethinf, struct _nlconnection *nlc, nlQuery query);
+int get_etherinfo(struct etherinfo *ethinf, struct nl_handle *nlc, nlQuery query);
void free_etherinfo(struct etherinfo *ptr);
void dump_etherinfo(FILE *, struct etherinfo *);
diff --git a/python-ethtool/etherinfo_struct.h b/python-ethtool/etherinfo_struct.h
index d627ba6..b1d453f 100644
--- a/python-ethtool/etherinfo_struct.h
+++ b/python-ethtool/etherinfo_struct.h
@@ -51,13 +51,6 @@ struct ipv6address {
struct ipv6address *next; /**< Pointer to next configured IPv6 address */
};
-/**
- * NETLINK connection handle and related information to be shared
- * among all the instantiated etherinfo objects.
- */
-struct _nlconnection {
- struct nl_handle *nlrt_handle;
-};
/**
* Contains the internal data structure of the
@@ -65,7 +58,7 @@ struct _nlconnection {
*
*/
struct etherinfo_obj_data {
- struct _nlconnection *nlc; /**< Contains NETLINK connection info */
+ struct nl_handle *nlc; /**< Contains NETLINK connection info */
struct etherinfo *ethinfo; /**< Contains info about our current interface */
};
diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c
index 52e274f..feb6917 100644
--- a/python-ethtool/ethtool.c
+++ b/python-ethtool/ethtool.c
@@ -31,7 +31,7 @@
#include "etherinfo_obj.h"
#include "etherinfo.h"
-static struct _nlconnection nlconnection;
+static struct nl_handle *nlconnection = NULL;
extern PyTypeObject ethtool_etherinfoType;
extern PyTypeObject ethtool_etherinfoIPv6Type;
@@ -307,7 +307,7 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
*/
objdata->ethinfo->device = strdup(fetch_devs[i]);
objdata->ethinfo->index = -1;
- objdata->nlc = &nlconnection; /* Global variable */
+ objdata->nlc = nlconnection; /* Global variable */
/* Instantiate a new etherinfo object with the device information */
ethinf_py = PyCObject_FromVoidPtr(objdata, NULL);
@@ -971,22 +971,22 @@ static struct PyMethodDef PyEthModuleMethods[] = {
/**
- * Connects to the NETLINK interface and stores the connection handles in the given struct. This
- * should be called as part of the main ethtool module init.
+ * Connects to the NETLINK interface. This should only be
+ * called once as part of the main ethtool module init.
*
- * @param nlc Structure which keeps the NETLINK connection handle
+ * @param nlc Structure which keeps the NETLINK connection handle (struct nl_handle)
*
* @return Returns 1 on success, otherwise 0.
*/
-int open_netlink(struct _nlconnection *nlc)
+int open_netlink(struct nl_handle **nlc)
{
- if( !nlc ) {
+ if( *nlc ) {
return 0;
}
- nlc->nlrt_handle = nl_handle_alloc();
- nl_connect(nlc->nlrt_handle, NETLINK_ROUTE);
- return (nlc->nlrt_handle != NULL);
+ *nlc = nl_handle_alloc();
+ nl_connect(*nlc, NETLINK_ROUTE);
+ return (*nlc != NULL);
}
@@ -994,25 +994,25 @@ int open_netlink(struct _nlconnection *nlc)
* Closes the NETLINK connection. This should be called automatically whenever
* the ethtool module is unloaded from Python.
*
- * @param ptr Points at a struct _nlconnection object with an open NETLINK connection
+ * @param ptr Pointer to the pointer of struct nl_handle, which contains the NETLINK connection
*/
-void close_netlink(void *ptr)
+void close_netlink(void **ptr)
{
- struct _nlconnection *nlc;
+ struct nl_handle *nlc;
- if( !ptr ) {
+ if( !ptr && !*ptr ) {
return;
}
- nlc = (struct _nlconnection *) ptr;
- if( !nlc->nlrt_handle ) {
+ nlc = (struct nl_handle *) *ptr;
+ if( !nlc ) {
return;
}
/* Close NETLINK connection */
- nl_close(nlc->nlrt_handle);
- nl_handle_destroy(nlc->nlrt_handle);
- nlc->nlrt_handle = NULL;
+ nl_close(nlc);
+ nl_handle_destroy(nlc);
+ *ptr = NULL; /* reset the pointers pointer address */
}