updated Doxyfile
[strongswan.git] / src / charon / kernel / kernel_net.h
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * Copyright (C) 2007 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 /**
20 * @defgroup kernel_net kernel_net
21 * @{ @ingroup kernel
22 */
23
24 #ifndef KERNEL_NET_H_
25 #define KERNEL_NET_H_
26
27 typedef struct kernel_net_t kernel_net_t;
28
29 #include <utils/enumerator.h>
30 #include <utils/host.h>
31
32 /**
33 * Interface to the network subsystem of the kernel.
34 *
35 * The kernel network interface handles the communication with the kernel
36 * for interface and IP address management.
37 */
38 struct kernel_net_t {
39
40 /**
41 * Get our outgoing source address for a destination.
42 *
43 * Does a route lookup to get the source address used to reach dest.
44 * The returned host is allocated and must be destroyed.
45 * An optional src address can be used to check if a route is available
46 * for given source to dest.
47 *
48 * @param dest target destination address
49 * @param src source address to check, or NULL
50 * @return outgoing source address, NULL if unreachable
51 */
52 host_t* (*get_source_addr)(kernel_net_t *this, host_t *dest, host_t *src);
53
54 /**
55 * Get the next hop for a destination.
56 *
57 * Does a route lookup to get the next hop used to reach dest.
58 * The returned host is allocated and must be destroyed.
59 *
60 * @param dest target destination address
61 * @return next hop address, NULL if unreachable
62 */
63 host_t* (*get_nexthop)(kernel_net_t *this, host_t *dest);
64
65 /**
66 * Get the interface name of a local address.
67 *
68 * @param host address to get interface name from
69 * @return allocated interface name, or NULL if not found
70 */
71 char* (*get_interface) (kernel_net_t *this, host_t *host);
72
73 /**
74 * Creates an enumerator over all local addresses.
75 *
76 * This function blocks an internal cached address list until the
77 * enumerator gets destroyed.
78 * The hosts are read-only, do not modify of free.
79 *
80 * @param include_down_ifaces TRUE to enumerate addresses from down interfaces
81 * @param include_virtual_ips TRUE to enumerate virtual ip addresses
82 * @return enumerator over host_t's
83 */
84 enumerator_t *(*create_address_enumerator) (kernel_net_t *this,
85 bool include_down_ifaces, bool include_virtual_ips);
86
87 /**
88 * Add a virtual IP to an interface.
89 *
90 * Virtual IPs are attached to an interface. If an IP is added multiple
91 * times, the IP is refcounted and not removed until del_ip() was called
92 * as many times as add_ip().
93 * The virtual IP is attached to the interface where the iface_ip is found.
94 *
95 * @param virtual_ip virtual ip address to assign
96 * @param iface_ip IP of an interface to attach virtual IP
97 * @return SUCCESS if operation completed
98 */
99 status_t (*add_ip) (kernel_net_t *this, host_t *virtual_ip,
100 host_t *iface_ip);
101
102 /**
103 * Remove a virtual IP from an interface.
104 *
105 * The kernel interface uses refcounting, see add_ip().
106 *
107 * @param virtual_ip virtual ip address to assign
108 * @return SUCCESS if operation completed
109 */
110 status_t (*del_ip) (kernel_net_t *this, host_t *virtual_ip);
111
112 /**
113 * Add a route.
114 *
115 * @param dst_net destination net
116 * @param prefixlen destination net prefix length
117 * @param gateway gateway for this route
118 * @param src_ip sourc ip of the route
119 * @param if_name name of the interface the route is bound to
120 * @return SUCCESS if operation completed
121 * ALREADY_DONE if the route already exists
122 */
123 status_t (*add_route) (kernel_net_t *this, chunk_t dst_net, u_int8_t prefixlen,
124 host_t *gateway, host_t *src_ip, char *if_name);
125
126 /**
127 * Delete a route.
128 *
129 * @param dst_net destination net
130 * @param prefixlen destination net prefix length
131 * @param gateway gateway for this route
132 * @param src_ip sourc ip of the route
133 * @param if_name name of the interface the route is bound to
134 * @return SUCCESS if operation completed
135 */
136 status_t (*del_route) (kernel_net_t *this, chunk_t dst_net, u_int8_t prefixlen,
137 host_t *gateway, host_t *src_ip, char *if_name);
138
139 /**
140 * Destroy the implementation.
141 */
142 void (*destroy) (kernel_net_t *this);
143 };
144
145 #endif /** KERNEL_NET_H_ @}*/