diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2015-07-22 11:11:12 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-07-22 11:20:58 +0200 |
commit | e8bc35c3efe80858a6a7a2df41e5219f3c1c8eb9 (patch) | |
tree | 4a8f132e68b3e78500c9de17f177093f4ba3ae9b /flowtop.c | |
parent | f4024343a161f50b73f106dd3dea24d68a934d5a (diff) |
flowtop: Replace bool lookup tables by switch statement
Use a switch statement instead of looking up a valid state in the
*_states_show bool arrays in presenter_flow_wrong_state(). This makes
the code a bit easier to read.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'flowtop.c')
-rw-r--r-- | flowtop.c | 77 |
1 files changed, 37 insertions, 40 deletions
@@ -152,19 +152,6 @@ static const char *const tcp_state2str[TCP_CONNTRACK_MAX] = { [TCP_CONNTRACK_SYN_SENT2] = "SYN_SENT2", }; -static const bool tcp_states_show[TCP_CONNTRACK_MAX] = { - [TCP_CONNTRACK_SYN_SENT] = true, - [TCP_CONNTRACK_SYN_RECV] = true, - [TCP_CONNTRACK_ESTABLISHED] = true, - [TCP_CONNTRACK_FIN_WAIT] = true, - [TCP_CONNTRACK_CLOSE_WAIT] = true, - [TCP_CONNTRACK_LAST_ACK] = true, - [TCP_CONNTRACK_TIME_WAIT] = true, - [TCP_CONNTRACK_CLOSE] = true, - [TCP_CONNTRACK_SYN_SENT2] = true, - [TCP_CONNTRACK_NONE] = true, -}; - static const char *const dccp_state2str[DCCP_CONNTRACK_MAX] = { [DCCP_CONNTRACK_NONE] = "NOSTATE", [DCCP_CONNTRACK_REQUEST] = "REQUEST", @@ -178,19 +165,6 @@ static const char *const dccp_state2str[DCCP_CONNTRACK_MAX] = { [DCCP_CONNTRACK_INVALID] = "INVALID", }; -static const uint8_t dccp_states_show[DCCP_CONNTRACK_MAX] = { - [DCCP_CONNTRACK_NONE] = true, - [DCCP_CONNTRACK_REQUEST] = true, - [DCCP_CONNTRACK_RESPOND] = true, - [DCCP_CONNTRACK_PARTOPEN] = true, - [DCCP_CONNTRACK_OPEN] = true, - [DCCP_CONNTRACK_CLOSEREQ] = true, - [DCCP_CONNTRACK_CLOSING] = true, - [DCCP_CONNTRACK_TIMEWAIT] = true, - [DCCP_CONNTRACK_IGNORE] = true, - [DCCP_CONNTRACK_INVALID] = true, -}; - static const char *const sctp_state2str[SCTP_CONNTRACK_MAX] = { [SCTP_CONNTRACK_NONE] = "NOSTATE", [SCTP_CONNTRACK_CLOSED] = "CLOSED", @@ -202,17 +176,6 @@ static const char *const sctp_state2str[SCTP_CONNTRACK_MAX] = { [SCTP_CONNTRACK_SHUTDOWN_ACK_SENT] = "SHUTDOWN_ACK_SENT", }; -static const uint8_t sctp_states_show[SCTP_CONNTRACK_MAX] = { - [SCTP_CONNTRACK_NONE] = true, - [SCTP_CONNTRACK_CLOSED] = true, - [SCTP_CONNTRACK_COOKIE_WAIT] = true, - [SCTP_CONNTRACK_COOKIE_ECHOED] = true, - [SCTP_CONNTRACK_ESTABLISHED] = true, - [SCTP_CONNTRACK_SHUTDOWN_SENT] = true, - [SCTP_CONNTRACK_SHUTDOWN_RECD] = true, - [SCTP_CONNTRACK_SHUTDOWN_ACK_SENT] = true, -}; - static const struct nfct_filter_ipv4 filter_ipv4 = { .addr = __constant_htonl(INADDR_LOOPBACK), .mask = 0xffffffff, @@ -883,16 +846,50 @@ static inline int presenter_flow_wrong_state(struct flow_entry *n) switch (n->l4_proto) { case IPPROTO_TCP: - if (tcp_states_show[n->tcp_state]) + switch (n->tcp_state) { + case TCP_CONNTRACK_SYN_SENT: + case TCP_CONNTRACK_SYN_RECV: + case TCP_CONNTRACK_ESTABLISHED: + case TCP_CONNTRACK_FIN_WAIT: + case TCP_CONNTRACK_CLOSE_WAIT: + case TCP_CONNTRACK_LAST_ACK: + case TCP_CONNTRACK_TIME_WAIT: + case TCP_CONNTRACK_CLOSE: + case TCP_CONNTRACK_SYN_SENT2: + case TCP_CONNTRACK_NONE: ret = 0; + break; + } break; case IPPROTO_SCTP: - if (sctp_states_show[n->sctp_state]) + switch (n->sctp_state) { + case SCTP_CONNTRACK_NONE: + case SCTP_CONNTRACK_CLOSED: + case SCTP_CONNTRACK_COOKIE_WAIT: + case SCTP_CONNTRACK_COOKIE_ECHOED: + case SCTP_CONNTRACK_ESTABLISHED: + case SCTP_CONNTRACK_SHUTDOWN_SENT: + case SCTP_CONNTRACK_SHUTDOWN_RECD: + case SCTP_CONNTRACK_SHUTDOWN_ACK_SENT: ret = 0; + break; + } break; case IPPROTO_DCCP: - if (dccp_states_show[n->dccp_state]) + switch (n->dccp_state) { + case DCCP_CONNTRACK_NONE: + case DCCP_CONNTRACK_REQUEST: + case DCCP_CONNTRACK_RESPOND: + case DCCP_CONNTRACK_PARTOPEN: + case DCCP_CONNTRACK_OPEN: + case DCCP_CONNTRACK_CLOSEREQ: + case DCCP_CONNTRACK_CLOSING: + case DCCP_CONNTRACK_TIMEWAIT: + case DCCP_CONNTRACK_IGNORE: + case DCCP_CONNTRACK_INVALID: ret = 0; + break; + } break; case IPPROTO_UDP: case IPPROTO_UDPLITE: |