From: "flichtenheld (Code Review)" Date: Fri, 8 May 2026 15:46:47 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="uXdc8tbJ2bs="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: lladdr: Clean up code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --uXdc8tbJ2bs= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1675?usp=3Demail to look at the new patch set (#3). Change subject: lladdr: Clean up code ...................................................................... lladdr: Clean up code cppcheck complained about the creation of a useless variable on Windows. With the old code this was not fixable in a good way. So rewrite the whole code to hopefully be much more readable. Change-Id: Ibe7b3c17176c97a1cbb4d9cc87735b05e62c4f43 Signed-off-by: Frank Lichtenheld --- M src/openvpn/lladdr.c 1 file changed, 39 insertions(+), 26 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/1675/3 diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c index d8bcad9..5160780 100644 --- a/src/openvpn/lladdr.c +++ b/src/openvpn/lladdr.c @@ -13,42 +13,55 @@ #include "lladdr.h" #include "proto.h" +#ifdef TARGET_LINUX +static int +set_lladdr_linux(openvpn_net_ctx_t *ctx, const char *ifname, const char *l= laddr) +{ + uint8_t addr[OPENVPN_ETH_ALEN]; + + sscanf(lladdr, MAC_FMT, MAC_SCAN_ARG(addr)); + return (net_addr_ll_set(ctx, ifname, addr) =3D=3D 0); +} +#else /* TARGET_LINUX */ + +#if defined(TARGET_SOLARIS) || defined(TARGET_FREEBSD) +#define IFCONFIG_LLADDR_CMD "ether" +#elif defined(TARGET_OPENBSD) || defined(TARGET_DARWIN) +#define IFCONFIG_LLADDR_CMD "lladdr" +#endif +static int +set_lladdr_ifconfig(const char *ifname, const char *lladdr, const struct e= nv_set *es) +{ +#ifdef IFCONFIG_LLADDR_CMD + struct argv argv =3D argv_new(); + argv_msg(M_INFO, &argv); + argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); + int r =3D openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to se= t link layer address."); + argv_free(&argv); + return r; +#else + msg(M_WARN, + "Sorry, but I don't know how to configure link layer addresses on = this operating system."); + return -1; +#endif +} +#endif /* TARGET_LINUX */ + int set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,= const struct env_set *es) { - int r; - if (!ifname || !lladdr) { return -1; } #if defined(TARGET_LINUX) - uint8_t addr[OPENVPN_ETH_ALEN]; + int r =3D set_lladdr_linux(ctx, ifname, lladdr); +#else + int r =3D set_lladdr_ifconfig(ifname, lladdr, es); +#endif - sscanf(lladdr, MAC_FMT, MAC_SCAN_ARG(addr)); - r =3D (net_addr_ll_set(ctx, ifname, addr) =3D=3D 0); -#else /* if defined(TARGET_LINUX) */ - struct argv argv =3D argv_new(); -#if defined(TARGET_SOLARIS) - argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); -#elif defined(TARGET_OPENBSD) - argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr); -#elif defined(TARGET_DARWIN) - argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr); -#elif defined(TARGET_FREEBSD) - argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); -#else /* if defined(TARGET_SOLARIS) */ - msg(M_WARN, - "Sorry, but I don't know how to configure link layer addresses on = this operating system."); - return -1; -#endif /* if defined(TARGET_SOLARIS) */ - argv_msg(M_INFO, &argv); - r =3D openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to set li= nk layer address."); - argv_free(&argv); -#endif /* if defined(TARGET_LINUX) */ - - if (r) + if (r > 0) { msg(M_INFO, "TUN/TAP link layer address set to %s", lladdr); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1675?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ibe7b3c17176c97a1cbb4d9cc87735b05e62c4f43 Gerrit-Change-Number: 1675 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --uXdc8tbJ2bs= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld uploaded patch set #3 to this change.

<= p>View C= hange

lladdr: Clean up code

cppcheck complained= about the creation of a useless
variable on Windows. With the old code = this was not
fixable in a good way. So rewrite the whole code to
hope= fully be much more readable.

Change-Id: Ibe7b3c17176c97a1cbb4d9cc877= 35b05e62c4f43
Signed-off-by: Frank Lichtenheld <frank@...2641...><= br>---
M src/openvpn/lladdr.c
1 file changed, 39 insertions(+), 26 de= letions(-)

git pull ssh://gerrit.openvpn.net:294=
18/openvpn refs/changes/75/1675/3
diff --git a/src/openvpn/lladdr.c=
 b/src/openvpn/lladdr.c
index d8bcad9..5160780 100644
--- a/src/openvpn/lladdr.c
+++ b/src/openvpn/lla= ddr.c
@@ -13,42 +13,55 @@
#include "l= laddr.h"
#include "proto.h"

+#ifdef TARGET_LIN= UX
+static int=
+set_lladdr_linux(openvpn_n= et_ctx_t *ctx, const char *ifname, const char *lladdr)
+{
+ uint8_t addr[OPENVPN_ETH_ALEN];
+
+ sscanf(lladdr, MAC_FMT, MAC_SCAN_ARG(addr));
<= span style=3D"color: hsl(120, 100%, 40%);">+ return (net_addr_ll_set(ctx= , ifname, addr) =3D=3D 0);
+}
+#else /* TA= RGET_LINUX */
+
+#if defined(TARGET_SOLARI= S) || defined(TARGET_FREEBSD)
+#define IFCONFIG_LLADDR_CMD "ether"
+#elif defined(TARGET_OPENBSD) || define= d(TARGET_DARWIN)
+#de= fine IFCONFIG_LLADDR_CMD "lladdr"
+#endif
+static int
+set_lladdr_ifconfig(const char *ifname, const char *lladdr, const struct = env_set *es)
+{
+#ifdef IFCONFIG_LLADDR_CM= D
+ struct argv ar= gv =3D argv_new();
+ = argv_msg(M_INFO, &argv);
+ argv_printf(&argv, "%s %s ether %s", IFCONFIG= _PATH, ifname, lladdr);
+ int r =3D openvpn_execve_check(&argv, es, M_WARN, "ERROR: = Unable to set link layer address.");
+ argv_free(&argv);
+ return r;
+#else
+ msg(M_WARN,
+ "Sorry, but I don't know how to configure link layer a= ddresses on this operating system.");
+ return -1;
+#endif
+}
+#endif /* TAR= GET_LINUX */
+=
int
set_lladdr(openvpn_net_ctx_t *ctx, const ch= ar *ifname, const char *lladdr, const struct env_set *es)
= {
- int r;-
if (!ifna= me || !lladdr)
{
return -1;
}

#if defined(TARGET= _LINUX)
- uint8_t ad= dr[OPENVPN_ETH_ALEN];
+ int r =3D set_lladdr_linux(ctx, ifname, lladdr);
+#else
+ int r =3D set_lladdr_ifconfig(ifname, lladdr, es);=
+#endif

- sscanf(lladd= r, MAC_FMT, MAC_SCAN_ARG(addr));
- r =3D (net_addr_ll_set(ctx, ifname, addr) =3D=3D 0);<= br>-#else /* if defined(TARGET_LI= NUX) */
- struct arg= v argv =3D argv_new();
= -#if defined(TARGET_SOLARIS)
- argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH= , ifname, lladdr);
-#el= if defined(TARGET_OPENBSD)
- argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH,= ifname, lladdr);
-#eli= f defined(TARGET_DARWIN)
-#elif = defined(TARGET_FREEBSD)
- argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifn= ame, lladdr);
-#else /= * if defined(TARGET_SOLARIS) */
- msg(M_WARN,
- "Sorry, but I don't know how to configure link layer a= ddresses on this operating system.");
- return -1;
-#endif /* if defined(TARGET_SOLARIS) */
- argv_msg(M_INFO, &argv);
= - r =3D openvpn_execve_check(&= amp;argv, es, M_WARN, "ERROR: Unable to set link layer address.")= ;
- argv_free(&a= rgv);
-#endif /* if def= ined(TARGET_LINUX) */
-=
- if (r)
= + if (r > 0)
{

msg(M_INFO, "TUN/TAP link layer ad= dress set to %s", lladdr);
}

To view, visit change 1675. To unsubscribe, or for help writing= mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ibe7b3c17176c97a1cbb4d9cc877= 35b05e62c4f43
Gerrit-Change-Number: 1675
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --uXdc8tbJ2bs=--