libgtp: Add back-reference to gsn from pdp context
[openggsn.git] / lib / tun.h
blob67ef39d6eb44ee6d1b48bf121340c38724969cc7
1 /*
2 * TUN interface functions.
3 * Copyright (C) 2002, 2003 Mondru AB.
4 * Copyright (C) 2017 by Harald Welte <laforge@gnumonks.org>
5 *
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.
13 #ifndef _TUN_H
14 #define _TUN_H
16 #include <net/if.h>
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
25 #include "config.h"
26 #ifndef HAVE_IPHDR
27 struct iphdr
29 #if __BYTE_ORDER == __LITTLE_ENDIAN
30 unsigned int ihl:4;
31 unsigned int version:4;
32 #elif __BYTE_ORDER == __BIG_ENDIAN
33 unsigned int version:4;
34 unsigned int ihl:4;
35 #else
36 # error "Please fix <bits/endian.h>"
37 #endif
38 u_int8_t tos;
39 u_int16_t tot_len;
40 u_int16_t id;
41 u_int16_t frag_off;
42 u_int8_t ttl;
43 u_int8_t protocol;
44 u_int16_t check;
45 u_int32_t saddr;
46 u_int32_t daddr;
47 /*The options start here. */
49 #endif /* !HAVE_IPHDR */
51 /* ***********************************************************
52 * Information storage for each tun instance
53 *************************************************************/
55 struct tun_t {
56 int fd; /* File descriptor to tun interface */
57 struct in_addr addr;
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) */
65 void *priv;
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,
84 unsigned len));
86 extern int tun_runscript(struct tun_t *tun, char *script);
88 #endif /* !_TUN_H */