OpenVPN
lladdr.c
Go to the documentation of this file.
1/*
2 * Support routine for configuring link layer address
3 */
4
5#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include "syshead.h"
10#include "error.h"
11#include "misc.h"
12#include "run_command.h"
13#include "lladdr.h"
14#include "proto.h"
15
16int
17set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
18{
19 int r;
20
21 if (!ifname || !lladdr)
22 {
23 return -1;
24 }
25
26#if defined(TARGET_LINUX)
27 uint8_t addr[OPENVPN_ETH_ALEN];
28
29 sscanf(lladdr, MAC_FMT, MAC_SCAN_ARG(addr));
30 r = (net_addr_ll_set(ctx, ifname, addr) == 0);
31#else /* if defined(TARGET_LINUX) */
32 struct argv argv = argv_new();
33#if defined(TARGET_SOLARIS)
34 argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr);
35#elif defined(TARGET_OPENBSD)
36 argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr);
37#elif defined(TARGET_DARWIN)
38 argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr);
39#elif defined(TARGET_FREEBSD)
40 argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr);
41#else /* if defined(TARGET_SOLARIS) */
42 msg(M_WARN,
43 "Sorry, but I don't know how to configure link layer addresses on this operating system.");
44 return -1;
45#endif /* if defined(TARGET_SOLARIS) */
47 r = openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to set link layer address.");
49#endif /* if defined(TARGET_LINUX) */
50
51 if (r)
52 {
53 msg(M_INFO, "TUN/TAP link layer address set to %s", lladdr);
54 }
55
56 return r;
57}
void argv_msg(const int msglev, const struct argv *a)
Write the arguments stored in a struct argv via the msg() command.
Definition argv.c:242
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:438
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
#define M_INFO
Definition errlevel.h:54
int set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
Definition lladdr.c:17
#define MAC_SCAN_ARG(_mac)
Definition misc.h:223
#define MAC_FMT
Definition misc.h:220
void * openvpn_net_ctx_t
Definition networking.h:38
#define msg(flags,...)
Definition error.h:150
#define M_WARN
Definition error.h:90
#define OPENVPN_ETH_ALEN
Definition proto.h:52
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
Definition argv.h:35
struct env_set * es