Skip to contentSkip to conversation

sitnl: fix ignoring EEXIST when sending a netlink command

PATCH In review Antonio Quartulli 2 participants 2 messages Apr 18, 2020 – Apr 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sitnl: fix ignoring EEXIST when sending a netlink command

The logic is to treat EEXIST as non-error because it means that the address/soute we wanted to install already exists, therefore we can move on and not fail.

However, this logic is currently based on checking errno == EEXIST. This is wrong, because sitnl_send() does not set errno, but returns the error directly as negative value.

Fix this issue by directly comparing the the return value with -EEXIST.

---
 src/openvpn/networking_sitnl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/networking_sitnl.c +2 -2
index 7adcb64c..713a213a 100644
@@ -717,7 +717,7 @@ sitnl_addr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,
     }
 
     ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
-    if ((ret < 0) && (errno == EEXIST))
+    if (ret == -EEXIST)
     {
         ret = 0;
     }
@@ -858,7 +858,7 @@ sitnl_route_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,
     }
 
     ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
-    if ((ret < 0) && (errno == EEXIST))
+    if (ret == -EEXIST)
     {
         ret = 0;
     }
Signature · 1 line
2.26.1
Acked-by on v1 1/1
#1 lore raw

Proper error handling is hard, we should just always crash with ASSERT() :-)

Your patch has been applied to the master branch.

commit db3d737ba3ef9d83c5ceffa2f653d0ee4a8abb54

Author: Antonio Quartulli
Date:   Sat Apr 18 11:43:50 2020 +0200
     sitnl: fix ignoring EEXIST when sending a netlink command

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19777.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering