jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [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. |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 4 | * |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 5 | * The contents of this file may be used under the terms of the GNU |
| 6 | * General Public License Version 2, provided that the above copyright |
| 7 | * notice and this permission notice is included in all copies or |
| 8 | * substantial portions of the software. |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 9 | * |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #ifndef _TUN_H |
| 13 | #define _TUN_H |
| 14 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 15 | #define PACKET_MAX 8196 /* Maximum packet size we receive */ |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 16 | #define TUN_SCRIPTSIZE 256 |
| 17 | #define TUN_ADDRSIZE 128 |
| 18 | #define TUN_NLBUFSIZE 1024 |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 19 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 20 | struct tun_packet_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 21 | unsigned int ver:4; |
| 22 | unsigned int ihl:4; |
| 23 | unsigned int dscp:6; |
| 24 | unsigned int ecn:2; |
| 25 | unsigned int length:16; |
| 26 | unsigned int id:16; |
| 27 | unsigned int flags:3; |
| 28 | unsigned int fragment:13; |
| 29 | unsigned int ttl:8; |
| 30 | unsigned int protocol:8; |
| 31 | unsigned int check:16; |
| 32 | unsigned int src:32; |
| 33 | unsigned int dst:32; |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 36 | /* *********************************************************** |
| 37 | * Information storage for each tun instance |
| 38 | *************************************************************/ |
| 39 | |
| 40 | struct tun_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 41 | int fd; /* File descriptor to tun interface */ |
| 42 | struct in_addr addr; |
| 43 | struct in_addr dstaddr; |
| 44 | struct in_addr netmask; |
| 45 | int addrs; /* Number of allocated IP addresses */ |
| 46 | int routes; /* One if we allocated an automatic route */ |
| 47 | char devname[IFNAMSIZ]; /* Name of the tun device */ |
| 48 | int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 51 | extern int tun_new(struct tun_t **tun); |
| 52 | extern int tun_free(struct tun_t *tun); |
| 53 | extern int tun_decaps(struct tun_t *this); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 54 | extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len); |
| 55 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 56 | extern int tun_addaddr(struct tun_t *this, struct in_addr *addr, |
| 57 | struct in_addr *dstaddr, struct in_addr *netmask); |
| 58 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 59 | extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr, |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 60 | struct in_addr *his_adr, struct in_addr *net_mask); |
| 61 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 62 | int tun_addroute(struct tun_t *this, struct in_addr *dst, |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 63 | struct in_addr *gateway, struct in_addr *mask); |
| 64 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 65 | extern int tun_set_cb_ind(struct tun_t *this, |
| 66 | int (*cb_ind) (struct tun_t * tun, void *pack, |
| 67 | unsigned len)); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 68 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 69 | extern int tun_runscript(struct tun_t *tun, char *script); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 70 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 71 | #endif /* !_TUN_H */ |