From 41e8560ea7c09533d03f523380c1cb5c62d87261 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 13 Mar 2009 14:00:59 +0100 Subject: sync-mode: add unicast UDP support to propagate state-changes This patch adds support for unicast UDP to the channel infrastructure. With this patch, you can select UDP unicast to propagate state-changes instead of multicast. Signed-off-by: Pablo Neira Ayuso --- include/Makefile.am | 2 +- include/channel.h | 9 ++++++++ include/conntrackd.h | 1 + include/udp.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 include/udp.h (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 0265620..f02ce89 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,6 @@ noinst_HEADERS = alarm.h jhash.h cache.h linux_list.h linux_rbtree.h \ - sync.h conntrackd.h local.h \ + sync.h conntrackd.h local.h udp.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 channel.h diff --git a/include/channel.h b/include/channel.h index ac1a93c..42534e0 100644 --- a/include/channel.h +++ b/include/channel.h @@ -2,12 +2,15 @@ #define _CHANNEL_H_ #include "mcast.h" +#include "udp.h" struct channel; struct nethdr; enum { + CHANNEL_NONE, CHANNEL_MCAST, + CHANNEL_UDP, CHANNEL_MAX, }; @@ -16,12 +19,18 @@ struct mcast_channel { struct mcast_sock *server; }; +struct udp_channel { + struct udp_sock *client; + struct udp_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 udp_conf udp; }; struct channel_conf { diff --git a/include/conntrackd.h b/include/conntrackd.h index cfb1ac5..f30a094 100644 --- a/include/conntrackd.h +++ b/include/conntrackd.h @@ -74,6 +74,7 @@ struct ct_conf { int hashsize; /* hashtable size */ int channel_num; int channel_default; + int channel_type_global; struct channel_conf channel[MULTICHANNEL_MAX]; struct local_conf local; /* unix socket facilities */ int nice; diff --git a/include/udp.h b/include/udp.h new file mode 100644 index 0000000..02b8af1 --- /dev/null +++ b/include/udp.h @@ -0,0 +1,58 @@ +#ifndef _UDP_H_ +#define _UDP_H_ + +#include +#include + +struct udp_conf { + int ipproto; + int reuseaddr; + int checksum; + unsigned short port; + union { + struct in_addr inet_addr; + struct in6_addr inet_addr6; + } server; + union { + struct in_addr inet_addr; + struct in6_addr inet_addr6; + } client; + int sndbuf; + int rcvbuf; +}; + +struct udp_stats { + uint64_t bytes; + uint64_t messages; + uint64_t error; +}; + +struct udp_sock { + int fd; + union { + struct sockaddr_in ipv4; + struct sockaddr_in6 ipv6; + } addr; + socklen_t sockaddr_len; + struct udp_stats stats; +}; + +struct udp_sock *udp_server_create(struct udp_conf *conf); +void udp_server_destroy(struct udp_sock *m); + +struct udp_sock *udp_client_create(struct udp_conf *conf); +void udp_client_destroy(struct udp_sock *m); + +ssize_t udp_send(struct udp_sock *m, const void *data, int size); +ssize_t udp_recv(struct udp_sock *m, void *data, int size); + +int udp_get_fd(struct udp_sock *m); + +int udp_snprintf_stats(char *buf, size_t buflen, char *ifname, + struct udp_stats *s, struct udp_stats *r); + +int udp_snprintf_stats2(char *buf, size_t buflen, const char *ifname, + const char *status, int active, + struct udp_stats *s, struct udp_stats *r); + +#endif -- cgit v1.2.3