OpenVPN
networking.h
Go to the documentation of this file.
1 /*
2  * Generic interface to platform specific networking code
3  *
4  * Copyright (C) 2016-2022 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 struct context;
27 
28 #ifdef ENABLE_SITNL
29 #include "networking_sitnl.h"
30 #elif ENABLE_IPROUTE
31 #include "networking_iproute2.h"
32 #else
33 /* define mock types to ensure code builds on any platform */
34 typedef void *openvpn_net_ctx_t;
35 typedef void *openvpn_net_iface_t;
36 #endif /* ifdef ENABLE_SITNL */
37 
38 /* Only the iproute2 backend implements these functions,
39  * the rest can rely on these stubs
40  */
41 #if !defined(ENABLE_IPROUTE)
42 static inline int
44 {
45  (void)c;
46  (void)ctx;
47 
48  return 0;
49 }
50 
51 static inline void
53 {
54  (void)ctx;
55 }
56 
57 static inline void
59 {
60  (void)ctx;
61 }
62 #endif /* !defined(ENABLE_IPROUTE) */
63 
64 #if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE)
65 
74 int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx);
75 
82 
89 
99 int net_iface_new(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
100  const char *type, void *arg);
101 
109 int net_iface_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface);
110 
120 int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
121  bool up);
122 
132 int net_iface_mtu_set(openvpn_net_ctx_t *ctx,
133  const openvpn_net_iface_t *iface, uint32_t mtu);
134 
144 int net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
145  uint8_t *addr);
146 
157 int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
158  const in_addr_t *addr, int prefixlen);
159 
171 int net_addr_v6_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
172  const struct in6_addr *addr, int prefixlen);
173 
183 int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
184  const in_addr_t *addr, int prefixlen);
185 
195 int net_addr_v6_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
196  const struct in6_addr *addr, int prefixlen);
197 
208 int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx,
209  const openvpn_net_iface_t *iface,
210  const in_addr_t *local, const in_addr_t *remote);
211 
222 int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx,
223  const openvpn_net_iface_t *iface,
224  const in_addr_t *local, const in_addr_t *remote);
225 
226 
241 int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
242  int prefixlen, const in_addr_t *gw,
243  const openvpn_net_iface_t *iface, uint32_t table,
244  int metric);
245 
260 int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
261  int prefixlen, const struct in6_addr *gw,
262  const openvpn_net_iface_t *iface,
263  uint32_t table, int metric);
264 
279 int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
280  int prefixlen, const in_addr_t *gw,
281  const openvpn_net_iface_t *iface, uint32_t table,
282  int metric);
283 
298 int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
299  int prefixlen, const struct in6_addr *gw,
300  const openvpn_net_iface_t *iface,
301  uint32_t table, int metric);
302 
314 int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
315  in_addr_t *best_gw, openvpn_net_iface_t *best_iface);
316 
328 int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
329  struct in6_addr *best_gw,
330  openvpn_net_iface_t *best_iface);
331 
332 #endif /* ENABLE_SITNL || ENABLE_IPROUTE */
333 
334 #endif /* NETWORKING_H_ */
in_addr_t
#define in_addr_t
Definition: config-msvc.h:67
context
Contains all state information for one tunnel.
Definition: openvpn.h:467
openvpn_net_ctx_t
void * openvpn_net_ctx_t
Definition: networking.h:26
net_ctx_init
static int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx)
Definition: networking.h:43
networking_sitnl.h
net_ctx_reset
static void net_ctx_reset(openvpn_net_ctx_t *ctx)
Definition: networking.h:52
iface
static char * iface
Definition: test_networking.c:6
net_ctx_free
static void net_ctx_free(openvpn_net_ctx_t *ctx)
Definition: networking.h:58
syshead.h
networking_iproute2.h
openvpn_net_iface_t
void * openvpn_net_iface_t
Definition: networking.h:35