Annotation of embedaddon/strongswan/src/libcharon/network/receiver.h, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2012 Tobias Brunner
! 3: * Copyright (C) 2005-2007 Martin Willi
! 4: * Copyright (C) 2005 Jan Hutter
! 5: * HSR 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:
! 18: /**
! 19: * @defgroup receiver receiver
! 20: * @{ @ingroup network
! 21: */
! 22:
! 23: #ifndef RECEIVER_H_
! 24: #define RECEIVER_H_
! 25:
! 26: typedef struct receiver_t receiver_t;
! 27:
! 28: #include <library.h>
! 29: #include <networking/host.h>
! 30: #include <networking/packet.h>
! 31:
! 32: /**
! 33: * Callback called for any received UDP encapsulated ESP packet.
! 34: *
! 35: * Implementation should be quick as the receiver doesn't receive any packets
! 36: * while calling this function.
! 37: *
! 38: * @param data data supplied during registration of the callback
! 39: * @param packet decapsulated ESP packet
! 40: */
! 41: typedef void (*receiver_esp_cb_t)(void *data, packet_t *packet);
! 42:
! 43: /**
! 44: * Receives packets from the socket and adds them to the job queue.
! 45: *
! 46: * The receiver uses a callback job, which reads on the blocking socket.
! 47: * A received packet is preparsed and a process_message_job is queued in the
! 48: * job queue.
! 49: *
! 50: * To endure DoS attacks, cookies are enabled when too many IKE_SAs are half
! 51: * open. The calculation of cookies is slightly different from the proposed
! 52: * method in RFC4306. We do not include a nonce, because we think the advantage
! 53: * we gain does not justify the overhead to parse the whole message.
! 54: * Instead of VersionIdOfSecret, we include a timestamp. This allows us to
! 55: * find out which key was used for cookie creation. Further, we can set a
! 56: * lifetime for the cookie, which allows us to reuse the secret for a longer
! 57: * time.
! 58: * COOKIE = time | sha1( IPi | SPIi | time | secret )
! 59: *
! 60: * The secret is changed after a certain amount of cookies sent. The old
! 61: * secret is stored to allow a clean migration between secret changes.
! 62: *
! 63: * Further, the number of half-initiated IKE_SAs is limited per peer. This
! 64: * makes it impossible for a peer to flood the server with its real IP address.
! 65: */
! 66: struct receiver_t {
! 67:
! 68: /**
! 69: * Register a callback which is called for any incoming ESP packets.
! 70: *
! 71: * @note Only the last callback registered will receive any packets.
! 72: *
! 73: * @param callback callback to register
! 74: * @param data data provided to callback
! 75: */
! 76: void (*add_esp_cb)(receiver_t *this, receiver_esp_cb_t callback,
! 77: void *data);
! 78:
! 79: /**
! 80: * Unregister a previously registered callback for ESP packets.
! 81: *
! 82: * @param callback previously registered callback
! 83: */
! 84: void (*del_esp_cb)(receiver_t *this, receiver_esp_cb_t callback);
! 85:
! 86: /**
! 87: * Destroys a receiver_t object.
! 88: */
! 89: void (*destroy)(receiver_t *this);
! 90: };
! 91:
! 92: /**
! 93: * Create a receiver_t object.
! 94: *
! 95: * The receiver thread will start working, get data
! 96: * from the socket and add those packets to the job queue.
! 97: *
! 98: * @return receiver_t object, NULL if initialization fails
! 99: */
! 100: receiver_t * receiver_create(void);
! 101:
! 102: #endif /** RECEIVER_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>