blob: c50bdf9d526f6d2788eb98d2bc69ea5a58ea810e [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
Harald Welte63ebccd2017-08-02 21:10:09 +020020#include "config.h"
21#ifndef HAVE_IPHDR
22struct iphdr
23 {
24#if __BYTE_ORDER == __LITTLE_ENDIAN
25 unsigned int ihl:4;
26 unsigned int version:4;
27#elif __BYTE_ORDER == __BIG_ENDIAN
28 unsigned int version:4;
29 unsigned int ihl:4;
30#else
31# error "Please fix <bits/endian.h>"
32#endif
33 u_int8_t tos;
34 u_int16_t tot_len;
35 u_int16_t id;
36 u_int16_t frag_off;
37 u_int8_t ttl;
38 u_int8_t protocol;
39 u_int16_t check;
40 u_int32_t saddr;
41 u_int32_t daddr;
42 /*The options start here. */
43 };
44#endif /* !HAVE_IPHDR */
jjakoa7cd2492003-04-11 09:40:12 +000045
jjako52c24142002-12-16 13:33:51 +000046/* ***********************************************************
47 * Information storage for each tun instance
48 *************************************************************/
49
50struct tun_t {
Harald Weltebed35df2011-11-02 13:06:18 +010051 int fd; /* File descriptor to tun interface */
52 struct in_addr addr;
53 struct in_addr dstaddr;
54 struct in_addr netmask;
55 int addrs; /* Number of allocated IP addresses */
56 int routes; /* One if we allocated an automatic route */
57 char devname[IFNAMSIZ]; /* Name of the tun device */
58 int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
jjako52c24142002-12-16 13:33:51 +000059};
60
jjakoa7cd2492003-04-11 09:40:12 +000061extern int tun_new(struct tun_t **tun);
62extern int tun_free(struct tun_t *tun);
63extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000064extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
65
jjakoa7cd2492003-04-11 09:40:12 +000066extern int tun_addaddr(struct tun_t *this, struct in_addr *addr,
67 struct in_addr *dstaddr, struct in_addr *netmask);
68
Harald Weltebed35df2011-11-02 13:06:18 +010069extern int tun_setaddr(struct tun_t *this, struct in_addr *our_adr,
jjakoa7cd2492003-04-11 09:40:12 +000070 struct in_addr *his_adr, struct in_addr *net_mask);
71
Harald Weltebed35df2011-11-02 13:06:18 +010072int tun_addroute(struct tun_t *this, struct in_addr *dst,
jjakoa7cd2492003-04-11 09:40:12 +000073 struct in_addr *gateway, struct in_addr *mask);
74
Harald Weltebed35df2011-11-02 13:06:18 +010075extern int tun_set_cb_ind(struct tun_t *this,
76 int (*cb_ind) (struct tun_t * tun, void *pack,
77 unsigned len));
jjakoa7cd2492003-04-11 09:40:12 +000078
Harald Weltebed35df2011-11-02 13:06:18 +010079extern int tun_runscript(struct tun_t *tun, char *script);
jjakoa7cd2492003-04-11 09:40:12 +000080
Harald Weltebed35df2011-11-02 13:06:18 +010081#endif /* !_TUN_H */