[Openvpn-devel,S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function

Message ID cbec232dce34db72a82f8ed000070d07ebb56f8a-HTML@gerrit.openvpn.net
State New
Headers show
Series [Openvpn-devel,S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function | expand

Commit Message

ordex (Code Review) Oct. 29, 2024, 1:44 p.m. UTC
Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/788?usp=email

to review the following change.


Change subject: sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function
......................................................................

sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function

The NLMSG_TAIL macro never had any reason to exist, because libnl
already provides a function doing exactly the same: nlmsg_tail().

Moreover, this macro was found to confuse gcc when compiling with -O3,
which would result in subsequent warnings like:

networking_sitnl.c:143:9: warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
  143 |         memcpy(RTA_DATA(rta), data, alen);
      |         ^
networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ of size 16
  101 |     struct nlmsghdr n;
      |                     ^

(Above warnings are critical on Fedora 40 as they are turned into errors)

Delete the macro, replace it with nlmsg_tail() and get rid of the
warnings.

Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
M src/openvpn/networking_sitnl.c
1 file changed, 4 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/788/1

Patch

diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c
index f53f5ee..8eeab72 100644
--- a/src/openvpn/networking_sitnl.c
+++ b/src/openvpn/networking_sitnl.c
@@ -40,6 +40,7 @@ 
 #include <sys/socket.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
+#include <netlink/msg.h>
 
 #define SNDBUF_SIZE (1024 * 2)
 #define RCVBUF_SIZE (1024 * 4)
@@ -52,19 +53,16 @@ 
         }                                                           \
     }
 
-#define NLMSG_TAIL(nmsg) \
-    ((struct rtattr *)(((uint8_t *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
-
 #define SITNL_NEST(_msg, _max_size, _attr)              \
     ({                                                  \
-        struct rtattr *_nest = NLMSG_TAIL(_msg);        \
+        struct rtattr *_nest = nlmsg_tail(_msg);        \
         SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \
         _nest;                                          \
     })
 
 #define SITNL_NEST_END(_msg, _nest)                                 \
     {                                                               \
-        _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest;  \
+        _nest->rta_len = (void *)nlmsg_tail(_msg) - (void *)_nest;  \
     }
 
 /**
@@ -130,7 +128,7 @@ 
         return -EMSGSIZE;
     }
 
-    rta = NLMSG_TAIL(n);
+    rta = nlmsg_tail(n);
     rta->rta_type = type;
     rta->rta_len = len;