summaryrefslogtreecommitdiff
path: root/src/openvpn/lladdr.c
diff options
context:
space:
mode:
authorAlberto Gonzalez Iniesta <agi@inittab.org>2012-11-05 16:28:10 +0100
committerAlberto Gonzalez Iniesta <agi@inittab.org>2012-11-05 16:28:10 +0100
commitd213c4e5576e2fd601679e0d7b2fb1262b807111 (patch)
tree5f0cc82bd0f11fb13b385417604d04c751245a92 /src/openvpn/lladdr.c
parent79c8d3ef7a938f86472e549ef64e1fb820dc80c4 (diff)
parent8dd0350e1607aa30f7a043c8d5ec7a7eeb874115 (diff)
Merge tag 'upstream/2.3_rc1'
Upstream version 2.3_rc1
Diffstat (limited to 'src/openvpn/lladdr.c')
-rw-r--r--src/openvpn/lladdr.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c
new file mode 100644
index 0000000..57f447b
--- /dev/null
+++ b/src/openvpn/lladdr.c
@@ -0,0 +1,67 @@
+/*
+ * Support routine for configuring link layer address
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#elif defined(_MSC_VER)
+#include "config-msvc.h"
+#endif
+
+#include "syshead.h"
+#include "error.h"
+#include "misc.h"
+
+int set_lladdr(const char *ifname, const char *lladdr,
+ const struct env_set *es)
+{
+ struct argv argv = argv_new ();
+ int r;
+
+ if (!ifname || !lladdr)
+ return -1;
+
+#if defined(TARGET_LINUX)
+#ifdef ENABLE_IPROUTE
+ argv_printf (&argv,
+ "%s link set addr %s dev %s",
+ iproute_path, lladdr, ifname);
+#else
+ argv_printf (&argv,
+ "%s %s hw ether %s",
+ IFCONFIG_PATH,
+ ifname, lladdr);
+#endif
+#elif 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
+ msg (M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system.");
+ return -1;
+#endif
+
+ argv_msg (M_INFO, &argv);
+ r = openvpn_execve_check (&argv, es, M_WARN, "ERROR: Unable to set link layer address.");
+ if (r)
+ msg (M_INFO, "TUN/TAP link layer address set to %s", lladdr);
+
+ argv_reset (&argv);
+ return r;
+}