cleaner error handling on UDP encapsultion sockopt failure
[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 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef SOCKET_H_
25 #define SOCKET_H_
26
27
28 #include <types.h>
29 #include <network/packet.h>
30
31
32 /**
33 * @brief Maximum size of a packet.
34 *
35 * 3000 Bytes should be sufficient, see IKEv2 RFC.
36 *
37 * @ingroup network
38 */
39 #define MAX_PACKET 3000
40
41
42 typedef struct socket_t socket_t;
43
44 /**
45 * @brief Abstraction all sockets (currently IPv4 only).
46 *
47 * All available IPv4 sockets are bound and the receive function
48 * reads from them. To allow binding of other daemons (pluto) to
49 * UDP/500, this implementation uses RAW sockets. An installed
50 * "Linux socket filter" filters out all non-IKEv2 traffic and handles
51 * just IKEv2 messages. An other daemon (pluto) must handle all traffic
52 * seperatly, e.g. ignore IKEv2 traffic, since charon handles that.
53 *
54 * @b Constructors:
55 * - socket_create()
56 *
57 * @todo add IPv6 support
58 *
59 * @todo We currently use multiple sockets for historic reasons. With the
60 * new RAW socket mechanism, we could use just one socket and filter
61 * addresses in userspace (or via linux socket filter). This would allow
62 * realtime interface/address management in a easy way...
63 *
64 * @ingroup network
65 */
66 struct socket_t {
67 /**
68 * @brief Receive a packet.
69 *
70 * Reads a packet from the socket and sets source/dest
71 * appropriately.
72 *
73 * @param sock socket_t object to work on
74 * @param packet pinter gets address from allocated packet_t
75 * @return
76 * - SUCCESS when packet successfully received
77 * - FAILED when unable to receive
78 */
79 status_t (*receive) (socket_t *sock, packet_t **packet);
80
81 /**
82 * @brief Send a packet.
83 *
84 * Sends a packet to the net using destination from the packet.
85 * Packet is sent using default routing mechanisms, thus the
86 * source address in packet is ignored.
87 *
88 * @param sock socket_t object to work on
89 * @param packet[out] packet_t to send
90 * @return
91 * - SUCCESS when packet successfully sent
92 * - FAILED when unable to send
93 */
94 status_t (*send) (socket_t *sock, packet_t *packet);
95
96 /**
97 * @brief Destroy sockets.
98 *
99 * close sockets and destroy socket_t object
100 *
101 * @param sock socket_t to destroy
102 */
103 void (*destroy) (socket_t *sock);
104 };
105
106 /**
107 * @brief Create a socket_t, wich binds multiple sockets.
108 *
109 * currently creates a raw socket and two send sockets
110 *
111 * @param port port to bind socket to
112 * @param natt_port port to float to in NAT-T
113 * @return socket_t object
114 *
115 * @ingroup network
116 */
117 socket_t *socket_create(u_int16_t port, u_int16_t natt_port);
118
119
120 #endif /*SOCKET_H_*/