OpenVPN
networking.h
Go to the documentation of this file.
1 /*
2  * Generic interface to platform specific networking code
3  *
4  * Copyright (C) 2016-2021 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 
115 int net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
116  uint8_t *addr);
117 
128 int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
129  const in_addr_t *addr, int prefixlen);
130 
142 int net_addr_v6_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
143  const struct in6_addr *addr, int prefixlen);
144 
154 int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
155  const in_addr_t *addr, int prefixlen);
156 
166 int net_addr_v6_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
167  const struct in6_addr *addr, int prefixlen);
168 
179 int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx,
180  const openvpn_net_iface_t *iface,
181  const in_addr_t *local, const in_addr_t *remote);
182 
193 int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx,
194  const openvpn_net_iface_t *iface,
195  const in_addr_t *local, const in_addr_t *remote);
196 
197 
212 int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
213  int prefixlen, const in_addr_t *gw,
214  const openvpn_net_iface_t *iface, uint32_t table,
215  int metric);
216 
231 int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
232  int prefixlen, const struct in6_addr *gw,
233  const openvpn_net_iface_t *iface,
234  uint32_t table, int metric);
235 
250 int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
251  int prefixlen, const in_addr_t *gw,
252  const openvpn_net_iface_t *iface, uint32_t table,
253  int metric);
254 
269 int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
270  int prefixlen, const struct in6_addr *gw,
271  const openvpn_net_iface_t *iface,
272  uint32_t table, int metric);
273 
285 int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
286  in_addr_t *best_gw, openvpn_net_iface_t *best_iface);
287 
299 int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
300  struct in6_addr *best_gw,
301  openvpn_net_iface_t *best_iface);
302 
303 #endif /* ENABLE_SITNL || ENABLE_IPROUTE */
304 
305 #endif /* NETWORKING_H_ */
Contains all state information for one tunnel.
Definition: openvpn.h:461
static char * iface
#define in_addr_t
Definition: config-msvc.h:103
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
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