blob: ce7b91ccb648cf4c15eb00fe0e02c404feaa302e [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
Harald Weltebed35df2011-11-02 13:06:18 +010015#define PACKET_MAX 8196 /* Maximum packet size we receive */
jjakoa7cd2492003-04-11 09:40:12 +000016#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 {
Harald Weltebed35df2011-11-02 13:06:18 +010021 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;
jjakoa7cd2492003-04-11 09:40:12 +000034};
35
jjako52c24142002-12-16 13:33:51 +000036/* ***********************************************************
37 * Information storage for each tun instance
38 *************************************************************/
39
40struct tun_t {
Harald Weltebed35df2011-11-02 13:06:18 +010041 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);
jjako52c24142002-12-16 13:33:51 +000049};
50
jjakoa7cd2492003-04-11 09:40:12 +000051extern int tun_new(struct tun_t **tun);
52extern int tun_free(struct tun_t *tun);
53extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000054extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
55
jjakoa7cd2492003-04-11 09:40:12 +000056extern int tun_addaddr(struct tun_t *this, struct in_addr *addr,
57 struct in_addr *dstaddr, struct in_addr *netmask);
58
Harald Weltebed35df2011-11-02 13:06:18 +010059extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr,
jjakoa7cd2492003-04-11 09:40:12 +000060 struct in_addr *his_adr, struct in_addr *net_mask);
61
Harald Weltebed35df2011-11-02 13:06:18 +010062int tun_addroute(struct tun_t *this, struct in_addr *dst,
jjakoa7cd2492003-04-11 09:40:12 +000063 struct in_addr *gateway, struct in_addr *mask);
64
Harald Weltebed35df2011-11-02 13:06:18 +010065extern int tun_set_cb_ind(struct tun_t *this,
66 int (*cb_ind) (struct tun_t * tun, void *pack,
67 unsigned len));
jjakoa7cd2492003-04-11 09:40:12 +000068
Harald Weltebed35df2011-11-02 13:06:18 +010069extern int tun_runscript(struct tun_t *tun, char *script);
jjakoa7cd2492003-04-11 09:40:12 +000070
Harald Weltebed35df2011-11-02 13:06:18 +010071#endif /* !_TUN_H */