pg: set frame level sw/hw interface indicies correctly 81/43881/3
authorDave Barach <[email protected]>
Sat, 11 Oct 2025 12:26:28 +0000 (08:26 -0400)
committerDave Barach <[email protected]>
Sat, 11 Oct 2025 15:09:32 +0000 (11:09 -0400)
"packet-generator new stream-name { ... interface loop0 ... }" wasn't
setting the ethernet frame sw/hw_if_index fields from the
stream. Packets always appeared to originate in one of the pg-XXX
interfaces, yielding dst MAC address drops.

Type: fix

Change-Id: I26e3021bb8c068e74dfa8b314b7b9a3a8b0dc65a
Signed-off-by: Dave Barach <[email protected]>
src/vnet/pg/input.c

index 18ad6db..143cf58 100644 (file)
@@ -1707,8 +1707,24 @@ pg_generate_packets (vlib_node_runtime_t * node,
          f->flags = ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX;
 
          ef = vlib_frame_scalar_args (f);
-         ef->sw_if_index = pi->sw_if_index;
-         ef->hw_if_index = pi->hw_if_index;
+         if (s->sw_if_index[VLIB_RX] == ~0)
+           {
+             /* Mark (all) packets in frame as originating from pg-XXX */
+             ef->sw_if_index = pi->sw_if_index;
+             ef->hw_if_index = pi->hw_if_index;
+           }
+         else
+           {
+             vnet_main_t *vnm = vnet_get_main ();
+             vnet_hw_interface_t *hw;
+
+             /* Mark packets from the configured interface: see
+              * cli.c:new_stream() */
+             ef->sw_if_index = s->sw_if_index[VLIB_RX];
+             hw = vnet_get_sup_hw_interface (vnm, ef->sw_if_index);
+             ef->hw_if_index = hw->hw_if_index;
+           }
+
          vlib_frame_no_append (f);
        }
       else