]>
git.saurik.com Git - apple/ipsec.git/blob - ipsec-tools/racoon/evt.c
1 /* $NetBSD: evt.c,v 1.5 2006/09/09 16:22:09 manu Exp $ */
3 /* Id: evt.c,v 1.5 2006/06/22 20:11:35 manubsd Exp */
6 * Copyright (C) 2004 Emmanuel Dreyfus
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #include <sys/queue.h>
43 #include <sys/socket.h>
52 #ifdef ENABLE_ADMINPORT
53 struct evtlist evtlist
= TAILQ_HEAD_INITIALIZER(evtlist
);
57 evt_push(src
, dst
, type
, optdata
)
63 struct evtdump
*evtdump
;
67 /* If admin socket is disabled, silently discard anything */
68 if (adminsock_path
== NULL
)
71 /* If we are above the limit, don't record anything */
72 if (evtlist_len
> EVTLIST_MAX
) {
73 plog(LLV_DEBUG
, LOCATION
, NULL
,
74 "Cannot record event: event queue overflowed\n");
78 /* If we hit the limit, record an overflow event instead */
79 if (evtlist_len
== EVTLIST_MAX
) {
80 plog(LLV_ERROR
, LOCATION
, NULL
,
81 "Cannot record event: event queue overflow\n");
88 len
= sizeof(*evtdump
);
92 if ((evtdump
= racoon_malloc(len
)) == NULL
) {
93 plog(LLV_ERROR
, LOCATION
, NULL
, "Cannot record event: %s\n",
98 if ((evt
= racoon_malloc(sizeof(*evt
))) == NULL
) {
99 plog(LLV_ERROR
, LOCATION
, NULL
, "Cannot record event: %s\n",
101 racoon_free(evtdump
);
106 memcpy(&evtdump
->src
, src
, sysdep_sa_len(src
));
108 memcpy(&evtdump
->dst
, dst
, sysdep_sa_len(dst
));
110 evtdump
->type
= type
;
111 time(&evtdump
->timestamp
);
114 memcpy(evtdump
+ 1, optdata
->v
, optdata
->l
);
117 TAILQ_INSERT_TAIL(&evtlist
, evt
, next
);
126 struct evtdump
*evtdump
;
129 if ((evt
= TAILQ_FIRST(&evtlist
)) == NULL
)
133 TAILQ_REMOVE(&evtlist
, evt
, next
);
142 struct evtdump
*evtdump
;
145 if ((evtdump
= evt_pop()) != NULL
) {
146 if ((buf
= vmalloc(evtdump
->len
)) == NULL
) {
147 plog(LLV_ERROR
, LOCATION
, NULL
,
148 "evt_dump failed: %s\n", strerror(errno
));
151 memcpy(buf
->v
, evtdump
, evtdump
->len
);
152 racoon_free(evtdump
);
158 #endif /* ENABLE_ADMINPORT */