1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/* $OpenBSD: sa.h,v 1.5 1999/02/26 03:50:26 niklas Exp $ */
/* $EOM: sa.h,v 1.40 1999/02/14 00:11:40 niklas Exp $ */
/*
* Copyright (c) 1998 Niklas Hallqvist. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Ericsson Radio Systems.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This code was written under funding by Ericsson Radio Systems.
*/
#ifndef _SA_H_
#define _SA_H_
#include <sys/param.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include "isakmp.h"
/* Remove a SA if it has not been fully negotiated in this time. */
#define SA_NEGOTIATION_MAX_TIME 120
struct crypto_xf;
struct doi;
struct event;
struct exchange;
struct keystate;
struct message;
struct payload;
struct sa;
struct transport;
/* A protection suite consists of a set of protocol descriptions like this. */
struct proto {
/* Link to the next protocol in the suite. */
TAILQ_ENTRY (proto) link;
/* The SA we belong to. */
struct sa *sa;
/* The protocol number as found in the proposal payload. */
u_int8_t no;
/* The protocol this SA is for. */
u_int8_t proto;
/* Security parameter index info. Element 0 - outgoing, 1 - incoming. */
u_int8_t spi_sz[2];
u_int8_t *spi[2];
/*
* The chosen transform, only valid while the incoming SA payload that held
* it is available for duplicate testing.
*/
struct payload *chosen;
/* The chosen transform's ID. */
u_int8_t id;
/* DOI-specific data. */
void *data;
};
struct sa {
/* Link to SAs with the same hash value. */
LIST_ENTRY (sa) link;
/*
* When several SA's are being negotiated in one message we connect them
* through this link.
*/
TAILQ_ENTRY (sa) next;
/* A name of the major policy deciding offers and acceptable proposals. */
char *name;
/* What transport does this SA denote (ISAKMP SA only). */
struct transport *transport;
/* Both initiator and responder cookies. */
u_int8_t cookies[ISAKMP_HDR_COOKIES_LEN];
/* The message ID signifying non-ISAKMP SAs. */
u_int8_t message_id[ISAKMP_HDR_MESSAGE_ID_LEN];
/* The protection suite chosen. */
TAILQ_HEAD (proto_head, proto) protos;
/* The exchange type we should use when rekeying. */
u_int8_t exch_type;
/* Phase is 1 for ISAKMP SAs, and 2 for application ones. */
u_int8_t phase;
/* Save last message from setup, which can be retransmitted for dups */
struct message *last_sent_in_setup;
/* Various flags, look below for descriptions. */
u_int32_t flags;
/* The DOI that is to handle DOI-specific issues for this SA. */
struct doi *doi;
/* Crypto info needed to encrypt/decrypt packets protected by this SA. */
struct crypto_xf *crypto;
int key_length;
struct keystate *keystate;
/* DOI-specific opaque data. */
void *data;
/* Lifetime data. */
u_int64_t seconds;
u_int64_t kilobytes;
/* The events that will occur when an SA has timed out. */
struct event *soft_death;
struct event *death;
};
/* This SA is alive. */
#define SA_FLAG_READY 1
extern void proto_free (struct proto *proto);
extern int sa_add_transform (struct sa *, struct payload *, int,
struct proto **);
extern int sa_create (struct exchange *, struct transport *);
extern void sa_delete (struct sa *, int);
extern struct sa *sa_find (int (*) (struct sa *, void *), void *);
extern void sa_free (struct sa *);
extern void sa_free_aux (struct sa *);
extern void sa_init (void);
extern struct sa *sa_isakmp_lookup_by_peer (struct sockaddr *, size_t addr);
extern void sa_isakmp_upgrade (struct message *);
extern struct sa *sa_lookup (u_int8_t *, u_int8_t *);
extern struct sa *sa_lookup_by_header (u_int8_t *, int);
extern struct sa *sa_lookup_by_name (char *, int);
extern struct sa *sa_lookup_from_icookie (u_int8_t *);
extern void sa_soft_expire (struct sa *);
extern void sa_hard_expire (struct sa *);
extern void sa_report (void);
#endif /* _SA_H_ */
|