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