2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 05:47:55 +00:00

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>
This commit is contained in:
Darrell Ball 2017-09-25 20:51:43 -07:00 committed by Ben Pfaff
parent 80cee1163e
commit 66f400f59b

View File

@ -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