From 448915fb55bcf5e24f44768f5859532b913eeaaf Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Mon, 23 Mar 2026 10:21:31 -0400 Subject: [PATCH] capture/napatech: 0-pad thread names Apply zero-padding to Napatech worker threads so alphanumeric sorting displays workers in proper order. Set padding for thread names according to stream count: 1-9 streams: no padding, e.g, nt1, nt9 10-99 streams: use padding, e.g, nt01, nt99 100-999 streams: use padding, e.g, nt001, nt099, nt999 This will insure that thread names, when sorted alphanumerically, maintain thread worker id order. Issue: 8337 --- plugins/napatech/runmode-napatech.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/napatech/runmode-napatech.c b/plugins/napatech/runmode-napatech.c index dce084d308..775791a284 100644 --- a/plugins/napatech/runmode-napatech.c +++ b/plugins/napatech/runmode-napatech.c @@ -132,12 +132,21 @@ static int NapatechRegisterDeviceStreams(void) num_configured_streams = stream_cnt; SCLogDebug("Configuring %d Napatech Streams...", stream_cnt); + // We will use zero-padding so the names sort properly alphanumerically + // Note: Napatech stream count is currently limited to 128 and is expected to not + // exceed 3 digits in the future. + // Stream count Example + // 4 nt1, nt4 + // 12 nt01, nt04, nt11 + // 104 nt001, nt004, nt011, nt103 + int width = (stream_cnt >= 100) ? 3 : (stream_cnt >= 10) ? 2 : 0; + for (uint16_t inst = 0; inst < stream_cnt; ++inst) { char *plive_dev_buf = SCCalloc(1, 9); if (unlikely(plive_dev_buf == NULL)) { FatalError("Failed to allocate memory for NAPATECH stream counter."); } - snprintf(plive_dev_buf, 9, "nt%d", stream_config[inst].stream_id); + snprintf(plive_dev_buf, 9, "nt%0*d", width, stream_config[inst].stream_id); if (auto_config) { if (stream_config[inst].is_active) {