From e08c951fc0f17f2b89b2b142c29d5cf766c44751 Mon Sep 17 00:00:00 2001 From: Ilya Bakhtin Date: Thu, 21 Mar 2024 16:04:29 +0100 Subject: [PATCH] napatech-numbering` clang-format auto formatting --- src/runmode-napatech.c | 2 ++ src/source-napatech.c | 51 ++++++++++++++++++++++++++++-------------- src/util-napatech.c | 19 +++++++++++----- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/runmode-napatech.c b/src/runmode-napatech.c index 3d503b965573..062a3d3a6ea3 100644 --- a/src/runmode-napatech.c +++ b/src/runmode-napatech.c @@ -216,6 +216,8 @@ static int NapatechInit(int runmode) exit(EXIT_FAILURE); } + NapatechGetAdapter(0); /* initialize port to adapter mapping */ + status = NapatechRegisterDeviceStreams(); if (status < 0 || num_configured_streams <= 0) { FatalError("Unable to find existing Napatech Streams"); diff --git a/src/source-napatech.c b/src/source-napatech.c index 7036178ad1e8..2a510c8262fd 100644 --- a/src/source-napatech.c +++ b/src/source-napatech.c @@ -315,25 +315,35 @@ int NapatechSetPortmap(int port, int peer) int NapatechGetAdapter(uint8_t port) { static int port_adapter_map[MAX_PORTS] = { -1 }; - int status; - NtInfo_t h_info; /* Info handle */ - NtInfoStream_t h_info_stream; /* Info stream handle */ - if (unlikely(port_adapter_map[port] == -1)) { - if ((status = NT_InfoOpen(&h_info_stream, "ExampleInfo")) != NT_SUCCESS) { + if (unlikely(port_adapter_map[0] == -1)) { + int status; + NtInfoStream_t h_info_stream; /* Info stream handle */ + + if ((status = NT_InfoOpen(&h_info_stream, "NapatechGetAdapter")) != NT_SUCCESS) { NAPATECH_ERROR(status); + FatalError("Unable to NT_InfoOpen"); return -1; } - /* Read the system info */ - h_info.cmd = NT_INFO_CMD_READ_PORT_V9; - h_info.u.port_v9.portNo = (uint8_t) port; - if ((status = NT_InfoRead(h_info_stream, &h_info)) != NT_SUCCESS) { - /* Get the status code as text */ - NAPATECH_ERROR(status); - NT_InfoClose(h_info_stream); - return -1; + for (size_t i = 0; i < MAX_PORTS; ++i) { + NtInfo_t h_info; /* Info handle */ + /* Read the system info */ + h_info.cmd = NT_INFO_CMD_READ_PORT_V9; + h_info.u.port_v9.portNo = (uint8_t)i; + if ((status = NT_InfoRead(h_info_stream, &h_info)) == NT_SUCCESS) { + port_adapter_map[i] = h_info.u.port_v9.data.adapterNo; + } else { + if (status != NT_ERROR_PORT_OUT_OF_RANGE) { + /* Get the status code as text */ + NAPATECH_ERROR(status); + } + port_adapter_map[i] = -1; + } } - port_adapter_map[port] = h_info.u.port_v9.data.adapterNo; + NT_InfoClose(h_info_stream); + } + if (port_adapter_map[port] == -1) { + FatalError("Adapter that holds port %u is unknown", port); } return port_adapter_map[port]; } @@ -711,6 +721,13 @@ static void NapatechReleasePacket(struct Packet_ *p) * before releasing the Napatech buffer back to NTService. */ #ifdef NAPATECH_ENABLE_BYPASS + /* + * https://supportportal.napatech.com/index.php?/selfhelp/view-article/how-to-configure-txport-in-inline-mode/340 + * If the descriptor is Dyn3, TxPortPos=28 should be used, which is the color_lo field in Dyn3. + */ + p->ntpv.dyn3->color_lo = + inline_port_map[p->ntpv.dyn3->rxPort + p->ntpv.nt_packet_buf->portOffset] - + p->ntpv.nt_packet_buf->portOffset; if (is_inline && PacketCheckAction(p, ACTION_DROP)) { p->ntpv.dyn3->wireLength = 0; } @@ -958,9 +975,8 @@ TmEcode NapatechPacketLoop(ThreadVars *tv, void *data, void *slot) #ifdef NAPATECH_ENABLE_BYPASS p->ntpv.dyn3 = _NT_NET_GET_PKT_DESCR_PTR_DYN3(packet_buffer); p->BypassPacketsFlow = (NapatechIsBypassSupported() ? NapatechBypassCallback : NULL); - NT_NET_SET_PKT_TXPORT(packet_buffer, inline_port_map[p->ntpv.dyn3->rxPort]); - p->ntpv.flow_stream = flow_stream[NapatechGetAdapter(p->ntpv.dyn3->rxPort)]; - + p->ntpv.flow_stream = + flow_stream[NapatechGetAdapter(p->ntpv.dyn3->rxPort + packet_buffer->portOffset)]; #endif p->ReleasePacket = NapatechReleasePacket; @@ -973,6 +989,7 @@ TmEcode NapatechPacketLoop(ThreadVars *tv, void *data, void *slot) SCReturnInt(TM_ECODE_FAILED); } + PKT_SET_SRC(p, PKT_SRC_WIRE); if (unlikely(TmThreadsSlotProcessPkt(ntv->tv, ntv->slot, p) != TM_ECODE_OK)) { SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/util-napatech.c b/src/util-napatech.c index affcd49cbb87..9f824b5198bb 100644 --- a/src/util-napatech.c +++ b/src/util-napatech.c @@ -1580,14 +1580,21 @@ uint32_t NapatechSetupTraffic(uint32_t first_stream, uint32_t last_stream) if (bypass_supported) { if (is_inline) { char inline_setup_cmd[512]; + /* + * https://supportportal.napatech.com/index.php?/selfhelp/view-article/how-to-configure-txport-in-inline-mode/340 + * If the descriptor is Dyn3, TxPortPos=28 should be used, which is the color_lo field + * in Dyn3. The TX port configuration will be done in the field from bit 28 of Dyn3. + */ if (first_stream == last_stream) { - snprintf(inline_setup_cmd, sizeof (ntpl_cmd), - "Setup[TxDescriptor=Dyn;TxPorts=%s;RxCRC=False;TxPortPos=112;UseWL=True] = StreamId == %d", - ports_spec.str, first_stream); + snprintf(inline_setup_cmd, sizeof(ntpl_cmd), + "Setup[TxDescriptor=Dyn;TxPorts=%s;RxCRC=False;TxPortPos=28;UseWL=True] = " + "StreamId == %d", + ports_spec.str, first_stream); } else { - snprintf(inline_setup_cmd, sizeof (ntpl_cmd), - "Setup[TxDescriptor=Dyn;TxPorts=%s;RxCRC=False;TxPortPos=112;UseWL=True] = StreamId == (%d..%d)", - ports_spec.str, first_stream, last_stream); + snprintf(inline_setup_cmd, sizeof(ntpl_cmd), + "Setup[TxDescriptor=Dyn;TxPorts=%s;RxCRC=False;TxPortPos=28;UseWL=True] = " + "StreamId == (%d..%d)", + ports_spec.str, first_stream, last_stream); } NapatechSetFilter(hconfig, inline_setup_cmd); }