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 | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 10 | * The initial developer of the original code is |
| 11 | * Jens Jakobsen <jj@openggsn.org> |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 12 | * |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 13 | * Contributor(s): |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 14 | * |
| 15 | */ |
| 16 | |
| 17 | #ifndef _TUN_H |
| 18 | #define _TUN_H |
| 19 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 20 | #define PACKET_MAX 8196 /* Maximum packet size we receive */ |
| 21 | #define TUN_SCRIPTSIZE 256 |
| 22 | #define TUN_ADDRSIZE 128 |
| 23 | #define TUN_NLBUFSIZE 1024 |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 24 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 25 | struct tun_packet_t { |
| 26 | unsigned int ver:4; |
| 27 | unsigned int ihl:4; |
| 28 | unsigned int dscp:6; |
| 29 | unsigned int ecn:2; |
| 30 | unsigned int length:16; |
| 31 | unsigned int id:16; |
| 32 | unsigned int flags:3; |
| 33 | unsigned int fragment:13; |
| 34 | unsigned int ttl:8; |
| 35 | unsigned int protocol:8; |
| 36 | unsigned int check:16; |
| 37 | unsigned int src:32; |
| 38 | unsigned int dst:32; |
| 39 | }; |
| 40 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 41 | |
| 42 | /* *********************************************************** |
| 43 | * Information storage for each tun instance |
| 44 | *************************************************************/ |
| 45 | |
| 46 | struct tun_t { |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 47 | int fd; /* File descriptor to tun interface */ |
| 48 | struct in_addr addr; |
| 49 | struct in_addr dstaddr; |
| 50 | struct in_addr netmask; |
| 51 | int addrs; /* Number of allocated IP addresses */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 52 | char devname[IFNAMSIZ];/* Name of the tun device */ |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 53 | int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 57 | extern int tun_new(struct tun_t **tun); |
| 58 | extern int tun_free(struct tun_t *tun); |
| 59 | extern int tun_decaps(struct tun_t *this); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 60 | extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len); |
| 61 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 62 | extern int tun_addaddr(struct tun_t *this, struct in_addr *addr, |
| 63 | struct in_addr *dstaddr, struct in_addr *netmask); |
| 64 | |
| 65 | |
| 66 | extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr, |
| 67 | struct in_addr *his_adr, struct in_addr *net_mask); |
| 68 | |
| 69 | int tun_addroute(struct tun_t *this, struct in_addr *dst, |
| 70 | struct in_addr *gateway, struct in_addr *mask); |
| 71 | |
| 72 | extern int tun_set_cb_ind(struct tun_t *this, |
| 73 | int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len)); |
| 74 | |
| 75 | |
| 76 | extern int tun_runscript(struct tun_t *tun, char* script); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 77 | |
| 78 | #endif /* !_TUN_H */ |