diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-03-12 21:09:27 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-03-12 21:09:27 +0100 |
commit | 656d5ad7c69a5a7d356c6251743890f1eec0bb71 (patch) | |
tree | 46c7fe13a32382c556a51d258fab5b7bebe9cd77 /include | |
parent | 56b484e3acc7205f0ebd71eec6905253eeace132 (diff) | |
download | conntrack-tools-656d5ad7c69a5a7d356c6251743890f1eec0bb71.tar.gz conntrack-tools-656d5ad7c69a5a7d356c6251743890f1eec0bb71.zip |
sync-mode: add abstract layer to make daemon independent of multicast
This patch reworks conntrackd to make it independent of the protocol
used to propagate state-changes. This patch adds the channel layer
abstraction, this layer allows you to add support for different
protocols like unicast UDP or TIPC.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/Makefile.am | 2 | ||||
-rw-r--r-- | include/channel.h | 95 | ||||
-rw-r--r-- | include/conntrackd.h | 10 | ||||
-rw-r--r-- | include/mcast.h | 26 | ||||
-rw-r--r-- | include/network.h | 5 |
5 files changed, 106 insertions, 32 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index c3f8904..0265620 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,5 +3,5 @@ noinst_HEADERS = alarm.h jhash.h cache.h linux_list.h linux_rbtree.h \ sync.h conntrackd.h local.h \ debug.h log.h hash.h mcast.h conntrack.h \ network.h filter.h queue.h vector.h cidr.h \ - traffic_stats.h netlink.h fds.h event.h bitops.h + traffic_stats.h netlink.h fds.h event.h bitops.h channel.h diff --git a/include/channel.h b/include/channel.h new file mode 100644 index 0000000..ac1a93c --- /dev/null +++ b/include/channel.h @@ -0,0 +1,95 @@ +#ifndef _CHANNEL_H_ +#define _CHANNEL_H_ + +#include "mcast.h" + +struct channel; +struct nethdr; + +enum { + CHANNEL_MCAST, + CHANNEL_MAX, +}; + +struct mcast_channel { + struct mcast_sock *client; + struct mcast_sock *server; +}; + +#define CHANNEL_F_DEFAULT (1 << 0) +#define CHANNEL_F_BUFFERED (1 << 1) +#define CHANNEL_F_MAX (1 << 2) + +union channel_type_conf { + struct mcast_conf mcast; +}; + +struct channel_conf { + int channel_type; + char channel_ifname[IFNAMSIZ]; + unsigned int channel_flags; + union channel_type_conf u; +}; + +struct nlif_handle; + +struct channel_ops { + void * (*open)(void *conf); + void (*close)(void *channel); + int (*send)(void *channel, const void *data, int len); + int (*recv)(void *channel, char *buf, int len); + int (*get_fd)(void *channel); + void (*stats)(struct channel *c, int fd); + void (*stats_extended)(struct channel *c, int active, + struct nlif_handle *h, int fd); +}; + +struct channel_buffer; + +struct channel { + int channel_type; + int channel_ifindex; + int channel_ifmtu; + unsigned int channel_flags; + struct channel_buffer *buffer; + struct channel_ops *ops; + void *data; +}; + +void channel_init(void); +struct channel *channel_open(struct channel_conf *conf); +void channel_close(struct channel *c); + +int channel_send(struct channel *c, const struct nethdr *net); +int channel_send_flush(struct channel *c); +int channel_recv(struct channel *c, char *buf, int size); + +int channel_get_fd(struct channel *c); +void channel_stats(struct channel *c, int fd); +void channel_stats_extended(struct channel *c, int active, + struct nlif_handle *h, int fd); + +#define MULTICHANNEL_MAX 4 + +struct multichannel { + int channel_num; + struct channel *channel[MULTICHANNEL_MAX]; + struct channel *current; +}; + +struct multichannel *multichannel_open(struct channel_conf *conf, int len); +void multichannel_close(struct multichannel *m); + +int multichannel_send(struct multichannel *c, const struct nethdr *net); +int multichannel_send_flush(struct multichannel *c); +int multichannel_recv(struct multichannel *c, char *buf, int size); + +void multichannel_stats(struct multichannel *m, int fd); +void multichannel_stats_extended(struct multichannel *m, + struct nlif_handle *h, int fd); + +int multichannel_get_ifindex(struct multichannel *m, int i); +int multichannel_get_current_ifindex(struct multichannel *m); +void multichannel_set_current_channel(struct multichannel *m, int i); + +#endif /* _CHANNEL_H_ */ diff --git a/include/conntrackd.h b/include/conntrackd.h index 536abc9..cfb1ac5 100644 --- a/include/conntrackd.h +++ b/include/conntrackd.h @@ -5,6 +5,7 @@ #include "local.h" #include "alarm.h" #include "filter.h" +#include "channel.h" #include <stdint.h> #include <stdio.h> @@ -71,9 +72,9 @@ struct ct_conf { int syslog_facility; char lockfile[FILENAME_MAXLEN]; int hashsize; /* hashtable size */ - int mcast_links; - int mcast_default_link; - struct mcast_conf mcast[MCAST_LINKS_MAX]; + int channel_num; + int channel_default; + struct channel_conf channel[MULTICHANNEL_MAX]; struct local_conf local; /* unix socket facilities */ int nice; int limit; @@ -163,8 +164,7 @@ struct ct_sync_state { struct cache *internal; /* internal events cache (netlink) */ struct cache *external; /* external events cache (mcast) */ - struct mcast_sock_multi *mcast_server; /* multicast incoming */ - struct mcast_sock_multi *mcast_client; /* multicast outgoing */ + struct multichannel *channel; struct nlif_handle *interface; struct queue *tx_queue; diff --git a/include/mcast.h b/include/mcast.h index 623f390..68d18e8 100644 --- a/include/mcast.h +++ b/include/mcast.h @@ -42,38 +42,22 @@ struct mcast_sock { struct mcast_stats stats; }; -#define MCAST_LINKS_MAX 4 - -struct mcast_sock_multi { - int num_links; - int max_mtu; - struct mcast_sock *current_link; - struct mcast_sock *multi[MCAST_LINKS_MAX]; -}; - struct mcast_sock *mcast_server_create(struct mcast_conf *conf); void mcast_server_destroy(struct mcast_sock *m); -struct mcast_sock_multi *mcast_server_create_multi(struct mcast_conf *conf, int conf_len); -void mcast_server_destroy_multi(struct mcast_sock_multi *m); struct mcast_sock *mcast_client_create(struct mcast_conf *conf); void mcast_client_destroy(struct mcast_sock *m); -struct mcast_sock_multi *mcast_client_create_multi(struct mcast_conf *conf, int conf_len); -void mcast_client_destroy_multi(struct mcast_sock_multi*m); ssize_t mcast_send(struct mcast_sock *m, void *data, int size); ssize_t mcast_recv(struct mcast_sock *m, void *data, int size); int mcast_get_fd(struct mcast_sock *m); -int mcast_get_ifidx(struct mcast_sock_multi *m, int i); -int mcast_get_current_ifidx(struct mcast_sock_multi *m); - -struct mcast_sock *mcast_get_current_link(struct mcast_sock_multi *m); -void mcast_set_current_link(struct mcast_sock_multi *m, int i); -void mcast_dump_stats(int fd, const struct mcast_sock_multi *s, const struct mcast_sock_multi *r); +int mcast_snprintf_stats(char *buf, size_t buflen, char *ifname, + struct mcast_stats *s, struct mcast_stats *r); -struct nlif_handle; +int mcast_snprintf_stats2(char *buf, size_t buflen, const char *ifname, + const char *status, int active, + struct mcast_stats *s, struct mcast_stats *r); -void mcast_dump_stats_extended(int fd, const struct mcast_sock_multi *s, const struct mcast_sock_multi *r, const struct nlif_handle *h); #endif diff --git a/include/network.h b/include/network.h index 29a6113..7019d7d 100644 --- a/include/network.h +++ b/include/network.h @@ -106,11 +106,6 @@ int mcast_track_is_seq_set(void); struct mcast_conf; -int mcast_buffered_init(int mtu); -void mcast_buffered_destroy(void); -int mcast_buffered_send_netmsg(struct mcast_sock_multi *m, const struct nethdr *net); -ssize_t mcast_buffered_pending_netmsg(struct mcast_sock_multi *m); - #define IS_DATA(x) (x->type <= NET_T_STATE_MAX && \ (x->flags & ~(NET_F_HELLO | NET_F_HELLO_BACK)) == 0) #define IS_ACK(x) (x->type == NET_T_CTL && x->flags & NET_F_ACK) |