Changeset c385e86 in rtems-libbsd for ipsec-tools/src/racoon/session.c


Ignore:
Timestamp:
02/23/21 13:18:26 (3 years ago)
Author:
Christian Mauderer <christian.mauderer@…>
Branches:
5-freebsd-12
Children:
35bdef1
Parents:
ea5d0c7
git-author:
Christian Mauderer <christian.mauderer@…> (02/23/21 13:18:26)
git-committer:
Christian Mauderer <christian.mauderer@…> (05/11/21 06:37:32)
Message:

racoon/session: Honor file descriptor maximum

Dynamically allocate a big enough file descriptor set for select(). A
better solution would be to use kqueue() instead of select().

Update #4361

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipsec-tools/src/racoon/session.c

    rea5d0c7 rc385e86  
    6666#include <paths.h>
    6767#include <err.h>
     68#ifdef __rtems__
     69#include <sys/param.h>
     70#include <rtems/libio_.h>
     71#endif /* __rtems__ */
    6872
    6973#include <netinet/in.h>
     
    124128static int close_sockets __P((void));
    125129
     130#ifndef __rtems__
    126131static fd_set preset_mask, active_mask;
    127132static struct fd_monitor fd_monitors[FD_SETSIZE];
     133#else /* __rtems__ */
     134static fd_set *allocated_preset_mask, *allocated_active_mask;
     135static struct fd_monitor *allocated_fd_monitors;
     136#define preset_mask (*allocated_preset_mask)
     137#define active_mask (*allocated_active_mask)
     138#define fd_monitors (allocated_fd_monitors)
     139#endif /* __rtems__ */
    128140static TAILQ_HEAD(fd_monitor_list, fd_monitor) fd_monitor_tree[NUM_PRIORITIES];
    129141static int nfds = 0;
     
    135147monitor_fd(int fd, int (*callback)(void *, int), void *ctx, int priority)
    136148{
     149#ifndef __rtems__
    137150        if (fd < 0 || fd >= FD_SETSIZE) {
     151#else /* __rtems__ */
     152        if (fd < 0 || fd >= rtems_libio_number_iops) {
     153#endif /* __rtems__ */
    138154                plog(LLV_ERROR, LOCATION, NULL, "fd_set overrun");
    139155                exit(1);
     
    159175unmonitor_fd(int fd)
    160176{
     177#ifndef __rtems__
    161178        if (fd < 0 || fd >= FD_SETSIZE) {
     179#else /* __rtems__ */
     180        if (fd < 0 || fd >= rtems_libio_number_iops) {
     181#endif /* __rtems__ */
    162182                plog(LLV_ERROR, LOCATION, NULL, "fd_set overrun");
    163183                exit(1);
     
    187207
    188208        nfds = 0;
     209#ifndef __rtems__
    189210        FD_ZERO(&preset_mask);
     211#else /* __rtems__ */
     212        allocated_preset_mask = calloc(sizeof(fd_set),
     213            howmany(rtems_libio_number_iops, sizeof(fd_set) * 8));
     214        if (allocated_preset_mask == NULL)
     215                errx(1, "failed to allocate preset_mask");
     216        allocated_active_mask = calloc(sizeof(fd_set),
     217            howmany(rtems_libio_number_iops, sizeof(fd_set) * 8));
     218        if (allocated_active_mask == NULL)
     219                errx(1, "failed to allocate active_mask");
     220        allocated_fd_monitors = calloc(
     221            rtems_libio_number_iops, sizeof(struct fd_monitor));
     222        if (allocated_fd_monitors == NULL)
     223                errx(1, "failed to allocate fd_monitors");
     224#endif /* __rtems__ */
    190225
    191226        for (i = 0; i < NUM_PRIORITIES; i++)
     
    357392        close_sockets();
    358393        backupsa_clean();
     394#ifdef __rtems__
     395        free(allocated_preset_mask); allocated_preset_mask = NULL;
     396        free(allocated_active_mask); allocated_active_mask = NULL;
     397        free(allocated_fd_monitors); allocated_fd_monitors = NULL;
     398#endif /* __rtems__ */
    359399
    360400        plog(LLV_INFO, LOCATION, NULL, "racoon process %d shutdown\n", getpid());
Note: See TracChangeset for help on using the changeset viewer.