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,
13 const in_addr_t *gw, const char *iface, uint32_t table,
14 int metric)
15{
16 char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
17 in_addr_t _dst, _gw;
18 struct argv argv = argv_new();
19 bool status;
20
21 _dst = ntohl(*dst);
22 _gw = ntohl(*gw);
23
24 argv_printf(&argv, "%s %s -net %s/%d %s -fib %d",
25 ROUTE_PATH, op,
26 inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)),
27 prefixlen,
28 inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)),
29 table);
30
33 "ERROR: FreeBSD route command failed");
34
36
37 return (!status);
38}
39
40static int
41net_route_v6(const char *op, const struct in6_addr *dst,
42 int prefixlen, const struct in6_addr *gw, const char *iface,
43 uint32_t table, int metric)
44{
45 char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
46 struct argv argv = argv_new();
47 bool status;
48
49 argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d",
50 ROUTE_PATH, op,
51 inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)),
52 prefixlen,
53 inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)),
54 table);
55
58 "ERROR: FreeBSD route command failed");
59
61
62 return (!status);
63}
64
65int
66net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
67 const in_addr_t *gw, const char *iface, uint32_t table,
68 int metric)
69{
70 return net_route_v4("add", dst, prefixlen, gw, iface, table, metric);
71}
72
73int
74net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
75 int prefixlen, const struct in6_addr *gw, const char *iface,
76 uint32_t table, int metric)
77{
78 return net_route_v6("add", dst, prefixlen, gw, iface, table, metric);
79}
80
81int
82net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
83 const in_addr_t *gw, const char *iface, uint32_t table,
84 int metric)
85{
86 return net_route_v4("del", dst, prefixlen, gw, iface, table, metric);
87}
88
89int
90net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
91 int prefixlen, const struct in6_addr *gw, const char *iface,
92 uint32_t table, int metric)
93{
94 return net_route_v6("del", dst, prefixlen, gw, iface, table, metric);
95}
96
97#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:243
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:102
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:440
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:88
#define M_INFO
Definition errlevel.h:55
static SERVICE_STATUS status
Definition interactive.c:53
void * openvpn_net_ctx_t
Definition networking.h:39
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