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
15int set_lladdr(const char *ifname, const char *lladdr,
16		const struct env_set *es)
17{
18  struct argv argv = argv_new ();
19  int r;
20
21  if (!ifname || !lladdr)
22    return -1;
23
24#if defined(TARGET_LINUX)
25#ifdef ENABLE_IPROUTE
26  argv_printf (&argv,
27		    "%s link set addr %s dev %s",
28		    iproute_path, lladdr, ifname);
29#else
30  argv_printf (&argv,
31		    "%s %s hw ether %s",
32		    IFCONFIG_PATH,
33		    ifname, lladdr);
34#endif
35#elif defined(TARGET_SOLARIS)
36  argv_printf (&argv,
37		    "%s %s ether %s",
38		    IFCONFIG_PATH,
39		    ifname, lladdr);
40#elif defined(TARGET_OPENBSD)
41  argv_printf (&argv,
42		    "%s %s lladdr %s",
43		    IFCONFIG_PATH,
44		    ifname, lladdr);
45#elif defined(TARGET_DARWIN)
46  argv_printf (&argv,
47		    "%s %s lladdr %s",
48		    IFCONFIG_PATH,
49		    ifname, lladdr);
50#elif defined(TARGET_FREEBSD)
51  argv_printf (&argv,
52		    "%s %s ether %s",
53		    IFCONFIG_PATH,
54		    ifname, lladdr);
55#else
56      msg (M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system.");
57      return -1;
58#endif
59
60  argv_msg (M_INFO, &argv);
61  r = openvpn_execve_check (&argv, es, M_WARN, "ERROR: Unable to set link layer address.");
62  if (r)
63    msg (M_INFO, "TUN/TAP link layer address set to %s", lladdr);
64
65  argv_reset (&argv);
66  return r;
67}
68