summaryrefslogtreecommitdiffstats
path: root/ipsec-tools/src/racoon/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'ipsec-tools/src/racoon/session.c')
-rw-r--r--ipsec-tools/src/racoon/session.c60
1 files changed, 55 insertions, 5 deletions
diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c
index 65124c15..bd2bd316 100644
--- a/ipsec-tools/src/racoon/session.c
+++ b/ipsec-tools/src/racoon/session.c
@@ -65,6 +65,10 @@
#include <sys/stat.h>
#include <paths.h>
#include <err.h>
+#ifdef __rtems__
+#include <sys/param.h>
+#include <rtems/libio_.h>
+#endif /* __rtems__ */
#include <netinet/in.h>
#include <resolv.h>
@@ -115,6 +119,7 @@ struct fd_monitor {
#define NUM_PRIORITIES 2
+#ifndef __rtems__
static void close_session __P((void));
static void initfds __P((void));
static void init_signal __P((void));
@@ -122,19 +127,34 @@ static int set_signal __P((int sig, RETSIGTYPE (*func) __P((int))));
static void check_sigreq __P((void));
static void check_flushsa __P((void));
static int close_sockets __P((void));
+#endif /* __rtems__ */
+#ifndef __rtems__
static fd_set preset_mask, active_mask;
static struct fd_monitor fd_monitors[FD_SETSIZE];
+#else /* __rtems__ */
+static fd_set *allocated_preset_mask, *allocated_active_mask;
+static struct fd_monitor *allocated_fd_monitors;
+#define preset_mask (*allocated_preset_mask)
+#define active_mask (*allocated_active_mask)
+#define fd_monitors (allocated_fd_monitors)
+#endif /* __rtems__ */
static TAILQ_HEAD(fd_monitor_list, fd_monitor) fd_monitor_tree[NUM_PRIORITIES];
static int nfds = 0;
+#ifndef __rtems__
static volatile sig_atomic_t sigreq[NSIG + 1];
static struct sched scflushsa = SCHED_INITIALIZER();
+#endif /* __rtems__ */
void
monitor_fd(int fd, int (*callback)(void *, int), void *ctx, int priority)
{
+#ifndef __rtems__
if (fd < 0 || fd >= FD_SETSIZE) {
+#else /* __rtems__ */
+ if (fd < 0 || fd >= rtems_libio_number_iops) {
+#endif /* __rtems__ */
plog(LLV_ERROR, LOCATION, NULL, "fd_set overrun");
exit(1);
}
@@ -158,7 +178,11 @@ monitor_fd(int fd, int (*callback)(void *, int), void *ctx, int priority)
void
unmonitor_fd(int fd)
{
+#ifndef __rtems__
if (fd < 0 || fd >= FD_SETSIZE) {
+#else /* __rtems__ */
+ if (fd < 0 || fd >= rtems_libio_number_iops) {
+#endif /* __rtems__ */
plog(LLV_ERROR, LOCATION, NULL, "fd_set overrun");
exit(1);
}
@@ -179,21 +203,42 @@ session(void)
{
struct timeval *timeout;
int error;
+#ifndef __rtems__
char pid_file[MAXPATHLEN];
FILE *fp;
pid_t racoon_pid = 0;
+#endif /* __rtems__ */
int i, count;
struct fd_monitor *fdm;
nfds = 0;
+#ifndef __rtems__
FD_ZERO(&preset_mask);
+#else /* __rtems__ */
+ size_t allocated_mask_size = sizeof(fd_set) *
+ howmany(rtems_libio_number_iops, sizeof(fd_set) * 8);
+ allocated_preset_mask = calloc(sizeof(fd_set),
+ howmany(rtems_libio_number_iops, sizeof(fd_set) * 8));
+ if (allocated_preset_mask == NULL)
+ errx(1, "failed to allocate preset_mask");
+ allocated_active_mask = calloc(sizeof(fd_set),
+ howmany(rtems_libio_number_iops, sizeof(fd_set) * 8));
+ if (allocated_active_mask == NULL)
+ errx(1, "failed to allocate active_mask");
+ allocated_fd_monitors = calloc(
+ rtems_libio_number_iops, sizeof(struct fd_monitor));
+ if (allocated_fd_monitors == NULL)
+ errx(1, "failed to allocate fd_monitors");
+#endif /* __rtems__ */
for (i = 0; i < NUM_PRIORITIES; i++)
TAILQ_INIT(&fd_monitor_tree[i]);
/* initialize schedular */
sched_init();
+#ifndef __rtems__
init_signal();
+#endif /* __rtems__ */
if (pfkey_init() < 0)
errx(1, "failed to initialize pfkey socket");
@@ -290,24 +335,31 @@ session(void)
racoon_pid = getpid();
fprintf(fp, "%ld\n", (long)racoon_pid);
fclose(fp);
-#endif /* __rtems__ */
for (i = 0; i <= NSIG; i++)
sigreq[i] = 0;
+#endif /* __rtems__ */
while (1) {
+#ifndef __rtems__
/*
* asynchronous requests via signal.
* make sure to reset sigreq to 0.
*/
check_sigreq();
+#endif /* __rtems__ */
/* scheduling */
timeout = schedular();
/* schedular can change select() mask, so we reset
* the working copy here */
+#ifndef __rtems__
active_mask = preset_mask;
+#else /* __rtems__ */
+ memcpy(allocated_active_mask, allocated_preset_mask,
+ allocated_mask_size);
+#endif /* __rtems__ */
error = select(nfds + 1, &active_mask, NULL, NULL, timeout);
if (error < 0) {
@@ -344,6 +396,7 @@ session(void)
}
}
+#ifndef __rtems__
/* clear all status and exit program. */
static void
close_session()
@@ -525,11 +578,7 @@ set_signal(sig, func)
memset((caddr_t)&sa, 0, sizeof(sa));
sa.sa_handler = func;
-#ifndef __rtems__
sa.sa_flags = SA_RESTART;
-#else /* __rtems__ */
- sa.sa_flags = 0;
-#endif /* __rtems__ */
if (sigemptyset(&sa.sa_mask) < 0)
return -1;
@@ -550,6 +599,7 @@ close_sockets()
#endif
return 0;
}
+#endif /* __rtems__ */
#ifdef __rtems__
#include "rtems-bsd-racoon-session-data.h"