blob: 7972c53f41d5e32dd6810a50bbac3c4cf9b8f06d [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
jjakoa7cd2492003-04-11 09:40:12 +00002 * TUN interface functions.
3 * Copyright (C) 2002, 2003 Mondru AB.
jjako52c24142002-12-16 13:33:51 +00004 *
jjakoa7cd2492003-04-11 09:40:12 +00005 * 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.
jjako52c24142002-12-16 13:33:51 +00009 *
jjako52c24142002-12-16 13:33:51 +000010 */
11
12#ifndef _TUN_H
13#define _TUN_H
14
jjakoa7cd2492003-04-11 09:40:12 +000015#define PACKET_MAX 8196 /* Maximum packet size we receive */
16#define TUN_SCRIPTSIZE 256
17#define TUN_ADDRSIZE 128
18#define TUN_NLBUFSIZE 1024
jjako52c24142002-12-16 13:33:51 +000019
jjakoa7cd2492003-04-11 09:40:12 +000020struct 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
jjako52c24142002-12-16 13:33:51 +000036
37/* ***********************************************************
38 * Information storage for each tun instance
39 *************************************************************/
40
41struct tun_t {
jjakoa7cd2492003-04-11 09:40:12 +000042 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 */
jjako163b4552004-12-30 15:33:58 +000047 int routes; /* One if we allocated an automatic route */
Emmanuel Bretelle87490d72010-09-07 20:22:36 +020048 char devname[IFNAMSIZ];/* Name of the tun device */
jjakoa7cd2492003-04-11 09:40:12 +000049 int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len);
jjako52c24142002-12-16 13:33:51 +000050};
51
52
jjakoa7cd2492003-04-11 09:40:12 +000053extern int tun_new(struct tun_t **tun);
54extern int tun_free(struct tun_t *tun);
55extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000056extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
57
jjakoa7cd2492003-04-11 09:40:12 +000058extern int tun_addaddr(struct tun_t *this, struct in_addr *addr,
59 struct in_addr *dstaddr, struct in_addr *netmask);
60
61
62extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr,
63 struct in_addr *his_adr, struct in_addr *net_mask);
64
65int tun_addroute(struct tun_t *this, struct in_addr *dst,
66 struct in_addr *gateway, struct in_addr *mask);
67
68extern int tun_set_cb_ind(struct tun_t *this,
69 int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len));
70
71
72extern int tun_runscript(struct tun_t *tun, char* script);
jjako52c24142002-12-16 13:33:51 +000073
74#endif /* !_TUN_H */