+struct netio_options {
+ struct thread_data *td;
+ unsigned int port;
+ unsigned int proto;
+ unsigned int listen;
+ unsigned int pingpong;
+ unsigned int nodelay;
+ unsigned int ttl;
+ char *intfc;
+};
+
+struct udp_close_msg {
+ uint32_t magic;
+ uint32_t cmd;
+};
+
+enum {
+ FIO_LINK_CLOSE = 0x89,
+ FIO_LINK_OPEN_CLOSE_MAGIC = 0x6c696e6b,
+ FIO_LINK_OPEN = 0x98,
+
+ FIO_TYPE_TCP = 1,
+ FIO_TYPE_UDP = 2,
+ FIO_TYPE_UNIX = 3,
+ FIO_TYPE_TCP_V6 = 4,
+ FIO_TYPE_UDP_V6 = 5,
+};
+
+static int str_hostname_cb(void *data, const char *input);
+static struct fio_option options[] = {
+ {
+ .name = "hostname",
+ .lname = "net engine hostname",
+ .type = FIO_OPT_STR_STORE,
+ .cb = str_hostname_cb,
+ .help = "Hostname for net IO engine",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_NETIO,
+ },
+ {
+ .name = "port",
+ .lname = "net engine port",
+ .type = FIO_OPT_INT,
+ .off1 = offsetof(struct netio_options, port),
+ .minval = 1,
+ .maxval = 65535,
+ .help = "Port to use for TCP or UDP net connections",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_NETIO,
+ },
+ {
+ .name = "protocol",
+ .lname = "net engine protocol",
+ .alias = "proto",
+ .type = FIO_OPT_STR,
+ .off1 = offsetof(struct netio_options, proto),
+ .help = "Network protocol to use",
+ .def = "tcp",
+ .posval = {
+ { .ival = "tcp",
+ .oval = FIO_TYPE_TCP,
+ .help = "Transmission Control Protocol",
+ },
+ { .ival = "tcpv6",
+ .oval = FIO_TYPE_TCP_V6,
+ .help = "Transmission Control Protocol V6",
+ },
+ { .ival = "udp",
+ .oval = FIO_TYPE_UDP,
+ .help = "User Datagram Protocol",
+ },
+ { .ival = "udpv6",
+ .oval = FIO_TYPE_UDP_V6,
+ .help = "User Datagram Protocol V6",
+ },
+ { .ival = "unix",
+ .oval = FIO_TYPE_UNIX,
+ .help = "UNIX domain socket",
+ },
+ },
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_NETIO,
+ },
+#ifdef CONFIG_TCP_NODELAY
+ {
+ .name = "nodelay",
+ .type = FIO_OPT_BOOL,
+ .off1 = offsetof(struct netio_options, nodelay),
+ .help = "Use TCP_NODELAY on TCP connections",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_NETIO,
+ },
+#endif
+ {
+ .name = "listen",
+ .lname = "net engine listen",
+ .type = FIO_OPT_STR_SET,
+ .off1 = offsetof(struct netio_options, listen),
+ .help = "Listen for incoming TCP connections",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_NETIO,
+ },
+ {
+ .name = "pingpong",
+ .type = FIO_OPT_STR_SET,
+ .off1 = offsetof(struct netio_options, pingpong),
+ .help = "Ping-pong IO requests",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_NETIO,
+ },
+ {
+ .name = "interface",
+ .lname = "net engine interface",
+ .type = FIO_OPT_STR_STORE,
+ .off1 = offsetof(struct netio_options, intfc),
+ .help = "Network interface to use",
+ .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,
+ },
+};
+
+static inline int is_udp(struct netio_options *o)
+{
+ return o->proto == FIO_TYPE_UDP || o->proto == FIO_TYPE_UDP_V6;
+}
+
+static inline int is_tcp(struct netio_options *o)
+{
+ return o->proto == FIO_TYPE_TCP || o->proto == FIO_TYPE_TCP_V6;
+}
+
+static inline int is_ipv6(struct netio_options *o)
+{
+ return o->proto == FIO_TYPE_UDP_V6 || o->proto == FIO_TYPE_TCP_V6;
+}
+
+/*
+ * Return -1 for error and 'nr events' for a positive number
+ * of events
+ */
+static int poll_wait(struct thread_data *td, int fd, short events)
+{
+ struct pollfd pfd;
+ int ret;
+
+ while (!td->terminate) {
+ pfd.fd = fd;
+ pfd.events = events;
+ ret = poll(&pfd, 1, -1);
+ if (ret < 0) {
+ if (errno == EINTR)
+ break;
+
+ td_verror(td, errno, "poll");
+ return -1;
+ } else if (!ret)
+ continue;
+
+ break;
+ }
+
+ if (pfd.revents & events)
+ return 1;
+
+ return -1;
+}
+
+static int fio_netio_is_multicast(const char *mcaddr)
+{
+ in_addr_t addr = inet_network(mcaddr);
+ if (addr == -1)
+ return 0;
+
+ if (inet_network("224.0.0.0") <= addr &&
+ inet_network("239.255.255.255") >= addr)
+ return 1;
+
+ return 0;
+}
+
+