tcp: conditionally initializing log track for unbind 12/43512/2
authorSteven Luong <[email protected]>
Fri, 1 Aug 2025 22:26:49 +0000 (15:26 -0700)
committerFlorin Coras <[email protected]>
Sat, 2 Aug 2025 06:27:20 +0000 (06:27 +0000)
elog track is initialized when tcp open, bind, or syn rcvd
message is received. Logging tcp unbind event requires and
expects elog track is already initialized. If tcp debug
is enabled after the aforementioned 3 messages and the
first event that tcp logs is unbind, we crash because elog
track is not initialized.

Let's check the elog track is initialized yet or not
prior to logging an unbind event. If not, we initialize
it.

Type: fix

Change-Id: Ib8fde694dc48f30a87aa3ecd378c1960857e8c38
Signed-off-by: Steven Luong <[email protected]>
src/vnet/tcp/tcp_debug.h

index 04e921c..8ae4565 100644 (file)
@@ -289,17 +289,17 @@ ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, _e,                    \
   TCP_EVT_STATE_CHANGE_HANDLER(_tc);                                   \
 }
 
-#define TCP_EVT_UNBIND_HANDLER(_tc, ...)                               \
-{                                                                      \
-  TCP_EVT_DEALLOC_HANDLER(_tc);                                                \
-  ELOG_TYPE_DECLARE (_e) =                                             \
-  {                                                                    \
-    .format = "unbind: listener %d",                                   \
-  };                                                                   \
-  TCP_DECLARE_ETD(_tc, _e, 1);                                         \
-  ed->data[0] = _tc->c_c_index;                                                \
-  TCP_EVT_DEALLOC_HANDLER(_tc);                                                \
-}
+#define TCP_EVT_UNBIND_HANDLER(_tc, ...)                                      \
+  {                                                                           \
+    if (_tc->c_elog_track.name == 0)                                          \
+      TCP_EVT_INIT_HANDLER (_tc, 1);                                          \
+    ELOG_TYPE_DECLARE (_e) = {                                                \
+      .format = "unbind: listener %d",                                        \
+    };                                                                        \
+    TCP_DECLARE_ETD (_tc, _e, 1);                                             \
+    ed->data[0] = _tc->c_c_index;                                             \
+    TCP_EVT_DEALLOC_HANDLER (_tc);                                            \
+  }
 
 #define TCP_EVT_DELETE_HANDLER(_tc, ...)                               \
 {                                                                      \