summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-08-01 11:04:06 +0300
committerTobias Klauser <tklauser@distanz.ch>2015-08-03 09:54:34 +0200
commita0aa230246ae57a03c44ba0c9d2be8e64507f97e (patch)
treeb9342da7de779d91f4db7b2cd3afae288abe20ba
parentd19a87a0b2d6c8a282a04ef80bee5a3b9f4547a1 (diff)
flowtop: Move filter creating to separate function
Move creating nfct filter to separate function to make collector() less messy. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--flowtop.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/flowtop.c b/flowtop.c
index 6466b47..aeb0f7e 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);