include demux.h only once
[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
15 #ifndef _DEMUX_H
16 #define _DEMUX_H
17
18 #include "packet.h"
19 #include "state.h"
20
21 extern void init_demux(void);
22 extern bool send_packet(struct state *st, const char *where);
23 extern void comm_handle(const struct iface *ifp);
24
25 extern u_int8_t reply_buffer[MAX_OUTPUT_UDP_SIZE];
26
27 /* State transition function infrastructure
28 *
29 * com_handle parses a message, decides what state object it applies to,
30 * and calls the appropriate state transition function (STF).
31 * These declarations define the interface to these functions.
32 *
33 * Each STF must be able to be restarted up to any failure point:
34 * a later message will cause the state to be re-entered. This
35 * explains the use of the replace macro and the care in handling
36 * MP_INT members of struct state.
37 */
38
39 struct payload_digest {
40 pb_stream pbs;
41 union payload payload;
42 struct payload_digest *next; /* of same kind */
43 };
44
45 /* message digest
46 * Note: raw_packet and packet_pbs are "owners" of space on heap.
47 */
48
49 struct msg_digest {
50 struct msg_digest *next; /* for free list */
51 chunk_t raw_packet; /* if encrypted, received packet before decryption */
52 const struct iface *iface; /* interface on which message arrived */
53 ip_address sender; /* where message came from */
54 u_int16_t sender_port; /* host order */
55 pb_stream packet_pbs; /* whole packet */
56 pb_stream message_pbs; /* message to be processed */
57 struct isakmp_hdr hdr; /* message's header */
58 bool encrypted; /* was it encrypted? */
59 enum state_kind from_state; /* state we started in */
60 const struct state_microcode *smc; /* microcode for initial state */
61 struct state *st; /* current state object */
62 pb_stream reply; /* room for reply */
63 pb_stream rbody; /* room for reply body (after header) */
64 notification_t note; /* reason for failure */
65 bool dpd; /* peer supports RFC 3706 DPD */
66 bool openpgp; /* peer supports OpenPGP certificates */
67 bool ms_nt5; /* peer is a windows 2000+ host */
68
69 # define PAYLIMIT 40
70 struct payload_digest
71 digest[PAYLIMIT],
72 *digest_roof,
73 *chain[ISAKMP_NEXT_ROOF];
74 unsigned short nat_traversal_vid;
75 };
76
77 extern void release_md(struct msg_digest *md);
78
79 /* status for state-transition-function
80 * Note: STF_FAIL + notification_t means fail with that notification
81 */
82
83 typedef enum {
84 STF_IGNORE, /* don't respond */
85 STF_SUSPEND, /* unfinished -- don't release resources */
86 STF_OK, /* success */
87 STF_INTERNAL_ERROR, /* discard everything, we failed */
88 STF_FAIL /* discard everything, something failed. notification_t added. */
89 } stf_status;
90
91 typedef stf_status state_transition_fn(struct msg_digest *md);
92
93 extern void complete_state_transition(struct msg_digest **mdp, stf_status result);
94
95 extern void free_md_pool(void);
96
97 #endif /* _DEMUX_H */