Use sideband also for challenge response.
[paraslash.git] / udp_recv.c
index 45d24ea..c1f2383 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2012 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 #include "fd.h"
 #include "buffer_tree.h"
 
-/**
- * Data specific to the udp receiver.
- *
- * \sa \ref receiver, \ref receiver_node.
- */
-struct private_udp_recv_data {
-       /** The socket file descriptor. */
-       int fd;
-       struct btr_pool *btrp;
-};
-
 static void udp_recv_pre_select(struct sched *s, struct task *t)
 {
        struct receiver_node *rn = container_of(t, struct receiver_node, task);
-       struct private_udp_recv_data *purd = rn->private_data;
 
        if (generic_recv_pre_select(s, t) <= 0)
                return;
-       para_fd_set(purd->fd, &s->rfds, &s->max_fileno);
+       para_fd_set(rn->fd, &s->rfds, &s->max_fileno);
 }
 
 static int udp_check_eof(size_t sz, struct iovec iov[2])
@@ -64,7 +52,6 @@ static int udp_check_eof(size_t sz, struct iovec iov[2])
 static void udp_recv_post_select(__a_unused struct sched *s, struct task *t)
 {
        struct receiver_node *rn = container_of(t, struct receiver_node, task);
-       struct private_udp_recv_data *purd = rn->private_data;
        struct btr_node *btrn = rn->btrn;
        size_t num_bytes;
        struct iovec iov[2];
@@ -74,11 +61,11 @@ static void udp_recv_post_select(__a_unused struct sched *s, struct task *t)
        ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
        if (ret <= 0)
                goto out;
-       iovcnt = btr_pool_get_buffers(purd->btrp, iov);
+       iovcnt = btr_pool_get_buffers(rn->btrp, iov);
        ret = -E_UDP_OVERRUN;
        if (iovcnt == 0)
                goto out;
-       ret = readv_nonblock(purd->fd, iov, iovcnt, &s->rfds, &num_bytes);
+       ret = readv_nonblock(rn->fd, iov, iovcnt, &s->rfds, &num_bytes);
        if (num_bytes == 0)
                goto out;
        readv_ret = ret;
@@ -86,10 +73,10 @@ static void udp_recv_post_select(__a_unused struct sched *s, struct task *t)
        if (ret < 0)
                goto out;
        if (iov[0].iov_len >= num_bytes)
-               btr_add_output_pool(purd->btrp, num_bytes, btrn);
+               btr_add_output_pool(rn->btrp, num_bytes, btrn);
        else { /* both buffers contain data */
-               btr_add_output_pool(purd->btrp, iov[0].iov_len, btrn);
-               btr_add_output_pool(purd->btrp, num_bytes - iov[0].iov_len,
+               btr_add_output_pool(rn->btrp, iov[0].iov_len, btrn);
+               btr_add_output_pool(rn->btrp, num_bytes - iov[0].iov_len,
                        btrn);
        }
        ret = readv_ret;
@@ -98,18 +85,15 @@ out:
                return;
        btr_remove_node(btrn);
        t->error = ret;
-       close(purd->fd);
-       purd->fd = -1;
+       close(rn->fd);
+       rn->fd = -1;
 }
 
 static void udp_recv_close(struct receiver_node *rn)
 {
-       struct private_udp_recv_data *purd = rn->private_data;
-
-       if (purd->fd >= 0)
-               close(purd->fd);
-       btr_pool_free(purd->btrp);
-       free(rn->private_data);
+       if (rn->fd >= 0)
+               close(rn->fd);
+       btr_pool_free(rn->btrp);
 }
 
 static void *udp_recv_parse_config(int argc, char **argv)
@@ -188,36 +172,31 @@ err:
 
 static int udp_recv_open(struct receiver_node *rn)
 {
-       struct private_udp_recv_data *purd;
        struct udp_recv_args_info *c = rn->conf;
        char  *iface = c->iface_given ? c->iface_arg : NULL;
        int ret;
 
-       rn->private_data = para_calloc(sizeof(struct private_udp_recv_data));
-       purd = rn->private_data;
-
        ret = makesock(IPPROTO_UDP, 1, c->host_arg, c->port_arg, NULL);
        if (ret < 0)
                goto err;
-       purd->fd = ret;
+       rn->fd = ret;
 
-       ret = mcast_receiver_setup(purd->fd, iface);
+       ret = mcast_receiver_setup(rn->fd, iface);
        if (ret < 0) {
-               close(purd->fd);
+               close(rn->fd);
                goto err;
        }
 
-       ret = mark_fd_nonblocking(purd->fd);
+       ret = mark_fd_nonblocking(rn->fd);
        if (ret < 0) {
-               close(purd->fd);
+               close(rn->fd);
                goto err;
        }
        PARA_INFO_LOG("receiving from %s:%d, fd=%d\n", c->host_arg,
-               c->port_arg, purd->fd);
-       purd->btrp = btr_pool_new("udp_recv", 320 * 1024);
-       return purd->fd;
+               c->port_arg, rn->fd);
+       rn->btrp = btr_pool_new("udp_recv", 320 * 1024);
+       return rn->fd;
 err:
-       free(rn->private_data);
        return ret;
 }