blob: 8d4618d21d11acc744e2ef417e81fd993f45d213 [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 *
jjakoa7cd2492003-04-11 09:40:12 +000010 * The initial developer of the original code is
11 * Jens Jakobsen <jj@openggsn.org>
jjako52c24142002-12-16 13:33:51 +000012 *
jjakoa7cd2492003-04-11 09:40:12 +000013 * Contributor(s):
jjako52c24142002-12-16 13:33:51 +000014 *
15 */
16
17#ifndef _TUN_H
18#define _TUN_H
19
jjakoa7cd2492003-04-11 09:40:12 +000020#define PACKET_MAX 8196 /* Maximum packet size we receive */
21#define TUN_SCRIPTSIZE 256
22#define TUN_ADDRSIZE 128
23#define TUN_NLBUFSIZE 1024
jjako52c24142002-12-16 13:33:51 +000024
jjakoa7cd2492003-04-11 09:40:12 +000025struct 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
jjako52c24142002-12-16 13:33:51 +000041
42/* ***********************************************************
43 * Information storage for each tun instance
44 *************************************************************/
45
46struct tun_t {
jjakoa7cd2492003-04-11 09:40:12 +000047 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 */
jjako52c24142002-12-16 13:33:51 +000052 char devname[IFNAMSIZ];/* Name of the tun device */
jjakoa7cd2492003-04-11 09:40:12 +000053 int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len);
jjako52c24142002-12-16 13:33:51 +000054};
55
56
jjakoa7cd2492003-04-11 09:40:12 +000057extern int tun_new(struct tun_t **tun);
58extern int tun_free(struct tun_t *tun);
59extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000060extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
61
jjakoa7cd2492003-04-11 09:40:12 +000062extern int tun_addaddr(struct tun_t *this, struct in_addr *addr,
63 struct in_addr *dstaddr, struct in_addr *netmask);
64
65
66extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr,
67 struct in_addr *his_adr, struct in_addr *net_mask);
68
69int tun_addroute(struct tun_t *this, struct in_addr *dst,
70 struct in_addr *gateway, struct in_addr *mask);
71
72extern int tun_set_cb_ind(struct tun_t *this,
73 int (*cb_ind) (struct tun_t *tun, void *pack, unsigned len));
74
75
76extern int tun_runscript(struct tun_t *tun, char* script);
jjako52c24142002-12-16 13:33:51 +000077
78#endif /* !_TUN_H */