OpenVPN
networking.h
Go to the documentation of this file.
1 /*
2  * Generic interface to platform specific networking code
3  *
4  * Copyright (C) 2016-2018 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 
37 static inline int
39 {
40  return 0;
41 }
42 
43 static inline void
45 {
46  (void)ctx;
47 }
48 
49 static inline void
51 {
52  (void)ctx;
53 }
54 #endif /* ifdef ENABLE_SITNL */
55 
56 #if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE)
57 
66 int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx);
67 
74 
81 
91 int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
92  bool up);
93 
103 int net_iface_mtu_set(openvpn_net_ctx_t *ctx,
104  const openvpn_net_iface_t *iface, uint32_t mtu);
105 
116 int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
117  const in_addr_t *addr, int prefixlen);
118 
130 int net_addr_v6_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
131  const struct in6_addr *addr, int prefixlen);
132 
142 int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
143  const in_addr_t *addr, int prefixlen);
144 
154 int net_addr_v6_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
155  const struct in6_addr *addr, int prefixlen);
156 
167 int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx,
168  const openvpn_net_iface_t *iface,
169  const in_addr_t *local, const in_addr_t *remote);
170 
181 int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx,
182  const openvpn_net_iface_t *iface,
183  const in_addr_t *local, const in_addr_t *remote);
184 
185 
200 int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
201  int prefixlen, const in_addr_t *gw,
202  const openvpn_net_iface_t *iface, uint32_t table,
203  int metric);
204 
219 int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
220  int prefixlen, const struct in6_addr *gw,
221  const openvpn_net_iface_t *iface,
222  uint32_t table, int metric);
223 
238 int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
239  int prefixlen, const in_addr_t *gw,
240  const openvpn_net_iface_t *iface, uint32_t table,
241  int metric);
242 
257 int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
258  int prefixlen, const struct in6_addr *gw,
259  const openvpn_net_iface_t *iface,
260  uint32_t table, int metric);
261 
273 int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
274  in_addr_t *best_gw, openvpn_net_iface_t *best_iface);
275 
287 int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
288  struct in6_addr *best_gw,
289  openvpn_net_iface_t *best_iface);
290 
291 #endif /* ENABLE_SITNL || ENABLE_IPROUTE */
292 
293 #endif /* NETWORKING_H_ */
Contains all state information for one tunnel.
Definition: openvpn.h:497
static char * iface
#define in_addr_t
Definition: config-msvc.h:141
void * openvpn_net_iface_t
Definition: networking.h:35
void * openvpn_net_ctx_t
Definition: networking.h:26
static int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx)
Definition: networking.h:38
unsigned __int32 uint32_t
Definition: config-msvc.h:158
static void net_ctx_free(openvpn_net_ctx_t *ctx)
Definition: networking.h:50
static void net_ctx_reset(openvpn_net_ctx_t *ctx)
Definition: networking.h:44
char * dst
Definition: compat-lz4.h:455