Re: [PATCH] BUILD/MEDIUM defer-accept flag support for FreeBSD proposal
Cheers ! On Sat, 13 Feb 2021 at 08:06, Willy Tarreau wrote: > > On Fri, Feb 12, 2021 at 06:58:59AM +, David CARLIER wrote: > > Hi hope this little patch will find its use. > > Thank you David, I've slightly adjusted it so that it's only enabled > when TCP_DEFER_ACCEPT is not defined. I'm pretty sure I've met > SO_ACCEPTFILTER in the past but don't remember where, and I'd definitely > not want to break the build on it or make it fail on startup when > TCP_DEFER_ACCEPT was already done. > > Thanks! > Willy
Re: [PATCH] BUILD/MEDIUM defer-accept flag support for FreeBSD proposal
On Fri, Feb 12, 2021 at 06:58:59AM +, David CARLIER wrote: > Hi hope this little patch will find its use. Thank you David, I've slightly adjusted it so that it's only enabled when TCP_DEFER_ACCEPT is not defined. I'm pretty sure I've met SO_ACCEPTFILTER in the past but don't remember where, and I'd definitely not want to break the build on it or make it fail on startup when TCP_DEFER_ACCEPT was already done. Thanks! Willy
[PATCH] BUILD/MEDIUM defer-accept flag support for FreeBSD proposal
Hi hope this little patch will find its use. Thanks. Regards. From 02dc058b4f0f41ad1deeb581653e1c3cfb2b2432 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 6 Feb 2021 12:11:11 + Subject: [PATCH] BUILD/MEDIUM: proto_tcp defer-accept flag support for FreeBSD. FreeBSD has a kernel feature (accf) and a sockopt flag similar to the Linux's TCP_DEFER_ACCEPT to filter incoming data upon ACK. The main difference is the filter needs to be placed when the socket actually listens. --- src/cfgparse-tcp.c | 4 ++-- src/proto_tcp.c| 12 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cfgparse-tcp.c b/src/cfgparse-tcp.c index 4dc39d547..e7868e6bf 100644 --- a/src/cfgparse-tcp.c +++ b/src/cfgparse-tcp.c @@ -61,7 +61,7 @@ static int bind_parse_transparent(char **args, int cur_arg, struct proxy *px, st } #endif -#ifdef TCP_DEFER_ACCEPT +#if defined(TCP_DEFER_ACCEPT) || defined(SO_ACCEPTFILTER) /* parse the "defer-accept" bind keyword */ static int bind_parse_defer_accept(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) { @@ -243,7 +243,7 @@ static int srv_parse_tcp_ut(char **args, int *cur_arg, struct proxy *px, struct * not enabled. */ static struct bind_kw_list bind_kws = { "TCP", { }, { -#ifdef TCP_DEFER_ACCEPT +#if defined(TCP_DEFER_ACCEPT) || defined(SO_ACCEPTFILTER) { "defer-accept", bind_parse_defer_accept, 0 }, /* wait for some data for 1 second max before doing accept */ #endif #ifdef SO_BINDTODEVICE diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 485603d57..85cd56360 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -711,6 +711,18 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) goto tcp_close_return; } +#if defined(SO_ACCEPTFILTER) + /* the socket needs to listen first */ + if (listener->options & LI_O_DEF_ACCEPT) { + struct accept_filter_arg accept; + memset(, 0, sizeof(accept)); + strcpy(accept.af_name, "dataready"); + if (setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, , sizeof(accept)) == -1) { + msg = "cannot enable ACCEPT_FILTER"; + err |= ERR_WARN; + } + } +#endif #if defined(TCP_QUICKACK) if (listener->options & LI_O_NOQUICKACK) setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, , sizeof(zero)); -- 2.30.0
[PATCH] BUILD/MEDIUM defer-accept flag support for FreeBSD proposal
Hi hope this little patch will find its use. Thanks. Regards. From 02dc058b4f0f41ad1deeb581653e1c3cfb2b2432 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 6 Feb 2021 12:11:11 + Subject: [PATCH] BUILD/MEDIUM: proto_tcp defer-accept flag support for FreeBSD. FreeBSD has a kernel feature (accf) and a sockopt flag similar to the Linux's TCP_DEFER_ACCEPT to filter incoming data upon ACK. The main difference is the filter needs to be placed when the socket actually listens. --- src/cfgparse-tcp.c | 4 ++-- src/proto_tcp.c| 12 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cfgparse-tcp.c b/src/cfgparse-tcp.c index 4dc39d547..e7868e6bf 100644 --- a/src/cfgparse-tcp.c +++ b/src/cfgparse-tcp.c @@ -61,7 +61,7 @@ static int bind_parse_transparent(char **args, int cur_arg, struct proxy *px, st } #endif -#ifdef TCP_DEFER_ACCEPT +#if defined(TCP_DEFER_ACCEPT) || defined(SO_ACCEPTFILTER) /* parse the "defer-accept" bind keyword */ static int bind_parse_defer_accept(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) { @@ -243,7 +243,7 @@ static int srv_parse_tcp_ut(char **args, int *cur_arg, struct proxy *px, struct * not enabled. */ static struct bind_kw_list bind_kws = { "TCP", { }, { -#ifdef TCP_DEFER_ACCEPT +#if defined(TCP_DEFER_ACCEPT) || defined(SO_ACCEPTFILTER) { "defer-accept", bind_parse_defer_accept, 0 }, /* wait for some data for 1 second max before doing accept */ #endif #ifdef SO_BINDTODEVICE diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 485603d57..85cd56360 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -711,6 +711,18 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) goto tcp_close_return; } +#if defined(SO_ACCEPTFILTER) + /* the socket needs to listen first */ + if (listener->options & LI_O_DEF_ACCEPT) { + struct accept_filter_arg accept; + memset(, 0, sizeof(accept)); + strcpy(accept.af_name, "dataready"); + if (setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, , sizeof(accept)) == -1) { + msg = "cannot enable ACCEPT_FILTER"; + err |= ERR_WARN; + } + } +#endif #if defined(TCP_QUICKACK) if (listener->options & LI_O_NOQUICKACK) setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, , sizeof(zero)); -- 2.30.0