Multi-namespace support (Request for comments)
RFC 1/1 Multi-namespace support (Request for comments)
This patch should not be considered complete! It was sent out with intention to propose feature and receive further comments.
It enables single conntrackd process to synchronize state among multiple namespaces. To test this patch apply it on the top of this one:
http://markmail.org/thread/npxklk4p6g4y3rup
And use following conntrackd.conf on both hosts:
Sync {
Mode NOTRACK {
DisableInternalCache On
DisableExternalCache On
}
UDP {
IPv4_Destination_Address <host[1|2]>
Interface breth0
SndSocketBuffer 1249280
Checksum on
Port 3781
}
}
General {
Nice -20
LogFile on
LockFile /var/lock/conntrack.lock
UNIX {
Path /var/run/conntrackd.ctl
Backlog 20
}
NetlinkBufferSize 2097152
NetlinkBufferSizeMaxGrowth 8388608
}The configuration above is used as template when instantiating the actual configuration for every namespace. Use following commands to do that:
host1: conntrackd -A namespace1 /var/run/netns/namespace1
host1: conntrackd -A namespace2 /var/run/netns/namespace2
host2: conntrackd -A namespace1 /var/run/netns/namespace1
host2: conntrackd -A namespace2 /var/run/netns/namespace2
The first argument is the namespace identifier and second is the path to the actual namespace mount point.
This patch doesn't work correctly yet with:
1. caches
2. FTFW or ALARM modes
3. filters (it seems a little bit tricky to unglobalize it)
4. expectations
5. and it even breaks the current conntrackd usage (it does not create state object for the current namespace)
Currently I am protoyping another patch that will allow to synchronize different namespace subsets between more than two hosts (i.e. each ns_state will reference the right multichannel structure and use it).
--- include/cache.h | 5 +- include/conntrackd.h | 35 +++++- include/external.h | 12 +- include/internal.h | 21 +++- include/local.h | 3 +- include/namespace.h | 2 + include/netlink.h | 2 +- include/network.h | 18 +-- src/build.c | 7 +- src/cache-ct.c | 4 +- src/cache-exp.c | 4 +- src/ctnl.c | 291 ++++++++++++++++++++++++++++++++++--------------- src/external_cache.c | 12 +- src/external_inject.c | 50 ++++----- src/internal_bypass.c | 42 ++++--- src/internal_cache.c | 18 ++- src/local.c | 10 +- src/main.c | 45 +++++++- src/namespace.c | 35 ++++-- src/netlink.c | 5 +- src/parse.c | 19 +++- src/stats-mode.c | 6 +- src/sync-alarm.c | 2 +- src/sync-ftfw.c | 3 +- src/sync-mode.c | 64 ++++++----- src/sync-notrack.c | 5 +- 26 files changed, 495 insertions(+), 225 deletions(-)
include/cache.h +4 -1
@@ -4,6 +4,7 @@#include <stdint.h> #include <stddef.h> #include "hash.h" +#include "conntrackd.h" #include "date.h" /* cache features */
@@ -58,6 +59,7 @@ enum cache_type {struct cache {char name[CACHE_MAX_NAMELEN ]; +char nsid[NAMESPACE_ID_MAXLEN ];enum cache_type type;struct hashtable *h;
@@ -122,7 +124,8 @@ struct cache_ops {int (*commit)(struct cache *c,struct nfct_handle *h,int clientfd);/* build network message from object. */ -struct nethdr *(*build_msg)(const struct cache_object *obj,int type); +struct nethdr *(*build_msg)(const struct cache_object *obj,int type, +const char *nsid); };/* templates to configure conntrack caching. */
include/conntrackd.h +34 -1
@@ -49,6 +49,8 @@#define ALL_COMMIT 46/* commit all tables */ #define EXP_DUMP_INT_XML 47/* dump internal cache in XML */ #define EXP_DUMP_EXT_XML 48/* dump external cache in XML */ +#define ADD_NAMESPACE 49/* add namespace to the config */ +#define DEL_NAMESPACE 50/* add namespace to the config */ #define DEFAULT_CONFIGFILE "/etc/conntrackd/conntrackd.conf"#define DEFAULT_LOCKFILE "/var/lock/conntrackd.lock"
@@ -76,6 +78,8 @@#define FILENAME_MAXLEN 256#endif +#define NAMESPACE_ID_MAXLEN 40 +union inet_address {uint32_t ipv4;uint32_t ipv6[4 ];
@@ -84,6 +88,11 @@ union inet_address {#define CONFIG (x) conf.x +struct ns_conf { +char namespace_id[NAMESPACE_ID_MAXLEN ]; +char netlink_namespace[FILENAME_MAXLEN ]; +}; +struct ct_conf {char logfile[FILENAME_MAXLEN ];int syslog_facility;
@@ -143,6 +152,28 @@ struct ct_conf {#define STATE (x) st.x +struct ns_state { +struct hashtable_node hashnode; + +char nsid[NAMESPACE_ID_MAXLEN ]; +struct { +int cur_fd;/* conntrack */ +int root_fd;/* channel*/ + } ns; +struct nfct_handle *event;/* event handler */ +struct nfct_handle *inject; + +struct nfct_handle *dump;/* dump handler */ +struct nfct_handle *resync;/* resync handler */ +struct nfct_handle *get;/* get handler */ +struct nfct_handle *flush;/* flusher */ + +/* I guess STATE(filter) should be unglobalized here too */ + +struct multichannel *channel; + +}; +struct ct_general_state {sigset_t block;FILE *log;
@@ -157,7 +188,6 @@ struct ct_general_state {int cur_fd;/* conntrack */ int root_fd;/* channel*/ } ns; -struct nfct_handle *event;/* event handler */ struct nfct_filter *filter;/* event filter */ int event_iterations_limit;
@@ -291,6 +321,9 @@ void ctnl_kill(void);int ctnl_local (int fd,int type,void *data);int ctnl_init (void ); +void destroy_state (const char *namespace_id); +void create_state (struct ns_conf ns); +/* basic cthelper functions */ void cthelper_kill (void );int cthelper_local (int fd,int type,void *data);
include/external.h +6 -6
@@ -8,9 +8,9 @@ struct external_handler {void (*close)(void );struct { -void (*new)(struct nf_conntrack *ct); -void (*upd)(struct nf_conntrack *ct); -void (*del)(struct nf_conntrack *ct); +void (*new)(struct nf_conntrack *ct,struct ns_state *ns); +void (*upd)(struct nf_conntrack *ct,struct ns_state *ns); +void (*del)(struct nf_conntrack *ct,struct ns_state *ns);void (*dump)(int fd,int type);void (*flush)(void );
@@ -19,9 +19,9 @@ struct external_handler {void (*stats_ext)(int fd); } ct;struct { -void (*new)(struct nf_expect *exp); -void (*upd)(struct nf_expect *exp); -void (*del)(struct nf_expect *exp); +void (*new)(struct nf_expect *exp,struct ns_state *ns); +void (*upd)(struct nf_expect *exp,struct ns_state *ns); +void (*del)(struct nf_expect *exp,struct ns_state *ns);void (*dump)(int fd,int type);void (*flush)(void );
include/internal.h +15 -6
@@ -3,6 +3,9 @@#include <libnetfilter_conntrack/libnetfilter_conntrack.h> +#include "conntrackd.h" + +struct ns_state ;/* But why do I need this here??*/ struct nf_conntrack ;enum {
@@ -20,9 +23,12 @@ struct internal_handler {struct {void *data; -void (*new)(struct nf_conntrack *ct,int origin_type); -void (*upd)(struct nf_conntrack *ct,int origin_type); -int (*del)(struct nf_conntrack *ct,int origin_type); +void (*new)(struct nf_conntrack *ct,int origin_type, +struct ns_state *s); +void (*upd)(struct nf_conntrack *ct,int origin_type, +struct ns_state *s); +int (*del)(struct nf_conntrack *ct,int origin_type, +struct ns_state *s);void (*dump)(int fd,int type);void (*populate)(struct nf_conntrack *ct);
@@ -37,9 +43,12 @@ struct internal_handler {struct {void *data; -void (*new)(struct nf_expect *exp,int origin_type); -void (*upd)(struct nf_expect *exp,int origin_type); -int (*del)(struct nf_expect *exp,int origin_type); +void (*new)(struct nf_expect *exp,int origin_type, +struct ns_state *s); +void (*upd)(struct nf_expect *exp,int origin_type, +struct ns_state *s); +int (*del)(struct nf_expect *exp,int origin_type, +struct ns_state *s);void (*dump)(int fd,int type);void (*populate)(struct nf_expect *exp);
include/local.h +2 -1
@@ -31,7 +31,8 @@ int do_local_server_step(struct local_server *server, void *data,int local_client_create (struct local_conf *conf);void local_client_destroy (int fd);int do_local_client_step (int fd,void (*process)(char *buf)); -int do_local_request (int ,struct local_conf *,void (*step)(char *buf)); +int do_local_request (int ,struct local_conf *,void (*step)(char *buf), +const char *buffer,int buflen);void local_step (char *buf);#endif
include/namespace.h +2 -0
@@ -10,4 +10,6 @@ int ns_init(void);struct nfct_handle *ns_nfct_open (u_int8_t ,unsigned ,int );struct mnl_socket *ns_mnl_socket_open (int ,int ); +extern struct hashtable *ns_table; +#endif
include/netlink.h +1 -1
@@ -6,7 +6,7 @@struct nf_conntrack ;struct nfct_handle ; -struct nfct_handle *nl_init_event_handler (void ); +struct nfct_handle *nl_init_event_handler (int );struct nlif_handle *nl_init_interface_handler (void );int nl_send_resync (struct nfct_handle *h);
include/network.h +10 -8
@@ -85,24 +85,24 @@ enum { MSG_BAD, }; -#define BUILD_NETMSG_FROM_CT (ct, query) \ +#define BUILD_NETMSG_FROM_CT (ct, query, ns) \ ({ \ static char __net[4096]; \ struct nethdr *__hdr = (struct nethdr *) __net; \ memset(__hdr, 0, NETHDR_SIZ); \ nethdr_set(__hdr, query); \ - ct2msg(ct, __hdr); \ + ct2msg(ct, __hdr, ns); \ HDR_HOST2NETWORK(__hdr); \ __hdr; \ }) -#define BUILD_NETMSG_FROM_EXP (exp, query) \ +#define BUILD_NETMSG_FROM_EXP (exp, query, ns) \ ({ \ static char __net[4096]; \ struct nethdr *__hdr = (struct nethdr *) __net; \ memset(__hdr, 0, NETHDR_SIZ); \ nethdr_set(__hdr, query); \ - exp2msg(exp, __hdr); \ + exp2msg(exp, __hdr, ns); \ HDR_HOST2NETWORK(__hdr); \ __hdr; \ })
@@ -240,6 +240,7 @@ enum nta_attr {NTA_TCP_WSCALE_ORIG ,/* uint8_t */ NTA_TCP_WSCALE_REPL ,/* uint8_t */ NTA_HELPER_NAME ,/* string (variable length) */ +NTA_NAMESPACE ,/* string (variable length) */ NTA_MAX };
@@ -252,8 +253,8 @@ struct nta_attr_natseqadj {uint32_t repl_seq_offset_after; }; -void ct2msg (const struct nf_conntrack *ct,struct nethdr *n); -int msg2ct (struct nf_conntrack *ct,struct nethdr *n,size_t remain); +void ct2msg (const struct nf_conntrack *ct,struct nethdr *n,const char *ns); +int msg2ct (struct nf_conntrack *ct,struct nethdr *n,size_t remain,char *ns);enum nta_exp_attr {NTA_EXP_MASTER_IPV4 =0 ,/* struct nfct_attr_grp_ipv4 */
@@ -277,10 +278,11 @@ enum nta_exp_attr {NTA_EXP_NAT_DIR ,/* uint32_t */ NTA_EXP_HELPER_NAME ,/* string (variable length) */ NTA_EXP_FN ,/* string (variable length) */ +NTA_EXP_NAMESPACE ,/* string (variable length) */ NTA_EXP_MAX }; -void exp2msg (const struct nf_expect *exp,struct nethdr *n); -int msg2exp (struct nf_expect *exp,struct nethdr *n,size_t remain); +void exp2msg (const struct nf_expect *exp,struct nethdr *n,const char *ns); +int msg2exp (struct nf_expect *exp,struct nethdr *n,size_t remain,char *ns);#endif
src/build.c +5 -2
@@ -173,7 +173,7 @@ static struct build_l4proto { [IPPROTO_UDP] = { .build = build_l4proto_udp }, }; -void ct2msg (const struct nf_conntrack *ct,struct nethdr *n) +void ct2msg (const struct nf_conntrack *ct,struct nethdr *n,const char *ns) {uint8_t l4proto =nfct_get_attr_u8 (ct,ATTR_L4PROTO );
@@ -233,6 +233,9 @@ void ct2msg(const struct nf_conntrack *ct, struct nethdr *n)if (nfct_attr_is_set (ct,ATTR_HELPER_NAME ))ct_build_str (ct,ATTR_HELPER_NAME , n,NTA_HELPER_NAME ); + +if (ns[0 ]) +addattr (n,NTA_NAMESPACE , ns,strlen (ns) +1 ); } static void
@@ -287,7 +290,7 @@ exp_build_str(const struct nf_expect *exp, int a, struct nethdr *n, int b)addattr (n, b, data,strlen (data)+1 ); } -void exp2msg (const struct nf_expect *exp,struct nethdr *n) +void exp2msg (const struct nf_expect *exp,struct nethdr *n,const char *ns) {const struct nf_conntrack *ct =nfexp_get_attr (exp,ATTR_EXP_MASTER );uint8_t l4proto =nfct_get_attr_u8 (ct,ATTR_L4PROTO );
src/cache-ct.c +2 -2
@@ -314,9 +314,9 @@ static int cache_ct_commit(struct cache *c, struct nfct_handle *h, int clientfd) }static struct nethdr * -cache_ct_build_msg (const struct cache_object *obj,int type) +cache_ct_build_msg (const struct cache_object *obj,int type,const char *nsid) { -return BUILD_NETMSG_FROM_CT (obj->ptr, type); +return BUILD_NETMSG_FROM_CT (obj->ptr, type, nsid); }/* template to cache conntracks coming from the kernel. */
src/cache-exp.c +2 -2
@@ -278,9 +278,9 @@ cache_exp_commit(struct cache *c, struct nfct_handle *h, int clientfd) }static struct nethdr * -cache_exp_build_msg (const struct cache_object *obj,int type) +cache_exp_build_msg (const struct cache_object *obj,int type,const char *nsid) { -return BUILD_NETMSG_FROM_EXP (obj->ptr, type); +return BUILD_NETMSG_FROM_EXP (obj->ptr, type, nsid); }/* template to cache expectations coming from the kernel. */
src/ctnl.c +206 -85
421 lines not on this page · raw message
src/external_cache.c +6 -6
@@ -54,7 +54,7 @@ static void external_cache_close(void)cache_destroy (external_exp); } -static void external_cache_ct_new (struct nf_conntrack *ct) +static void external_cache_ct_new (struct nf_conntrack *ct,struct ns_state *ns) {struct cache_object *obj;int id;
@@ -77,12 +77,12 @@ retry: } } -static void external_cache_ct_upd (struct nf_conntrack *ct) +static void external_cache_ct_upd (struct nf_conntrack *ct,struct ns_state *ns) {cache_update_force (external, ct); } -static void external_cache_ct_del (struct nf_conntrack *ct) +static void external_cache_ct_del (struct nf_conntrack *ct,struct ns_state *ns) {struct cache_object *obj;int id;
@@ -119,7 +119,7 @@ static void external_cache_ct_stats_ext(int fd)cache_stats_extended (external, fd); } -static void external_cache_exp_new (struct nf_expect *exp) +static void external_cache_exp_new (struct nf_expect *exp,struct ns_state *ns) {struct cache_object *obj;int id;
@@ -142,12 +142,12 @@ retry: } } -static void external_cache_exp_upd (struct nf_expect *exp) +static void external_cache_exp_upd (struct nf_expect *exp,struct ns_state *ns) {cache_update_force (external_exp, exp); } -static void external_cache_exp_del (struct nf_expect *exp) +static void external_cache_exp_del (struct nf_expect *exp,struct ns_state *ns) {struct cache_object *obj;int id;
src/external_inject.c +20 -30
123 lines not on this page · raw message
src/internal_bypass.c +24 -18
102 lines not on this page · raw message
src/internal_cache.c +12 -6
@@ -139,7 +139,8 @@ internal_cache_ct_resync(enum nf_conntrack_msg_type type,return NFCT_CB_CONTINUE ; } -static void internal_cache_ct_event_new (struct nf_conntrack *ct,int origin) +static void internal_cache_ct_event_new (struct nf_conntrack *ct,int origin, +struct ns_state *s) {struct cache_object *obj;int id;
@@ -176,7 +177,8 @@ retry: } } -static void internal_cache_ct_event_upd (struct nf_conntrack *ct,int origin) +static void internal_cache_ct_event_upd (struct nf_conntrack *ct,int origin, +struct ns_state *s) {struct cache_object *obj;
@@ -192,7 +194,8 @@ static void internal_cache_ct_event_upd(struct nf_conntrack *ct, int origin)sync_send (obj,NET_T_STATE_CT_UPD ); } -static int internal_cache_ct_event_del (struct nf_conntrack *ct,int origin) +static int internal_cache_ct_event_del (struct nf_conntrack *ct,int origin, +struct ns_state *s) {struct cache_object *obj;int id;
@@ -293,7 +296,8 @@ internal_cache_exp_resync(enum nf_conntrack_msg_type type,return NFCT_CB_CONTINUE ; } -static void internal_cache_exp_event_new (struct nf_expect *exp,int origin) +static void internal_cache_exp_event_new (struct nf_expect *exp,int origin, +struct ns_state *s) {struct cache_object *obj;int id;
@@ -324,7 +328,8 @@ retry: } } -static void internal_cache_exp_event_upd (struct nf_expect *exp,int origin) +static void internal_cache_exp_event_upd (struct nf_expect *exp,int origin, +struct ns_state *s) {struct cache_object *obj;
@@ -340,7 +345,8 @@ static void internal_cache_exp_event_upd(struct nf_expect *exp, int origin)sync_send (obj,NET_T_STATE_EXP_UPD ); } -static int internal_cache_exp_event_del (struct nf_expect *exp,int origin) +static int internal_cache_exp_event_del (struct nf_expect *exp,int origin, +struct ns_state *s) {struct cache_object *obj;int id;
src/local.c +8 -2
@@ -138,7 +138,9 @@ void local_step(char *buf)int do_local_request (int request,struct local_conf *conf, -void (*step)(char *buf)) +void (*step)(char *buf), +const char *buffer, +int buflen) {int fd, ret;
@@ -149,7 +151,11 @@ int do_local_request(int request, ret =send (fd, &request,sizeof (int ),0 );if (ret ==-1 )return -1 ; - +if (buflen) { + ret =send (fd, buffer, buflen,0 ); +if (ret ==-1 ) +return -1 ; + }do_local_client_step (fd, step);local_client_destroy (fd);
src/main.c +44 -1
63 lines not on this page · raw message
src/namespace.c +27 -8
@@ -30,8 +30,11 @@#include <sys/stat.h> #include <unistd.h> +#include "jhash.h" #include "log.h" +struct hashtable *ns_table; +#ifndef HAVE_SETNS static int setns (int fd,int nstype) {#ifdef __NR_setns
@@ -43,6 +46,19 @@ static int setns(int fd, int nstype) { }#endif /* HAVE_SETNS */ + +static uint32_t ns_hash (const void *data,const struct hashtable *table) +{ +const char *f = data; +return jhash (f,strlen (f),0 ) % table->hashsize; +} + +static int ns_cmp (const void *data1,const void *data2) +{ +const struct ns_state *f1 = data1; +return !strcmp (f1->nsid, data2); +} +static int ctd_change_namespace (int fd) {
@@ -67,12 +83,6 @@ static int do_ns_init(void) strerror(errno));return -1 ; } -STATE (ns).root_fd =open ("/proc/self/ns/net" ,O_RDONLY ); -if (STATE (ns).root_fd ==-1 ) { -dlog (LOG_WARNING ,"couldn't open root namespace: %s" , -strerror (errno)); -return -1 ; - }return 0 ; }
@@ -83,6 +93,15 @@ int ns_init(void)STATE (ns).root_fd =-1 ;STATE (ns).cur_fd =-1 ; +STATE (ns).root_fd =open ("/proc/self/ns/net" ,O_RDONLY ); +if (STATE (ns).root_fd ==-1 ) { +dlog (LOG_WARNING ,"couldn't open root namespace: %s" , +strerror (errno)); +return -1 ; + } + + ns_table =hashtable_create (1024 ,4096 , ns_hash, ns_cmp); +if (!CONFIG (netlink_namespace)[0 ])return 0 ;#ifndef HAVE_SETNS
@@ -103,7 +122,7 @@ struct nfct_handle *ns_nfct_open(u_int8_t subsys_id, unsigned subscriptions,return NULL ; handle =nfct_open (subsys_id, subscriptions); -if (ctd_change_namespace (STATE (ns).root_fd) <0 ) { +if (ns_fd !=-1 &&ctd_change_namespace (STATE (ns).root_fd) <0 ) {if (handle)nfct_close (handle);return NULL ;
@@ -118,7 +137,7 @@ struct mnl_socket *ns_mnl_socket_open(int bus, int ns_fd)if (ctd_change_namespace (ns_fd) <0 )return NULL ; handle =mnl_socket_open (bus); -if (ctd_change_namespace (STATE (ns).root_fd) <0 ) { +if (ns_fd !=-1 &&ctd_change_namespace (STATE (ns).root_fd) <0 ) {if (handle)mnl_socket_close (handle);return NULL ;
src/netlink.c +2 -3
@@ -30,12 +30,11 @@#include <sys/fcntl.h> #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h> -struct nfct_handle *nl_init_event_handler (void ) +struct nfct_handle *nl_init_event_handler (int fd) {struct nfct_handle *h; - h =ns_nfct_open (CONFIG (netlink).subsys_id,CONFIG (netlink).groups, -STATE (ns).cur_fd); + h =ns_nfct_open (CONFIG (netlink).subsys_id,CONFIG (netlink).groups, fd);if (h ==NULL )return NULL ;
src/parse.c +16 -3
@@ -17,9 +17,11 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "conntrackd.h" #include "network.h" #include <stdlib.h> +#include <string.h> #include <libnetfilter_conntrack/libnetfilter_conntrack.h> #ifndef ssizeof
@@ -180,6 +182,11 @@ static struct ct_parser h[NTA_MAX] = { .attr = ATTR_HELPER_NAME, .max_size = NFCT_HELPER_NAME_MAX, }, + [NTA_NAMESPACE] = { + .parse = ct_parse_str, + .attr = 0, + .max_size = NAMESPACE_ID_MAXLEN, + }, }; static void
@@ -233,11 +240,12 @@ ct_parse_nat_seq_adj(struct nf_conntrack *ct, int attr, void *data) ntohl(this->repl_seq_offset_after)); } -int msg2ct (struct nf_conntrack *ct,struct nethdr *net,size_t remain) +int msg2ct (struct nf_conntrack *ct,struct nethdr *net,size_t remain,char *ns) {int len;struct netattr *attr; + ns[0 ] =0 ;if (remain < net->len)return -1 ;
@@ -260,7 +268,11 @@ int msg2ct(struct nf_conntrack *ct, struct nethdr *net, size_t remain) attr =NTA_NEXT (attr, len);continue ; } - h[attr->nta_attr].parse (ct, attr->nta_attr,NTA_DATA (attr)); +if (attr->nta_attr ==NTA_NAMESPACE ) +strncpy (ns, (char *)NTA_DATA (attr),NAMESPACE_ID_MAXLEN ); +else + h[attr->nta_attr].parse (ct, attr->nta_attr, +NTA_DATA (attr)); attr =NTA_NEXT (attr, len); }
@@ -423,12 +435,13 @@ static void exp_parse_str(void *exp, int attr, void *data)nfexp_set_attr (exp, exp_h[attr].exp_attr, data); } -int msg2exp (struct nf_expect *exp,struct nethdr *net,size_t remain) +int msg2exp (struct nf_expect *exp,struct nethdr *net,size_t remain,char *ns) {int len;struct netattr *attr;struct nf_conntrack *master, *expected, *mask, *nat; + ns[0 ] =0 ;if (remain < net->len)return -1 ;
src/stats-mode.c +3 -3
@@ -143,7 +143,7 @@ static void stats_purge(void)cache_iterate (STATE_STATS (cache),NULL , purge_step); } -static void stats_event_new (struct nf_conntrack *ct,int origin) +static void stats_event_new (struct nf_conntrack *ct,int origin,struct ns_state *s) {int id;struct cache_object *obj;
@@ -164,13 +164,13 @@ static void stats_event_new(struct nf_conntrack *ct, int origin)return ; } -static void stats_event_upd (struct nf_conntrack *ct,int origin) +static void stats_event_upd (struct nf_conntrack *ct,int origin,struct ns_state *s) {nfct_attr_unset (ct,ATTR_TIMEOUT );cache_update_force (STATE_STATS (cache), ct); } -static int stats_event_del (struct nf_conntrack *ct,int origin) +static int stats_event_del (struct nf_conntrack *ct,int origin,struct ns_state *s) {int id;struct cache_object *obj;
src/sync-alarm.c +1 -1
@@ -137,7 +137,7 @@ static int tx_queue_xmit(struct queue_node *n, const void *data) ca = (struct cache_alarm *)n; type =object_status_to_network_type (ca->obj); - net = ca->obj->cache->ops->build_msg (ca->obj, type); + net = ca->obj->cache->ops->build_msg (ca->obj, type,"BUG" );multichannel_send (STATE_SYNC (channel), net);cache_object_put (ca->obj);break ;
src/sync-ftfw.c +2 -1
@@ -57,6 +57,7 @@ struct cache_ftfw {struct queue_node qnode;struct cache_object *obj;uint32_t seq; +uint32_t nsid; };static void cache_ftfw_add (struct cache_object *obj,void *data)
@@ -518,7 +519,7 @@ static int tx_queue_xmit(struct queue_node *n, const void *data) cn = (struct cache_ftfw *)n; type =object_status_to_network_type (cn->obj); - net = cn->obj->cache->ops->build_msg (cn->obj, type); + net = cn->obj->cache->ops->build_msg (cn->obj, type,"BUG" );nethdr_set_hello (net); dp("tx_list sq: %u fl:%u len:%u\n",
src/sync-mode.c +38 -26
118 lines not on this page · raw message
src/sync-notrack.c +3 -2
@@ -90,7 +90,7 @@ static int kernel_resync_cb(enum nf_conntrack_msg_type type, {struct nethdr *net; - net =BUILD_NETMSG_FROM_CT (ct,NET_T_STATE_CT_NEW ); + net =BUILD_NETMSG_FROM_CT (ct,NET_T_STATE_CT_NEW ,"BUG" );multichannel_send (STATE_SYNC (channel), net);return NFCT_CB_CONTINUE ;
@@ -204,7 +204,7 @@ static int tx_queue_xmit(struct queue_node *n, const void *data2) cn = (struct cache_notrack *)n; type =object_status_to_network_type (cn->obj); - net = cn->obj->cache->ops->build_msg (cn->obj, type); + net = cn->obj->cache->ops->build_msg (cn->obj, type,"BUG" );multichannel_send (STATE_SYNC (channel), net);queue_del (n);
@@ -247,6 +247,7 @@ static void tx_queue_add_ctlmsg2(uint32_t flags)static void do_alive_alarm (struct alarm_block *a,void *data) { +/* Here we put the keepalive message */ tx_queue_add_ctlmsg2 (NET_F_ALIVE );add_alarm (&alive_alarm,ALIVE_INT ,0 ); }
Signature · 1 line
1.7.9.5
Pablo Neira Ayuso
maintainerQuoted 55 lines · Ansis Atteka
This patch should not be considered complete! It was sent out with intention to propose feature and receive further comments.
It enables single conntrackd process to synchronize state among multiple namespaces. To test this patch apply it on the top of this one:
http://markmail.org/thread/npxklk4p6g4y3rup
And use following conntrackd.conf on both hosts:
Sync { Mode NOTRACK { DisableInternalCache On DisableExternalCache On } UDP { IPv4_Destination_Address <host[1|2]> Interface breth0 SndSocketBuffer 1249280 Checksum on Port 3781 } } General { Nice -20 LogFile on LockFile /var/lock/conntrack.lock UNIX { Path /var/run/conntrackd.ctl Backlog 20 } NetlinkBufferSize 2097152 NetlinkBufferSizeMaxGrowth 8388608 }The configuration above is used as template when instantiating the actual configuration for every namespace. Use following commands to do that:
host1: conntrackd -A namespace1
/var/run/netns/namespace1
host1: conntrackd -A namespace2/var/run/netns/namespace2
host2: conntrackd -A namespace1/var/run/netns/namespace1
host2: conntrackd -A namespace2/var/run/netns/namespace2The first argument is the namespace identifier and second is the path to the actual namespace mount point.
This patch doesn't work correctly yet with:
1. caches
2. FTFW or ALARM modes
3. filters (it seems a little bit tricky to unglobalize it)
4. expectations
5. and it even breaks the current conntrackd usage (it does not create state object for the current namespace)
Quoted 4 lines
Currently I am protoyping another patch that will allow to synchronize different namespace subsets between more than two hosts (i.e. each
ns_statewill reference the right multichannel structure and use it).
This is a large changeset but seems reasonable if you put care on it, and that will require several rounds of comments.
I have dedicated a lot of time to stabilize this software. If you want me to take this feature, you'll have to put *a lot* of care on the patches, really.
BTW, better split this in some patch stack. First small patches for little changes you require to prepare the ground for your feature. Then, the last patch should be your new feature.
Check tools like stgit to work with stack of patches in case you are not familiar with.