blob: eb8216202a285b1eda1e04f3d52f11563f3280e0 [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 */
jjako52c24142002-12-16 13:33:51 +000047 char devname[IFNAMSIZ];/* Name of the tun device */
jjakoa7cd2492003-04-11 09:40:12 +000048 int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len);
jjako52c24142002-12-16 13:33:51 +000049};
50
51
jjakoa7cd2492003-04-11 09:40:12 +000052extern int tun_new(struct tun_t **tun);
53extern int tun_free(struct tun_t *tun);
54extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000055extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
56
jjakoa7cd2492003-04-11 09:40:12 +000057extern int tun_addaddr(struct tun_t *this, struct in_addr *addr,
58 struct in_addr *dstaddr, struct in_addr *netmask);
59
60
61extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr,
62 struct in_addr *his_adr, struct in_addr *net_mask);
63
64int tun_addroute(struct tun_t *this, struct in_addr *dst,
65 struct in_addr *gateway, struct in_addr *mask);
66
67extern int tun_set_cb_ind(struct tun_t *this,
68 int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len));
69
70
71extern int tun_runscript(struct tun_t *tun, char* script);
jjako52c24142002-12-16 13:33:51 +000072
73#endif /* !_TUN_H */