Browse code

dco_linux: use M_FATAL instead of M_ERR in netlink error code paths

Netlink code doesn't set errno upon error (with the exception of
any *alloc() function which probably inherits the errno=ENOMEM
from the underlying malloc call), therefore we should not print
error messages with M_ERR, but rather rely on M_FATAL.

M_ERR is equivalent to M_FATAL with the addition of appending
": $errno" to the error string.

Since errno is not meaningful in this context, we can just opt
for the less confusing M_FATAL.

Change-Id: Ifc442b4426c02de7282d0f69629e8a10b679c589
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250723063039.25449-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32271.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Antonio Quartulli authored on 2025/07/23 15:30:30
Showing 1 changed files
... ...
@@ -114,7 +114,7 @@ ovpn_dco_nlmsg_create(dco_context_t *dco, int cmd)
114 114
     struct nl_msg *nl_msg = nlmsg_alloc();
115 115
     if (!nl_msg)
116 116
     {
117
-        msg(M_ERR, "cannot allocate netlink message");
117
+        msg(M_FATAL, "cannot allocate netlink message");
118 118
         return NULL;
119 119
     }
120 120
 
... ...
@@ -140,7 +140,7 @@ ovpn_nl_recvmsgs(dco_context_t *dco, const char *prefix)
140 140
             break;
141 141
 
142 142
         case -NLE_NOMEM:
143
-            msg(M_ERR, "%s: netlink out of memory error", prefix);
143
+            msg(M_FATAL, "%s: netlink out of memory error", prefix);
144 144
             break;
145 145
 
146 146
         case -NLE_AGAIN:
... ...
@@ -148,7 +148,7 @@ ovpn_nl_recvmsgs(dco_context_t *dco, const char *prefix)
148 148
             break;
149 149
 
150 150
         case -NLE_NODEV:
151
-            msg(M_ERR, "%s: netlink reports device not found:", prefix);
151
+            msg(M_FATAL, "%s: netlink reports device not found:", prefix);
152 152
             break;
153 153
 
154 154
         case -NLE_OBJ_NOTFOUND:
... ...
@@ -387,19 +387,19 @@ ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
387 387
 static void
388 388
 ovpn_dco_init_netlink(dco_context_t *dco)
389 389
 {
390
-    dco->ovpn_dco_id = resolve_ovpn_netlink_id(M_ERR);
390
+    dco->ovpn_dco_id = resolve_ovpn_netlink_id(M_FATAL);
391 391
 
392 392
     dco->nl_sock = nl_socket_alloc();
393 393
 
394 394
     if (!dco->nl_sock)
395 395
     {
396
-        msg(M_ERR, "Cannot create netlink socket");
396
+        msg(M_FATAL, "Cannot create netlink socket");
397 397
     }
398 398
 
399 399
     int ret = genl_connect(dco->nl_sock);
400 400
     if (ret)
401 401
     {
402
-        msg(M_ERR, "Cannot connect to generic netlink: %s",
402
+        msg(M_FATAL, "Cannot connect to generic netlink: %s",
403 403
             nl_geterror(ret));
404 404
     }
405 405
 
... ...
@@ -415,7 +415,7 @@ ovpn_dco_init_netlink(dco_context_t *dco)
415 415
     dco->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
416 416
     if (!dco->nl_cb)
417 417
     {
418
-        msg(M_ERR, "failed to allocate netlink callback");
418
+        msg(M_FATAL, "failed to allocate netlink callback");
419 419
     }
420 420
 
421 421
     nl_socket_set_cb(dco->nl_sock, dco->nl_cb);
... ...
@@ -478,7 +478,7 @@ ovpn_dco_register(dco_context_t *dco)
478 478
 
479 479
     if (dco->ovpn_dco_mcast_id < 0)
480 480
     {
481
-        msg(M_ERR, "cannot get mcast group: %s",  nl_geterror(dco->ovpn_dco_mcast_id));
481
+        msg(M_FATAL, "cannot get mcast group: %s",  nl_geterror(dco->ovpn_dco_mcast_id));
482 482
     }
483 483
 
484 484
     /* Register for ovpn-dco specific multicast messages that the kernel may
... ...
@@ -487,7 +487,7 @@ ovpn_dco_register(dco_context_t *dco)
487 487
     int ret = nl_socket_add_membership(dco->nl_sock, dco->ovpn_dco_mcast_id);
488 488
     if (ret)
489 489
     {
490
-        msg(M_ERR, "%s: failed to join groups: %d", __func__, ret);
490
+        msg(M_FATAL, "%s: failed to join groups: %d", __func__, ret);
491 491
     }
492 492
 }
493 493