Pau Espin Pedrol | fdd732b | 2017-10-13 14:32:24 +0200 | [diff] [blame] | 1 | /* |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 2 | * TUN interface functions. |
| 3 | * Copyright (C) 2002, 2003 Mondru AB. |
Harald Welte | c5efb5b | 2018-04-25 17:38:51 +0200 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 by Harald Welte <laforge@gnumonks.org> |
Pau Espin Pedrol | fdd732b | 2017-10-13 14:32:24 +0200 | [diff] [blame] | 5 | * |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 6 | * The contents of this file may be used under the terms of the GNU |
| 7 | * General Public License Version 2, provided that the above copyright |
| 8 | * notice and this permission notice is included in all copies or |
| 9 | * substantial portions of the software. |
Pau Espin Pedrol | fdd732b | 2017-10-13 14:32:24 +0200 | [diff] [blame] | 10 | * |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef _TUN_H |
| 14 | #define _TUN_H |
| 15 | |
Harald Welte | f228639 | 2018-04-25 19:02:31 +0200 | [diff] [blame] | 16 | #include <stdbool.h> |
Harald Welte | c55ece8 | 2017-08-12 15:09:08 +0200 | [diff] [blame] | 17 | #include <net/if.h> |
| 18 | |
Harald Welte | 2e48a44 | 2017-08-03 00:47:03 +0200 | [diff] [blame] | 19 | #include "../lib/in46_addr.h" |
| 20 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 21 | #define PACKET_MAX 8196 /* Maximum packet size we receive */ |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 22 | #define TUN_SCRIPTSIZE 256 |
| 23 | #define TUN_ADDRSIZE 128 |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 24 | |
Harald Welte | 63ebccd | 2017-08-02 21:10:09 +0200 | [diff] [blame] | 25 | #include "config.h" |
Harald Welte | c5efb5b | 2018-04-25 17:38:51 +0200 | [diff] [blame] | 26 | #include "netdev.h" |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 27 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 28 | /* *********************************************************** |
| 29 | * Information storage for each tun instance |
| 30 | *************************************************************/ |
| 31 | |
| 32 | struct tun_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 33 | int fd; /* File descriptor to tun interface */ |
Stefan Sperling | b0b9c28 | 2018-11-22 08:36:35 +0100 | [diff] [blame] | 34 | struct in46_addr addr; |
| 35 | struct in46_addr dstaddr; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 36 | struct in_addr netmask; |
| 37 | int addrs; /* Number of allocated IP addresses */ |
| 38 | int routes; /* One if we allocated an automatic route */ |
| 39 | char devname[IFNAMSIZ]; /* Name of the tun device */ |
| 40 | int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len); |
Harald Welte | 881e97e | 2017-08-12 14:56:10 +0200 | [diff] [blame] | 41 | /* to be used by libgtp callers/users (to attach their own private state) */ |
| 42 | void *priv; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Harald Welte | f228639 | 2018-04-25 19:02:31 +0200 | [diff] [blame] | 45 | extern int tun_new(struct tun_t **tun, const char *dev_name, bool use_kernel, int fd0, int fd1u); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 46 | extern int tun_free(struct tun_t *tun); |
| 47 | extern int tun_decaps(struct tun_t *this); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 48 | extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len); |
| 49 | |
Pau Espin Pedrol | f5e40b7 | 2017-12-14 14:01:23 +0100 | [diff] [blame] | 50 | extern int tun_addaddr(struct tun_t *this, struct in46_addr *addr, |
| 51 | struct in46_addr *dstaddr, size_t prefixlen); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 52 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 53 | extern int tun_set_cb_ind(struct tun_t *this, |
| 54 | int (*cb_ind) (struct tun_t * tun, void *pack, |
| 55 | unsigned len)); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 56 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 57 | extern int tun_runscript(struct tun_t *tun, char *script); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 58 | |
Pau Espin Pedrol | a037e59 | 2017-10-16 14:41:37 +0200 | [diff] [blame] | 59 | int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list, |
| 60 | size_t prefix_size, int flags); |
Harald Welte | f85fe97 | 2017-09-24 20:00:34 +0800 | [diff] [blame] | 61 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 62 | #endif /* !_TUN_H */ |