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
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 
117 int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
118  const in_addr_t *addr, int prefixlen,
119  const in_addr_t *broadcast);
120 
132 int net_addr_v6_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
133  const struct in6_addr *addr, int prefixlen);
134 
144 int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
145  const in_addr_t *addr, int prefixlen);
146 
156 int net_addr_v6_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
157  const struct in6_addr *addr, int prefixlen);
158 
169 int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx,
170  const openvpn_net_iface_t *iface,
171  const in_addr_t *local, const in_addr_t *remote);
172 
183 int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx,
184  const openvpn_net_iface_t *iface,
185  const in_addr_t *local, const in_addr_t *remote);
186 
187 
202 int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
203  int prefixlen, const in_addr_t *gw,
204  const openvpn_net_iface_t *iface, uint32_t table,
205  int metric);
206 
221 int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
222  int prefixlen, const struct in6_addr *gw,
223  const openvpn_net_iface_t *iface,
224  uint32_t table, int metric);
225 
240 int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
241  int prefixlen, const in_addr_t *gw,
242  const openvpn_net_iface_t *iface, uint32_t table,
243  int metric);
244 
259 int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
260  int prefixlen, const struct in6_addr *gw,
261  const openvpn_net_iface_t *iface,
262  uint32_t table, int metric);
263 
275 int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
276  in_addr_t *best_gw, openvpn_net_iface_t *best_iface);
277 
289 int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
290  struct in6_addr *best_gw,
291  openvpn_net_iface_t *best_iface);
292 
293 #endif /* ENABLE_SITNL || ENABLE_IPROUTE */
294 
295 #endif /* NETWORKING_H_ */
Contains all state information for one tunnel.
Definition: openvpn.h:502
static char * iface
#define in_addr_t
Definition: config-msvc.h:104
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:121
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