From a33337bb3941103068465990584b19d0c5cc0726 Mon Sep 17 00:00:00 2001 From: "Fabio M. Di Nitto" Date: Mon, 16 Mar 2020 15:50:29 +0100 Subject: [PATCH] [lists] drop internal implementation and use libqb one Signed-off-by: Fabio M. Di Nitto --- configure.ac | 4 +- kronosnet.spec.in | 4 +- libknet/Makefile.am | 2 +- libknet/internals.h | 170 +-------------------------------------- libknet/transport_sctp.c | 26 +++--- libknet/transport_udp.c | 14 ++-- 6 files changed, 26 insertions(+), 194 deletions(-) diff --git a/configure.ac b/configure.ac index 3534c0f1f..0a8477fa4 100644 --- a/configure.ac +++ b/configure.ac @@ -272,6 +272,8 @@ if test "x$enable_man" = "xyes"; then ac_cv_path_PKG_CONFIG="$saved_ac_cv_path_PKG_CONFIG" fi +PKG_CHECK_MODULES([libqb], [libqb]) + # checks for libnozzle if test "x$enable_libnozzle" = xyes; then if `echo $host_os | grep -q linux`; then @@ -294,8 +296,6 @@ if test "x$enable_kronosnetd" = xyes; then [AC_SUBST([pam_misc_LIBS], [-lpam_misc])], [AC_MSG_ERROR([Unable to find LinuxPAM MISC devel files])])]) - PKG_CHECK_MODULES([libqb], [libqb]) - AC_CHECK_LIB([qb], [qb_log_thread_priority_set], [have_qb_log_thread_priority_set="yes"], [have_qb_log_thread_priority_set="no"]) diff --git a/kronosnet.spec.in b/kronosnet.spec.in index 28b0ea20e..6c0b6c5d0 100644 --- a/kronosnet.spec.in +++ b/kronosnet.spec.in @@ -49,10 +49,10 @@ URL: https://kronosnet.org Source0: https://kronosnet.org/releases/%{name}-%{version}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}.tar.gz # Build dependencies -BuildRequires: gcc +BuildRequires: gcc libqb-devel # required to build man pages %if %{with buildman} -BuildRequires: libqb-devel libxml2-devel doxygen +BuildRequires: libxml2-devel doxygen %endif %if %{with sctp} BuildRequires: lksctp-tools-devel diff --git a/libknet/Makefile.am b/libknet/Makefile.am index f9ba25dbd..1be2bee89 100644 --- a/libknet/Makefile.am +++ b/libknet/Makefile.am @@ -87,7 +87,7 @@ lib_LTLIBRARIES = libknet.la libknet_la_SOURCES = $(sources) -libknet_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) +libknet_la_CFLAGS = $(AM_CFLAGS) $(libqb_CFLAGS) $(PTHREAD_CFLAGS) EXTRA_libknet_la_DEPENDENCIES = $(SYMFILE) diff --git a/libknet/internals.h b/libknet/internals.h index e2f882b1a..af0d50c3f 100644 --- a/libknet/internals.h +++ b/libknet/internals.h @@ -16,6 +16,7 @@ #include #include +#include #include "libknet.h" #include "onwire.h" #include "compat.h" @@ -409,173 +410,4 @@ struct pretty_names { uint8_t val; }; -/** - * This is a kernel style list implementation. - * - * @author Steven Dake - */ - -struct knet_list_head { - struct knet_list_head *next; - struct knet_list_head *prev; -}; - -/** - * @def KNET_LIST_DECLARE() - * Declare and initialize a list head. - */ -#define KNET_LIST_DECLARE(name) \ - struct knet_list_head name = { &(name), &(name) } - -#define KNET_INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) - -/** - * Initialize the list entry. - * - * Points next and prev pointers to head. - * @param head pointer to the list head - */ -static inline void knet_list_init(struct knet_list_head *head) -{ - head->next = head; - head->prev = head; -} - -/** - * Add this element to the list. - * - * @param element the new element to insert. - * @param head pointer to the list head - */ -static inline void knet_list_add(struct knet_list_head *element, - struct knet_list_head *head) -{ - head->next->prev = element; - element->next = head->next; - element->prev = head; - head->next = element; -} - -/** - * Add to the list (but at the end of the list). - * - * @param element pointer to the element to add - * @param head pointer to the list head - * @see knet_list_add() - */ -static inline void knet_list_add_tail(struct knet_list_head *element, - struct knet_list_head *head) -{ - head->prev->next = element; - element->next = head; - element->prev = head->prev; - head->prev = element; -} - -/** - * Delete an entry from the list. - * - * @param _remove the list item to remove - */ -static inline void knet_list_del(struct knet_list_head *_remove) -{ - _remove->next->prev = _remove->prev; - _remove->prev->next = _remove->next; -} - -/** - * Replace old entry by new one - * @param old: the element to be replaced - * @param new: the new element to insert - */ -static inline void knet_list_replace(struct knet_list_head *old, - struct knet_list_head *new) -{ - new->next = old->next; - new->next->prev = new; - new->prev = old->prev; - new->prev->next = new; -} - -/** - * Tests whether list is the last entry in list head - * @param list: the entry to test - * @param head: the head of the list - * @return boolean true/false - */ -static inline int knet_list_is_last(const struct knet_list_head *list, - const struct knet_list_head *head) -{ - return list->next == head; -} - -/** - * A quick test to see if the list is empty (pointing to it's self). - * @param head pointer to the list head - * @return boolean true/false - */ -static inline int32_t knet_list_empty(const struct knet_list_head *head) -{ - return head->next == head; -} - - -/** - * Get the struct for this entry - * @param ptr: the &struct list_head pointer. - * @param type: the type of the struct this is embedded in. - * @param member: the name of the list_struct within the struct. - */ -#define knet_list_entry(ptr,type,member) ({ \ - ((type *)((char*)ptr - offsetof(type, member))); }) - -/** - * Get the first element from a list - * @param ptr: the &struct list_head pointer. - * @param type: the type of the struct this is embedded in. - * @param member: the name of the list_struct within the struct. - */ -#define knet_list_first_entry(ptr, type, member) \ - knet_list_entry((ptr)->next, type, member) - -/** - * Iterate over a list - * @param pos: the &struct list_head to use as a loop counter. - * @param head: the head for your list. - */ -#define knet_list_for_each(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) - -/** - * Iterate over a list backwards - * @param pos: the &struct list_head to use as a loop counter. - * @param head: the head for your list. - */ -#define knet_list_for_each_reverse(pos, head) \ - for (pos = (head)->prev; pos != (head); pos = pos->prev) - -/** - * Iterate over a list safe against removal of list entry - * @param pos: the &struct list_head to use as a loop counter. - * @param n: another &struct list_head to use as temporary storage - * @param head: the head for your list. - */ -#define knet_list_for_each_safe(pos, n, head) \ - for (pos = (head)->next, n = pos->next; pos != (head); \ - pos = n, n = pos->next) - -/** - * Iterate over list of given type - * @param pos: the type * to use as a loop counter. - * @param head: the head for your list. - * @param member: the name of the list_struct within the struct. - */ -#define knet_list_for_each_entry(pos, head, member) \ - for (pos = knet_list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = knet_list_entry(pos->member.next, typeof(*pos), member)) - - #endif diff --git a/libknet/transport_sctp.c b/libknet/transport_sctp.c index 667d80cfc..dc208ba2c 100644 --- a/libknet/transport_sctp.c +++ b/libknet/transport_sctp.c @@ -33,8 +33,8 @@ #include "transport_sctp.h" typedef struct sctp_handle_info { - struct knet_list_head listen_links_list; - struct knet_list_head connect_links_list; + struct qb_list_head listen_links_list; + struct qb_list_head connect_links_list; int connect_epollfd; int connectsockfd[2]; int listen_epollfd; @@ -59,7 +59,7 @@ typedef struct sctp_handle_info { #define MAX_ACCEPTED_SOCKS 256 typedef struct sctp_listen_link_info { - struct knet_list_head list; + struct qb_list_head list; int listen_sock; int accepted_socks[MAX_ACCEPTED_SOCKS]; struct sockaddr_storage src_address; @@ -75,7 +75,7 @@ typedef struct sctp_accepted_link_info { } sctp_accepted_link_info_t ; typedef struct sctp_connect_link_info { - struct knet_list_head list; + struct qb_list_head list; sctp_listen_link_info_t *listener; struct knet_link *link; struct sockaddr_storage dst_address; @@ -977,7 +977,7 @@ static sctp_listen_link_info_t *sctp_link_listener_start(knet_handle_t knet_h, s /* * Only allocate a new listener if src address is different */ - knet_list_for_each_entry(info, &handle_info->listen_links_list, list) { + qb_list_for_each_entry(info, &handle_info->listen_links_list, list) { if (memcmp(&info->src_address, &kn_link->src_addr, sizeof(struct sockaddr_storage)) == 0) { if ((check_add(knet_h, info->listen_sock, KNET_TRANSPORT_SCTP, -1, &kn_link->dst_addr, &kn_link->dst_addr, CHECK_TYPE_ADDRESS, CHECK_ACCEPT) < 0) && (errno != EEXIST)) { @@ -1059,7 +1059,7 @@ static sctp_listen_link_info_t *sctp_link_listener_start(knet_handle_t knet_h, s info->on_listener_epoll = 1; info->listen_sock = listen_sock; - knet_list_add(&info->list, &handle_info->listen_links_list); + qb_list_add(&info->list, &handle_info->listen_links_list); log_debug(knet_h, KNET_SUB_TRANSP_SCTP, "Listening on fd %d for %s:%s", listen_sock, kn_link->status.src_ipaddr, kn_link->status.src_port); @@ -1169,7 +1169,7 @@ static int sctp_link_listener_stop(knet_handle_t knet_h, struct knet_link *kn_li } } - knet_list_del(&info->list); + qb_list_del(&info->list); free(info); this_link_info->listener = NULL; @@ -1216,7 +1216,7 @@ int sctp_transport_link_set_config(knet_handle_t knet_h, struct knet_link *kn_li kn_link->outsock = info->connect_sock; } - knet_list_add(&info->list, &handle_info->connect_links_list); + qb_list_add(&info->list, &handle_info->connect_links_list); exit_error: if (err) { @@ -1271,7 +1271,7 @@ int sctp_transport_link_clear_config(knet_handle_t knet_h, struct knet_link *kn_ goto exit_error; } - knet_list_del(&info->list); + qb_list_del(&info->list); free(info); kn_link->transport_link = NULL; @@ -1305,10 +1305,10 @@ int sctp_transport_free(knet_handle_t knet_h) /* * keep it here while we debug list usage and such */ - if (!knet_list_empty(&handle_info->listen_links_list)) { + if (!qb_list_empty(&handle_info->listen_links_list)) { log_err(knet_h, KNET_SUB_TRANSP_SCTP, "Internal error. listen links list is not empty"); } - if (!knet_list_empty(&handle_info->connect_links_list)) { + if (!qb_list_empty(&handle_info->connect_links_list)) { log_err(knet_h, KNET_SUB_TRANSP_SCTP, "Internal error. connect links list is not empty"); } @@ -1441,8 +1441,8 @@ int sctp_transport_init(knet_handle_t knet_h) goto exit_fail; } - knet_list_init(&handle_info->listen_links_list); - knet_list_init(&handle_info->connect_links_list); + qb_list_init(&handle_info->listen_links_list); + qb_list_init(&handle_info->connect_links_list); handle_info->listen_epollfd = epoll_create(KNET_EPOLL_MAX_EVENTS + 1); if (handle_info->listen_epollfd < 0) { diff --git a/libknet/transport_udp.c b/libknet/transport_udp.c index 2b3e4327c..17f539862 100644 --- a/libknet/transport_udp.c +++ b/libknet/transport_udp.c @@ -33,11 +33,11 @@ #include "threads_common.h" typedef struct udp_handle_info { - struct knet_list_head links_list; + struct qb_list_head links_list; } udp_handle_info_t; typedef struct udp_link_info { - struct knet_list_head list; + struct qb_list_head list; struct sockaddr_storage local_address; int socket_fd; int on_epoll; @@ -57,7 +57,7 @@ int udp_transport_link_set_config(knet_handle_t knet_h, struct knet_link *kn_lin /* * Only allocate a new link if the local address is different */ - knet_list_for_each_entry(info, &handle_info->links_list, list) { + qb_list_for_each_entry(info, &handle_info->links_list, list) { if (memcmp(&info->local_address, &kn_link->src_addr, sizeof(struct sockaddr_storage)) == 0) { log_debug(knet_h, KNET_SUB_TRANSP_UDP, "Re-using existing UDP socket for new link"); kn_link->outsock = info->socket_fd; @@ -152,7 +152,7 @@ int udp_transport_link_set_config(knet_handle_t knet_h, struct knet_link *kn_lin memmove(&info->local_address, &kn_link->src_addr, sizeof(struct sockaddr_storage)); info->socket_fd = sock; - knet_list_add(&info->list, &handle_info->links_list); + qb_list_add(&info->list, &handle_info->links_list); kn_link->outsock = sock; kn_link->transport_link = info; @@ -226,7 +226,7 @@ int udp_transport_link_clear_config(knet_handle_t knet_h, struct knet_link *kn_l } close(info->socket_fd); - knet_list_del(&info->list); + qb_list_del(&info->list); free(kn_link->transport_link); exit_error: @@ -248,7 +248,7 @@ int udp_transport_free(knet_handle_t knet_h) /* * keep it here while we debug list usage and such */ - if (!knet_list_empty(&handle_info->links_list)) { + if (!qb_list_empty(&handle_info->links_list)) { log_err(knet_h, KNET_SUB_TRANSP_UDP, "Internal error. handle list is not empty"); return -1; } @@ -278,7 +278,7 @@ int udp_transport_init(knet_handle_t knet_h) knet_h->transports[KNET_TRANSPORT_UDP] = handle_info; - knet_list_init(&handle_info->links_list); + qb_list_init(&handle_info->links_list); return 0; }