}
}
-static void udp_delete_target(struct udp_target *ut, const char *msg)
+static void udp_delete_target(struct sender_client *sc, const char *msg)
{
- PARA_NOTICE_LOG("deleting %s (%s) from list\n", ut->sc->name, msg);
- udp_close_target(ut->sc);
+ struct udp_target *ut = sc->private_data;
+
+ PARA_NOTICE_LOG("deleting %s (%s) from list\n", sc->name, msg);
+ udp_close_target(sc);
vss_del_fec_client(ut->fc);
- list_del(&ut->sc->node);
- free(ut->sc->name);
- free(ut->sc);
+ list_del(&sc->node);
+ free(sc->name);
+ free(sc);
free(ut);
}
if (getpeername(sc->fd, (struct sockaddr *)&ss, &sslen) < 0)
goto err;
+ assert(ss.ss_family == AF_INET || ss.ss_family == AF_INET6);
/* RFC 3493, 5.2: -1 means 'use kernel default' */
if (ttl < 0 || ttl > 255)
if (setsockopt(sc->fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) < 0)
break;
return 0;
- default:
- PARA_ERROR_LOG("address family %d not supported", ss.ss_family);
- return -E_ADDRESS_LOOKUP;
}
err:
return -ERRNO_TO_PARA_ERROR(errno);
static int udp_com_delete(struct sender_command_data *scd)
{
- struct udp_target *ut = sc->private_data;
struct sender_client *sc = udp_lookup_target(scd);
if (sc) {
- udp_delete_target(ut, "com_delete");
+ udp_delete_target(sc, "com_delete");
return 1;
}
PARA_NOTICE_LOG("not deleting non-existing target '%s'\n", scd->host);
}
/** Check and clear socket error if any. */
-static int udp_check_socket_state(struct udp_target *ut)
+static int udp_check_socket_state(struct sender_client *sc)
{
+ struct udp_target *ut = sc->private_data;
int ret;
socklen_t errlen = sizeof(ret);
- if (getsockopt(ut->sc->fd, SOL_SOCKET, SO_ERROR, &ret, &errlen) < 0) {
+ if (getsockopt(sc->fd, SOL_SOCKET, SO_ERROR, &ret, &errlen) < 0) {
PARA_ERROR_LOG("SO_ERROR failed: %s\n", strerror(ret));
return 0;
} else if (ret == 0) {
*/
PARA_NOTICE_LOG("Evicting %s after %d seconds "
"of connection errors.\n",
- ut->sc->name, (int)dist);
+ sc->name, (int)dist);
}
}
return -ERRNO_TO_PARA_ERROR(ret);
static int udp_send_fec(struct sender_client *sc, char *buf, size_t len)
{
- struct udp_target *ut = sc->private_data;
int ret;
if (sender_status == SENDER_OFF)
return 0;
- if (len == 0 && !cq_peek(ut->sc->cq))
+ if (len == 0 && !cq_peek(sc->cq))
return 0;
- ret = udp_check_socket_state(ut);
+ ret = udp_check_socket_state(sc);
if (ret < 0)
goto fail;
ret = send_queued_chunks(sc->fd, sc->cq);
}
return 1;
fail:
- udp_delete_target(ut, para_strerror(-ret));
+ udp_delete_target(sc, para_strerror(-ret));
return ret;
}
ut->fcp.init_fec = udp_init_fec;
ut->fcp.send_fec = udp_send_fec;
- ut->sc->private_data = ut;
- ut->sc->fd = -1;
+ sc->private_data = ut;
+ sc->fd = -1;
ret = para_connect_simple(IPPROTO_UDP, scd->host, scd->port);
if (ret < 0)
goto err;
- ut->sc->fd = ret;
+ sc->fd = ret;
- ret = mcast_sender_setup(ut->sc);
+ ret = mcast_sender_setup(sc);
if (ret < 0)
goto err;
- ret = mark_fd_nonblocking(ut->sc->fd);
+ ret = mark_fd_nonblocking(sc->fd);
if (ret < 0)
goto err;
- ut->sc->name = para_strdup(remote_name(ut->sc->fd));
- PARA_INFO_LOG("adding to target list (%s)\n", ut->sc->name);
- ut->fc = vss_add_fec_client(ut->sc, &ut->fcp);
- para_list_add(&ut->sc->node, &targets);
+ sc->name = para_strdup(remote_name(sc->fd));
+ PARA_INFO_LOG("adding to target list (%s)\n", sc->name);
+ ut->fc = vss_add_fec_client(sc, &ut->fcp);
+ para_list_add(&sc->node, &targets);
return 1;
err:
- if (ut->sc->fd >= 0)
- close(ut->sc->fd);
+ if (sc->fd >= 0)
+ close(sc->fd);
PARA_NOTICE_LOG("failed to set up %s:%d (%s)- not adding it\n",
scd->host, scd->port, para_strerror(-ret));
- free(ut->sc);
+ free(sc);
free(ut);
return ret;
}
list_for_each_entry(sc, &targets, node) {
struct udp_target *ut = sc->private_data;
- char *tmp = make_message("%s%s/%u:%u:%u ", tgts ? : "",
- ut->sc->name,
+ char *tmp = make_message("%s%s/%u:%u:%u ",
+ tgts ? : "", sc->name,
ut->fcp.max_slice_bytes,
ut->fcp.data_slices_per_group,
ut->fcp.slices_per_group
" add [FF05::42]:1500 (IPv6 multicast)\n"
" add [::1] (IPv6 localhost/default port)\n"
" delete myhost.net (host with port wildcard)\n"
+ " delete 10.1.2.3:456 (IPv4 with explicit port)\n"
" delete [badc0de::1] (IPv6 with port wildcard)\n"
);
}