From fa1b197781bebcf4e2095eb0c52f51a5ebc077a0 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Fri, 7 Jun 2024 09:01:42 +0200 Subject: [PATCH] datapath: add debug traces Signed-off-by: Robin Jarry --- modules/infra/datapath/br_datapath.h | 4 +-- modules/infra/datapath/drop.c | 2 +- modules/infra/datapath/rx.c | 2 +- modules/infra/datapath/tx.c | 2 +- modules/ipip/control.c | 54 ++++++++++++++++++++++++++-- modules/ipip/datapath_in.c | 1 + modules/ipip/ipip_priv.h | 2 ++ 7 files changed, 60 insertions(+), 7 deletions(-) diff --git a/modules/infra/datapath/br_datapath.h b/modules/infra/datapath/br_datapath.h index 9ce2b678..ba507fa5 100644 --- a/modules/infra/datapath/br_datapath.h +++ b/modules/infra/datapath/br_datapath.h @@ -19,7 +19,7 @@ void *br_datapath_loop(void *priv); #ifdef TRACE_PACKETS -static inline void trace_packet(const char *node, const struct rte_mbuf *m) { +static inline void trace_packet(const char *prefix, const char *node, const struct rte_mbuf *m) { char buf[BUFSIZ], src[64], dst[64]; const struct rte_ether_hdr *eth; uint16_t ether_type; @@ -149,7 +149,7 @@ static inline void trace_packet(const char *node, const struct rte_mbuf *m) { } n += snprintf(buf + n, sizeof(buf) - n, ", (pkt_len=%u)", m->pkt_len); - LOG(NOTICE, "[%s p%u] %s", node, m->port, buf); + LOG(NOTICE, "[%s%s p%u] %s", prefix ?: "", node, m->port, buf); } #else #define trace_packet(node, mbuf) diff --git a/modules/infra/datapath/drop.c b/modules/infra/datapath/drop.c index a7cabe1f..2c9d5e6d 100644 --- a/modules/infra/datapath/drop.c +++ b/modules/infra/datapath/drop.c @@ -17,7 +17,7 @@ uint16_t br_node_drop_process( (void)graph; for (uint16_t i = 0; i < nb_objs; i++) - trace_packet(node->name, objs[i]); + trace_packet("DROP ", node->name, objs[i]); rte_pktmbuf_free_bulk((struct rte_mbuf **)objs, nb_objs); return nb_objs; diff --git a/modules/infra/datapath/rx.c b/modules/infra/datapath/rx.c index b506df10..3eb78ae4 100644 --- a/modules/infra/datapath/rx.c +++ b/modules/infra/datapath/rx.c @@ -46,7 +46,7 @@ rx_process(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t struct rte_mbuf *m = node->objs[i]; struct eth_input_mbuf_data *if_in = eth_input_mbuf_data(m); if_in->iface = port_get_iface(m->port); - trace_packet(node->name, m); + trace_packet("", "RX", m); } rte_node_enqueue(graph, node, ETH_IN, node->objs, count); diff --git a/modules/infra/datapath/tx.c b/modules/infra/datapath/tx.c index 659fedd5..6ccf7918 100644 --- a/modules/infra/datapath/tx.c +++ b/modules/infra/datapath/tx.c @@ -49,7 +49,7 @@ tx_process(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t for (i = 0; i < nb_objs; i++) { struct rte_mbuf *mbuf = objs[i]; - trace_packet(node->name, mbuf); + trace_packet("", "TX", mbuf); if (mbuf->port != port_id) { if (burst_start != i) { diff --git a/modules/ipip/control.c b/modules/ipip/control.c index c2cc98f0..4445a199 100644 --- a/modules/ipip/control.c +++ b/modules/ipip/control.c @@ -28,13 +28,52 @@ static struct rte_hash *ipip_hash; struct iface *ipip_get_iface(ip4_addr_t local, ip4_addr_t remote, uint16_t vrf_id) { struct ipip_key key = {local, remote, vrf_id}; void *data; + int ret; - if (rte_hash_lookup_data(ipip_hash, &key, &data) < 0) - return NULL; + if ((ret = rte_hash_lookup_data(ipip_hash, &key, &data)) < 0) { + char buf[256], l[64], r[64]; + inet_ntop(AF_INET, &local, l, sizeof(l)); + inet_ntop(AF_INET, &remote, r, sizeof(r)); + snprintf( + buf, + sizeof(buf), + "rte_hash_lookup_data: (local=%s, remote=%s, vrf_id=%u)", + l, + r, + vrf_id + ); + return errno_log_null(-ret, buf); + } return data; } +void list_ipip(void) { + char local[64], remote[64]; + const struct iface *iface; + const struct ipip_key *k; + const void *key; + uint32_t iter; + int32_t idx; + void *data; + + iter = 0; + while ((idx = rte_hash_iterate(ipip_hash, &key, &data, &iter)) >= 0) { + iface = data; + k = key; + + inet_ntop(AF_INET, &k->local, local, sizeof(local)); + inet_ntop(AF_INET, &k->remote, remote, sizeof(remote)); + + LOG(INFO, + "(local=%s remote=%s vrf_id=%u) -> iface=%s", + local, + remote, + k->vrf_id, + iface->name); + } +} + static int iface_ipip_reconfig( struct iface *iface, uint64_t set_attrs, @@ -67,6 +106,17 @@ static int iface_ipip_reconfig( if ((ret = rte_hash_add_key_data(ipip_hash, &next_key, iface)) < 0) return errno_log(-ret, "rte_hash_add_key_data"); + char local[64], remote[64]; + inet_ntop(AF_INET, &next->local, local, sizeof(local)); + inet_ntop(AF_INET, &next->remote, remote, sizeof(remote)); + + LOG(INFO, + "(local=%s remote=%s vrf_id=%u) -> iface=%s", + local, + remote, + vrf_id, + iface->name); + cur->local = next->local; cur->remote = next->remote; iface->vrf_id = vrf_id; diff --git a/modules/ipip/datapath_in.c b/modules/ipip/datapath_in.c index 539482b4..2ada29dc 100644 --- a/modules/ipip/datapath_in.c +++ b/modules/ipip/datapath_in.c @@ -37,6 +37,7 @@ ipip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, ip_data = ip_local_mbuf_data(mbuf); ipip = ipip_get_iface(ip_data->dst, ip_data->src, ip_data->vrf_id); if (ipip == NULL) { + list_ipip(); next = NO_TUNNEL; goto next; } diff --git a/modules/ipip/ipip_priv.h b/modules/ipip/ipip_priv.h index eac39d4f..4c0b96f1 100644 --- a/modules/ipip/ipip_priv.h +++ b/modules/ipip/ipip_priv.h @@ -16,4 +16,6 @@ struct iface_info_ipip { struct iface *ipip_get_iface(ip4_addr_t local, ip4_addr_t remote, uint16_t vrf_id); +void list_ipip(void); + #endif