show kind of notify contained in messages in log
[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 typedef struct socket_t socket_t;
29
30 #include <library.h>
31 #include <network/packet.h>
32 #include <utils/host.h>
33 #include <utils/linked_list.h>
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 * @brief Abstraction of all sockets (IPv6/IPv6 send/receive).
46 *
47 * All available 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 * @ingroup network
58 */
59 struct socket_t {
60
61 /**
62 * @brief Receive a packet.
63 *
64 * Reads a packet from the socket and sets source/dest
65 * appropriately.
66 *
67 * @param this socket_t object to work on
68 * @param packet pinter gets address from allocated packet_t
69 * @return
70 * - SUCCESS when packet successfully received
71 * - FAILED when unable to receive
72 */
73 status_t (*receive) (socket_t *this, packet_t **packet);
74
75 /**
76 * @brief Send a packet.
77 *
78 * Sends a packet to the net using destination from the packet.
79 * Packet is sent using default routing mechanisms, thus the
80 * source address in packet is ignored.
81 *
82 * @param this socket_t object to work on
83 * @param packet[out] packet_t to send
84 * @return
85 * - SUCCESS when packet successfully sent
86 * - FAILED when unable to send
87 */
88 status_t (*send) (socket_t *this, packet_t *packet);
89
90 /**
91 * @brief Destroy sockets.
92 *
93 * close sockets and destroy socket_t object
94 *
95 * @param this socket_t to destroy
96 */
97 void (*destroy) (socket_t *this);
98 };
99
100 /**
101 * @brief Create a socket_t, wich binds multiple sockets.
102 *
103 * @param port port to bind socket to
104 * @param natt_port port to float to in NAT-T
105 * @return socket_t object
106 *
107 * @ingroup network
108 */
109 socket_t *socket_create(u_int16_t port, u_int16_t natt_port);
110
111
112 #endif /*SOCKET_H_*/