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 #elif defined(_MSC_VER)
8 #include "config-msvc.h"
9 #endif
10 
11 #include "syshead.h"
12 #include "error.h"
13 #include "misc.h"
14 #include "run_command.h"
15 #include "lladdr.h"
16 
17 int
18 set_lladdr(const char *ifname, const char *lladdr,
19  const struct env_set *es)
20 {
21  struct argv argv = argv_new();
22  int r;
23 
24  if (!ifname || !lladdr)
25  {
26  return -1;
27  }
28 
29 #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",
38  ifname, lladdr);
39 #endif
40 #elif defined(TARGET_SOLARIS)
41  argv_printf(&argv,
42  "%s %s ether %s",
44  ifname, lladdr);
45 #elif defined(TARGET_OPENBSD)
46  argv_printf(&argv,
47  "%s %s lladdr %s",
49  ifname, lladdr);
50 #elif defined(TARGET_DARWIN)
51  argv_printf(&argv,
52  "%s %s lladdr %s",
54  ifname, lladdr);
55 #elif defined(TARGET_FREEBSD)
56  argv_printf(&argv,
57  "%s %s ether %s",
59  ifname, lladdr);
60 #else /* if defined(TARGET_LINUX) */
61  msg(M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system.");
62  return -1;
63 #endif /* if defined(TARGET_LINUX) */
64 
65  argv_msg(M_INFO, &argv);
66  r = openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to set link layer address.");
67  if (r)
68  {
69  msg(M_INFO, "TUN/TAP link layer address set to %s", lladdr);
70  }
71 
72  argv_reset(&argv);
73  return r;
74 }
#define IFCONFIG_PATH
Definition: config.h:700
struct argv argv_new(void)
Definition: argv.c:52
#define M_INFO
Definition: errlevel.h:55
void argv_msg(const int msglev, const struct argv *a)
Definition: argv.c:206
#define msg
Definition: error.h:173
int set_lladdr(const char *ifname, const char *lladdr, const struct env_set *es)
Definition: lladdr.c:18
#define M_WARN
Definition: error.h:96
void argv_reset(struct argv *a)
Definition: argv.c:60
Definition: argv.h:35
bool openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
Definition: run_command.c:195
void argv_printf(struct argv *a, const char *format,...)
Definition: argv.c:318