From 656d5ad7c69a5a7d356c6251743890f1eec0bb71 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 12 Mar 2009 21:09:27 +0100 Subject: 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 --- src/mcast.c | 169 +----------------------------------------------------------- 1 file changed, 2 insertions(+), 167 deletions(-) (limited to 'src/mcast.c') diff --git a/src/mcast.c b/src/mcast.c index 8f11762..8eedd07 100644 --- a/src/mcast.c +++ b/src/mcast.c @@ -143,52 +143,12 @@ struct mcast_sock *mcast_server_create(struct mcast_conf *conf) return m; } -struct mcast_sock_multi * -mcast_server_create_multi(struct mcast_conf *conf, int conf_len) -{ - struct mcast_sock_multi *m; - int i, j; - - if (conf_len <= 0 || conf_len > MCAST_LINKS_MAX) - return NULL; - - m = calloc(sizeof(struct mcast_sock_multi), 1); - if (m == NULL) - return NULL; - - m->max_mtu = INT_MAX; - for (i=0; imulti[i] = mcast_server_create(&conf[i]); - if (m->multi[i] == NULL) { - for (j=0; jmulti[j]); - } - free(m); - return NULL; - } - if (m->max_mtu > conf[i].mtu) - m->max_mtu = conf[i].mtu; - } - m->num_links = conf_len; - - return m; -} - void mcast_server_destroy(struct mcast_sock *m) { close(m->fd); free(m); } -void mcast_server_destroy_multi(struct mcast_sock_multi *m) -{ - int i; - - for (i=0; inum_links; i++) - mcast_server_destroy(m->multi[i]); - free(m); -} - static int __mcast_client_create_ipv4(struct mcast_sock *m, struct mcast_conf *conf) { @@ -306,52 +266,12 @@ struct mcast_sock *mcast_client_create(struct mcast_conf *conf) return m; } -struct mcast_sock_multi * -mcast_client_create_multi(struct mcast_conf *conf, int conf_len) -{ - struct mcast_sock_multi *m; - int i, j; - - if (conf_len <= 0 || conf_len > MCAST_LINKS_MAX) - return NULL; - - m = calloc(sizeof(struct mcast_sock_multi), 1); - if (m == NULL) - return NULL; - - m->max_mtu = INT_MAX; - for (i=0; imulti[i] = mcast_client_create(&conf[i]); - if (m->multi[i] == NULL) { - for (j=0; jmulti[j]); - } - free(m); - return NULL; - } - if (m->max_mtu > conf[i].mtu) - m->max_mtu = conf[i].mtu; - } - m->num_links = conf_len; - - return m; -} - void mcast_client_destroy(struct mcast_sock *m) { close(m->fd); free(m); } -void mcast_client_destroy_multi(struct mcast_sock_multi *m) -{ - int i; - - for (i=0; inum_links; i++) - mcast_client_destroy(m->multi[i]); - free(m); -} - ssize_t mcast_send(struct mcast_sock *m, void *data, int size) { ssize_t ret; @@ -395,32 +315,12 @@ ssize_t mcast_recv(struct mcast_sock *m, void *data, int size) return ret; } -void mcast_set_current_link(struct mcast_sock_multi *m, int i) -{ - m->current_link = m->multi[i]; -} - -struct mcast_sock *mcast_get_current_link(struct mcast_sock_multi *m) -{ - return m->current_link; -} - int mcast_get_fd(struct mcast_sock *m) { return m->fd; } -int mcast_get_current_ifidx(struct mcast_sock_multi *m) -{ - return m->current_link->interface_idx; -} - -int mcast_get_ifidx(struct mcast_sock_multi *m, int i) -{ - return m->multi[i]->interface_idx; -} - -static int +int mcast_snprintf_stats(char *buf, size_t buflen, char *ifname, struct mcast_stats *s, struct mcast_stats *r) { @@ -443,7 +343,7 @@ mcast_snprintf_stats(char *buf, size_t buflen, char *ifname, return size; } -static int +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) @@ -467,68 +367,3 @@ mcast_snprintf_stats2(char *buf, size_t buflen, const char *ifname, (unsigned long long)r->error); return size; } - -void -mcast_dump_stats(int fd, - const struct mcast_sock_multi *s, - const struct mcast_sock_multi *r) -{ - int i; - struct mcast_stats snd = { 0, 0, 0}; - struct mcast_stats rcv = { 0, 0, 0}; - char ifname[IFNAMSIZ], buf[512]; - int size; - - /* it is the same for the receiver, no need to do it twice */ - if_indextoname(s->current_link->interface_idx, ifname); - - for (i=0; inum_links && inum_links; i++) { - snd.bytes += s->multi[i]->stats.bytes; - snd.messages += s->multi[i]->stats.messages; - snd.error += s->multi[i]->stats.error; - rcv.bytes += r->multi[i]->stats.bytes; - rcv.messages += r->multi[i]->stats.messages; - rcv.error += r->multi[i]->stats.error; - } - size = mcast_snprintf_stats(buf, sizeof(buf), ifname, &snd, &rcv); - send(fd, buf, size, 0); -} - -void -mcast_dump_stats_extended(int fd, - const struct mcast_sock_multi *s, - const struct mcast_sock_multi *r, - const struct nlif_handle *h) -{ - int i; - char buf[4096]; - int size = 0; - - for (i=0; inum_links && inum_links; i++) { - int idx = s->multi[i]->interface_idx, active; - unsigned int flags; - char ifname[IFNAMSIZ]; - const char *status; - - if_indextoname(idx, ifname); - nlif_get_ifflags(h, idx, &flags); - active = (s->multi[i] == s->current_link); - /* - * IFF_UP shows administrative status - * IFF_RUNNING shows carrier status - */ - if (flags & IFF_UP) { - if (!(flags & IFF_RUNNING)) - status = "NO-CARRIER"; - else - status = "RUNNING"; - } else { - status = "DOWN"; - } - size += mcast_snprintf_stats2(buf+size, sizeof(buf), - ifname, status, active, - &s->multi[i]->stats, - &r->multi[i]->stats); - } - send(fd, buf, size, 0); -} -- cgit v1.2.3