From: Shawn Bohrer Date: Fri, 19 Jul 2013 18:24:08 +0000 (-0500) Subject: net: Add option to set outgoing multicast TTL X-Git-Tag: fio-2.1.2~33 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=d3a623deee774b82e4f92c6b9b4b0233b0f4454c net: Add option to set outgoing multicast TTL Signed-off-by: Shawn Bohrer Signed-off-by: Jens Axboe --- diff --git a/HOWTO b/HOWTO index 38eafdd3..a2de4706 100644 --- a/HOWTO +++ b/HOWTO @@ -1448,6 +1448,10 @@ that defines them is selected. [net] interface=str The IP address of the network interface used to send or receive UDP multicast +[netsplice] ttl=int +[net] ttl=int Time-to-live value for outgoing UDP multicast packets. + Default: 1 + [netsplice] nodelay=bool [net] nodelay=bool Set TCP_NODELAY on TCP connections. diff --git a/engines/net.c b/engines/net.c index 4804a206..0c90e1ca 100644 --- a/engines/net.c +++ b/engines/net.c @@ -37,6 +37,7 @@ struct netio_options { unsigned int listen; unsigned int pingpong; unsigned int nodelay; + unsigned int ttl; char * interface; }; @@ -138,6 +139,17 @@ static struct fio_option options[] = { .category = FIO_OPT_C_ENGINE, .group = FIO_OPT_G_NETIO, }, + { + .name = "ttl", + .lname = "net engine multicast ttl", + .type = FIO_OPT_INT, + .off1 = offsetof(struct netio_options, ttl), + .def = "1", + .minval = 0, + .help = "Time-to-live value for outgoing UDP multicast packets", + .category = FIO_OPT_C_ENGINE, + .group = FIO_OPT_G_NETIO, + }, { .name = NULL, }, @@ -542,7 +554,10 @@ static int fio_netio_connect(struct thread_data *td, struct fio_file *f) #endif if (o->proto == FIO_TYPE_UDP) { - if (o->interface && fio_netio_is_multicast(td->o.filename)) { + if (!fio_netio_is_multicast(td->o.filename)) + return 0; + + if (o->interface) { struct in_addr interface_addr; if (inet_aton(o->interface, &interface_addr) == 0) { log_err("fio: interface not valid interface IP\n"); @@ -555,6 +570,11 @@ static int fio_netio_connect(struct thread_data *td, struct fio_file *f) return 1; } } + if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_TTL, &o->ttl, sizeof(o->ttl)) < 0) { + td_verror(td, errno, "setsockopt IP_MULTICAST_TTL"); + close(f->fd); + return 1; + } return 0; } else if (o->proto == FIO_TYPE_TCP) { socklen_t len = sizeof(nd->addr); diff --git a/fio.1 b/fio.1 index ca8a5ca5..62f7bb65 100644 --- a/fio.1 +++ b/fio.1 @@ -1225,6 +1225,9 @@ The TCP or UDP port to bind to or connect to. The IP address of the network interface used to send or receive UDP multicast packets. .TP +.BI (net,netsplice)ttl \fR=\fPint +Time-to-live value for outgoing UDP multicast packets. Default: 1 +.TP .BI (net,netsplice)nodelay \fR=\fPbool Set TCP_NODELAY on TCP connections. .TP