OpenVPN
src
openvpn
networking.h
Go to the documentation of this file.
1
/*
2
* Generic interface to platform specific networking code
3
*
4
* Copyright (C) 2016-2025 Antonio Quartulli <a@unstable.cc>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2
8
* as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program (see the file COPYING included with this
17
* distribution); if not, see <https://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef NETWORKING_H_
21
#define NETWORKING_H_
22
23
#include "
syshead.h
"
24
25
#define IFACE_TYPE_LEN_MAX 64
26
27
struct
context
;
28
29
#ifdef ENABLE_SITNL
30
#include "
networking_sitnl.h
"
31
#elif ENABLE_IPROUTE
32
#include "
networking_iproute2.h
"
33
#elif defined(TARGET_FREEBSD)
34
typedef
void
*
openvpn_net_ctx_t
;
35
typedef
char
openvpn_net_iface_t
;
36
#else
/* ifdef ENABLE_SITNL */
37
/* define mock types to ensure code builds on any platform */
38
typedef
void
*
openvpn_net_ctx_t
;
39
typedef
void
*
openvpn_net_iface_t
;
40
#endif
/* ifdef ENABLE_SITNL */
41
42
/* Only the iproute2 backend implements these functions,
43
* the rest can rely on these stubs
44
*/
45
#if !defined(ENABLE_IPROUTE)
46
static
inline
int
47
net_ctx_init
(
struct
context
*c,
openvpn_net_ctx_t
*ctx)
48
{
49
(void)c;
50
(void)ctx;
51
52
return
0;
53
}
54
55
static
inline
void
56
net_ctx_reset
(
openvpn_net_ctx_t
*ctx)
57
{
58
(void)ctx;
59
}
60
61
static
inline
void
62
net_ctx_free
(
openvpn_net_ctx_t
*ctx)
63
{
64
(void)ctx;
65
}
66
#endif
/* !defined(ENABLE_IPROUTE) */
67
68
#if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE)
69
78
int
net_ctx_init
(
struct
context
*c,
openvpn_net_ctx_t
*ctx);
79
85
void
net_ctx_reset
(
openvpn_net_ctx_t
*ctx);
86
92
void
net_ctx_free
(
openvpn_net_ctx_t
*ctx);
93
104
int
net_iface_new(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
const
char
*type,
105
void
*arg);
106
116
int
net_iface_type(
openvpn_net_ctx_t
*ctx,
const
char
*
iface
,
char
type[
IFACE_TYPE_LEN_MAX
]);
117
125
int
net_iface_del(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
);
126
136
int
net_iface_up(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
bool
up);
137
147
int
net_iface_mtu_set(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
, uint32_t mtu);
148
158
int
net_addr_ll_set(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
, uint8_t *addr);
159
170
int
net_addr_v4_add(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
const
in_addr_t *addr,
171
int
prefixlen);
172
184
int
net_addr_v6_add(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
185
const
struct
in6_addr *addr,
int
prefixlen);
186
196
int
net_addr_v4_del(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
const
in_addr_t *addr,
197
int
prefixlen);
198
208
int
net_addr_v6_del(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
209
const
struct
in6_addr *addr,
int
prefixlen);
210
221
int
net_addr_ptp_v4_add(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
222
const
in_addr_t *local,
const
in_addr_t *remote);
223
234
int
net_addr_ptp_v4_del(
openvpn_net_ctx_t
*ctx,
const
openvpn_net_iface_t
*
iface
,
235
const
in_addr_t *local,
const
in_addr_t *remote);
236
237
#endif
/* ENABLE_SITNL || ENABLE_IPROUTE */
238
239
#if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE) || defined(TARGET_FREEBSD)
254
int
net_route_v4_add(
openvpn_net_ctx_t
*ctx,
const
in_addr_t *dst,
int
prefixlen,
255
const
in_addr_t *gw,
const
openvpn_net_iface_t
*
iface
, uint32_t table,
256
int
metric);
257
272
int
net_route_v6_add(
openvpn_net_ctx_t
*ctx,
const
struct
in6_addr *dst,
int
prefixlen,
273
const
struct
in6_addr *gw,
const
openvpn_net_iface_t
*
iface
, uint32_t table,
274
int
metric);
275
290
int
net_route_v4_del(
openvpn_net_ctx_t
*ctx,
const
in_addr_t *dst,
int
prefixlen,
291
const
in_addr_t *gw,
const
openvpn_net_iface_t
*
iface
, uint32_t table,
292
int
metric);
293
308
int
net_route_v6_del(
openvpn_net_ctx_t
*ctx,
const
struct
in6_addr *dst,
int
prefixlen,
309
const
struct
in6_addr *gw,
const
openvpn_net_iface_t
*
iface
, uint32_t table,
310
int
metric);
311
312
#endif
/* ENABLE_SITNL || ENABLE_IPROUTE || TARGET_FREEBSD */
313
314
#if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE)
315
327
int
net_route_v4_best_gw(
openvpn_net_ctx_t
*ctx,
const
in_addr_t *dst, in_addr_t *best_gw,
328
openvpn_net_iface_t
*best_iface);
329
341
int
net_route_v6_best_gw(
openvpn_net_ctx_t
*ctx,
const
struct
in6_addr *dst,
342
struct
in6_addr *best_gw,
openvpn_net_iface_t
*best_iface);
343
344
#endif
/* ENABLE_SITNL || ENABLE_IPROUTE */
345
346
#endif
/* NETWORKING_H_ */
net_ctx_reset
static void net_ctx_reset(openvpn_net_ctx_t *ctx)
Definition
networking.h:56
openvpn_net_iface_t
void * openvpn_net_iface_t
Definition
networking.h:39
IFACE_TYPE_LEN_MAX
#define IFACE_TYPE_LEN_MAX
Definition
networking.h:25
net_ctx_init
static int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx)
Definition
networking.h:47
net_ctx_free
static void net_ctx_free(openvpn_net_ctx_t *ctx)
Definition
networking.h:62
openvpn_net_ctx_t
void * openvpn_net_ctx_t
Definition
networking.h:38
networking_iproute2.h
networking_sitnl.h
context
Contains all state information for one tunnel.
Definition
openvpn.h:474
syshead.h
iface
static char * iface
Definition
test_networking.c:7
Generated by
1.9.8