From nobody Mon Feb 9 16:50:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487765872388883.5546551517183; Wed, 22 Feb 2017 04:17:52 -0800 (PST) Received: from localhost ([::1]:51813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVrg-0000Bg-As for importer@patchew.org; Wed, 22 Feb 2017 07:17:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVph-0006e3-4t for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpd-0003hn-LX for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:45 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46433 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgVpd-0003hX-6y for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:41 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MC9pxK014496 for ; Wed, 22 Feb 2017 07:15:40 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 28s7gxfwmw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:40 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:38 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:35 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id AC76A17D805A; Wed, 22 Feb 2017 12:18:45 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFZPI56557742; Wed, 22 Feb 2017 12:15:35 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E659BAE04D; Wed, 22 Feb 2017 11:13:25 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9ECA0AE056; Wed, 22 Feb 2017 11:13:25 +0000 (GMT) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.55]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 22 Feb 2017 11:13:25 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:20 +0100 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170222121527.7009-1-cornelia.huck@de.ibm.com> References: <20170222121527.7009-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17022212-0040-0000-0000-0000032FCB44 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0041-0000-0000-00002440C931 Message-Id: <20170222121527.7009-2-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702220118 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 1/8] chardev: Basic support for TN3270 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jing Liu , agraf@suse.de, borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, pbonzini@redhat.com, Cornelia Huck , marcandre.lureau@redhat.com, Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jing Liu This introduces basic support for TN3270, which needs to negotiate three Telnet options during handshake: - End of Record - Binary Transmission - Terminal-Type As a basic implementation, this simply ignores NOP and Interrupt Process(IP) commands. More work should be done for them later. For more details, please refer to RFC 854 and 1576. Signed-off-by: Jing Liu Signed-off-by: Yang Chen Reviewed-by: QingFeng Hao Acked-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- chardev/char-socket.c | 76 +++++++++++++++++++++++++++++++++++++----------= ---- chardev/char.c | 11 ++++++-- include/sysemu/char.h | 8 ++++++ qapi-schema.json | 3 ++ 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 865c52762e..9819320058 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -56,6 +56,7 @@ typedef struct { SocketAddress *addr; bool is_listen; bool is_telnet; + bool is_tn3270; =20 guint reconnect_timer; int64_t reconnect_time; @@ -142,19 +143,25 @@ static int tcp_chr_read_poll(void *opaque) return s->max_size; } =20 -#define IAC 255 -#define IAC_BREAK 243 static void tcp_chr_process_IAC_bytes(Chardev *chr, SocketChardev *s, uint8_t *buf, int *size) { - /* Handle any telnet client's basic IAC options to satisfy char by - * char mode with no echo. All IAC options will be removed from - * the buf and the do_telnetopt variable will be used to track the - * state of the width of the IAC information. + /* Handle any telnet or tn3270 client's basic IAC options. + * For telnet options, it satisfies char by char mode with no echo. + * For tn3270 options, it satisfies binary mode with EOR. + * All IAC options will be removed from the buf and the do_opt + * pointer will be used to track the state of the width of the + * IAC information. * - * IAC commands come in sets of 3 bytes with the exception of the - * "IAC BREAK" command and the double IAC. + * RFC854: "All TELNET commands consist of at least a two byte sequenc= e. + * The commands dealing with option negotiation are three byte sequenc= es, + * the third byte being the code for the option referenced." + * "IAC BREAK", "IAC IP", "IAC NOP" and the double IAC are two bytes. + * "IAC SB", "IAC SE" and "IAC EOR" are saved to split up data boundary + * for tn3270. + * NOP, Break and Interrupt Process(IP) might be encountered during a = TN3270 + * session, and NOP and IP need to be done later. */ =20 int i; @@ -175,6 +182,18 @@ static void tcp_chr_process_IAC_bytes(Chardev *chr, /* Handle IAC break commands by sending a serial break= */ qemu_chr_be_event(chr, CHR_EVENT_BREAK); s->do_telnetopt++; + } else if (s->is_tn3270 && ((unsigned char)buf[i] =3D=3D I= AC_EOR + || (unsigned char)buf[i] =3D=3D IAC_SB + || (unsigned char)buf[i] =3D=3D IAC_SE) + && s->do_telnetopt =3D=3D 2) { + buf[j++] =3D IAC; + buf[j++] =3D buf[i]; + s->do_telnetopt++; + } else if (s->is_tn3270 && ((unsigned char)buf[i] =3D=3D I= AC_IP + || (unsigned char)buf[i] =3D=3D IAC_NOP) + && s->do_telnetopt =3D=3D 2) { + /* TODO: IP and NOP need to be implemented later. */ + s->do_telnetopt++; } s->do_telnetopt++; } @@ -509,7 +528,7 @@ static void tcp_chr_update_read_handler(Chardev *chr, =20 typedef struct { Chardev *chr; - char buf[12]; + char buf[21]; size_t buflen; } TCPChardevTelnetInit; =20 @@ -547,9 +566,6 @@ static void tcp_chr_telnet_init(Chardev *chr) TCPChardevTelnetInit *init =3D g_new0(TCPChardevTelnetInit, 1); size_t n =3D 0; =20 - init->chr =3D chr; - init->buflen =3D 12; - #define IACSET(x, a, b, c) \ do { \ x[n++] =3D a; \ @@ -557,12 +573,26 @@ static void tcp_chr_telnet_init(Chardev *chr) x[n++] =3D c; \ } while (0) =20 - /* Prep the telnet negotion to put telnet in binary, - * no echo, single char mode */ - IACSET(init->buf, 0xff, 0xfb, 0x01); /* IAC WILL ECHO */ - IACSET(init->buf, 0xff, 0xfb, 0x03); /* IAC WILL Suppress go ahead */ - IACSET(init->buf, 0xff, 0xfb, 0x00); /* IAC WILL Binary */ - IACSET(init->buf, 0xff, 0xfd, 0x00); /* IAC DO Binary */ + init->chr =3D chr; + if (!s->is_tn3270) { + init->buflen =3D 12; + /* Prep the telnet negotion to put telnet in binary, + * no echo, single char mode */ + IACSET(init->buf, 0xff, 0xfb, 0x01); /* IAC WILL ECHO */ + IACSET(init->buf, 0xff, 0xfb, 0x03); /* IAC WILL Suppress go ahea= d */ + IACSET(init->buf, 0xff, 0xfb, 0x00); /* IAC WILL Binary */ + IACSET(init->buf, 0xff, 0xfd, 0x00); /* IAC DO Binary */ + } else { + init->buflen =3D 21; + /* Prep the TN3270 negotion based on RFC1576 */ + IACSET(init->buf, 0xff, 0xfd, 0x19); /* IAC DO EOR */ + IACSET(init->buf, 0xff, 0xfb, 0x19); /* IAC WILL EOR */ + IACSET(init->buf, 0xff, 0xfd, 0x00); /* IAC DO BINARY */ + IACSET(init->buf, 0xff, 0xfb, 0x00); /* IAC WILL BINARY */ + IACSET(init->buf, 0xff, 0xfd, 0x18); /* IAC DO TERMINAL TYPE */ + IACSET(init->buf, 0xff, 0xfa, 0x18); /* IAC SB TERMINAL TYPE */ + IACSET(init->buf, 0x01, 0xff, 0xf0); /* SEND IAC SE */ + } =20 #undef IACSET =20 @@ -582,7 +612,8 @@ static void tcp_chr_tls_handshake(QIOTask *task, if (qio_task_propagate_error(task, NULL)) { tcp_chr_disconnect(chr); } else { - if (s->do_telnetopt) { + /* tn3270 does not support TLS yet */ + if (s->do_telnetopt && !s->is_tn3270) { tcp_chr_telnet_init(chr); } else { tcp_chr_connect(chr); @@ -821,6 +852,7 @@ static void qmp_chardev_open_socket(Chardev *chr, bool do_nodelay =3D sock->has_nodelay ? sock->nodelay : false; bool is_listen =3D sock->has_server ? sock->server : true; bool is_telnet =3D sock->has_telnet ? sock->telnet : false; + bool is_tn3270 =3D sock->has_tn3270 ? sock->tn3270 : false; bool is_waitconnect =3D sock->has_wait ? sock->wait : false; int64_t reconnect =3D sock->has_reconnect ? sock->reconnect : 0; QIOChannelSocket *sioc =3D NULL; @@ -828,6 +860,7 @@ static void qmp_chardev_open_socket(Chardev *chr, s->is_unix =3D addr->type =3D=3D SOCKET_ADDRESS_KIND_UNIX; s->is_listen =3D is_listen; s->is_telnet =3D is_telnet; + s->is_tn3270 =3D is_tn3270; s->do_nodelay =3D do_nodelay; if (sock->tls_creds) { Object *creds; @@ -876,7 +909,7 @@ static void qmp_chardev_open_socket(Chardev *chr, addr, is_listen, is_telnet); =20 if (is_listen) { - if (is_telnet) { + if (is_telnet || is_tn3270) { s->do_telnetopt =3D 1; } } else if (reconnect > 0) { @@ -930,6 +963,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Chard= evBackend *backend, bool is_listen =3D qemu_opt_get_bool(opts, "server", false); bool is_waitconnect =3D is_listen && qemu_opt_get_bool(opts, "wait", t= rue); bool is_telnet =3D qemu_opt_get_bool(opts, "telnet", false); + bool is_tn3270 =3D qemu_opt_get_bool(opts, "tn3270", false); bool do_nodelay =3D !qemu_opt_get_bool(opts, "delay", true); int64_t reconnect =3D qemu_opt_get_number(opts, "reconnect", 0); const char *path =3D qemu_opt_get(opts, "path"); @@ -965,6 +999,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Chard= evBackend *backend, sock->server =3D is_listen; sock->has_telnet =3D true; sock->telnet =3D is_telnet; + sock->has_tn3270 =3D true; + sock->tn3270 =3D is_tn3270; sock->has_wait =3D true; sock->wait =3D is_waitconnect; sock->has_reconnect =3D true; diff --git a/chardev/char.c b/chardev/char.c index abd525f75e..cd6d694d1f 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -695,7 +695,8 @@ QemuOpts *qemu_chr_parse_compat(const char *label, cons= t char *filename) return opts; } if (strstart(filename, "tcp:", &p) || - strstart(filename, "telnet:", &p)) { + strstart(filename, "telnet:", &p) || + strstart(filename, "tn3270:", &p)) { if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) { host[0] =3D 0; if (sscanf(p, ":%32[^,]%n", port, &pos) < 1) @@ -711,8 +712,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, con= st char *filename) goto fail; } } - if (strstart(filename, "telnet:", &p)) + if (strstart(filename, "telnet:", &p)) { qemu_opt_set(opts, "telnet", "on", &error_abort); + } else if (strstart(filename, "tn3270:", &p)) { + qemu_opt_set(opts, "tn3270", "on", &error_abort); + } return opts; } if (strstart(filename, "udp:", &p)) { @@ -1176,6 +1180,9 @@ QemuOptsList qemu_chardev_opts =3D { .name =3D "telnet", .type =3D QEMU_OPT_BOOL, },{ + .name =3D "tn3270", + .type =3D QEMU_OPT_BOOL, + },{ .name =3D "tls-creds", .type =3D QEMU_OPT_STRING, },{ diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 450881d42c..f6d5cd0c9b 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -7,6 +7,14 @@ #include "qemu/bitmap.h" #include "qom/object.h" =20 +#define IAC_EOR 239 +#define IAC_SE 240 +#define IAC_NOP 241 +#define IAC_BREAK 243 +#define IAC_IP 244 +#define IAC_SB 250 +#define IAC 255 + /* character device */ =20 typedef enum { diff --git a/qapi-schema.json b/qapi-schema.json index baa0d263d6..ee144871bf 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4774,6 +4774,8 @@ # @nodelay: #optional set TCP_NODELAY socket option (default: false) # @telnet: #optional enable telnet protocol on server # sockets (default: false) +# @tn3270: #optional enable tn3270 protocol on server +# sockets (default: false) # @reconnect: #optional For a client socket, if a socket is disconnected, # then attempt a reconnect after the given number of seconds. # Setting this to zero disables this function. (default: 0) @@ -4787,6 +4789,7 @@ '*wait' : 'bool', '*nodelay' : 'bool', '*telnet' : 'bool', + '*tn3270' : 'bool', '*reconnect' : 'int' }, 'base': 'ChardevCommon' } =20 --=20 2.11.0