libradius: Use poll(2) to wait for RADIUS responses
[strongswan.git] / src / libstrongswan / networking / tun_device.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup tun_device tun_device
20 * @{ @ingroup networking
21 */
22
23 #ifndef TUN_DEVICE_H_
24 #define TUN_DEVICE_H_
25
26 #include <networking/host.h>
27
28 typedef struct tun_device_t tun_device_t;
29
30 /**
31 * Class to create TUN devices
32 *
33 * Creating such a device requires the CAP_NET_ADMIN capability.
34 *
35 * @note The implementation is currently very Linux specific
36 */
37 struct tun_device_t {
38
39 /**
40 * Read a packet from the TUN device
41 *
42 * @note This call blocks until a packet is available. It is a thread
43 * cancellation point.
44 *
45 * @param packet the packet read from the device
46 * @return TRUE if successful
47 */
48 bool (*read_packet)(tun_device_t *this, chunk_t *packet);
49
50 /**
51 * Write a packet to the TUN device
52 *
53 * @param packet the packet to write to the TUN device
54 * @return TRUE if successful
55 */
56 bool (*write_packet)(tun_device_t *this, chunk_t packet);
57
58 /**
59 * Set the IP address of the device
60 *
61 * @param addr the desired interface address
62 * @param netmask the netmask to use
63 * @return TRUE if operation successful
64 */
65 bool (*set_address)(tun_device_t *this, host_t *addr, u_int8_t netmask);
66
67 /**
68 * Get the IP address previously assigned to using set_address().
69 *
70 * @param netmask pointer receiving the configured netmask, or NULL
71 * @return address previously set, NULL if none
72 */
73 host_t* (*get_address)(tun_device_t *this, u_int8_t *netmask);
74
75 /**
76 * Bring the TUN device up
77 *
78 * @return TRUE if operation successful
79 */
80 bool (*up)(tun_device_t *this);
81
82 /**
83 * Set the MTU for this TUN device
84 *
85 * @param mtu new MTU
86 * @return TRUE if operation successful
87 */
88 bool (*set_mtu)(tun_device_t *this, int mtu);
89
90 /**
91 * Get the current MTU for this TUN device
92 *
93 * @return current MTU
94 */
95 int (*get_mtu)(tun_device_t *this);
96
97 /**
98 * Get the interface name of this device
99 *
100 * @return interface name
101 */
102 char *(*get_name)(tun_device_t *this);
103
104 /**
105 * Get the underlying tun file descriptor.
106 *
107 * @return file descriptor of this tun device
108 */
109 int (*get_fd)(tun_device_t *this);
110
111 /**
112 * Destroy a tun_device_t
113 */
114 void (*destroy)(tun_device_t *this);
115
116 };
117
118 /**
119 * Create a TUN device using the given name template.
120 *
121 * @param name_tmpl name template, defaults to "tun%d" if not given
122 * @return TUN device
123 */
124 tun_device_t *tun_device_create(const char *name_tmpl);
125
126 #endif /** TUN_DEVICE_H_ @}*/