From a1351738ba11c8e2d38f6df5276cc59f7acb2d2f Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 17 Jan 2017 14:11:31 +0100 Subject: list: Remove cds_list_* wrappers Use the cds_list_* types and macros directly instead of redefining them. This makes it clear that we're not using the Linux kernel implementation of list_head but the one from urcu. Also make sure _LGPL_SOURCE is defined everywhere the urcu functionality is used, such that we get the statically linkable version with reduced overhead. Reference: https://lwn.net/Articles/573424/#qq2answer Signed-off-by: Tobias Klauser --- flowtop.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'flowtop.c') diff --git a/flowtop.c b/flowtop.c index 3cee0ec..b2d6546 100644 --- a/flowtop.c +++ b/flowtop.c @@ -19,13 +19,16 @@ #include #include #include -#include #include #include #include #include #include +#include +#include +#include + #include "ui.h" #include "die.h" #include "xmalloc.h" @@ -50,7 +53,7 @@ #endif struct flow_entry { - struct list_head entry; + struct cds_list_head entry; struct rcu_head rcu; uint32_t flow_id, use, status; @@ -79,7 +82,7 @@ struct flow_entry { }; struct flow_list { - struct list_head head; + struct cds_list_head head; }; enum flow_direction { @@ -369,7 +372,7 @@ static void flow_entry_xfree_rcu(struct rcu_head *head) static inline void flow_list_init(struct flow_list *fl) { - INIT_LIST_HEAD(&fl->head); + CDS_INIT_LIST_HEAD(&fl->head); } static inline bool nfct_is_dns(const struct nf_conntrack *ct) @@ -398,7 +401,7 @@ static int flow_list_new_entry(struct flow_list *fl, struct nf_conntrack *ct) flow_entry_from_ct(n, ct); flow_entry_get_extended(n); - list_add_rcu(&n->entry, &fl->head); + cds_list_add_rcu(&n->entry, &fl->head); n->is_visible = true; @@ -409,7 +412,7 @@ static struct flow_entry *flow_list_find_id(struct flow_list *fl, uint32_t id) { struct flow_entry *n; - list_for_each_entry_rcu(n, &fl->head, entry) { + cds_list_for_each_entry_rcu(n, &fl->head, entry) { if (n->flow_id == id) return n; } @@ -423,7 +426,7 @@ static int flow_list_del_entry(struct flow_list *fl, const struct nf_conntrack * n = flow_list_find_id(fl, nfct_get_attr_u32(ct, ATTR_ID)); if (n) { - list_del_rcu(&n->entry); + cds_list_del_rcu(&n->entry); call_rcu(&n->rcu, flow_entry_xfree_rcu); } @@ -434,8 +437,8 @@ static void flow_list_destroy(struct flow_list *fl) { struct flow_entry *n, *tmp; - list_for_each_entry_safe(n, tmp, &fl->head, entry) { - list_del_rcu(&n->entry); + cds_list_for_each_entry_safe(n, tmp, &fl->head, entry) { + cds_list_del_rcu(&n->entry); call_rcu(&n->rcu, flow_entry_xfree_rcu); } } @@ -1012,14 +1015,14 @@ static void draw_flows(WINDOW *screen, struct flow_list *fl, rcu_read_lock(); - if (list_empty(&fl->head)) + if (cds_list_empty(&fl->head)) mvwprintw(screen, line, 2, "(No sessions! " "Is netfilter running?)"); ui_table_clear(&flows_tbl); ui_table_header_print(&flows_tbl); - list_for_each_entry_rcu(n, &fl->head, entry) { + cds_list_for_each_entry_rcu(n, &fl->head, entry) { if (!n->is_visible) continue; if (presenter_flow_wrong_state(n)) @@ -1398,8 +1401,9 @@ static void collector_refresh_flows(struct nfct_handle *handle) { struct flow_entry *n; - list_for_each_entry_rcu(n, &flow_list.head, entry) + cds_list_for_each_entry_rcu(n, &flow_list.head, entry) { nfct_query(handle, NFCT_Q_GET, n->ct); + } } static void collector_create_filter(struct nfct_handle *nfct) -- cgit v1.2.3-54-g00ecf