From 890aea491bd4326a5d03adba92495e4722a6b63e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 7 Aug 2015 09:47:15 +0200 Subject: flowtop: Simplify nfct_is_dns() Instead of creating an additional struct flow_entry on the stack just to use the CP_NFCT macros, call nfct_get_attr_u16() directly. Signed-off-by: Tobias Klauser --- flowtop.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/flowtop.c b/flowtop.c index 9cc7302..d988590 100644 --- a/flowtop.c +++ b/flowtop.c @@ -205,8 +205,6 @@ static void signal_handler(int number) static void flow_entry_from_ct(struct flow_entry *n, struct nf_conntrack *ct); static void flow_entry_get_extended(struct flow_entry *n); -static bool nfct_is_dns(struct nf_conntrack *ct); - static void help(void) { printf("flowtop %s, top-like netfilter TCP/UDP/SCTP/.. flow tracking\n", @@ -264,6 +262,14 @@ static inline void flow_list_init(struct flow_list *fl) spinlock_init(&fl->lock); } +static inline bool nfct_is_dns(struct nf_conntrack *ct) +{ + uint16_t port_src = nfct_get_attr_u16(ct, ATTR_ORIG_PORT_SRC); + uint16_t port_dst = nfct_get_attr_u16(ct, ATTR_ORIG_PORT_DST); + + return ntohs(port_src) == 53 || ntohs(port_dst) == 53; +} + static void flow_list_new_entry(struct flow_list *fl, struct nf_conntrack *ct) { struct flow_entry *n; @@ -532,17 +538,6 @@ enum flow_entry_direction { flow_entry_dst, }; -static bool nfct_is_dns(struct nf_conntrack *ct) -{ - struct flow_entry fl; - struct flow_entry *n = &fl; - - CP_NFCT(port_src, ATTR_ORIG_PORT_SRC, 16); - CP_NFCT(port_dst, ATTR_ORIG_PORT_DST, 16); - - return ntohs(n->port_src) == 53 || ntohs(n->port_dst) == 53; -} - #define SELFLD(dir,src_member,dst_member) \ (((dir) == flow_entry_src) ? n->src_member : n->dst_member) -- cgit v1.2.3-54-g00ecf