fixed UDP decapsulation by adding inbound bypass policy for send socket
[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
32
33 /**
34 * @brief Maximum size of a packet.
35 *
36 * 3000 Bytes should be sufficient, see IKEv2 RFC.
37 *
38 * @ingroup network
39 */
40 #define MAX_PACKET 3000
41
42
43 typedef struct socket_t socket_t;
44
45 /**
46 * @brief Abstraction all sockets (currently IPv4 only).
47 *
48 * All available IPv4 sockets are bound and the receive function
49 * reads from them. To allow binding of other daemons (pluto) to
50 * UDP/500, this implementation uses RAW sockets. An installed
51 * "Linux socket filter" filters out all non-IKEv2 traffic and handles
52 * just IKEv2 messages. An other daemon (pluto) must handle all traffic
53 * seperatly, e.g. ignore IKEv2 traffic, since charon handles that.
54 *
55 * @b Constructors:
56 * - socket_create()
57 *
58 * @todo add IPv6 support
59 *
60 * @todo We currently use multiple sockets for historic reasons. With the
61 * new RAW socket mechanism, we could use just one socket and filter
62 * addresses in userspace (or via linux socket filter). This would allow
63 * realtime interface/address management in a easy way...
64 *
65 * @ingroup network
66 */
67 struct socket_t {
68 /**
69 * @brief Receive a packet.
70 *
71 * Reads a packet from the socket and sets source/dest
72 * appropriately.
73 *
74 * @param sock socket_t object to work on
75 * @param packet pinter gets address from allocated packet_t
76 * @return
77 * - SUCCESS when packet successfully received
78 * - FAILED when unable to receive
79 */
80 status_t (*receive) (socket_t *sock, packet_t **packet);
81
82 /**
83 * @brief Send a packet.
84 *
85 * Sends a packet to the net using destination from the packet.
86 * Packet is sent using default routing mechanisms, thus the
87 * source address in packet is ignored.
88 *
89 * @param sock socket_t object to work on
90 * @param packet[out] packet_t to send
91 * @return
92 * - SUCCESS when packet successfully sent
93 * - FAILED when unable to send
94 */
95 status_t (*send) (socket_t *sock, packet_t *packet);
96
97 /**
98 * @brief Destroy sockets.
99 *
100 * close sockets and destroy socket_t object
101 *
102 * @param sock socket_t to destroy
103 */
104 void (*destroy) (socket_t *sock);
105 };
106
107 /**
108 * @brief Create a socket_t, wich binds multiple sockets.
109 *
110 * currently creates a raw socket and two send sockets
111 *
112 * @param port port to bind socket to
113 * @param natt_port port to float to in NAT-T
114 * @return socket_t object
115 *
116 * @ingroup network
117 */
118 socket_t *socket_create(u_int16_t port, u_int16_t natt_port);
119
120
121 #endif /*SOCKET_H_*/