blob: 6bf141fdaa501378ee01647b134c791b8932a369 [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 Weltef2286392018-04-25 19:02:31 +020016#include <stdbool.h>
Harald Weltec55ece82017-08-12 15:09:08 +020017#include <net/if.h>
18
Harald Welte2e48a442017-08-03 00:47:03 +020019#include "../lib/in46_addr.h"
20
Harald Weltebed35df2011-11-02 13:06:18 +010021#define PACKET_MAX 8196 /* Maximum packet size we receive */
jjakoa7cd2492003-04-11 09:40:12 +000022#define TUN_SCRIPTSIZE 256
23#define TUN_ADDRSIZE 128
jjako52c24142002-12-16 13:33:51 +000024
Harald Welte63ebccd2017-08-02 21:10:09 +020025#include "config.h"
Harald Weltec5efb5b2018-04-25 17:38:51 +020026#include "netdev.h"
jjakoa7cd2492003-04-11 09:40:12 +000027
jjako52c24142002-12-16 13:33:51 +000028/* ***********************************************************
29 * Information storage for each tun instance
30 *************************************************************/
31
32struct tun_t {
Harald Weltebed35df2011-11-02 13:06:18 +010033 int fd; /* File descriptor to tun interface */
34 struct in_addr addr;
35 struct in_addr dstaddr;
36 struct in_addr netmask;
37 int addrs; /* Number of allocated IP addresses */
38 int routes; /* One if we allocated an automatic route */
39 char devname[IFNAMSIZ]; /* Name of the tun device */
40 int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
Harald Welte881e97e2017-08-12 14:56:10 +020041 /* to be used by libgtp callers/users (to attach their own private state) */
42 void *priv;
jjako52c24142002-12-16 13:33:51 +000043};
44
Harald Weltef2286392018-04-25 19:02:31 +020045extern int tun_new(struct tun_t **tun, const char *dev_name, bool use_kernel, int fd0, int fd1u);
jjakoa7cd2492003-04-11 09:40:12 +000046extern int tun_free(struct tun_t *tun);
47extern int tun_decaps(struct tun_t *this);
jjako52c24142002-12-16 13:33:51 +000048extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
49
Pau Espin Pedrolf5e40b72017-12-14 14:01:23 +010050extern int tun_addaddr(struct tun_t *this, struct in46_addr *addr,
51 struct in46_addr *dstaddr, size_t prefixlen);
jjakoa7cd2492003-04-11 09:40:12 +000052
Harald Weltebed35df2011-11-02 13:06:18 +010053extern int tun_set_cb_ind(struct tun_t *this,
54 int (*cb_ind) (struct tun_t * tun, void *pack,
55 unsigned len));
jjakoa7cd2492003-04-11 09:40:12 +000056
Harald Weltebed35df2011-11-02 13:06:18 +010057extern int tun_runscript(struct tun_t *tun, char *script);
jjakoa7cd2492003-04-11 09:40:12 +000058
Pau Espin Pedrola037e592017-10-16 14:41:37 +020059int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list,
60 size_t prefix_size, int flags);
Harald Weltef85fe972017-09-24 20:00:34 +080061
Harald Weltebed35df2011-11-02 13:06:18 +010062#endif /* !_TUN_H */