doubled PAYLIMIT to 40 payloads
[strongswan.git] / src / pluto / demux.h
1 /* demultiplex incoming IKE messages
2 * Copyright (C) 1998-2002 D. Hugh Redelmeier.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * RCSID $Id: demux.h,v 1.4 2004/07/22 22:57:25 as Exp $
15 */
16
17 #include "packet.h"
18
19 struct state; /* forward declaration of tag */
20 extern void init_demux(void);
21 extern bool send_packet(struct state *st, const char *where);
22 extern void comm_handle(const struct iface *ifp);
23
24 extern u_int8_t reply_buffer[MAX_OUTPUT_UDP_SIZE];
25
26 /* State transition function infrastructure
27 *
28 * com_handle parses a message, decides what state object it applies to,
29 * and calls the appropriate state transition function (STF).
30 * These declarations define the interface to these functions.
31 *
32 * Each STF must be able to be restarted up to any failure point:
33 * a later message will cause the state to be re-entered. This
34 * explains the use of the replace macro and the care in handling
35 * MP_INT members of struct state.
36 */
37
38 struct payload_digest {
39 pb_stream pbs;
40 union payload payload;
41 struct payload_digest *next; /* of same kind */
42 };
43
44 /* message digest
45 * Note: raw_packet and packet_pbs are "owners" of space on heap.
46 */
47
48 struct msg_digest {
49 struct msg_digest *next; /* for free list */
50 chunk_t raw_packet; /* if encrypted, received packet before decryption */
51 const struct iface *iface; /* interface on which message arrived */
52 ip_address sender; /* where message came from */
53 u_int16_t sender_port; /* host order */
54 pb_stream packet_pbs; /* whole packet */
55 pb_stream message_pbs; /* message to be processed */
56 struct isakmp_hdr hdr; /* message's header */
57 bool encrypted; /* was it encrypted? */
58 enum state_kind from_state; /* state we started in */
59 const struct state_microcode *smc; /* microcode for initial state */
60 struct state *st; /* current state object */
61 pb_stream reply; /* room for reply */
62 pb_stream rbody; /* room for reply body (after header) */
63 notification_t note; /* reason for failure */
64 bool dpd; /* peer supports RFC 3706 DPD */
65 bool openpgp; /* peer supports OpenPGP certificates */
66
67 # define PAYLIMIT 40
68 struct payload_digest
69 digest[PAYLIMIT],
70 *digest_roof,
71 *chain[ISAKMP_NEXT_ROOF];
72 unsigned short nat_traversal_vid;
73 };
74
75 extern void release_md(struct msg_digest *md);
76
77 /* status for state-transition-function
78 * Note: STF_FAIL + notification_t means fail with that notification
79 */
80
81 typedef enum {
82 STF_IGNORE, /* don't respond */
83 STF_SUSPEND, /* unfinished -- don't release resources */
84 STF_OK, /* success */
85 STF_INTERNAL_ERROR, /* discard everything, we failed */
86 STF_FAIL /* discard everything, something failed. notification_t added. */
87 } stf_status;
88
89 typedef stf_status state_transition_fn(struct msg_digest *md);
90
91 extern void complete_state_transition(struct msg_digest **mdp, stf_status result);
92
93 extern void free_md_pool(void);