Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
Hello Chris, Am 28.03.21 um 04:43 schrieb Chris Johns: On 22/3/21 7:45 pm, Christian MAUDERER wrote: Hello Chris, Am 19.03.21 um 02:11 schrieb Chris Johns: On 3/3/21 7:41 pm, Christian MAUDERER wrote: Hello Chris, Am 03.03.21 um 02:17 schrieb Chris Johns: On 2/3/21 7:26 pm, Christian MAUDERER wrote: Hello Chris, Am 02.03.21 um 01:03 schrieb Chris Johns: On 1/3/21 7:24 pm, Christian MAUDERER wrote: Hello Chris, thanks for the review. Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: Dynamically allocate a big enough file descriptor set for select(). A better solution would be to use kqueue() instead of select(). --- .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- ipsec-tools/src/racoon/session.c | 40 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h index b869a1518..196107a35 100644 --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h @@ -2,11 +2,11 @@ #include #include "rtems-bsd-racoon-data.h" /* session.c */ -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_active_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_preset_mask); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor fd_monitors[]); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c index 65124c15e..90120c761 100644 --- a/ipsec-tools/src/racoon/session.c +++ b/ipsec-tools/src/racoon/session.c @@ -65,6 +65,10 @@ #include #include #include +#ifdef __rtems__ +#include +#include +#endif /* __rtems__ */ #include #include @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); static void check_flushsa __P((void)); static int close_sockets __P((void)); +#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; @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); 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 +174,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); } @@ -186,7 +206,22 @@ session(void) struct fd_monitor *fdm; nfds = 0; +#ifndef __rtems__ FD_ZERO(_mask); +#else /* __rtems__ */ + allocated_preset_mask = calloc(sizeof(fd_set), + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? To be honest: I'm not sure. According to the comment in file.h: extern int maxfiles; /* kernel limit on number of open files */ Yes. Sounds like it _can_ be the same as the maximum file number but doesn't have to. I think we need to have them be the same value. I didn't find where we implement it. It's declared as an extern int maxfiles but I didn't find any definition. I found it only in libbsd in freebsd/sys/kern/uipc_socket.c where it is defined like follows: #define maxfiles rtems_libio_number_iops Ah OK. I knew it had been assigned somewhere and yes it looks like it is local to that file. So
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
On 22/3/21 7:45 pm, Christian MAUDERER wrote: > Hello Chris, > > Am 19.03.21 um 02:11 schrieb Chris Johns: >> On 3/3/21 7:41 pm, Christian MAUDERER wrote: >>> Hello Chris, >>> >>> Am 03.03.21 um 02:17 schrieb Chris Johns: On 2/3/21 7:26 pm, Christian MAUDERER wrote: > Hello Chris, > > Am 02.03.21 um 01:03 schrieb Chris Johns: >> On 1/3/21 7:24 pm, Christian MAUDERER wrote: >>> Hello Chris, >>> >>> thanks for the review. >>> >>> Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: > Dynamically allocate a big enough file descriptor set for select(). A > better solution would be to use kqueue() instead of select(). > --- > .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- > ipsec-tools/src/racoon/session.c | 40 > +++ > 2 files changed, 43 insertions(+), 3 deletions(-) > > diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > index b869a1518..196107a35 100644 > --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > @@ -2,11 +2,11 @@ > #include > #include "rtems-bsd-racoon-data.h" > /* session.c */ > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set > active_mask); > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set > preset_mask); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set > *allocated_active_mask); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set > *allocated_preset_mask); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int > signals[]); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t > volatile > volatile sigreq[]); > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor > fd_monitors[]); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor > *allocated_fd_monitors); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct > fd_monitor_list > fd_monitor_tree[]); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched > scflushsa); > diff --git a/ipsec-tools/src/racoon/session.c > b/ipsec-tools/src/racoon/session.c > index 65124c15e..90120c761 100644 > --- a/ipsec-tools/src/racoon/session.c > +++ b/ipsec-tools/src/racoon/session.c > @@ -65,6 +65,10 @@ > #include > #include > #include > +#ifdef __rtems__ > +#include > +#include > +#endif /* __rtems__ */ > #include > #include > @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); > static void check_flushsa __P((void)); > static int close_sockets __P((void)); > +#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; > @@ -134,7 +146,11 @@ static struct sched scflushsa = > SCHED_INITIALIZER(); > 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 +174,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
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
Hello Chris, Am 19.03.21 um 02:11 schrieb Chris Johns: On 3/3/21 7:41 pm, Christian MAUDERER wrote: Hello Chris, Am 03.03.21 um 02:17 schrieb Chris Johns: On 2/3/21 7:26 pm, Christian MAUDERER wrote: Hello Chris, Am 02.03.21 um 01:03 schrieb Chris Johns: On 1/3/21 7:24 pm, Christian MAUDERER wrote: Hello Chris, thanks for the review. Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: Dynamically allocate a big enough file descriptor set for select(). A better solution would be to use kqueue() instead of select(). --- .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- ipsec-tools/src/racoon/session.c | 40 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h index b869a1518..196107a35 100644 --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h @@ -2,11 +2,11 @@ #include #include "rtems-bsd-racoon-data.h" /* session.c */ -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_active_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_preset_mask); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor fd_monitors[]); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c index 65124c15e..90120c761 100644 --- a/ipsec-tools/src/racoon/session.c +++ b/ipsec-tools/src/racoon/session.c @@ -65,6 +65,10 @@ #include #include #include +#ifdef __rtems__ +#include +#include +#endif /* __rtems__ */ #include #include @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); static void check_flushsa __P((void)); static int close_sockets __P((void)); +#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; @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); 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 +174,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); } @@ -186,7 +206,22 @@ session(void) struct fd_monitor *fdm; nfds = 0; +#ifndef __rtems__ FD_ZERO(_mask); +#else /* __rtems__ */ + allocated_preset_mask = calloc(sizeof(fd_set), + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? To be honest: I'm not sure. According to the comment in file.h: extern int maxfiles; /* kernel limit on number of open files */ Yes. Sounds like it _can_ be the same as the maximum file number but doesn't have to. I think we need to have them be the same value. I didn't find where we implement it. It's declared as an extern int maxfiles but I didn't find any definition. I found it only in libbsd in freebsd/sys/kern/uipc_socket.c where it is defined like follows: #define maxfiles rtems_libio_number_iops Ah OK. I knew it had been assigned somewhere and yes it looks like it is local to that file. So question is: Where and how is maxfiles defined? I have provided a value in the rtemsbsd init file as part of the set og globals we need to
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
On 3/3/21 7:41 pm, Christian MAUDERER wrote: > Hello Chris, > > Am 03.03.21 um 02:17 schrieb Chris Johns: >> On 2/3/21 7:26 pm, Christian MAUDERER wrote: >>> Hello Chris, >>> >>> Am 02.03.21 um 01:03 schrieb Chris Johns: On 1/3/21 7:24 pm, Christian MAUDERER wrote: > Hello Chris, > > thanks for the review. > > Am 26.02.21 um 19:04 schrieb Chris Johns: >> On 26/2/21 2:01 am, Christian Mauderer wrote: >>> Dynamically allocate a big enough file descriptor set for select(). A >>> better solution would be to use kqueue() instead of select(). >>> --- >>> .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- >>> ipsec-tools/src/racoon/session.c | 40 >>> +++ >>> 2 files changed, 43 insertions(+), 3 deletions(-) >>> >>> diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> index b869a1518..196107a35 100644 >>> --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> @@ -2,11 +2,11 @@ >>> #include >>> #include "rtems-bsd-racoon-data.h" >>> /* session.c */ >>> -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); >>> -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); >>> +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set >>> *allocated_active_mask); >>> +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set >>> *allocated_preset_mask); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t >>> volatile >>> volatile sigreq[]); >>> -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor >>> fd_monitors[]); >>> +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor >>> *allocated_fd_monitors); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct >>> fd_monitor_list >>> fd_monitor_tree[]); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched >>> scflushsa); >>> diff --git a/ipsec-tools/src/racoon/session.c >>> b/ipsec-tools/src/racoon/session.c >>> index 65124c15e..90120c761 100644 >>> --- a/ipsec-tools/src/racoon/session.c >>> +++ b/ipsec-tools/src/racoon/session.c >>> @@ -65,6 +65,10 @@ >>> #include >>> #include >>> #include >>> +#ifdef __rtems__ >>> +#include >>> +#include >>> +#endif /* __rtems__ */ >>> #include >>> #include >>> @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); >>> static void check_flushsa __P((void)); >>> static int close_sockets __P((void)); >>> +#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; >>> @@ -134,7 +146,11 @@ static struct sched scflushsa = >>> SCHED_INITIALIZER(); >>> 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 +174,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); >>> } >>> @@ -186,7 +206,22 @@ session(void) >>> struct fd_monitor *fdm; >>> nfds = 0; >>> +#ifndef __rtems__ >>> FD_ZERO(_mask); >>> +#else /* __rtems__ */ >>> + allocated_preset_mask = calloc(sizeof(fd_set), >>> + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); >>
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
Hello Chris, Am 03.03.21 um 02:17 schrieb Chris Johns: On 2/3/21 7:26 pm, Christian MAUDERER wrote: Hello Chris, Am 02.03.21 um 01:03 schrieb Chris Johns: On 1/3/21 7:24 pm, Christian MAUDERER wrote: Hello Chris, thanks for the review. Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: Dynamically allocate a big enough file descriptor set for select(). A better solution would be to use kqueue() instead of select(). --- .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- ipsec-tools/src/racoon/session.c | 40 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h index b869a1518..196107a35 100644 --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h @@ -2,11 +2,11 @@ #include #include "rtems-bsd-racoon-data.h" /* session.c */ -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_active_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_preset_mask); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor fd_monitors[]); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c index 65124c15e..90120c761 100644 --- a/ipsec-tools/src/racoon/session.c +++ b/ipsec-tools/src/racoon/session.c @@ -65,6 +65,10 @@ #include #include #include +#ifdef __rtems__ +#include +#include +#endif /* __rtems__ */ #include #include @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); static void check_flushsa __P((void)); static int close_sockets __P((void)); +#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; @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); 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 +174,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); } @@ -186,7 +206,22 @@ session(void) struct fd_monitor *fdm; nfds = 0; +#ifndef __rtems__ FD_ZERO(_mask); +#else /* __rtems__ */ + allocated_preset_mask = calloc(sizeof(fd_set), + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? To be honest: I'm not sure. According to the comment in file.h: extern int maxfiles; /* kernel limit on number of open files */ Yes. Sounds like it _can_ be the same as the maximum file number but doesn't have to. I think we need to have them be the same value. I didn't find where we implement it. It's declared as an extern int maxfiles but I didn't find any definition. I found it only in libbsd in freebsd/sys/kern/uipc_socket.c where it is defined like follows: #define maxfiles rtems_libio_number_iops Ah OK. I knew it had been assigned somewhere and yes it looks like it is local to that file. So question is: Where and how is maxfiles defined? I have provided a value in the rtemsbsd init file as part of the set og globals we need to maintained. Somehow I missed that. Where can I find it? Again sorry, I was in a rush and I was not clear. I have add this in my new changes for
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
On 2/3/21 7:26 pm, Christian MAUDERER wrote: > Hello Chris, > > Am 02.03.21 um 01:03 schrieb Chris Johns: >> On 1/3/21 7:24 pm, Christian MAUDERER wrote: >>> Hello Chris, >>> >>> thanks for the review. >>> >>> Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: > Dynamically allocate a big enough file descriptor set for select(). A > better solution would be to use kqueue() instead of select(). > --- > .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- > ipsec-tools/src/racoon/session.c | 40 +++ > 2 files changed, 43 insertions(+), 3 deletions(-) > > diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > index b869a1518..196107a35 100644 > --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > @@ -2,11 +2,11 @@ > #include > #include "rtems-bsd-racoon-data.h" > /* session.c */ > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set > *allocated_active_mask); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set > *allocated_preset_mask); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t > volatile > volatile sigreq[]); > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor > fd_monitors[]); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor > *allocated_fd_monitors); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct > fd_monitor_list > fd_monitor_tree[]); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched > scflushsa); > diff --git a/ipsec-tools/src/racoon/session.c > b/ipsec-tools/src/racoon/session.c > index 65124c15e..90120c761 100644 > --- a/ipsec-tools/src/racoon/session.c > +++ b/ipsec-tools/src/racoon/session.c > @@ -65,6 +65,10 @@ > #include > #include > #include > +#ifdef __rtems__ > +#include > +#include > +#endif /* __rtems__ */ > #include > #include > @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); > static void check_flushsa __P((void)); > static int close_sockets __P((void)); > +#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; > @@ -134,7 +146,11 @@ static struct sched scflushsa = > SCHED_INITIALIZER(); > 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 +174,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); > } > @@ -186,7 +206,22 @@ session(void) > struct fd_monitor *fdm; > nfds = 0; > +#ifndef __rtems__ > FD_ZERO(_mask); > +#else /* __rtems__ */ > + allocated_preset_mask = calloc(sizeof(fd_set), > + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? >>> >>> To be honest: I'm not sure. >>> >>> According to the comment in file.h: >>> >>> extern int maxfiles; /* kernel limit on number of open files */ >>> >> >> Yes. >> >>> Sounds like it _can_ be the same as the maximum file number but doesn't >>> have to. >> >> I think we need to have them be the same value. >> >>> I didn't find where we implement it.
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
Hello Chris, Am 02.03.21 um 01:03 schrieb Chris Johns: On 1/3/21 7:24 pm, Christian MAUDERER wrote: Hello Chris, thanks for the review. Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: Dynamically allocate a big enough file descriptor set for select(). A better solution would be to use kqueue() instead of select(). --- .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- ipsec-tools/src/racoon/session.c | 40 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h index b869a1518..196107a35 100644 --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h @@ -2,11 +2,11 @@ #include #include "rtems-bsd-racoon-data.h" /* session.c */ -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_active_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_preset_mask); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor fd_monitors[]); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c index 65124c15e..90120c761 100644 --- a/ipsec-tools/src/racoon/session.c +++ b/ipsec-tools/src/racoon/session.c @@ -65,6 +65,10 @@ #include #include #include +#ifdef __rtems__ +#include +#include +#endif /* __rtems__ */ #include #include @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); static void check_flushsa __P((void)); static int close_sockets __P((void)); +#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; @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); 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 +174,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); } @@ -186,7 +206,22 @@ session(void) struct fd_monitor *fdm; nfds = 0; +#ifndef __rtems__ FD_ZERO(_mask); +#else /* __rtems__ */ + allocated_preset_mask = calloc(sizeof(fd_set), + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? To be honest: I'm not sure. According to the comment in file.h: extern int maxfiles; /* kernel limit on number of open files */ Yes. Sounds like it _can_ be the same as the maximum file number but doesn't have to. I think we need to have them be the same value. I didn't find where we implement it. It's declared as an extern int maxfiles but I didn't find any definition. I found it only in libbsd in freebsd/sys/kern/uipc_socket.c where it is defined like follows: #define maxfiles rtems_libio_number_iops Ah OK. I knew it had been assigned somewhere and yes it looks like it is local to that file. So question is: Where and how is maxfiles defined? I have provided a value in the rtemsbsd init file as part of the set og globals we need to maintained. Somehow I missed that. Where can I find it? + 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
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
On 1/3/21 7:24 pm, Christian MAUDERER wrote: > Hello Chris, > > thanks for the review. > > Am 26.02.21 um 19:04 schrieb Chris Johns: >> On 26/2/21 2:01 am, Christian Mauderer wrote: >>> Dynamically allocate a big enough file descriptor set for select(). A >>> better solution would be to use kqueue() instead of select(). >>> --- >>> .../racoon/rtems-bsd-racoon-session-data.h | 6 +-- >>> ipsec-tools/src/racoon/session.c | 40 +++ >>> 2 files changed, 43 insertions(+), 3 deletions(-) >>> >>> diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> index b869a1518..196107a35 100644 >>> --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h >>> @@ -2,11 +2,11 @@ >>> #include >>> #include "rtems-bsd-racoon-data.h" >>> /* session.c */ >>> -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); >>> -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); >>> +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set >>> *allocated_active_mask); >>> +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set >>> *allocated_preset_mask); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile >>> volatile sigreq[]); >>> -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor >>> fd_monitors[]); >>> +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor >>> *allocated_fd_monitors); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list >>> fd_monitor_tree[]); >>> RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched >>> scflushsa); >>> diff --git a/ipsec-tools/src/racoon/session.c >>> b/ipsec-tools/src/racoon/session.c >>> index 65124c15e..90120c761 100644 >>> --- a/ipsec-tools/src/racoon/session.c >>> +++ b/ipsec-tools/src/racoon/session.c >>> @@ -65,6 +65,10 @@ >>> #include >>> #include >>> #include >>> +#ifdef __rtems__ >>> +#include >>> +#include >>> +#endif /* __rtems__ */ >>> #include >>> #include >>> @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); >>> static void check_flushsa __P((void)); >>> static int close_sockets __P((void)); >>> +#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; >>> @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); >>> 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 +174,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); >>> } >>> @@ -186,7 +206,22 @@ session(void) >>> struct fd_monitor *fdm; >>> nfds = 0; >>> +#ifndef __rtems__ >>> FD_ZERO(_mask); >>> +#else /* __rtems__ */ >>> + allocated_preset_mask = calloc(sizeof(fd_set), >>> + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); >> >> Does `maxfiles` work here? >> > > To be honest: I'm not sure. > > According to the comment in file.h: > > extern int maxfiles; /* kernel limit on number of open files */ > Yes. > Sounds like it _can_ be the same as the maximum file number but doesn't have > to. I think we need to have them be the same value. > I didn't find where we implement it. It's declared as an extern int maxfiles > but > I didn't find any definition. I found it only in libbsd in > freebsd/sys/kern/uipc_socket.c where it is defined like follows: > > #define maxfiles rtems_libio_number_iops Ah OK. I knew it had been assigned somewhere and yes it looks like it is local to that file. > > So question is: Where and how is maxfiles defined? > I have provided a value in the rtemsbsd init
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
Hello Chris, thanks for the review. Am 26.02.21 um 19:04 schrieb Chris Johns: On 26/2/21 2:01 am, Christian Mauderer wrote: Dynamically allocate a big enough file descriptor set for select(). A better solution would be to use kqueue() instead of select(). --- .../racoon/rtems-bsd-racoon-session-data.h| 6 +-- ipsec-tools/src/racoon/session.c | 40 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h index b869a1518..196107a35 100644 --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h @@ -2,11 +2,11 @@ #include #include "rtems-bsd-racoon-data.h" /* session.c */ -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_active_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_preset_mask); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor fd_monitors[]); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c index 65124c15e..90120c761 100644 --- a/ipsec-tools/src/racoon/session.c +++ b/ipsec-tools/src/racoon/session.c @@ -65,6 +65,10 @@ #include #include #include +#ifdef __rtems__ +#include +#include +#endif /* __rtems__ */ #include #include @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); static void check_flushsa __P((void)); static int close_sockets __P((void)); +#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; @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); 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 +174,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); } @@ -186,7 +206,22 @@ session(void) struct fd_monitor *fdm; nfds = 0; +#ifndef __rtems__ FD_ZERO(_mask); +#else /* __rtems__ */ + allocated_preset_mask = calloc(sizeof(fd_set), + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? To be honest: I'm not sure. According to the comment in file.h: extern int maxfiles; /* kernel limit on number of open files */ Sounds like it _can_ be the same as the maximum file number but doesn't have to. I didn't find where we implement it. It's declared as an extern int maxfiles but I didn't find any definition. I found it only in libbsd in freebsd/sys/kern/uipc_socket.c where it is defined like follows: #define maxfiles rtems_libio_number_iops So question is: Where and how is maxfiles defined? + 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"); At the core of this issue is the rotating fd allocation that we have in libio. A
Re: [PATCH rtems-libbsd 1/2] racoon/session: Honor file descriptor maximum
On 26/2/21 2:01 am, Christian Mauderer wrote: > Dynamically allocate a big enough file descriptor set for select(). A > better solution would be to use kqueue() instead of select(). > --- > .../racoon/rtems-bsd-racoon-session-data.h| 6 +-- > ipsec-tools/src/racoon/session.c | 40 +++ > 2 files changed, 43 insertions(+), 3 deletions(-) > > diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > index b869a1518..196107a35 100644 > --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h > @@ -2,11 +2,11 @@ > #include > #include "rtems-bsd-racoon-data.h" > /* session.c */ > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set > *allocated_active_mask); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set > *allocated_preset_mask); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile > volatile sigreq[]); > -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor > fd_monitors[]); > +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor > *allocated_fd_monitors); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list > fd_monitor_tree[]); > RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); > diff --git a/ipsec-tools/src/racoon/session.c > b/ipsec-tools/src/racoon/session.c > index 65124c15e..90120c761 100644 > --- a/ipsec-tools/src/racoon/session.c > +++ b/ipsec-tools/src/racoon/session.c > @@ -65,6 +65,10 @@ > #include > #include > #include > +#ifdef __rtems__ > +#include > +#include > +#endif /* __rtems__ */ > > #include > #include > @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); > static void check_flushsa __P((void)); > static int close_sockets __P((void)); > > +#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; > > @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); > 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 +174,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); > } > @@ -186,7 +206,22 @@ session(void) > struct fd_monitor *fdm; > > nfds = 0; > +#ifndef __rtems__ > FD_ZERO(_mask); > +#else /* __rtems__ */ > + allocated_preset_mask = calloc(sizeof(fd_set), > + howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); Does `maxfiles` work here? > + 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"); At the core of this issue is the rotating fd allocation that we have in libio. A report from a FreeBSD machine I have is: $ sysctl -a | grep maxfiles kern.maxfiles: 1037243 kern.maxfilesperproc: 933516 I doubt a select process in FreeBSD needs a select array with that many bits. I have added similar code else where but I am wondering if this is really what we want to do. A side effect for us is the stack usage is not bounded and that is a problem. I think our newlib based max setting is too small. FYI I have a major set of changes to
[PATCH rtems-libbsd 1/2] 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(). --- .../racoon/rtems-bsd-racoon-session-data.h| 6 +-- ipsec-tools/src/racoon/session.c | 40 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h index b869a1518..196107a35 100644 --- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h +++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h @@ -2,11 +2,11 @@ #include #include "rtems-bsd-racoon-data.h" /* session.c */ -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set active_mask); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set preset_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_active_mask); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static _types_fd_set *allocated_preset_mask); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]); -RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor fd_monitors[]); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]); RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa); diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c index 65124c15e..90120c761 100644 --- a/ipsec-tools/src/racoon/session.c +++ b/ipsec-tools/src/racoon/session.c @@ -65,6 +65,10 @@ #include #include #include +#ifdef __rtems__ +#include +#include +#endif /* __rtems__ */ #include #include @@ -123,8 +127,16 @@ static void check_sigreq __P((void)); static void check_flushsa __P((void)); static int close_sockets __P((void)); +#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; @@ -134,7 +146,11 @@ static struct sched scflushsa = SCHED_INITIALIZER(); 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 +174,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); } @@ -186,7 +206,22 @@ session(void) struct fd_monitor *fdm; nfds = 0; +#ifndef __rtems__ FD_ZERO(_mask); +#else /* __rtems__ */ + 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(_monitor_tree[i]); @@ -356,6 +391,11 @@ close_session() flushsainfo(); close_sockets(); backupsa_clean(); +#ifdef __rtems__ + free(allocated_preset_mask); allocated_preset_mask = NULL; + free(allocated_active_mask); allocated_active_mask = NULL; + free(allocated_fd_monitors); allocated_fd_monitors = NULL; +#endif /* __rtems__ */ plog(LLV_INFO, LOCATION, NULL, "racoon process %d shutdown\n", getpid()); -- 2.26.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel