diff options
Diffstat (limited to 'python-ethtool/etherinfo.c')
| -rw-r--r-- | python-ethtool/etherinfo.c | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c index 8d56279..3039a27 100644 --- a/python-ethtool/etherinfo.c +++ b/python-ethtool/etherinfo.c @@ -20,14 +20,10 @@ #include <stdio.h> #include <string.h> #include <sys/types.h> -#include <unistd.h> -#include <fcntl.h> #include <stdlib.h> #include <asm/types.h> #include <sys/socket.h> #include <arpa/inet.h> -#include <netlink/netlink.h> -#include <netlink/socket.h> #include <netlink/cache.h> #include <netlink/addr.h> #include <netlink/route/addr.h> @@ -39,8 +35,6 @@ #include "etherinfo_struct.h" #include "etherinfo.h" -pthread_mutex_t nlc_counter_mtx = PTHREAD_MUTEX_INITIALIZER; - /* * * Internal functions for working with struct etherinfo @@ -287,83 +281,3 @@ int get_etherinfo(struct etherinfo_obj_data *data, nlQuery query) } return ret; } - - -/** - * Connects to the NETLINK interface. This will be called - * for each etherinfo object being generated, and it will - * keep a separate file descriptor open for each object - * - * @param data etherinfo_obj_data structure - * - * @return Returns 1 on success, otherwise 0. - */ -int open_netlink(struct etherinfo_obj_data *data) -{ - if( !data ) { - return 0; - } - - /* Reuse already established NETLINK connection, if a connection exists */ - if( *data->nlc ) { - /* If this object has not used NETLINK earlier, tag it as a user */ - if( !data->nlc_active ) { - pthread_mutex_lock(&nlc_counter_mtx); - (*data->nlc_users)++; - pthread_mutex_unlock(&nlc_counter_mtx); - } - data->nlc_active = 1; - return 1; - } - - /* No earlier connections exists, establish a new one */ - *data->nlc = nl_socket_alloc(); - nl_connect(*data->nlc, NETLINK_ROUTE); - if( (*data->nlc != NULL) ) { - /* Force O_CLOEXEC flag on the NETLINK socket */ - if( fcntl(nl_socket_get_fd(*data->nlc), F_SETFD, FD_CLOEXEC) == -1 ) { - fprintf(stderr, - "**WARNING** Failed to set O_CLOEXEC on NETLINK socket: %s\n", - strerror(errno)); - } - - /* Tag this object as an active user */ - pthread_mutex_lock(&nlc_counter_mtx); - (*data->nlc_users)++; - pthread_mutex_unlock(&nlc_counter_mtx); - data->nlc_active = 1; - return 1; - } else { - return 0; - } -} - - -/** - * Closes the NETLINK connection. This should be called automatically whenever - * the corresponding etherinfo object is deleted. - * - * @param ptr Pointer to the pointer of struct nl_handle, which contains the NETLINK connection - */ -void close_netlink(struct etherinfo_obj_data *data) -{ - if( !data || !(*data->nlc) ) { - return; - } - - /* Untag this object as a NETLINK user */ - data->nlc_active = 0; - pthread_mutex_lock(&nlc_counter_mtx); - (*data->nlc_users)--; - pthread_mutex_unlock(&nlc_counter_mtx); - - /* Don't close the connection if there are more users */ - if( *data->nlc_users > 0) { - return; - } - - /* Close NETLINK connection */ - nl_close(*data->nlc); - nl_socket_free(*data->nlc); - *data->nlc = NULL; -} |
