diff options
Diffstat (limited to 'flowtop.c')
-rw-r--r-- | flowtop.c | 84 |
1 files changed, 33 insertions, 51 deletions
@@ -421,20 +421,6 @@ static struct flow_entry *flow_list_find_prev_id(const struct flow_list *fl, return NULL; } -static void flow_list_update_entry(struct flow_list *fl, - const struct nf_conntrack *ct) -{ - struct flow_entry *n; - - n = flow_list_find_id(fl, nfct_get_attr_u32(ct, ATTR_ID)); - if (n == NULL) { - flow_list_new_entry(fl, ct); - return; - } - - flow_entry_from_ct(n, ct); -} - static void flow_list_destroy_entry(struct flow_list *fl, const struct nf_conntrack *ct) { @@ -1373,34 +1359,6 @@ static void presenter(void) lookup_cleanup(LT_PORTS_TCP); } -static int flow_event_cb(enum nf_conntrack_msg_type type, - struct nf_conntrack *ct, void *data __maybe_unused) -{ - if (sigint) - return NFCT_CB_STOP; - - synchronize_rcu(); - spinlock_lock(&flow_list.lock); - - switch (type) { - case NFCT_T_NEW: - flow_list_new_entry(&flow_list, ct); - break; - case NFCT_T_UPDATE: - flow_list_update_entry(&flow_list, ct); - break; - case NFCT_T_DESTROY: - flow_list_destroy_entry(&flow_list, ct); - break; - default: - break; - } - - spinlock_unlock(&flow_list.lock); - - return NFCT_CB_CONTINUE; -} - static void restore_sysctl(void *obj) { struct sysctl_params_ctx *sysctl_ctx = obj; @@ -1463,17 +1421,10 @@ static void flow_entry_filter(struct flow_entry *n) n->is_visible = true; } -static int flow_update_cb(enum nf_conntrack_msg_type type, - struct nf_conntrack *ct, void *data __maybe_unused) +static int flow_list_update_entry(struct flow_list *fl, struct nf_conntrack *ct) { struct flow_entry *n; - if (type != NFCT_T_UPDATE) - return NFCT_CB_CONTINUE; - - if (sigint) - return NFCT_CB_STOP; - n = flow_list_find_id(&flow_list, nfct_get_attr_u32(ct, ATTR_ID)); if (!n) return NFCT_CB_CONTINUE; @@ -1486,6 +1437,37 @@ static int flow_update_cb(enum nf_conntrack_msg_type type, return NFCT_CB_CONTINUE; } +static int flow_event_cb(enum nf_conntrack_msg_type type, + struct nf_conntrack *ct, void *data __maybe_unused) +{ + if (sigint) + return NFCT_CB_STOP; + + synchronize_rcu(); + spinlock_lock(&flow_list.lock); + + switch (type) { + case NFCT_T_NEW: + flow_list_new_entry(&flow_list, ct); + break; + case NFCT_T_UPDATE: + flow_list_update_entry(&flow_list, ct); + break; + case NFCT_T_DESTROY: + flow_list_destroy_entry(&flow_list, ct); + break; + default: + break; + } + + spinlock_unlock(&flow_list.lock); + + if (sigint) + return NFCT_CB_STOP; + + return NFCT_CB_CONTINUE; +} + static void collector_refresh_flows(struct nfct_handle *handle) { struct flow_entry *n; @@ -1653,7 +1635,7 @@ static void *collector(void *null __maybe_unused) if (!ct_update) panic("Cannot create a nfct handle: %s\n", strerror(errno)); - nfct_callback_register(ct_update, NFCT_T_ALL, flow_update_cb, NULL); + nfct_callback_register(ct_update, NFCT_T_ALL, flow_event_cb, NULL); poll_fd[0].fd = nfct_fd(ct_event); poll_fd[0].events = POLLIN; |