summaryrefslogtreecommitdiff
path: root/zebra
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2025-03-19 12:39:37 -0400
committerDonald Sharp <sharpd@nvidia.com>2025-03-19 13:47:01 -0400
commit9c273fad26fb25be4d2b606993174a0dc2ee16ec (patch)
tree3d8a299357222c204c2566bf8816f57f1a0a87d5 /zebra
parent04d6adc94bfebde195a7ff245388d7e8d5e6d563 (diff)
zebra: Add timestamp to output
It's interesting to know the time we received the route. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'zebra')
-rw-r--r--zebra/fpm_listener.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/zebra/fpm_listener.c b/zebra/fpm_listener.c
index 00c3c3e6f5..70dcaf91a1 100644
--- a/zebra/fpm_listener.c
+++ b/zebra/fpm_listener.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#ifdef GNU_LINUX
#include <stdint.h>
@@ -71,6 +72,24 @@ get_print_buf(size_t *buf_len)
}
/*
+ * get_timestamp
+ * Returns a timestamp string.
+ */
+static const char *get_timestamp(void)
+{
+ static char timestamp[64];
+ struct timespec ts;
+ struct tm tm;
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+ localtime_r(&ts.tv_sec, &tm);
+ snprintf(timestamp, sizeof(timestamp), "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
+ ts.tv_nsec);
+ return timestamp;
+}
+
+/*
* create_listen_sock
*/
static int create_listen_sock(int port, int *sock_p)
@@ -131,7 +150,7 @@ static int accept_conn(int listen_sock)
&client_len);
if (sock >= 0) {
- fprintf(glob->output_file, "Accepted client %s\n",
+ fprintf(glob->output_file, "[%s] Accepted client %s\n", get_timestamp(),
inet_ntop(AF_INET, &client_addr.sin_addr, buf, sizeof(buf)));
return sock;
}
@@ -585,12 +604,10 @@ static int netlink_msg_ctx_snprint(struct netlink_msg_ctx *ctx, char *buf,
cur = buf;
end = buf + buf_len;
- cur += snprintf(cur, end - cur, "%s %s/%d, Prot: %s(%u)",
+ cur += snprintf(cur, end - cur, "[%s] %s %s/%d, Prot: %s(%u)", get_timestamp(),
netlink_msg_type_to_s(hdr->nlmsg_type),
- addr_to_s(rtmsg->rtm_family, RTA_DATA(ctx->dest)),
- rtmsg->rtm_dst_len,
- netlink_prot_to_s(rtmsg->rtm_protocol),
- rtmsg->rtm_protocol);
+ addr_to_s(rtmsg->rtm_family, RTA_DATA(ctx->dest)), rtmsg->rtm_dst_len,
+ netlink_prot_to_s(rtmsg->rtm_protocol), rtmsg->rtm_protocol);
if (ctx->metric)
cur += snprintf(cur, end - cur, ", Metric: %d", *ctx->metric);
@@ -712,8 +729,9 @@ static void parse_netlink_msg(char *buf, size_t buf_len, fpm_msg_hdr_t *fpm)
if (glob->reflect && hdr->nlmsg_type == RTM_NEWROUTE &&
ctx->rtmsg->rtm_protocol > RTPROT_STATIC) {
- fprintf(glob->output_file, " Route %s(%u) reflecting back as %s\n",
- netlink_prot_to_s(ctx->rtmsg->rtm_protocol),
+ fprintf(glob->output_file,
+ "[%s] Route %s(%u) reflecting back as %s\n",
+ get_timestamp(), netlink_prot_to_s(ctx->rtmsg->rtm_protocol),
ctx->rtmsg->rtm_protocol,
glob->reflect_fail_all ? "Offload Failed" : "Offloaded");
if (glob->reflect_fail_all)
@@ -725,8 +743,9 @@ static void parse_netlink_msg(char *buf, size_t buf_len, fpm_msg_hdr_t *fpm)
break;
default:
- fprintf(glob->output_file, "Ignoring netlink message - Type: %s(%d)\n",
- netlink_msg_type_to_s(hdr->nlmsg_type), hdr->nlmsg_type);
+ fprintf(glob->output_file, "[%s] Ignoring netlink message - Type: %s(%d)\n",
+ get_timestamp(), netlink_msg_type_to_s(hdr->nlmsg_type),
+ hdr->nlmsg_type);
}
}
}
@@ -736,8 +755,8 @@ static void parse_netlink_msg(char *buf, size_t buf_len, fpm_msg_hdr_t *fpm)
*/
static void process_fpm_msg(fpm_msg_hdr_t *hdr)
{
- fprintf(glob->output_file, "FPM message - Type: %d, Length %d\n", hdr->msg_type,
- ntohs(hdr->msg_len));
+ fprintf(glob->output_file, "[%s] FPM message - Type: %d, Length %d\n", get_timestamp(),
+ hdr->msg_type, ntohs(hdr->msg_len));
if (hdr->msg_type != FPM_MSG_TYPE_NETLINK) {
fprintf(stderr, "Unknown fpm message type %u\n", hdr->msg_type);