OpenVPN
networking.h
Go to the documentation of this file.
1/*
2 * Generic interface to platform specific networking code
3 *
4 * Copyright (C) 2016-2024 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, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef NETWORKING_H_
22#define NETWORKING_H_
23
24#include "syshead.h"
25
26#define IFACE_TYPE_LEN_MAX 64
27
28struct context;
29
30#ifdef ENABLE_SITNL
31#include "networking_sitnl.h"
32#elif ENABLE_IPROUTE
33#include "networking_iproute2.h"
34#elif defined(TARGET_FREEBSD)
35typedef void *openvpn_net_ctx_t;
36typedef char openvpn_net_iface_t;
37#else /* ifdef ENABLE_SITNL */
38/* define mock types to ensure code builds on any platform */
39typedef void *openvpn_net_ctx_t;
40typedef void *openvpn_net_iface_t;
41#endif /* ifdef ENABLE_SITNL */
42
43/* Only the iproute2 backend implements these functions,
44 * the rest can rely on these stubs
45 */
46#if !defined(ENABLE_IPROUTE)
47static inline int
49{
50 (void)c;
51 (void)ctx;
52
53 return 0;
54}
55
56static inline void
58{
59 (void)ctx;
60}
61
62static inline void
64{
65 (void)ctx;
66}
67#endif /* !defined(ENABLE_IPROUTE) */
68
69#if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE)
70
79int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx);
80
87
94
105int net_iface_new(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
106 const char *type, void *arg);
107
117int net_iface_type(openvpn_net_ctx_t *ctx, const char *iface,
118 char type[IFACE_TYPE_LEN_MAX]);
119
127int net_iface_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface);
128
138int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
139 bool up);
140
150int net_iface_mtu_set(openvpn_net_ctx_t *ctx,
151 const openvpn_net_iface_t *iface, uint32_t mtu);
152
162int net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
163 uint8_t *addr);
164
175int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
176 const in_addr_t *addr, int prefixlen);
177
189int net_addr_v6_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
190 const struct in6_addr *addr, int prefixlen);
191
201int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
202 const in_addr_t *addr, int prefixlen);
203
213int net_addr_v6_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
214 const struct in6_addr *addr, int prefixlen);
215
226int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx,
228 const in_addr_t *local, const in_addr_t *remote);
229
240int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx,
242 const in_addr_t *local, const in_addr_t *remote);
243
244#endif /* ENABLE_SITNL || ENABLE_IPROUTE */
245
246#if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE) || defined(TARGET_FREEBSD)
261int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
262 int prefixlen, const in_addr_t *gw,
263 const openvpn_net_iface_t *iface, uint32_t table,
264 int metric);
265
280int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
281 int prefixlen, const struct in6_addr *gw,
283 uint32_t table, int metric);
284
299int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
300 int prefixlen, const in_addr_t *gw,
301 const openvpn_net_iface_t *iface, uint32_t table,
302 int metric);
303
318int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
319 int prefixlen, const struct in6_addr *gw,
321 uint32_t table, int metric);
322
323#endif /* ENABLE_SITNL || ENABLE_IPROUTE || TARGET_FREEBSD */
324
325#if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE)
326
338int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
339 in_addr_t *best_gw, openvpn_net_iface_t *best_iface);
340
352int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
353 struct in6_addr *best_gw,
354 openvpn_net_iface_t *best_iface);
355
356#endif /* ENABLE_SITNL || ENABLE_IPROUTE */
357
358#endif /* NETWORKING_H_ */
static void net_ctx_reset(openvpn_net_ctx_t *ctx)
Definition networking.h:57
void * openvpn_net_iface_t
Definition networking.h:40
#define IFACE_TYPE_LEN_MAX
Definition networking.h:26
static int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx)
Definition networking.h:48
static void net_ctx_free(openvpn_net_ctx_t *ctx)
Definition networking.h:63
void * openvpn_net_ctx_t
Definition networking.h:39
Contains all state information for one tunnel.
Definition openvpn.h:474
static char * iface