blob: 74c42daad8258c57487a522d56fce2f8b4bed397 [file] [log] [blame]
Harald Weltec5efb5b2018-04-25 17:38:51 +02001#pragma once
2/*
3 * TUN interface functions.
4 * Copyright (C) 2002, 2003 Mondru AB.
5 * Copyright (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
6 *
7 * The contents of this file may be used under the terms of the GNU
8 * General Public License Version 2, provided that the above copyright
9 * notice and this permission notice is included in all copies or
10 * substantial portions of the software.
11 *
12 */
13
14#include <net/if.h>
15
16#include "../lib/in46_addr.h"
17
18#define TUN_NLBUFSIZE 1024
19
20#include "config.h"
21
22/* ipv6 ip type flags for tun_ipv6_local_get() */
23enum {
24 IP_TYPE_IPv4 = 1,
25 IP_TYPE_IPv6_LINK = 2,
26 IP_TYPE_IPv6_NONLINK = 4,
27};
28#define IP_TYPE_IPv6 (IP_TYPE_IPv6_LINK | IP_TYPE_IPv6_NONLINK)
29
30
31#ifndef HAVE_IPHDR
32struct iphdr
33 {
34#if __BYTE_ORDER == __LITTLE_ENDIAN
35 unsigned int ihl:4;
36 unsigned int version:4;
37#elif __BYTE_ORDER == __BIG_ENDIAN
38 unsigned int version:4;
39 unsigned int ihl:4;
40#else
41# error "Please fix <bits/endian.h>"
42#endif
43 u_int8_t tos;
44 u_int16_t tot_len;
45 u_int16_t id;
46 u_int16_t frag_off;
47 u_int8_t ttl;
48 u_int8_t protocol;
49 u_int16_t check;
50 u_int32_t saddr;
51 u_int32_t daddr;
52 /*The options start here. */
53 };
54#endif /* !HAVE_IPHDR */
55
56extern int netdev_setaddr4(const char *devname, struct in_addr *addr,
57 struct in_addr *dstaddr, struct in_addr *netmask);
58
59extern int netdev_setaddr6(const char *devname, struct in6_addr *addr, struct in6_addr *dstaddr,
60 size_t prefixlen);
61
62extern int netdev_addaddr4(const char *devname, struct in_addr *addr,
63 struct in_addr *dstaddr, struct in_addr *netmask);
64
65extern int netdev_addaddr6(const char *devname, struct in6_addr *addr,
66 struct in6_addr *dstaddr, int prefixlen);
67
68extern int netdev_addroute(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
69extern int netdev_delroute(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
70
71extern int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list,
72 size_t prefix_size, int flags);