conntrackd: factorice tx_queue functions
PATCH 1/4 conntrackd: factorice tx_queue functions
They are shared by both sync-ftfw and sync-notrack.
--- include/Makefile.am | 2 +- include/queue_tx.h | 7 ++++++ src/Makefile.am | 2 +- src/queue_tx.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/sync-ftfw.c | 37 +------------------------------ src/sync-notrack.c | 37 +------------------------------ 6 files changed, 71 insertions(+), 74 deletions(-) create mode 100644 include/queue_tx.h create mode 100644 src/queue_tx.c
include/Makefile.am +1 -1
@@ -6,5 +6,5 @@ noinst_HEADERS = alarm.h jhash.h cache.h linux_list.h linux_rbtree.h \ network.h filter.h queue.h vector.h cidr.h \ traffic_stats.h netlink.h fds.h event.h bitops.h channel.h \ process.h origin.h internal.h external.h date.h nfct.h \ - helper.h myct.h stack.h systemd.h + helper.h myct.h stack.h systemd.h queue_tx.h
include/queue_tx.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _QUEUE_TX_H_ +#define _QUEUE_TX_H_ + +void tx_queue_add_ctlmsg (uint32_t flags,uint32_t from,uint32_t to); +void tx_queue_add_ctlmsg2 (uint32_t flags); + +#endif /* _QUEUE_TX_H_ */
src/Makefile.am +1 -1
@@ -37,7 +37,7 @@ endif nfct_LDFLAGS = -export-dynamic @LAZY_LDFLAGS@ -conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c rbtree.c \ +conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c queue_tx.c rbtree.c \ local.c log.c mcast.c udp.c netlink.c vector.c \ filter.c fds.c event.c process.c origin.c date.c \ cache.c cache-ct.c cache-exp.c \
src/queue_tx.c new file +60 -0
60 lines not on this page · raw message
src/sync-ftfw.c +1 -36
@@ -20,6 +20,7 @@#include "conntrackd.h" #include "sync.h" #include "queue.h" +#include "queue_tx.h" #include "network.h" #include "alarm.h" #include "log.h"
@@ -95,42 +96,6 @@ static void nethdr_set_hello(struct nethdr *net) } } -static void tx_queue_add_ctlmsg (uint32_t flags,uint32_t from,uint32_t to) -{ -struct queue_object *qobj; -struct nethdr_ack *ack; - - qobj =queue_object_new (Q_ELEM_CTL ,sizeof (struct nethdr_ack )); -if (qobj ==NULL ) -return ; - - ack = (struct nethdr_ack *)qobj->data; - ack->type =NET_T_CTL ; - ack->flags = flags; - ack->from = from; - ack->to = to; - -if (queue_add (STATE_SYNC (tx_queue), &qobj->qnode) <0 ) -queue_object_free (qobj); -} - -static void tx_queue_add_ctlmsg2 (uint32_t flags) -{ -struct queue_object *qobj; -struct nethdr *ctl; - - qobj =queue_object_new (Q_ELEM_CTL ,sizeof (struct nethdr_ack )); -if (qobj ==NULL ) -return ; - - ctl = (struct nethdr *)qobj->data; - ctl->type =NET_T_CTL ; - ctl->flags = flags; - -if (queue_add (STATE_SYNC (tx_queue), &qobj->qnode) <0 ) -queue_object_free (qobj); -} -/* this function is called from the alarm framework */ static void do_alive_alarm (struct alarm_block *a,void *data) {
src/sync-notrack.c +1 -36
@@ -20,6 +20,7 @@#include "conntrackd.h" #include "sync.h" #include "queue.h" +#include "queue_tx.h" #include "network.h" #include "log.h" #include "cache.h"
@@ -56,25 +57,6 @@ static struct cache_extra cache_notrack_extra = { .destroy = cache_notrack_del }; -static void tx_queue_add_ctlmsg (uint32_t flags,uint32_t from,uint32_t to) -{ -struct queue_object *qobj; -struct nethdr_ack *ack; - - qobj =queue_object_new (Q_ELEM_CTL ,sizeof (struct nethdr_ack )); -if (qobj ==NULL ) -return ; - - ack = (struct nethdr_ack *)qobj->data; - ack->type =NET_T_CTL ; - ack->flags = flags; - ack->from = from; - ack->to = to; - -if (queue_add (STATE_SYNC (tx_queue), &qobj->qnode) <0 ) -queue_object_free (qobj); -} -static int do_cache_to_tx (void *data1,void *data2) {struct cache_object *obj = data2;
@@ -228,23 +210,6 @@ static void notrack_enqueue(struct cache_object *obj, int query)cache_object_get (obj); } -static void tx_queue_add_ctlmsg2 (uint32_t flags) -{ -struct queue_object *qobj; -struct nethdr *ctl; - - qobj =queue_object_new (Q_ELEM_CTL ,sizeof (struct nethdr_ack )); -if (qobj ==NULL ) -return ; - - ctl = (struct nethdr *)qobj->data; - ctl->type =NET_T_CTL ; - ctl->flags = flags; - -if (queue_add (STATE_SYNC (tx_queue), &qobj->qnode) <0 ) -queue_object_free (qobj); -} -static void do_alive_alarm (struct alarm_block *a,void *data) {tx_queue_add_ctlmsg2 (NET_F_ALIVE );
PATCH 2/4 conntrackd: warn users about queue allocation errors
These warnings, if they happen, should help users.
--- src/channel.c | 6 +++++- src/queue_tx.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
src/channel.c +5 -1
@@ -19,6 +19,7 @@#include "channel.h" #include "network.h" #include "queue.h" +#include "log.h" static struct channel_ops *ops[CHANNEL_MAX ];extern struct channel_ops channel_mcast;
@@ -161,8 +162,11 @@ static void channel_enqueue_errors(struct channel *c)struct channel_error *error; qobj =queue_object_new (Q_ELEM_ERR ,sizeof (struct channel_error )); -if (qobj ==NULL ) +if (qobj ==NULL ) { +dlog (LOG_WARNING ,"could not enqueue channel errors, failed to" +" allocate memory" );return ; + } error = (struct channel_error *)qobj->data; error->len = c->buffer->len;
src/queue_tx.c +9 -2
@@ -22,6 +22,7 @@#include "queue.h" #include "conntrackd.h" #include "network.h" +#include "log.h" void tx_queue_add_ctlmsg (uint32_t flags,uint32_t from,uint32_t to) {
@@ -29,8 +30,11 @@ void tx_queue_add_ctlmsg(uint32_t flags, uint32_t from, uint32_t to)struct nethdr_ack *ack; qobj =queue_object_new (Q_ELEM_CTL ,sizeof (struct nethdr_ack )); -if (qobj ==NULL ) +if (qobj ==NULL ) { +dlog (LOG_WARNING ,"could not queue ACK message. Failed to " +"allocate memory" );return ; + } ack = (struct nethdr_ack *)qobj->data; ack->type =NET_T_CTL ;
@@ -48,8 +52,11 @@ void tx_queue_add_ctlmsg2(uint32_t flags)struct nethdr *ctl; qobj =queue_object_new (Q_ELEM_CTL ,sizeof (struct nethdr_ack )); -if (qobj ==NULL ) +if (qobj ==NULL ) { +dlog (LOG_WARNING ,"could not queue CTL message. Failed to " +"allocate memory" );return ; + } ctl = (struct nethdr *)qobj->data; ctl->type =NET_T_CTL ;
PATCH 3/4 conntrackd: factorize resync operations
In reply to Arturo Borrero GonzalezResync operations factorization. There are two:
* resync_send --> conntrackd -B (send bulk resync)
* resync_req --> conntrackd -n (request resync)
Future patches reuse this factorized code.
--- include/Makefile.am | 2 +- include/resync.h | 7 +++++++ src/Makefile.am | 2 +- src/resync.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/sync-ftfw.c | 10 +++------- src/sync-notrack.c | 14 +++----------- 6 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 include/resync.h create mode 100644 src/resync.c
include/Makefile.am +1 -1
@@ -6,5 +6,5 @@ noinst_HEADERS = alarm.h jhash.h cache.h linux_list.h linux_rbtree.h \ network.h filter.h queue.h vector.h cidr.h \ traffic_stats.h netlink.h fds.h event.h bitops.h channel.h \ process.h origin.h internal.h external.h date.h nfct.h \ - helper.h myct.h stack.h systemd.h queue_tx.h + helper.h myct.h stack.h systemd.h queue_tx.h resync.h
include/resync.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _RESYNC_H_ +#define _RESYNC_H_ + +void resync_req (void ); +void resync_send (int (*do_cache_to_tx)(void *data1,void *data2)); + +#endif /*_RESYNC_H_ */
src/Makefile.am +1 -1
@@ -52,7 +52,7 @@ conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c queue_tx.c rbtree.c \ external_cache.c external_inject.c \ internal_cache.c internal_bypass.c \ read_config_yy.y read_config_lex.l \ - stack.c + stack.c resync.c if HAVE_CTHELPER conntrackd_SOURCES += cthelper.c helpers.c utils.c expect.c
src/resync.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* (C) 2006-2011 by Pablo Neira Ayuso <[email protected]> +* (C) 2011 by Vyatta Inc. <http://www.vyatta.com> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "conntrackd.h" +#include "network.h" +#include "log.h" +#include "queue_tx.h" +#include "resync.h" +#include "cache.h" + +void resync_req (void ) +{ +dlog (LOG_NOTICE ,"resync requested" ); +tx_queue_add_ctlmsg (NET_F_RESYNC ,0 ,0 ); +} + +void resync_send (int (*do_cache_to_tx)(void *data1,void *data2)) +{ +dlog (LOG_NOTICE ,"sending bulk update" ); +cache_iterate (STATE (mode)->internal->ct.data, +NULL , do_cache_to_tx); +cache_iterate (STATE (mode)->internal->exp.data, +NULL , do_cache_to_tx); +}
src/sync-ftfw.c +3 -7
@@ -26,6 +26,7 @@#include "log.h" #include "cache.h" #include "fds.h" +#include "resync.h" #include <string.h> #include <errno.h>
@@ -189,15 +190,10 @@ static int ftfw_local(int fd, int type, void *data)switch (type) {case REQUEST_DUMP : -dlog (LOG_NOTICE ,"request resync" ); -tx_queue_add_ctlmsg (NET_F_RESYNC ,0 ,0 ); +resync_req ();break ;case SEND_BULK : -dlog (LOG_NOTICE ,"sending bulk update" ); -cache_iterate (STATE (mode)->internal->ct.data, -NULL , do_cache_to_tx); -cache_iterate (STATE (mode)->internal->exp.data, -NULL , do_cache_to_tx); +resync_send (do_cache_to_tx);break ;case STATS_RSQUEUE :ftfw_local_queue (fd);
src/sync-notrack.c +3 -11
@@ -25,6 +25,7 @@#include "log.h" #include "cache.h" #include "fds.h" +#include "resync.h" #include <string.h>
@@ -103,19 +104,10 @@ static int notrack_local(int fd, int type, void *data)switch (type) {case REQUEST_DUMP : -dlog (LOG_NOTICE ,"request resync" ); -tx_queue_add_ctlmsg (NET_F_RESYNC ,0 ,0 ); +resync_req ();break ;case SEND_BULK : -dlog (LOG_NOTICE ,"sending bulk update" ); -if (CONFIG (sync).internal_cache_disable) { -kernel_resync (); - }else { -cache_iterate (STATE (mode)->internal->ct.data, -NULL , do_cache_to_tx); -cache_iterate (STATE (mode)->internal->exp.data, -NULL , do_cache_to_tx); - } +resync_send (do_cache_to_tx);break ;default : ret =0 ;
PATCH 4/4 conntrackd: introduce RequestResync option
In reply to Arturo Borrero GonzalezIn some environments where both nodes of a cluster share all the conntracks, after an initial or manual resync, the conntrack information diverges from node to node.
I have observed that this is not due to syncronization problems, given the link between the nodes is very stable and stats show no issues. So, this could be due to every node of the cluster seing slighly different traffic and flow updates, perhaps different tiemouts being applied to the conntracks in every node.
A manual resync (using conntrackd -n) resolves these issues inmediately.
This new configuration option tells conntrackd to request a resync with the other node, similar to what could happen manually using the 'conntrackd -n' command.
By now this option is only valid in NOTRACK sync mode.
Example configuration:
[...]
Sync {
Mode NOTRACK {
DisableInternalCache on
DisableExternalCache on
RequestResync 30
}
TCP {
IPv4_address 127.0.0.1
IPv4_Destination_Address 127.0.0.1
Port 3780
Interface eth0
SndSocketBuffer 1249280
RcvSocketBuffer 1249280
Checksum on
}
Options {
TCPWindowTracking Off
ExpectationSync On
}
}[...]
--- conntrackd.conf.5 | 9 +++++++++ include/conntrackd.h | 1 + include/resync.h | 1 + src/read_config_lex.l | 1 + src/read_config_yy.y | 8 +++++++- src/resync.c | 21 +++++++++++++++++++++ src/run.c | 3 +++ 7 files changed, 43 insertions(+), 1 deletion(-)
conntrackd.conf.5 +9 -0
@@ -195,6 +195,15 @@ messages are directly sent through the dedicated link. This option is set off by default. .TP +.BI "RequestResync <seconds>" +Request the other node a complete resync. This should help resolve +synchronization more easily if they happen in your environment. + +Example: RequestResync 60 + +This option is set off by default. + +.TP .BI "DisableExternalCache <on|off>" Same as in \fBFTFW\fP mode.
include/conntrackd.h +1 -0
@@ -111,6 +111,7 @@ struct ct_conf {int event_iterations_limit;int systemd;int running_mode; +int request_resync;struct {int error_queue_length; } channelc;
include/resync.h +1 -0
@@ -3,5 +3,6 @@void resync_req (void );void resync_send (int (*do_cache_to_tx)(void *data1,void *data2)); +void resync_run_init (void );#endif /*_RESYNC_H_ */
src/read_config_lex.l +1 -0
@@ -136,6 +136,7 @@ notrack [N|n][O|o][T|t][R|r][A|a][C|c][K|k] "ExpectMax" { return T_HELPER_EXPECT_MAX; } "ExpectTimeout" { return T_HELPER_EXPECT_TIMEOUT; } "Systemd" { return T_SYSTEMD; } +"RequestResync" { return T_REQUEST_RESYNC; } {is_on} { return T_ON; } {is_off} { return T_OFF; }
src/read_config_yy.y +7 -1
@@ -81,7 +81,7 @@ enum { %token T_OPTIONS T_TCP_WINDOW_TRACKING T_EXPECT_SYNC %token T_HELPER T_HELPER_QUEUE_NUM T_HELPER_QUEUE_LEN T_HELPER_POLICY %token T_HELPER_EXPECT_TIMEOUT T_HELPER_EXPECT_MAX -%token T_SYSTEMD +%token T_SYSTEMD T_REQUEST_RESYNC %token <string> T_IP T_PATH_VAL %token <val> T_NUMBER
@@ -777,6 +777,7 @@ sync_mode_notrack_line: timeout | purge | disable_internal_cache | disable_external_cache + | request_resync ; disable_internal_cache: T_DISABLE_INTERNAL_CACHE T_ON
@@ -804,6 +805,11 @@ resend_queue_size: T_RESEND_QUEUE_SIZE T_NUMBER conf.resend_queue_size = $2; }; +request_resync: T_REQUEST_RESYNC T_NUMBER +{ + conf.request_resync = $2; +}; + window_size: T_WINDOWSIZE T_NUMBER { conf.window_size = $2;
src/resync.c +21 -0
@@ -23,6 +23,9 @@#include "queue_tx.h" #include "resync.h" #include "cache.h" +#include "alarm.h" + +static struct alarm_block resync_run_alarm;void resync_req (void ) {
@@ -38,3 +41,21 @@ void resync_send(int (*do_cache_to_tx)(void *data1, void *data2))cache_iterate (STATE (mode)->internal->exp.data,NULL , do_cache_to_tx); } + +static void resync_run (struct alarm_block *a,void *data) +{ +resync_req (); +add_alarm (&resync_run_alarm,CONFIG (request_resync),0 ); +} + +void resync_run_init (void ) +{ +if (CONFIG (request_resync) ==0 ) +return ; + +dlog (LOG_NOTICE ,"setting up atomatic resync requests every %d " +"seconds" ,CONFIG (request_resync)); + +init_alarm (&resync_run_alarm,NULL , resync_run); +add_alarm (&resync_run_alarm,CONFIG (request_resync),0 ); +}
src/run.c +3 -0
@@ -31,6 +31,7 @@#include "date.h" #include "internal.h" #include "systemd.h" +#include "resync.h" #include <errno.h> #include <signal.h>
@@ -284,6 +285,8 @@ init(void)#endif time (&STATE (stats).daemon_start_time); +resync_run_init (); +dlog (LOG_NOTICE ,"initialization completed" );return 0 ;