2002-12-16 13:33:51 +00:00
|
|
|
/*
|
2003-04-11 09:40:12 +00:00
|
|
|
* TUN interface functions.
|
|
|
|
* Copyright (C) 2002, 2003 Mondru AB.
|
2017-08-02 22:47:03 +00:00
|
|
|
* Copyright (C) 2017 by Harald Welte <laforge@gnumonks.org>
|
2002-12-16 13:33:51 +00:00
|
|
|
*
|
2003-04-11 09:40:12 +00:00
|
|
|
* The contents of this file may be used under the terms of the GNU
|
|
|
|
* General Public License Version 2, provided that the above copyright
|
|
|
|
* notice and this permission notice is included in all copies or
|
|
|
|
* substantial portions of the software.
|
2002-12-16 13:33:51 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TUN_H
|
|
|
|
#define _TUN_H
|
|
|
|
|
2017-08-02 22:47:03 +00:00
|
|
|
#include "../lib/in46_addr.h"
|
|
|
|
|
2011-11-02 12:06:18 +00:00
|
|
|
#define PACKET_MAX 8196 /* Maximum packet size we receive */
|
2003-04-11 09:40:12 +00:00
|
|
|
#define TUN_SCRIPTSIZE 256
|
|
|
|
#define TUN_ADDRSIZE 128
|
|
|
|
#define TUN_NLBUFSIZE 1024
|
|
|
|
|
2017-08-02 19:10:09 +00:00
|
|
|
#include "config.h"
|
|
|
|
#ifndef HAVE_IPHDR
|
|
|
|
struct iphdr
|
|
|
|
{
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
unsigned int ihl:4;
|
|
|
|
unsigned int version:4;
|
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
unsigned int version:4;
|
|
|
|
unsigned int ihl:4;
|
|
|
|
#else
|
|
|
|
# error "Please fix <bits/endian.h>"
|
|
|
|
#endif
|
|
|
|
u_int8_t tos;
|
|
|
|
u_int16_t tot_len;
|
|
|
|
u_int16_t id;
|
|
|
|
u_int16_t frag_off;
|
|
|
|
u_int8_t ttl;
|
|
|
|
u_int8_t protocol;
|
|
|
|
u_int16_t check;
|
|
|
|
u_int32_t saddr;
|
|
|
|
u_int32_t daddr;
|
|
|
|
/*The options start here. */
|
|
|
|
};
|
|
|
|
#endif /* !HAVE_IPHDR */
|
2002-12-16 13:33:51 +00:00
|
|
|
|
|
|
|
/* ***********************************************************
|
|
|
|
* Information storage for each tun instance
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
struct tun_t {
|
2011-11-02 12:06:18 +00:00
|
|
|
int fd; /* File descriptor to tun interface */
|
|
|
|
struct in_addr addr;
|
|
|
|
struct in_addr dstaddr;
|
|
|
|
struct in_addr netmask;
|
|
|
|
int addrs; /* Number of allocated IP addresses */
|
|
|
|
int routes; /* One if we allocated an automatic route */
|
|
|
|
char devname[IFNAMSIZ]; /* Name of the tun device */
|
|
|
|
int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
|
2002-12-16 13:33:51 +00:00
|
|
|
};
|
|
|
|
|
2003-04-11 09:40:12 +00:00
|
|
|
extern int tun_new(struct tun_t **tun);
|
|
|
|
extern int tun_free(struct tun_t *tun);
|
|
|
|
extern int tun_decaps(struct tun_t *this);
|
2002-12-16 13:33:51 +00:00
|
|
|
extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
|
|
|
|
|
2003-04-11 09:40:12 +00:00
|
|
|
extern int tun_addaddr(struct tun_t *this, struct in_addr *addr,
|
|
|
|
struct in_addr *dstaddr, struct in_addr *netmask);
|
|
|
|
|
2017-08-02 22:47:03 +00:00
|
|
|
extern int tun_setaddr(struct tun_t *this, struct in46_addr *our_adr,
|
|
|
|
struct in46_addr *his_adr, size_t prefixlen);
|
2003-04-11 09:40:12 +00:00
|
|
|
|
2011-11-02 12:06:18 +00:00
|
|
|
int tun_addroute(struct tun_t *this, struct in_addr *dst,
|
2003-04-11 09:40:12 +00:00
|
|
|
struct in_addr *gateway, struct in_addr *mask);
|
|
|
|
|
2011-11-02 12:06:18 +00:00
|
|
|
extern int tun_set_cb_ind(struct tun_t *this,
|
|
|
|
int (*cb_ind) (struct tun_t * tun, void *pack,
|
|
|
|
unsigned len));
|
2003-04-11 09:40:12 +00:00
|
|
|
|
2011-11-02 12:06:18 +00:00
|
|
|
extern int tun_runscript(struct tun_t *tun, char *script);
|
2002-12-16 13:33:51 +00:00
|
|
|
|
2011-11-02 12:06:18 +00:00
|
|
|
#endif /* !_TUN_H */
|