Go to the documentation of this file.
25 #if defined(TARGET_LINUX) && defined(ENABLE_IPROUTE)
37 #include <netinet/in.h>
84 msg(
M_WARN,
"%s: operation not supported by iproute2 backend", __func__);
139 "%s link set addr " MAC_FMT " dev %s",
144 "Linux ip link set addr failed"))
156 const in_addr_t *addr,
int prefixlen)
163 addr_str, prefixlen);
174 const struct in6_addr *addr,
int prefixlen)
179 argv_printf(&
argv,
"%s -6 addr add %s/%d dev %s", iproute_path, addr_str,
183 "Linux ip -6 addr add failed");
192 const in_addr_t *addr,
int prefixlen)
198 addr_str, prefixlen);
210 const struct in6_addr *addr,
int prefixlen)
216 addr_str, prefixlen,
iface);
227 const in_addr_t *local,
const in_addr_t *remote)
233 argv_printf(&
argv,
"%s addr add dev %s local %s peer %s", iproute_path,
234 iface, local_str, remote_str);
245 const in_addr_t *local,
const in_addr_t *remote)
251 argv_printf(&
argv,
"%s addr del dev %s local %s peer %s", iproute_path,
252 iface, local_str, remote_str);
263 const in_addr_t *gw,
const char *
iface, uint32_t table,
270 argv_printf(&
argv,
"%s route add %s/%d", iproute_path, dst_str, prefixlen);
302 int prefixlen,
const struct in6_addr *gw,
const char *
iface,
303 uint32_t table,
int metric)
309 argv_printf(&
argv,
"%s -6 route add %s/%d dev %s", iproute_path, dst_str,
337 const in_addr_t *gw,
const char *
iface, uint32_t table,
344 argv_printf(&
argv,
"%s route del %s/%d", iproute_path, dst_str, prefixlen);
364 int prefixlen,
const struct in6_addr *gw,
const char *
iface,
365 uint32_t table,
int metric)
371 argv_printf(&
argv,
"%s -6 route del %s/%d dev %s", iproute_path, dst_str,
399 in_addr_t *best_gw,
char *best_iface)
401 best_iface[0] =
'\0';
403 FILE *fp = fopen(
"/proc/net/route",
"r");
411 unsigned int lowest_metric = UINT_MAX;
412 while (fgets(line,
sizeof(line), fp) != NULL)
416 unsigned int net_x = 0;
417 unsigned int mask_x = 0;
418 unsigned int gw_x = 0;
419 unsigned int metric = 0;
420 unsigned int flags = 0;
424 const int np = sscanf(line,
"%15s\t%x\t%x\t%x\t%*s\t%*s\t%d\t%x",
425 name, &net_x, &gw_x, &flags, &metric,
428 if (
np == 6 && (flags & IFF_UP))
430 const in_addr_t net = ntohl(net_x);
431 const in_addr_t mask = ntohl(mask_x);
432 const in_addr_t gw = ntohl(gw_x);
434 if (!net && !mask && metric < lowest_metric)
437 strcpy(best_iface, name);
438 lowest_metric = metric;
static struct gc_arena gc_new(void)
#define IFACE_TYPE_LEN_MAX
Contains all state information for one tunnel.
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
static void gc_reset(struct gc_arena *a)
static int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx)
static const char * np(const char *str)
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
#define MAC_PRINT_ARG(_mac)
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
static void net_ctx_reset(openvpn_net_ctx_t *ctx)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
static void net_ctx_free(openvpn_net_ctx_t *ctx)
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
struct env_set * es
Set of environment variables.
static void gc_free(struct gc_arena *a)
void argv_msg(const int msglev, const struct argv *a)
Write the arguments stored in a struct argv via the msg() command.
void * openvpn_net_iface_t