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 | |
Harald Welte | 63ebccd | 2017-08-02 21:10:09 +0200 | [diff] [blame] | 20 | #include "config.h" |
| 21 | #ifndef HAVE_IPHDR |
| 22 | struct iphdr |
| 23 | { |
| 24 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 25 | unsigned int ihl:4; |
| 26 | unsigned int version:4; |
| 27 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 28 | unsigned int version:4; |
| 29 | unsigned int ihl:4; |
| 30 | #else |
| 31 | # error "Please fix <bits/endian.h>" |
| 32 | #endif |
| 33 | u_int8_t tos; |
| 34 | u_int16_t tot_len; |
| 35 | u_int16_t id; |
| 36 | u_int16_t frag_off; |
| 37 | u_int8_t ttl; |
| 38 | u_int8_t protocol; |
| 39 | u_int16_t check; |
| 40 | u_int32_t saddr; |
| 41 | u_int32_t daddr; |
| 42 | /*The options start here. */ |
| 43 | }; |
| 44 | #endif /* !HAVE_IPHDR */ |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 45 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 46 | /* *********************************************************** |
| 47 | * Information storage for each tun instance |
| 48 | *************************************************************/ |
| 49 | |
| 50 | struct tun_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 51 | int fd; /* File descriptor to tun interface */ |
| 52 | struct in_addr addr; |
| 53 | struct in_addr dstaddr; |
| 54 | struct in_addr netmask; |
| 55 | int addrs; /* Number of allocated IP addresses */ |
| 56 | int routes; /* One if we allocated an automatic route */ |
| 57 | char devname[IFNAMSIZ]; /* Name of the tun device */ |
| 58 | int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 61 | extern int tun_new(struct tun_t **tun); |
| 62 | extern int tun_free(struct tun_t *tun); |
| 63 | extern int tun_decaps(struct tun_t *this); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 64 | extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len); |
| 65 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 66 | extern int tun_addaddr(struct tun_t *this, struct in_addr *addr, |
| 67 | struct in_addr *dstaddr, struct in_addr *netmask); |
| 68 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 69 | extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr, |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 70 | struct in_addr *his_adr, struct in_addr *net_mask); |
| 71 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 72 | int tun_addroute(struct tun_t *this, struct in_addr *dst, |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 73 | struct in_addr *gateway, struct in_addr *mask); |
| 74 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 75 | extern int tun_set_cb_ind(struct tun_t *this, |
| 76 | int (*cb_ind) (struct tun_t * tun, void *pack, |
| 77 | unsigned len)); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 78 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 79 | extern int tun_runscript(struct tun_t *tun, char *script); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 80 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 81 | #endif /* !_TUN_H */ |