linux-cp: fix segfault while receiving nl messages 65/42065/2
authorArtem Glazychev <glazychev@mts.ru>
Wed, 18 Dec 2024 08:50:13 +0000 (15:50 +0700)
committerMatthew Smith <mgsmith@netgate.com>
Thu, 16 Jan 2025 15:32:54 +0000 (15:32 +0000)
- check nl socket before receiving messages
- we don't need extra callback after adding an lcp pair because we start draining messages (due to epoll) right after opening socket

Type: fix

Change-Id: I0ecb03b758f066662015fd6c6b9d3c48cb520c0d
Signed-off-by: Artem Glazychev <glazychev@mts.ru>
src/plugins/linux-cp/lcp_nl.c

index 85b6447..71104d3 100644 (file)
@@ -732,7 +732,8 @@ lcp_nl_drain_messages (void)
   nl_main_t *nm = &nl_main;
 
   /* Read until there's an error */
-  while ((err = nl_recvmsgs_default (nm->sk_route)) > -1)
+  while ((err = nm->sk_route ? nl_recvmsgs_default (nm->sk_route) :
+                              -NLE_BAD_SOCK) > -1)
     ;
 
   /* If there was an error other then EAGAIN, signal process node */
@@ -752,12 +753,6 @@ lcp_nl_drain_messages (void)
   return err;
 }
 
-void
-lcp_nl_pair_add_cb (lcp_itf_pair_t *pair)
-{
-  lcp_nl_drain_messages ();
-}
-
 static clib_error_t *
 nl_route_read_cb (clib_file_t *f)
 {
@@ -1008,16 +1003,12 @@ clib_error_t *
 lcp_nl_init (vlib_main_t *vm)
 {
   nl_main_t *nm = &nl_main;
-  lcp_itf_pair_vft_t nl_itf_pair_vft = {
-    .pair_add_fn = lcp_nl_pair_add_cb,
-  };
 
   nm->nl_status = NL_STATUS_NOTIF_PROC;
   nm->clib_file_index = ~0;
   nm->nl_logger = vlib_log_register_class ("nl", "nl");
 
   lcp_nl_open_socket ();
-  lcp_itf_pair_register_vft (&nl_itf_pair_vft);
 
   return (NULL);
 }