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