From f23ab8bad3e0230b6c22613a8d81b30716c2e6e5 Mon Sep 17 00:00:00 2001 From: Yi-Hung Wei Date: Tue, 27 Jun 2017 11:11:32 -0700 Subject: [PATCH] conntrack: Move ct_state parsing to lib/flow.c This patch moves conntrack state parsing function from ovn-trace.c to lib/flow.c, because it will be used by ofproto/trace unixctl command later on. It also updates the ct_state checking logic, since we no longer assume CS_TRACKED is enable by default. Signed-off-by: Yi-Hung Wei Signed-off-by: Ben Pfaff --- utilities/ovn-trace.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c index 8bdb7d8a30..ab56221d78 100644 --- a/utilities/ovn-trace.c +++ b/utilities/ovn-trace.c @@ -169,34 +169,16 @@ default_ovs(void) static void parse_ct_option(const char *state_s_) { - uint32_t state = CS_TRACKED; - - char *state_s = xstrdup(state_s_); - char *save_ptr = NULL; - for (char *cs = strtok_r(state_s, ", ", &save_ptr); cs; - cs = strtok_r(NULL, ", ", &save_ptr)) { - uint32_t bit = ct_state_from_string(cs); - if (!bit) { - ovs_fatal(0, "%s: unknown connection tracking state flag", cs); - } - state |= bit; - } - free(state_s); + uint32_t state; + struct ds ds = DS_EMPTY_INITIALIZER; - /* Check constraints listed in ovs-fields(7). */ - if (state & CS_INVALID && state & ~(CS_TRACKED | CS_INVALID)) { - VLOG_WARN("%s: invalid connection state: " - "when \"inv\" is set, only \"trk\" may also be set", - state_s_); - } - if (state & CS_NEW && state & CS_ESTABLISHED) { - VLOG_WARN("%s: invalid connection state: " - "\"new\" and \"est\" are mutually exclusive", state_s_); + if (!parse_ct_state(state_s_, CS_TRACKED, &state, &ds)) { + ovs_fatal(0, "%s", ds_cstr(&ds)); } - if (state & CS_NEW && state & CS_REPLY_DIR) { - VLOG_WARN("%s: invalid connection state: " - "\"new\" and \"rpy\" are mutually exclusive", state_s_); + if (!validate_ct_state(state, &ds)) { + VLOG_WARN("%s", ds_cstr(&ds)); } + ds_destroy(&ds); ct_states = xrealloc(ct_states, (n_ct_states + 1) * sizeof *ct_states); ct_states[n_ct_states++] = state;