2f1f627272a6946f46aa8ebc3a45123c7820cb57
[strongswan.git] / src / charon / network / socket.h
1 /*
2 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
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 * $Id$
18 */
19
20 /**
21 * @defgroup socket socket
22 * @{ @ingroup network
23 */
24
25 #ifndef SOCKET_H_
26 #define SOCKET_H_
27
28 typedef struct socket_t socket_t;
29
30 #include <library.h>
31 #include <network/packet.h>
32 #include <utils/host.h>
33 #include <utils/enumerator.h>
34
35 /**
36 * Maximum size of a packet.
37 *
38 * 3000 Bytes should be sufficient, see IKEv2 RFC. However, we currently
39 * do not support HASH_AND_URL certificates, so we require to transmit
40 * the full certificates. To run our multi-CA test with 2 intermediate CAs,
41 * 5000 bytes is sufficient.
42 */
43 #define MAX_PACKET 5000
44
45 /**
46 * Abstraction of all sockets (IPv4/IPv6 send/receive).
47 *
48 * All available sockets are bound and the receive function
49 * reads from them. There are actually two implementations:
50 * The first uses raw sockets to allow binding of other daemons (pluto) to
51 * UDP/500. An installed "Linux socket filter" filters out all non-IKEv2
52 * traffic and handles just IKEv2 messages. An other daemon (pluto) must
53 * handle all traffic separately, e.g. ignore IKEv2 traffic, since charon
54 * handles that.
55 * The other implementation uses normal sockets and is built if
56 * --disable-pluto is given to the configure script.
57 */
58 struct socket_t {
59
60 /**
61 * Receive a packet.
62 *
63 * Reads a packet from the socket and sets source/dest
64 * appropriately.
65 *
66 * @param packet pinter gets address from allocated packet_t
67 * @return
68 * - SUCCESS when packet successfully received
69 * - FAILED when unable to receive
70 */
71 status_t (*receive) (socket_t *this, packet_t **packet);
72
73 /**
74 * Send a packet.
75 *
76 * Sends a packet to the net using destination from the packet.
77 * Packet is sent using default routing mechanisms, thus the
78 * source address in packet is ignored.
79 *
80 * @param packet packet_t to send
81 * @return
82 * - SUCCESS when packet successfully sent
83 * - FAILED when unable to send
84 */
85 status_t (*send) (socket_t *this, packet_t *packet);
86
87 /**
88 * Enumerate the underlying sockets.
89 *
90 * @return enumerator_t object
91 */
92 enumerator_t *(*create_enumerator) (socket_t *this);
93
94 /**
95 * Destroy socket.
96 */
97 void (*destroy) (socket_t *this);
98 };
99
100 /**
101 * Create a socket_t, which binds multiple sockets.
102 *
103 * @return socket_t object
104 */
105 socket_t *socket_create();
106
107 #endif /*SOCKET_H_ @} */