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 | c55ece8 | 2017-08-12 15:09:08 +0200 | [diff] [blame] | 16 | #include <net/if.h> |
| 17 | |
Harald Welte | 2e48a44 | 2017-08-03 00:47:03 +0200 | [diff] [blame] | 18 | #include "../lib/in46_addr.h" |
| 19 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 20 | #define PACKET_MAX 8196 /* Maximum packet size we receive */ |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 21 | #define TUN_SCRIPTSIZE 256 |
| 22 | #define TUN_ADDRSIZE 128 |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 23 | |
Harald Welte | 63ebccd | 2017-08-02 21:10:09 +0200 | [diff] [blame] | 24 | #include "config.h" |
Harald Welte | c5efb5b | 2018-04-25 17:38:51 +0200 | [diff] [blame] | 25 | #include "netdev.h" |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 26 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 27 | /* *********************************************************** |
| 28 | * Information storage for each tun instance |
| 29 | *************************************************************/ |
| 30 | |
| 31 | struct tun_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 32 | int fd; /* File descriptor to tun interface */ |
| 33 | struct in_addr addr; |
| 34 | struct in_addr dstaddr; |
| 35 | struct in_addr netmask; |
| 36 | int addrs; /* Number of allocated IP addresses */ |
| 37 | int routes; /* One if we allocated an automatic route */ |
| 38 | char devname[IFNAMSIZ]; /* Name of the tun device */ |
| 39 | int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len); |
Harald Welte | 881e97e | 2017-08-12 14:56:10 +0200 | [diff] [blame] | 40 | /* to be used by libgtp callers/users (to attach their own private state) */ |
| 41 | void *priv; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
Harald Welte | dda21ed | 2017-08-12 15:07:02 +0200 | [diff] [blame] | 44 | extern int tun_new(struct tun_t **tun, const char *dev_name); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 45 | extern int tun_free(struct tun_t *tun); |
| 46 | extern int tun_decaps(struct tun_t *this); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 47 | extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len); |
| 48 | |
Pau Espin Pedrol | f5e40b7 | 2017-12-14 14:01:23 +0100 | [diff] [blame] | 49 | extern int tun_addaddr(struct tun_t *this, struct in46_addr *addr, |
| 50 | struct in46_addr *dstaddr, size_t prefixlen); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 51 | |
Harald Welte | 2e48a44 | 2017-08-03 00:47:03 +0200 | [diff] [blame] | 52 | extern int tun_setaddr(struct tun_t *this, struct in46_addr *our_adr, |
| 53 | struct in46_addr *his_adr, size_t prefixlen); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 54 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 55 | extern int tun_set_cb_ind(struct tun_t *this, |
| 56 | int (*cb_ind) (struct tun_t * tun, void *pack, |
| 57 | unsigned len)); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 58 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 59 | extern int tun_runscript(struct tun_t *tun, char *script); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 60 | |
Pau Espin Pedrol | a037e59 | 2017-10-16 14:41:37 +0200 | [diff] [blame] | 61 | int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list, |
| 62 | size_t prefix_size, int flags); |
Harald Welte | f85fe97 | 2017-09-24 20:00:34 +0800 | [diff] [blame] | 63 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 64 | #endif /* !_TUN_H */ |