From a0aa230246ae57a03c44ba0c9d2be8e64507f97e Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 1 Aug 2015 11:04:06 +0300 Subject: [PATCH] flowtop: Move filter creating to separate function Move creating nfct filter to separate function to make collector() less messy. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- flowtop.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/flowtop.c b/flowtop.c index 6466b474..aeb0f7e9 100644 --- a/flowtop.c +++ b/flowtop.c @@ -1126,28 +1126,15 @@ static void collector_refresh_flows(struct nfct_handle *handle) } } -static void *collector(void *null __maybe_unused) +static void collector_create_filter(struct nfct_handle *nfct) { - struct nfct_handle *ct_event; - struct nfct_handle *ct_dump; struct nfct_filter *filter; - struct pollfd poll_fd[1]; int ret; - ct_event = nfct_open(CONNTRACK, NF_NETLINK_CONNTRACK_NEW | - NF_NETLINK_CONNTRACK_UPDATE | - NF_NETLINK_CONNTRACK_DESTROY); - if (!ct_event) - panic("Cannot create a nfct handle: %s\n", strerror(errno)); - filter = nfct_filter_create(); if (!filter) panic("Cannot create a nfct filter: %s\n", strerror(errno)); - ret = nfct_filter_attach(nfct_fd(ct_event), filter); - if (ret < 0) - panic("Cannot attach filter to handle: %s\n", strerror(errno)); - if (what & INCLUDE_UDP) { nfct_filter_add_attr_u32(filter, NFCT_FILTER_L4PROTO, IPPROTO_UDP); nfct_filter_add_attr_u32(filter, NFCT_FILTER_L4PROTO, IPPROTO_UDPLITE); @@ -1171,11 +1158,26 @@ static void *collector(void *null __maybe_unused) nfct_filter_add_attr(filter, NFCT_FILTER_SRC_IPV6, &filter_ipv6); } - ret = nfct_filter_attach(nfct_fd(ct_event), filter); + ret = nfct_filter_attach(nfct_fd(nfct), filter); if (ret < 0) panic("Cannot attach filter to handle: %s\n", strerror(errno)); nfct_filter_destroy(filter); +} + +static void *collector(void *null __maybe_unused) +{ + struct nfct_handle *ct_event; + struct nfct_handle *ct_dump; + struct pollfd poll_fd[1]; + + ct_event = nfct_open(CONNTRACK, NF_NETLINK_CONNTRACK_NEW | + NF_NETLINK_CONNTRACK_UPDATE | + NF_NETLINK_CONNTRACK_DESTROY); + if (!ct_event) + panic("Cannot create a nfct handle: %s\n", strerror(errno)); + + collector_create_filter(ct_event); nfct_callback_register(ct_event, NFCT_T_ALL, collector_cb, NULL); flow_list_init(&flow_list); @@ -1201,7 +1203,7 @@ static void *collector(void *null __maybe_unused) rcu_register_thread(); - while (!sigint && ret >= 0) { + while (!sigint) { int status; usleep(300000); -- 2.11.4.GIT