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 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 15 | #define PACKET_MAX 8196 /* Maximum packet size we receive */ |
| 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 { |
| 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; |
| 34 | }; |
| 35 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 36 | |
| 37 | /* *********************************************************** |
| 38 | * Information storage for each tun instance |
| 39 | *************************************************************/ |
| 40 | |
| 41 | struct tun_t { |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 42 | int fd; /* File descriptor to tun interface */ |
| 43 | struct in_addr addr; |
| 44 | struct in_addr dstaddr; |
| 45 | struct in_addr netmask; |
| 46 | int addrs; /* Number of allocated IP addresses */ |
jjako | 163b455 | 2004-12-30 15:33:58 +0000 | [diff] [blame] | 47 | int routes; /* One if we allocated an automatic route */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 48 | char devname[IFNAMSIZ];/* Name of the tun device */ |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 49 | int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 53 | extern int tun_new(struct tun_t **tun); |
| 54 | extern int tun_free(struct tun_t *tun); |
| 55 | extern int tun_decaps(struct tun_t *this); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 56 | extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len); |
| 57 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 58 | extern int tun_addaddr(struct tun_t *this, struct in_addr *addr, |
| 59 | struct in_addr *dstaddr, struct in_addr *netmask); |
| 60 | |
| 61 | |
| 62 | extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr, |
| 63 | struct in_addr *his_adr, struct in_addr *net_mask); |
| 64 | |
| 65 | int tun_addroute(struct tun_t *this, struct in_addr *dst, |
| 66 | struct in_addr *gateway, struct in_addr *mask); |
| 67 | |
| 68 | extern int tun_set_cb_ind(struct tun_t *this, |
| 69 | int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len)); |
| 70 | |
| 71 | |
| 72 | extern int tun_runscript(struct tun_t *tun, char* script); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 73 | |
| 74 | #endif /* !_TUN_H */ |