Skip to content

Commit 7205cdd

Browse files
ordexcron2
authored andcommitted
set_lladdr: use networking API net_addr_ll_set() on Linux
Make sure that set_addr() uses the proper networking backend when setting the LL address of a TAP interface. This operation was overlooked while implementing the networking APIs on the Linux platform. Reported-by: Jan Hugo Prins <[email protected]> Signed-off-by: Antonio Quartulli <[email protected]> Tested-by: Jan Hugo Prins <[email protected]> Acked-by: Gert Doering <[email protected]> Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg22791.html Signed-off-by: Gert Doering <[email protected]>
1 parent cb5d294 commit 7205cdd

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

src/openvpn/init.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ do_persist_tuntap(const struct options *options, openvpn_net_ctx_t *ctx)
11761176
ctx);
11771177
if (options->persist_mode && options->lladdr)
11781178
{
1179-
set_lladdr(options->dev, options->lladdr, NULL);
1179+
set_lladdr(ctx, options->dev, options->lladdr, NULL);
11801180
}
11811181
return true;
11821182
#else /* ifdef ENABLE_FEATURE_TUN_PERSIST */
@@ -1853,7 +1853,8 @@ do_open_tun(struct context *c)
18531853
/* set the hardware address */
18541854
if (c->options.lladdr)
18551855
{
1856-
set_lladdr(c->c1.tuntap->actual_name, c->options.lladdr, c->c2.es);
1856+
set_lladdr(&c->net_ctx, c->c1.tuntap->actual_name, c->options.lladdr,
1857+
c->c2.es);
18571858
}
18581859

18591860
/* do ifconfig */

src/openvpn/lladdr.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
#include "lladdr.h"
1616

1717
int
18-
set_lladdr(const char *ifname, const char *lladdr,
18+
set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,
1919
const struct env_set *es)
2020
{
21-
struct argv argv = argv_new();
2221
int r;
2322

2423
if (!ifname || !lladdr)
@@ -27,17 +26,13 @@ set_lladdr(const char *ifname, const char *lladdr,
2726
}
2827

2928
#if defined(TARGET_LINUX)
30-
#ifdef ENABLE_IPROUTE
31-
argv_printf(&argv,
32-
"%s link set addr %s dev %s",
33-
iproute_path, lladdr, ifname);
34-
#else
35-
argv_printf(&argv,
36-
"%s %s hw ether %s",
37-
IFCONFIG_PATH,
38-
ifname, lladdr);
39-
#endif
40-
#elif defined(TARGET_SOLARIS)
29+
uint8_t addr[ETH_ALEN];
30+
31+
sscanf(lladdr, MAC_FMT, MAC_SCAN_ARG(addr));
32+
r = (net_addr_ll_set(ctx, ifname, addr) == 0);
33+
#else /* if defined(TARGET_LINUX) */
34+
struct argv argv = argv_new();
35+
#if defined(TARGET_SOLARIS)
4136
argv_printf(&argv,
4237
"%s %s ether %s",
4338
IFCONFIG_PATH,
@@ -57,18 +52,19 @@ set_lladdr(const char *ifname, const char *lladdr,
5752
"%s %s ether %s",
5853
IFCONFIG_PATH,
5954
ifname, lladdr);
60-
#else /* if defined(TARGET_LINUX) */
55+
#else /* if defined(TARGET_SOLARIS) */
6156
msg(M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system.");
6257
return -1;
63-
#endif /* if defined(TARGET_LINUX) */
64-
58+
#endif /* if defined(TARGET_SOLARIS) */
6559
argv_msg(M_INFO, &argv);
6660
r = openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to set link layer address.");
61+
argv_free(&argv);
62+
#endif /* if defined(TARGET_LINUX) */
63+
6764
if (r)
6865
{
6966
msg(M_INFO, "TUN/TAP link layer address set to %s", lladdr);
7067
}
7168

72-
argv_free(&argv);
7369
return r;
7470
}

src/openvpn/lladdr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
#include "misc.h"
6+
#include "networking.h"
67

7-
int set_lladdr(const char *ifname, const char *lladdr,
8+
int set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,
89
const struct env_set *es);

0 commit comments

Comments
 (0)