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 
16 int
17 set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,
18  const struct env_set *es)
19 {
20  int r;
21 
22  if (!ifname || !lladdr)
23  {
24  return -1;
25  }
26 
27 #if defined(TARGET_LINUX)
28  uint8_t addr[OPENVPN_ETH_ALEN];
29 
30  sscanf(lladdr, MAC_FMT, MAC_SCAN_ARG(addr));
31  r = (net_addr_ll_set(ctx, ifname, addr) == 0);
32 #else /* if defined(TARGET_LINUX) */
33  struct argv argv = argv_new();
34 #if defined(TARGET_SOLARIS)
36  "%s %s ether %s",
38  ifname, lladdr);
39 #elif defined(TARGET_OPENBSD)
41  "%s %s lladdr %s",
43  ifname, lladdr);
44 #elif defined(TARGET_DARWIN)
46  "%s %s lladdr %s",
48  ifname, lladdr);
49 #elif defined(TARGET_FREEBSD)
51  "%s %s ether %s",
53  ifname, lladdr);
54 #else /* if defined(TARGET_SOLARIS) */
55  msg(M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system.");
56  return -1;
57 #endif /* if defined(TARGET_SOLARIS) */
58  argv_msg(M_INFO, &argv);
59  r = openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to set link layer address.");
60  argv_free(&argv);
61 #endif /* if defined(TARGET_LINUX) */
62 
63  if (r)
64  {
65  msg(M_INFO, "TUN/TAP link layer address set to %s", lladdr);
66  }
67 
68  return r;
69 }
M_INFO
#define M_INFO
Definition: errlevel.h:55
error.h
run_command.h
set_lladdr
int set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
Definition: lladdr.c:17
argv
Definition: argv.h:35
lladdr.h
es
struct env_set * es
Definition: test_pkcs11.c:133
argv_free
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition: argv.c:102
openvpn_net_ctx_t
void * openvpn_net_ctx_t
Definition: networking.h:28
openvpn_execve_check
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
Definition: run_command.c:193
MAC_FMT
#define MAC_FMT
Definition: misc.h:220
proto.h
misc.h
M_WARN
#define M_WARN
Definition: error.h:97
syshead.h
env_set
Definition: env_set.h:42
argv_new
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition: argv.c:88
argv_printf
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition: argv.c:440
IFCONFIG_PATH
#define IFCONFIG_PATH
Definition: config.h:465
OPENVPN_ETH_ALEN
#define OPENVPN_ETH_ALEN
Definition: proto.h:54
argv_msg
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:243
config.h
MAC_SCAN_ARG
#define MAC_SCAN_ARG(_mac)
Definition: misc.h:224
msg
#define msg(flags,...)
Definition: error.h:150