OSDN Git Service

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