OpenVPN
networking_freebsd.c
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4#include "syshead.h"
5#include "errlevel.h"
6#include "run_command.h"
7#include "networking.h"
8
9#if defined(TARGET_FREEBSD)
10
11static int
12net_route_v4(const char *op, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
13 const char *iface, uint32_t table, int metric)
14{
15 char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
16 in_addr_t _dst, _gw;
17 struct argv argv = argv_new();
18 bool status;
19
20 _dst = ntohl(*dst);
21 _gw = ntohl(*gw);
22
23 argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
24 inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
25 inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
26
28 status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
29
31
32 return (!status);
33}
34
35static int
36net_route_v6(const char *op, const struct in6_addr *dst, int prefixlen, const struct in6_addr *gw,
37 const char *iface, uint32_t table, int metric)
38{
39 char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
40 struct argv argv = argv_new();
41 bool status;
42
43 argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
44 inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
45 inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
46
48 status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
49
51
52 return (!status);
53}
54
55int
56net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
57 const char *iface, uint32_t table, int metric)
58{
59 return net_route_v4("add", dst, prefixlen, gw, iface, table, metric);
60}
61
62int
63net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
64 const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
65{
66 return net_route_v6("add", dst, prefixlen, gw, iface, table, metric);
67}
68
69int
70net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
71 const char *iface, uint32_t table, int metric)
72{
73 return net_route_v4("del", dst, prefixlen, gw, iface, table, metric);
74}
75
76int
77net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
78 const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
79{
80 return net_route_v6("del", dst, prefixlen, gw, iface, table, metric);
81}
82
83#endif /* if defined(TARGET_FREEBSD) */
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:242
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:438
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
#define M_INFO
Definition errlevel.h:54
static SERVICE_STATUS status
Definition interactive.c:51
void * openvpn_net_ctx_t
Definition networking.h:38
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
Definition argv.h:35
static char * iface