conntrackd: evaluate configuration earlier
PATCH 1/4 conntrackd: evaluate configuration earlier
Run the evaluation step sooner in the conntrackd startup routine. Don't close log or unlink lockfile at this stage.
--- src/main.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
src/main.c +9 -11
@@ -338,6 +338,15 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } +/* +* Evaluate configuration +*/ +if (evaluate () ==-1 ) { +dlog (LOG_ERR ,"conntrackd cannot start, please review your " +"configuration" ); +exit (EXIT_FAILURE ); + } +if (type ==REQUEST ) {if (do_local_request (action, &conf.local, local_step) ==-1 ) { dlog(LOG_ERR, "can't connect: is conntrackd "
@@ -383,17 +392,6 @@ int main(int argc, char *argv[]) }/* -* Evaluate configuration -*/ -if (evaluate () ==-1 ) { -dlog (LOG_ERR ,"conntrackd cannot start, please review your " -"configuration" ); -close_log (); -unlink (CONFIG (lockfile)); -exit (EXIT_FAILURE ); - } - -/* * initialization process */
PATCH 2/4 conntrackd: make the daemon run in RT mode by default
In order to prevent netlink buffer overrun, conntrackd is recommended to run at max priority.
Make conntrackd to use a RT (SHED_RR) scheduler by default at max priority. This is common among other HA daemons. For example corosync uses SCHED_RR by default.
This change should help ease the configuration of conntrackd.
Note that a sched priority that high makes the nice value useless, so deprecate both options now.
The code is moved to the init() routine. In case of error setting the scheduler, the system default will be used. Report a message to the user and continue working.
--- conntrackd.conf.5 | 46 +++----------------------------------- doc/helper/conntrackd.conf | 21 ----------------- doc/stats/conntrackd.conf | 19 ---------------- doc/sync/alarm/conntrackd.conf | 21 ----------------- doc/sync/ftfw/conntrackd.conf | 21 ----------------- doc/sync/notrack/conntrackd.conf | 21 ----------------- include/conntrackd.h | 5 ---- src/main.c | 28 ----------------------- src/read_config_yy.y | 21 +++++------------ src/run.c | 18 +++++++++++++++ 10 files changed, 28 insertions(+), 193 deletions(-)
conntrackd.conf.5 +4 -42
@@ -480,14 +480,8 @@ By default runtime support is disabled. .TP .BI "Nice <value>" -Set the \fBnice(1)\fP value of the daemon, this value goes from -20 (most -favorable scheduling) to 19 (least favorable). Using a very low value reduces -the chances to lose state-change events. - -Example: Nice -20 - -Default is 0 but this example sets it to most favourable scheduling as -this is generally a good idea. +Deprecated. This option will be removed in the future. +Conntrackd now uses by default a RT scheduler. .TP .BI "HashSize <value>"
@@ -731,29 +725,8 @@ Example: .fi .SS SCHEDULER -Select a different scheduler for the daemon, you can select between \fBRR\fP -and \fBFIFO\fP and the process priority. - -See \fBsched_setscheduler(2)\fP for more information. Using a RT scheduler -reduces the chances to overrun the Netlink buffer. - -Example: -.nf - Scheduler { - Type FIFO - Priority 99 - } -.fi - -.TP -.BI "Type <type>" -Supported values are \fBRR\fP or \fBFIFO\fP. - -.TP -.BI "Priority <value>" -Value of the scheduler priority. - -Minimum is 0, maximum is 99. +Deprecated. This section will be removed in the future. +Conntrackd now uses by default a RT scheduler. .SH STATS This top-level section indicates \fBconntrackd(8)\fP to work as a statistic
@@ -907,7 +880,6 @@ Stats { } General { Systemd on - Nice -1 HashSize 8192 HashLimit 65535 Syslog on
@@ -973,11 +945,6 @@ Sync { } General { Systemd on - Nice -20 - Scheduler { - Type FIFO - Priority 99 - } HashSize 32768 HashLimit 131072 LogFile on
@@ -1036,11 +1003,6 @@ Sync { } General { Systemd on - Nice -20 - Scheduler { - Type FIFO - Priority 99 - } HashSize 32768 HashLimit 131072 LogFile on
doc/helper/conntrackd.conf +0 -21
@@ -103,27 +103,6 @@ Helper { # General { # - # Set the nice value of the daemon, this value goes from -20 - # (most favorable scheduling) to 19 (least favorable). Using a - # very low value reduces the chances to lose state-change events. - # Default is 0 but this example file sets it to most favourable - # scheduling as this is generally a good idea. See man nice(1) for - # more information. - # - Nice -20 - - # - # Select a different scheduler for the daemon, you can select between - # RR and FIFO and the process priority (minimum is 0, maximum is 99). - # See man sched_setscheduler(2) for more information. Using a RT - # scheduler reduces the chances to overrun the Netlink buffer. - # - # Scheduler { - # Type FIFO - # Priority 99 - # } - - # # Logfile: on (/var/log/conntrackd.log), off, or a filename # Default: off #
doc/stats/conntrackd.conf +0 -19
@@ -11,25 +11,6 @@ General { #Systemd on # - # Set the nice value of the daemon. This value goes from -20 - # (most favorable scheduling) to 19 (least favorable). Using a - # negative value reduces the chances to lose state-change events. - # Default is 0. See man nice(1) for more information. - # - Nice -1 - - # - # Select a different scheduler for the daemon, you can select between - # RR and FIFO and the process priority (minimum is 0, maximum is 99). - # See man sched_setscheduler(2) for more information. Using a RT - # scheduler reduces the chances to overrun the Netlink buffer. - # - # Scheduler { - # Type FIFO - # Priority 99 - # } - - # # Number of buckets in the caches: hash table # HashSize 8192
doc/sync/alarm/conntrackd.conf +0 -21
@@ -226,27 +226,6 @@ General { #Systemd on # - # Set the nice value of the daemon, this value goes from -20 - # (most favorable scheduling) to 19 (least favorable). Using a - # very low value reduces the chances to lose state-change events. - # Default is 0 but this example file sets it to most favourable - # scheduling as this is generally a good idea. See man nice(1) for - # more information. - # - Nice -20 - - # - # Select a different scheduler for the daemon, you can select between - # RR and FIFO and the process priority (minimum is 0, maximum is 99). - # See man sched_setscheduler(2) for more information. Using a RT - # scheduler reduces the chances to overrun the Netlink buffer. - # - # Scheduler { - # Type FIFO - # Priority 99 - # } - - # # Number of buckets in the cache hashtable. The bigger it is, # the closer it gets to O(1) at the cost of consuming more memory. # Read some documents about tuning hashtables for further reference.
doc/sync/ftfw/conntrackd.conf +0 -21
@@ -249,27 +249,6 @@ General { #Systemd on # - # Set the nice value of the daemon, this value goes from -20 - # (most favorable scheduling) to 19 (least favorable). Using a - # very low value reduces the chances to lose state-change events. - # Default is 0 but this example file sets it to most favourable - # scheduling as this is generally a good idea. See man nice(1) for - # more information. - # - Nice -20 - - # - # Select a different scheduler for the daemon, you can select between - # RR and FIFO and the process priority (minimum is 0, maximum is 99). - # See man sched_setscheduler(2) for more information. Using a RT - # scheduler reduces the chances to overrun the Netlink buffer. - # - # Scheduler { - # Type FIFO - # Priority 99 - # } - - # # Number of buckets in the cache hashtable. The bigger it is, # the closer it gets to O(1) at the cost of consuming more memory. # Read some documents about tuning hashtables for further reference.
doc/sync/notrack/conntrackd.conf +0 -21
@@ -288,27 +288,6 @@ General { #Systemd on # - # Set the nice value of the daemon, this value goes from -20 - # (most favorable scheduling) to 19 (least favorable). Using a - # very low value reduces the chances to lose state-change events. - # Default is 0 but this example file sets it to most favourable - # scheduling as this is generally a good idea. See man nice(1) for - # more information. - # - Nice -20 - - # - # Select a different scheduler for the daemon, you can select between - # RR and FIFO and the process priority (minimum is 0, maximum is 99). - # See man sched_setscheduler(2) for more information. Using a RT - # scheduler reduces the chances to overrun the Netlink buffer. - # - # Scheduler { - # Type FIFO - # Priority 99 - # } - - # # Number of buckets in the cache hashtable. The bigger it is, # the closer it gets to O(1) at the cost of consuming more memory. # Read some documents about tuning hashtables for further reference.
include/conntrackd.h +0 -5
@@ -94,7 +94,6 @@ struct ct_conf {int channel_type_global;struct channel_conf channel[MULTICHANNEL_MAX ];struct local_conf local;/* unix socket facilities */ -int nice;int limit;int refresh;int cache_timeout;/* cache entries timeout */
@@ -129,10 +128,6 @@ struct ct_conf {int commit_steps; } general;struct { -int type; -int prio; - } sched; -struct {char logfile[FILENAME_MAXLEN ];int syslog_facility;size_t buffer_size;
src/main.c +0 -28
@@ -31,7 +31,6 @@#include <string.h> #include <stdlib.h> #include <unistd.h> -#include <sched.h> #include <limits.h> struct ct_general_state st;
@@ -112,15 +111,6 @@ set_action_by_table(int i, int argc, char *argv[], }static void -set_nice_value (int nv) -{ - errno =0 ; -if (nice (nv) ==-1 && errno)/* warn only */ -dlog (LOG_WARNING ,"Cannot set nice level %d: %s" , - nv,strerror (errno)); -} - -static void do_chdir (const char *d) {if (chdir (d))
@@ -374,24 +364,6 @@ int main(int argc, char *argv[])close (ret);/* -* Setting process priority and scheduler -*/ -set_nice_value (CONFIG (nice)); - -if (CONFIG (sched).type !=SCHED_OTHER ) { -struct sched_param schedparam = { - .sched_priority =CONFIG (sched).prio, - }; - - ret =sched_setscheduler (0 ,CONFIG (sched).type, &schedparam); -if (ret ==-1 ) { -dlog (LOG_ERR ,"scheduler configuration failed: %s" , -strerror (errno)); -exit (EXIT_FAILURE ); - } - } - -/* * initialization process */
src/read_config_yy.y +6 -15
@@ -30,7 +30,6 @@ #include "cidr.h" #include "helper.h" #include "stack.h" -#include <sched.h> #include <dlfcn.h> #include <libnetfilter_conntrack/libnetfilter_conntrack.h> #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
@@ -963,7 +962,8 @@ netlink_events_reliable : T_NETLINK_EVENTS_RELIABLE T_OFF nice : T_NICE T_SIGNED_NUMBER { - conf.nice = $2; + dlog(LOG_WARNING, "deprecated nice configuration. " + "Now conntrackd uses RT by default."); }; scheduler : T_SCHEDULER '{' scheduler_options '}';
@@ -974,23 +974,14 @@ scheduler_options : scheduler_line : T_TYPE T_STRING { - if (strcasecmp($2, "rr") == 0) { - conf.sched.type = SCHED_RR; - } else if (strcasecmp($2, "fifo") == 0) { - conf.sched.type = SCHED_FIFO; - } else { - dlog(LOG_ERR, "unknown scheduler `%s'", $2); - exit(EXIT_FAILURE); - } + dlog(LOG_WARNING, "deprecated scheduler configuration. " + "Now conntrackd uses RT by default."); }; scheduler_line : T_PRIO T_NUMBER { - conf.sched.prio = $2; - if (conf.sched.prio < 0 || conf.sched.prio > 99) { - dlog(LOG_ERR, "`Priority' must be [0, 99]\n", $2); - exit(EXIT_FAILURE); - } + dlog(LOG_WARNING, "deprecated scheduler configuration. " + "Now conntrackd uses RT by default."); }; event_iterations_limit : T_EVENT_ITER_LIMIT T_NUMBER
src/run.c +18 -0
@@ -32,6 +32,7 @@#include "internal.h" #include "systemd.h" +#include <sched.h> #include <errno.h> #include <signal.h> #include <stdlib.h>
@@ -234,11 +235,28 @@ int evaluate(void)return 0 ; } + +static void set_scheduler (void ) +{ +int prio =sched_get_priority_max (SCHED_RR ); +struct sched_param schedparam = { + .sched_priority = prio, + }; + +if (sched_setscheduler (0 ,SCHED_RR , &schedparam) <0 ) +dlog (LOG_WARNING ,"scheduler configuration failed: %s. " +"Likely a bug in conntrackd, please report it. " +"Continuing with system default scheduler." , +strerror (errno)); +} +int init (void ) {do_gettimeofday (); +set_scheduler (); +STATE (fds) =create_fds ();if (STATE (fds) ==NULL ) {dlog (LOG_ERR ,"can't create file descriptor pool" );
Pablo Neira Ayuso
maintainerRe: [conntrack-tools PATCH 2/4] conntrackd: make the daemon run in RT mode by default
Hi Arturo,
Quoted 7 lines · Arturo Borrero Gonzalez
In order to prevent netlink buffer overrun, conntrackd is recommended to run at max priority.
Make conntrackd to use a RT (SHED_RR) scheduler by default at max priority. This is common among other HA daemons. For example corosync usesSCHED_RRby default.
This change should help ease the configuration of conntrackd.
Quoted 6 lines
Note that a sched priority that high makes the nice value useless, so deprecate both options now.
The code is moved to the
init()routine. In case of error setting the scheduler, the system default will be used. Report a message to the user and continue working.
I think we should provide a good default if someone doesn't specify anything. So defaulting to RT is fine to me so we converge to what other HA software is doing.
But I think we should keep the Nice and Scheduler clauses. Just in case anyone wants to do this fine grain tunning.
So my proposal is:
1) Remove them from the examples configuration files.
2) Keep these toggles documented in manpage.
3) Provide this default if someone doesn't specify anything.
So the idea is that we provide good defaults.
BTW, an option I would really deprecate is the Checksum, a lot of experimentation was going on at the time I added this (more than 10 years ago), this should really go away since I don't see a usecase for this.
Thanks!
Re: [conntrack-tools PATCH 2/4] conntrackd: make the daemon run in RT mode by default
Quoted 4 lines · Pablo Neira Ayuso
But I think we should keep the Nice and Scheduler clauses. Just in case anyone wants to do this fine grain tunning.
The nice value can be changed at runtime externally: using the nice/renice commands
Perhaps is a bit redundant to have it included in the conntrackd code. Also, nice values are somehow overridden by either SCHED_RR (our default) or SCHED_FIFO.
Not sure if it makes sense to run in RT and then lower priority by means of nice.
I'm tempted to just remove the nice thing in v2, what do you think?
Pablo Neira Ayuso
maintainerRe: [conntrack-tools PATCH 2/4] conntrackd: make the daemon run in RT mode by default
Quoted 14 lines · Arturo Borrero Gonzalez
Quoted 4 lines · Pablo Neira Ayuso
But I think we should keep the Nice and Scheduler clauses. Just in case anyone wants to do this fine grain tunning.
The nice value can be changed at runtime externally: using the nice/renice commands
Perhaps is a bit redundant to have it included in the conntrackd code. Also, nice values are somehow overridden by eitherSCHED_RR(our default) orSCHED_FIFO.
Not sure if it makes sense to run in RT and then lower priority by means of nice.
Quoted 1 line
I'm tempted to just remove the nice thing in v2, what do you think?
Nice and Sched overlap, yes.
So we can just deprecate Nice and still keep Sched around.
Fine with this?
PATCH 3/4 conntrackd: cleanup if failed forking
In reply to Arturo Borrero GonzalezClose the logs and lockfile if error while forking.
--- src/main.c | 2 ++ 1 file changed, 2 insertions(+)
src/main.c +2 -0
@@ -386,6 +386,8 @@ int main(int argc, char *argv[])if ((pid =fork ()) ==-1 ) {dlog (LOG_ERR ,"fork has failed: %s" ,strerror (errno)); +close_log (); +unlink (CONFIG (lockfile));exit (EXIT_FAILURE ); }else if (pid) {sd_ct_mainpid (pid);
Pablo Neira Ayuso
maintainerRe: [conntrack-tools PATCH 3/4] conntrackd: cleanup if failed forking
Quoted 1 line · Arturo Borrero Gonzalez
Close the logs and lockfile if error while forking.
Also applied, thanks.
PATCH 4/4 conntrackd: deprecate unix backlog configuration
In reply to Arturo Borrero GonzalezThis configuration option doesn't add any value to users.
Use the magic value of 100 (i.e, the socket will keep 100 pending connections), which I think is fair enough for what conntrackd can do in the unix socket.
--- conntrackd.conf.5 | 8 +------- doc/helper/conntrackd.conf | 1 - doc/stats/conntrackd.conf | 1 - doc/sync/alarm/conntrackd.conf | 1 - doc/sync/ftfw/conntrackd.conf | 1 - doc/sync/notrack/conntrackd.conf | 1 - include/local.h | 1 - src/local.c | 4 +++- src/read_config_yy.y | 2 +- 9 files changed, 5 insertions(+), 15 deletions(-)
conntrackd.conf.5 +1 -7
@@ -603,7 +603,6 @@ Example: .nf UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } .fi
@@ -615,9 +614,7 @@ Example: Path /var/run/conntrackd.ctl .TP .BI "Backlog <value>" -Number of items in the backlog. - -Example: Backlog 20 +Deprecated option. .SS FILTER Event filtering. This clause allows you to filter certain traffic.
@@ -886,7 +883,6 @@ General { LockFile /var/lock/conntrack.lock UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } NetlinkBufferSize 262142 NetlinkBufferSizeMaxGrowth 655355
@@ -952,7 +948,6 @@ General { LockFile /var/lock/conntrack.lock UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } NetlinkBufferSize 2097152 NetlinkBufferSizeMaxGrowth 8388608
@@ -1010,7 +1005,6 @@ General { LockFile /var/lock/conntrack.lock UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } NetlinkBufferSize 2097152 NetlinkBufferSizeMaxGrowth 8388608
doc/helper/conntrackd.conf +0 -1
@@ -124,6 +124,5 @@ General { # UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } }
doc/stats/conntrackd.conf +0 -1
@@ -43,7 +43,6 @@ General { # UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } #
doc/sync/alarm/conntrackd.conf +0 -1
@@ -262,7 +262,6 @@ General { # UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } #
doc/sync/ftfw/conntrackd.conf +0 -1
@@ -285,7 +285,6 @@ General { # UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } #
doc/sync/notrack/conntrackd.conf +0 -1
@@ -324,7 +324,6 @@ General { # UNIX { Path /var/run/conntrackd.ctl - Backlog 20 } #
include/local.h +0 -1
@@ -6,7 +6,6 @@#endif struct local_conf { -int backlog;int reuseaddr;char path[UNIX_PATH_MAX ]; };
src/local.c +3 -1
@@ -26,6 +26,8 @@#include <arpa/inet.h> #include <sys/un.h> +#define UNIX_SOCKET_BACKLOG 100 +int local_server_create (struct local_server *server,struct local_conf *conf) {int fd;
@@ -53,7 +55,7 @@ int local_server_create(struct local_server *server, struct local_conf *conf)return -1 ; } -if (listen (fd, conf->backlog) ==-1 ) { +if (listen (fd,UNIX_SOCKET_BACKLOG ) ==-1 ) {close (fd);unlink (conf->path);return -1 ;
src/read_config_yy.y +1 -1
@@ -650,7 +650,7 @@ unix_option : T_PATH T_PATH_VAL unix_option : T_BACKLOG T_NUMBER { - conf.local.backlog = $2; + dlog(LOG_WARNING, "deprecated unix backlog configuration."); }; sync: T_SYNC '{' sync_list '}'
Pablo Neira Ayuso
maintainerRe: [conntrack-tools PATCH 4/4] conntrackd: deprecate unix backlog configuration
Quoted 3 lines · Arturo Borrero Gonzalez
This configuration option doesn't add any value to users.
Use the magic value of 100 (i.e, the socket will keep 100 pending connections), which I think is fair enough for what conntrackd can do in the unix socket.
I don't think conntrackd will ever get more than 100 connection that are pending to be accepted.
So I'm fine with this 4/4 patch.
Pablo Neira Ayuso
maintainerRe: [conntrack-tools PATCH 4/4] conntrackd: deprecate unix backlog configuration
Quoted 7 lines · Pablo Neira Ayuso
Quoted 3 lines · Arturo Borrero Gonzalez
This configuration option doesn't add any value to users.
Use the magic value of 100 (i.e, the socket will keep 100 pending connections), which I think is fair enough for what conntrackd can do in the unix socket.I don't think conntrackd will ever get more than 100 connection that are pending to be accepted.
And this only refers to unix socket indeed, really we can deprecate this.
Back to what I said for Nice/Scheduler, I'm not so sure about removing them. Actually I remember this was useful when I was testing long time ago.
Basically what I observed is that RT scheduler + process pinning to spare CPU makes Netlink reliable (no event message loss). And that is good to have in place under high load, otherwise nodes get out of sync.
Pablo Neira Ayuso
maintainerRe: [conntrack-tools PATCH 4/4] conntrackd: deprecate unix backlog configuration
In reply to Arturo Borrero GonzalezQuoted 3 lines · Arturo Borrero Gonzalez
This configuration option doesn't add any value to users.
Use the magic value of 100 (i.e, the socket will keep 100 pending connections), which I think is fair enough for what conntrackd can do in the unix socket.
And this one applied, thanks.
So you only have to sort out patch 3/4.
Quoted 2 lines · Arturo Borrero Gonzalez
Run the evaluation step sooner in the conntrackd startup routine. Don't close log or unlink lockfile at this stage.
Applied, thanks Arturo!