212a55cde96c28ee04c26a9eac0eabd26654c705
[strongswan.git] / src / charon / network / socket.h
1 /**
2 * @file socket.h
3 *
4 * @brief Interface for socket_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #ifndef SOCKET_H_
26 #define SOCKET_H_
27
28
29 #include <types.h>
30 #include <network/packet.h>
31 #include <utils/host.h>
32 #include <utils/linked_list.h>
33
34
35 /**
36 * @brief Maximum size of a packet.
37 *
38 * 3000 Bytes should be sufficient, see IKEv2 RFC.
39 *
40 * @ingroup network
41 */
42 #define MAX_PACKET 3000
43
44
45 typedef struct socket_t socket_t;
46
47 /**
48 * @brief Abstraction all sockets (currently IPv4 only).
49 *
50 * All available IPv4 sockets are bound and the receive function
51 * reads from them. To allow binding of other daemons (pluto) to
52 * UDP/500, this implementation uses RAW sockets. An installed
53 * "Linux socket filter" filters out all non-IKEv2 traffic and handles
54 * just IKEv2 messages. An other daemon (pluto) must handle all traffic
55 * seperatly, e.g. ignore IKEv2 traffic, since charon handles that.
56 *
57 * @b Constructors:
58 * - socket_create()
59 *
60 * @ingroup network
61 */
62 struct socket_t {
63
64 /**
65 * @brief Receive a packet.
66 *
67 * Reads a packet from the socket and sets source/dest
68 * appropriately.
69 *
70 * @param this socket_t object to work on
71 * @param packet pinter gets address from allocated packet_t
72 * @return
73 * - SUCCESS when packet successfully received
74 * - FAILED when unable to receive
75 */
76 status_t (*receive) (socket_t *this, packet_t **packet);
77
78 /**
79 * @brief Send a packet.
80 *
81 * Sends a packet to the net using destination from the packet.
82 * Packet is sent using default routing mechanisms, thus the
83 * source address in packet is ignored.
84 *
85 * @param this socket_t object to work on
86 * @param packet[out] packet_t to send
87 * @return
88 * - SUCCESS when packet successfully sent
89 * - FAILED when unable to send
90 */
91 status_t (*send) (socket_t *this, packet_t *packet);
92
93 /**
94 * @brief Check if an address is an address of this host.
95 *
96 * @param this socket_t object to work on
97 * @param host address to check
98 * @return TRUE if local address, FALSE otherwise
99 */
100 bool (*is_local_address) (socket_t *this, host_t *host);
101
102 /**
103 * @brief Create a list of hosts with all local addresses.
104 *
105 * @param this socket_t object to work on
106 * @return list with host_t objects
107 */
108 linked_list_t *(*create_local_address_list) (socket_t *this);
109
110 /**
111 * @brief Destroy sockets.
112 *
113 * close sockets and destroy socket_t object
114 *
115 * @param this socket_t to destroy
116 */
117 void (*destroy) (socket_t *this);
118 };
119
120 /**
121 * @brief Create a socket_t, wich binds multiple sockets.
122 *
123 * currently creates a raw socket and two send sockets
124 *
125 * @param port port to bind socket to
126 * @param natt_port port to float to in NAT-T
127 * @return socket_t object
128 *
129 * @ingroup network
130 */
131 socket_t *socket_create(u_int16_t port, u_int16_t natt_port);
132
133
134 #endif /*SOCKET_H_*/