]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libhydra/kernel/kernel_net.h
Moved kernel interface to libhydra.
[thirdparty/strongswan.git] / src / libhydra / 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
17 /**
18 * @defgroup kernel_net kernel_net
19 * @{ @ingroup hkernel
20 */
21
22 #ifndef KERNEL_NET_H_
23 #define KERNEL_NET_H_
24
25 typedef struct kernel_net_t kernel_net_t;
26
27 #include <utils/enumerator.h>
28 #include <utils/host.h>
29
30 /**
31 * Interface to the network subsystem of the kernel.
32 *
33 * The kernel network interface handles the communication with the kernel
34 * for interface and IP address management.
35 */
36 struct kernel_net_t {
37
38 /**
39 * Get our outgoing source address for a destination.
40 *
41 * Does a route lookup to get the source address used to reach dest.
42 * The returned host is allocated and must be destroyed.
43 * An optional src address can be used to check if a route is available
44 * for given source to dest.
45 *
46 * @param dest target destination address
47 * @param src source address to check, or NULL
48 * @return outgoing source address, NULL if unreachable
49 */
50 host_t* (*get_source_addr)(kernel_net_t *this, host_t *dest, host_t *src);
51
52 /**
53 * Get the next hop for a destination.
54 *
55 * Does a route lookup to get the next hop used to reach dest.
56 * The returned host is allocated and must be destroyed.
57 *
58 * @param dest target destination address
59 * @return next hop address, NULL if unreachable
60 */
61 host_t* (*get_nexthop)(kernel_net_t *this, host_t *dest);
62
63 /**
64 * Get the interface name of a local address.
65 *
66 * @param host address to get interface name from
67 * @return allocated interface name, or NULL if not found
68 */
69 char* (*get_interface) (kernel_net_t *this, host_t *host);
70
71 /**
72 * Creates an enumerator over all local addresses.
73 *
74 * This function blocks an internal cached address list until the
75 * enumerator gets destroyed.
76 * The hosts are read-only, do not modify of free.
77 *
78 * @param include_down_ifaces TRUE to enumerate addresses from down interfaces
79 * @param include_virtual_ips TRUE to enumerate virtual ip addresses
80 * @return enumerator over host_t's
81 */
82 enumerator_t *(*create_address_enumerator) (kernel_net_t *this,
83 bool include_down_ifaces, bool include_virtual_ips);
84
85 /**
86 * Add a virtual IP to an interface.
87 *
88 * Virtual IPs are attached to an interface. If an IP is added multiple
89 * times, the IP is refcounted and not removed until del_ip() was called
90 * as many times as add_ip().
91 * The virtual IP is attached to the interface where the iface_ip is found.
92 *
93 * @param virtual_ip virtual ip address to assign
94 * @param iface_ip IP of an interface to attach virtual IP
95 * @return SUCCESS if operation completed
96 */
97 status_t (*add_ip) (kernel_net_t *this, host_t *virtual_ip,
98 host_t *iface_ip);
99
100 /**
101 * Remove a virtual IP from an interface.
102 *
103 * The kernel interface uses refcounting, see add_ip().
104 *
105 * @param virtual_ip virtual ip address to assign
106 * @return SUCCESS if operation completed
107 */
108 status_t (*del_ip) (kernel_net_t *this, host_t *virtual_ip);
109
110 /**
111 * Add a route.
112 *
113 * @param dst_net destination net
114 * @param prefixlen destination net prefix length
115 * @param gateway gateway for this route
116 * @param src_ip sourc ip of the route
117 * @param if_name name of the interface the route is bound to
118 * @return SUCCESS if operation completed
119 * ALREADY_DONE if the route already exists
120 */
121 status_t (*add_route) (kernel_net_t *this, chunk_t dst_net,
122 u_int8_t prefixlen, host_t *gateway, host_t *src_ip,
123 char *if_name);
124
125 /**
126 * Delete a route.
127 *
128 * @param dst_net destination net
129 * @param prefixlen destination net prefix length
130 * @param gateway gateway for this route
131 * @param src_ip sourc ip of the route
132 * @param if_name name of the interface the route is bound to
133 * @return SUCCESS if operation completed
134 */
135 status_t (*del_route) (kernel_net_t *this, chunk_t dst_net,
136 u_int8_t prefixlen, host_t *gateway, host_t *src_ip,
137 char *if_name);
138
139 /**
140 * Destroy the implementation.
141 */
142 void (*destroy) (kernel_net_t *this);
143 };
144
145 #endif /** KERNEL_NET_H_ @}*/