2 * TUN interface functions.
3 * Copyright (C) 2002, 2003 Mondru AB.
4 * Copyright (C) 2017 by Harald Welte <laforge@gnumonks.org>
6 * The contents of this file may be used under the terms of the GNU
7 * General Public License Version 2, provided that the above copyright
8 * notice and this permission notice is included in all copies or
9 * substantial portions of the software.
18 #include "../lib/in46_addr.h"
20 #define PACKET_MAX 8196 /* Maximum packet size we receive */
21 #define TUN_SCRIPTSIZE 256
22 #define TUN_ADDRSIZE 128
23 #define TUN_NLBUFSIZE 1024
29 #if __BYTE_ORDER == __LITTLE_ENDIAN
31 unsigned int version
:4;
32 #elif __BYTE_ORDER == __BIG_ENDIAN
33 unsigned int version
:4;
36 # error "Please fix <bits/endian.h>"
47 /*The options start here. */
49 #endif /* !HAVE_IPHDR */
51 /* ***********************************************************
52 * Information storage for each tun instance
53 *************************************************************/
56 int fd
; /* File descriptor to tun interface */
58 struct in_addr dstaddr
;
59 struct in_addr netmask
;
60 int addrs
; /* Number of allocated IP addresses */
61 int routes
; /* One if we allocated an automatic route */
62 char devname
[IFNAMSIZ
]; /* Name of the tun device */
63 int (*cb_ind
) (struct tun_t
* tun
, void *pack
, unsigned len
);
64 /* to be used by libgtp callers/users (to attach their own private state) */
68 extern int tun_new(struct tun_t
**tun
);
69 extern int tun_free(struct tun_t
*tun
);
70 extern int tun_decaps(struct tun_t
*this);
71 extern int tun_encaps(struct tun_t
*tun
, void *pack
, unsigned len
);
73 extern int tun_addaddr(struct tun_t
*this, struct in_addr
*addr
,
74 struct in_addr
*dstaddr
, struct in_addr
*netmask
);
76 extern int tun_setaddr(struct tun_t
*this, struct in46_addr
*our_adr
,
77 struct in46_addr
*his_adr
, size_t prefixlen
);
79 int tun_addroute(struct tun_t
*this, struct in_addr
*dst
,
80 struct in_addr
*gateway
, struct in_addr
*mask
);
82 extern int tun_set_cb_ind(struct tun_t
*this,
83 int (*cb_ind
) (struct tun_t
* tun
, void *pack
,
86 extern int tun_runscript(struct tun_t
*tun
, char *script
);