xref: /openbsd/sbin/isakmpd/message.h (revision ed76d6b8)
1 /* $OpenBSD: message.h,v 1.24 2005/05/26 06:11:09 hshoexer Exp $	 */
2 /* $EOM: message.h,v 1.51 2000/10/10 12:36:39 provos Exp $	 */
3 
4 /*
5  * Copyright (c) 1998, 1999 Niklas Hallqvist.  All rights reserved.
6  * Copyright (c) 1999 Angelos D. Keromytis.  All rights reserved.
7  * Copyright (c) 2001, 2004 H�kan Olsson.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * This code was written under funding by Ericsson Radio Systems.
32  */
33 
34 #ifndef _MESSAGE_H_
35 #define _MESSAGE_H_
36 
37 #include <sys/param.h>
38 #include <sys/queue.h>
39 #include <sys/socket.h>
40 #include <sys/uio.h>
41 
42 #include "isakmp.h"
43 
44 struct event;
45 struct message;
46 struct proto;
47 struct sa;
48 struct transport;
49 
50 struct payload {
51 	/* Link all payloads of the same type through here.  */
52 	TAILQ_ENTRY(payload) link;
53 
54 	/* The pointer to the actual payload data.  */
55 	u_int8_t       *p;
56 
57 	/*
58 	 * A pointer to the parent payload, used for proposal and transform
59 	 * payloads.
60          */
61 	struct payload *context;
62 
63 	/* Payload flags described below.  */
64 	int             flags;
65 };
66 
67 /* Payload flags.  */
68 
69 /*
70  * Set this when a payload has been handled, so we later can sweep over
71  * unhandled ones.
72  */
73 #define PL_MARK 1
74 
75 /* A post-send chain of functions to be called.  */
76 struct post_send {
77 	/* Link to the next function in the chain.  */
78 	TAILQ_ENTRY(post_send) link;
79 
80 	/* The actual function.  */
81 	void            (*func) (struct message *);
82 };
83 
84 struct message {
85 	/* Link message in send queues via this link.  */
86 	TAILQ_ENTRY(message) link;
87 
88 	/* Message flags described below.  */
89 	u_int           flags;
90 
91 	/*
92 	 * This is the transport the message either arrived on or will be sent
93 	 * to.
94          */
95 	struct transport *transport;
96 
97 	/*
98 	 * This is the ISAKMP SA protecting this message.
99 	 * XXX Needs to be redone to some keystate pointer or something.
100          */
101 	struct sa      *isakmp_sa;
102 
103 	/* This is the exchange where this message appears.  */
104 	struct exchange *exchange;
105 
106 	/*
107 	 * A segmented buffer structure holding the messages raw contents.  On
108 	 * input only segment 0 will be filled, holding all of the message.
109 	 * On output, as long as the message body is unencrypted each segment
110 	 * will be one payload, after encryption segment 0 will be the
111 	 * unencrypted header, and segment 1 will be the encrypted payloads,
112 	 * all of them.
113          */
114 	struct iovec   *iov;
115 
116 	/* The segment count.  */
117 	u_int           iovlen;
118 
119 	/* Pointer to the last "next payload" field.  */
120 	u_int8_t       *nextp;
121 
122 	/* "Smart" pointers to each payload, sorted by type.  */
123 	TAILQ_HEAD(payload_head, payload) *payload;
124 
125 	/* Number of times this message has been sent.  */
126 	int             xmits;
127 
128 	/* The timeout event causing retransmission of this message.  */
129 	struct event   *retrans;
130 
131 	/* The (possibly encrypted) message text, used for duplicate testing. */
132 	u_int8_t       *orig;
133 	size_t          orig_sz;
134 
135 	/*
136 	 * Extra baggage needed to travel with the message.  Used transiently
137 	 * in context sensitive ways.
138          */
139 	void           *extra;
140 
141 	/*
142 	 * Hooks for stuff needed to be done after the message has gone out to
143 	 * the wire.
144          */
145 	TAILQ_HEAD(post_send_head, post_send) post_send;
146 };
147 
148 /* Message flags.  */
149 
150 /*
151  * This is the last message of an exchange, meaning it should not be
152  * retransmitted other than if we see duplicates from our peer's last
153  * message.
154  */
155 #define MSG_LAST	0x01
156 
157 /* The message has already been encrypted.  */
158 #define MSG_ENCRYPTED	0x02
159 
160 /* The message is on the send queue.  */
161 #define MSG_IN_TRANSIT	0x04
162 
163 /* This message should be kept on the prioritized sendq.  */
164 #define MSG_PRIORITIZED	0x08
165 
166 /* This message has successfully been authenticated. */
167 #define MSG_AUTHENTICATED	0x10
168 
169 TAILQ_HEAD(msg_head, message);
170 
171 /* The number of different ISAKMP payloads supported.  */
172 extern u_int8_t payload_index_max;
173 
174 extern int	message_add_payload(struct message *, u_int8_t, u_int8_t *,
175 		    size_t, int);
176 extern int      message_add_sa_payload(struct message *);
177 extern struct message *message_alloc(struct transport *, u_int8_t *, size_t);
178 extern struct message *message_alloc_reply(struct message *);
179 extern u_int8_t *message_copy(struct message *, size_t, size_t *);
180 extern void     message_drop(struct message *, int, struct proto *, int, int);
181 extern void     message_dump_raw(char *, struct message *, int);
182 extern void     message_free(struct message *);
183 extern void	message_init(void);
184 extern int	message_negotiate_sa(struct message *,
185 		    int (*)(struct exchange *, struct sa *, struct sa *));
186 extern int      message_recv(struct message *);
187 extern int      message_register_post_send(struct message *,
188 		    void (*) (struct message *));
189 extern void     message_post_send(struct message *);
190 extern void     message_send(struct message *);
191 extern void     message_send_expire(struct message *);
192 extern void     message_send_delete(struct sa *);
193 extern int      message_send_info(struct message *);
194 extern void     message_send_notification(struct message *, struct sa *,
195 		    u_int16_t, struct proto *, int);
196 extern void     message_setup_header(struct message *, u_int8_t, u_int8_t,
197 		    u_int8_t *);
198 struct payload *payload_first(struct message *, u_int8_t);
199 
200 extern void	message_send_dpd_notify(struct sa*, u_int16_t, u_int32_t);
201 
202 #endif				/* _MESSAGE_H_ */
203