summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDarrell Ball <dlu998@gmail.com>2017-09-25 20:51:43 -0700
committerBen Pfaff <blp@ovn.org>2017-09-26 15:54:48 -0700
commit66f400f59b6efa7dfd40a69e22a6ca1021e56a3d (patch)
tree49c7ac69159bd744ae9d13d38ee13a3773f27bd5 /lib
parent80cee1163e6301dd1c0bd01c5f0323fb1a45adf4 (diff)
downloadopenvswitch-66f400f59b6efa7dfd40a69e22a6ca1021e56a3d.tar.gz
conntrack: Add function ct_print_conn_info().
A new debug function is added and used in a subsequent patch. Acked-by: Antonio Fischetti <antonio.fischetti@intel.com> Signed-off-by: Darrell Ball <dlu998@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/conntrack.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/conntrack.c b/lib/conntrack.c
index 746ca3328..3c9f34400 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -67,6 +67,9 @@ enum ct_alg_mode {
CT_TFTP_MODE,
};
+void ct_print_conn_info(struct conn *c, char *log_msg, enum vlog_level vll,
+ bool force, bool rl_on);
+
static bool conn_key_extract(struct conntrack *, struct dp_packet *,
ovs_be16 dl_type, struct conn_lookup_ctx *,
uint16_t zone);
@@ -223,6 +226,61 @@ conn_key_cmp(const struct conn_key *key1, const struct conn_key *key2)
return 1;
}
+void
+ct_print_conn_info(struct conn *c, char *log_msg, enum vlog_level vll,
+ bool force, bool rl_on)
+{
+#define CT_VLOG(RL_ON, LEVEL, ...) \
+ do { \
+ if (RL_ON) { \
+ static struct vlog_rate_limit rl_ = VLOG_RATE_LIMIT_INIT(5, 5); \
+ vlog_rate_limit(&this_module, LEVEL, &rl_, __VA_ARGS__); \
+ } else { \
+ vlog(&this_module, LEVEL, __VA_ARGS__); \
+ } \
+ } while (0)
+
+ if (OVS_UNLIKELY(force || vlog_is_enabled(&this_module, vll))) {
+ if (c->key.dl_type == htons(ETH_TYPE_IP)) {
+ CT_VLOG(rl_on, vll, "%s: src ip "IP_FMT" dst ip "IP_FMT" rev src "
+ "ip "IP_FMT" rev dst ip "IP_FMT" src/dst ports "
+ "%"PRIu16"/%"PRIu16" rev src/dst ports "
+ "%"PRIu16"/%"PRIu16" zone/rev zone "
+ "%"PRIu16"/%"PRIu16" nw_proto/rev nw_proto "
+ "%"PRIu8"/%"PRIu8, log_msg,
+ IP_ARGS(c->key.src.addr.ipv4_aligned),
+ IP_ARGS(c->key.dst.addr.ipv4_aligned),
+ IP_ARGS(c->rev_key.src.addr.ipv4_aligned),
+ IP_ARGS(c->rev_key.dst.addr.ipv4_aligned),
+ ntohs(c->key.src.port), ntohs(c->key.dst.port),
+ ntohs(c->rev_key.src.port), ntohs(c->rev_key.dst.port),
+ c->key.zone, c->rev_key.zone, c->key.nw_proto,
+ c->rev_key.nw_proto);
+ } else {
+ char ip6_s[INET6_ADDRSTRLEN];
+ inet_ntop(AF_INET6, &c->key.src.addr.ipv6, ip6_s, sizeof ip6_s);
+ char ip6_d[INET6_ADDRSTRLEN];
+ inet_ntop(AF_INET6, &c->key.dst.addr.ipv6, ip6_d, sizeof ip6_d);
+ char ip6_rs[INET6_ADDRSTRLEN];
+ inet_ntop(AF_INET6, &c->rev_key.src.addr.ipv6, ip6_rs,
+ sizeof ip6_rs);
+ char ip6_rd[INET6_ADDRSTRLEN];
+ inet_ntop(AF_INET6, &c->rev_key.dst.addr.ipv6, ip6_rd,
+ sizeof ip6_rd);
+
+ CT_VLOG(rl_on, vll, "%s: src ip %s dst ip %s rev src ip %s"
+ " rev dst ip %s src/dst ports %"PRIu16"/%"PRIu16
+ " rev src/dst ports %"PRIu16"/%"PRIu16" zone/rev zone "
+ "%"PRIu16"/%"PRIu16" nw_proto/rev nw_proto "
+ "%"PRIu8"/%"PRIu8, log_msg, ip6_s, ip6_d, ip6_rs,
+ ip6_rd, ntohs(c->key.src.port), ntohs(c->key.dst.port),
+ ntohs(c->rev_key.src.port), ntohs(c->rev_key.dst.port),
+ c->key.zone, c->rev_key.zone, c->key.nw_proto,
+ c->rev_key.nw_proto);
+ }
+ }
+}
+
/* Initializes the connection tracker 'ct'. The caller is responsible for
* calling 'conntrack_destroy()', when the instance is not needed anymore */
void