blob: c9e8e3484a65889dde6aaa9ae96445026ae6c62c [file] [log] [blame]
Pau Espin Pedrolfdd732b2017-10-13 14:32:24 +02001/*
jjakoa7cd2492003-04-11 09:40:12 +00002 * TUN interface functions.
3 * Copyright (C) 2002, 2003 Mondru AB.
Harald Weltec5efb5b2018-04-25 17:38:51 +02004 * Copyright (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Pau Espin Pedrolfdd732b2017-10-13 14:32:24 +02005 *
jjakoa7cd2492003-04-11 09:40:12 +00006 * 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.
Pau Espin Pedrolfdd732b2017-10-13 14:32:24 +020010 *
jjako52c24142002-12-16 13:33:51 +000011 */
12
13#ifndef _TUN_H
14#define _TUN_H
15
Harald Weltec55ece82017-08-12 15:09:08 +020016#include <net/if.h>
17
Harald Welte2e48a442017-08-03 00:47:03 +020018#include "../lib/in46_addr.h"
19
Harald Weltebed35df2011-11-02 13:06:18 +010020#define PACKET_MAX 8196 /* Maximum packet size we receive */
jjakoa7cd2492003-04-11 09:40:12 +000021#define TUN_SCRIPTSIZE 256
22#define TUN_ADDRSIZE 128
jjako52c24142002-12-16 13:33:51 +000023
Harald Welte63ebccd2017-08-02 21:10:09 +020024#include "config.h"
Harald Weltec5efb5b2018-04-25 17:38:51 +020025#include "netdev.h"
jjakoa7cd2492003-04-11 09:40:12 +000026
jjako52c24142002-12-16 13:33:51 +000027/* ***********************************************************
28 * Information storage for each tun instance
29 *************************************************************/
30
31struct tun_t {
Harald Weltebed35df2011-11-02 13:06:18 +010032 int fd; /* File descriptor to tun interface */
33 struct in_addr addr;
34 struct in_addr dstaddr;
35 struct in_addr netmask;
36 int addrs; /* Number of allocated IP addresses */
37 int routes; /* One if we allocated an automatic route */
38 char devname[IFNAMSIZ]; /* Name of the tun device */
39 int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
Harald Welte881e97e2017-08-12 14:56:10 +020040 /* to be used by libgtp callers/users (to attach their own private state) */
41 void *priv;
jjako52c24142002-12-16 13:33:51 +000042};
43
Harald Weltedda21ed2017-08-12 15:07:02 +020044extern int tun_new(struct tun_t **tun, const char *dev_name);
jjakoa7cd2492003-04-11 09:40:12 +000045extern int tun_free(struct tun_t *tun);
46extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000047extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
48
Pau Espin Pedrolf5e40b72017-12-14 14:01:23 +010049extern int tun_addaddr(struct tun_t *this, struct in46_addr *addr,
50 struct in46_addr *dstaddr, size_t prefixlen);
jjakoa7cd2492003-04-11 09:40:12 +000051
Harald Welte2e48a442017-08-03 00:47:03 +020052extern int tun_setaddr(struct tun_t *this, struct in46_addr *our_adr,
53 struct in46_addr *his_adr, size_t prefixlen);
jjakoa7cd2492003-04-11 09:40:12 +000054
Harald Weltebed35df2011-11-02 13:06:18 +010055extern int tun_set_cb_ind(struct tun_t *this,
56 int (*cb_ind) (struct tun_t * tun, void *pack,
57 unsigned len));
jjakoa7cd2492003-04-11 09:40:12 +000058
Harald Weltebed35df2011-11-02 13:06:18 +010059extern int tun_runscript(struct tun_t *tun, char *script);
jjakoa7cd2492003-04-11 09:40:12 +000060
Pau Espin Pedrola037e592017-10-16 14:41:37 +020061int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list,
62 size_t prefix_size, int flags);
Harald Weltef85fe972017-09-24 20:00:34 +080063
Harald Weltebed35df2011-11-02 13:06:18 +010064#endif /* !_TUN_H */