Skip to contentSkip to conversation

Network Virtual Terminal

Ver. 2 In review Rodolfo Giometti 4 participants 7 messages Jan 10, 2011 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

Hello,

here my implementation of Network Virtual terminals (NVT tty) according to RFC 854 and RFC 2217... actually this is the client side part since as remote server I used sredird
(http://freshmeat.net/projects/sredird/).

I tested the code under the following configuration:

        ------------------+
             +---------+  |
             | minicom |  |
             +---------+  |
                  |       | local PC with no
                  v       | serial ports
             /dev/nvtty0  |
                  |       |
        ------------------+
                  |
                  v
             /\/\/\/\/\
            | network |
             \/\/\/\/\/
                  |
        ------------------+
                  |       |
                  v       |
             +---------+  |
             | sredird |  |
             +---------+  | remote PC with
                  |       | serial ports
                  v       |
             /dev/ttyS0   |
                  |       |
        ------------------+
                  |
                  v
         embedded PC with
         a serial console

however it could work on a different schema I suppose.

By using minicom I can setup the serial settings of the /dev/ttyS0 device through the /dev/nvtty0 virtual device, then the communication with the embedded PC can start as if it was directly connected with my local machine.

Ciao,

Rodolfo

--

CHANGELOG:

Ver. 2:

* typo bugs fixed.

#1 lore raw

PATCH 1/1 char nvtty: Network Virtual Terminal support

A Network Virtual terminal (NVT tty) is a software device consisting of one halves: a client device, which is identical to a physical terminal, who, is turn, get connected with a remote server where real tty devices are located.

These devices are specified by RFC 854 and RFC 2217 and ther name into the system is /dev/nvttyX (by default you have 4 devices).

By using these devices and a proper compatible server (not included here but you can use sredird) you can get access to a remote tty device as the tty device itself was conneted with your local host. All data and settings are sent and received through the network.

---
 Documentation/ABI/testing/sysfs-nvtty |   35 +
 drivers/char/Kconfig                  |   22 +
 drivers/char/Makefile                 |    1 +
 drivers/char/nvtty.c                  | 1557 +++++++++++++++++++++++++++++++++
 4 files changed, 1615 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-nvtty
 create mode 100644 drivers/char/nvtty.c
Documentation/ABI/testing/sysfs-nvtty new file +35 -0
new file mode 100644
index 0000000..a52d319
@@ -0,0 +1,35 @@
+What:		/sys/class/tty/nvttyX/
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/ directory is related to X-th
+		NVT tty device into the system. Each directory will
+		contain files to manage and control its NVT tty device.
+
+What:		/sys/class/tty/nvttyX/connection
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/connection file reports 1 if the
+		related NVT tty device is connected with remote server and
+		0 otherwise.
+
+What:		/sys/class/tty/nvttyX/ip
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/ip file reports the IP address
+		of the remote server where to connecto to.
+		User should change this value, when no connection is active,
+		in order to select a different remote server.
+		Default is localhost (127.0.0.1).
+
+What:		/sys/class/tty/nvttyX/port
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/port file reports the IP port number
+		of the remote server where to connecto to.
+		User should change this value, when no connection is active,
+		in order to select a different port.
+		Default is 32769.
drivers/char/Kconfig +22 -0
index 43d3395..b0a1055 100644
@@ -451,6 +451,28 @@ config UNIX98_PTYS
 	  All modern Linux systems use the Unix98 ptys.  Say Y unless
 	  you're on an embedded system and want to conserve memory.
 
+config NVT_TTY
+	tristate "Network Virtual Terminal"
+	default n
+	---help---
+	  A Network Virtual terminal (NVT tty) is a software device
+	  consisting of one halve: a client device, which is
+	  identical to a physical terminal, who, is turn, gets
+	  connected to a remote server where real tty devices are
+	  located.
+
+	  These devices are specified by RFC 854 and RFC 2217 and their
+	  name into the system is /dev/nvttyX (by default there are 4
+	  devices).
+
+	  By using these devices and a proper compatible server (not
+	  included here but you can use sredird) you can get access to
+	  a remote tty device as though the tty device itself was connected
+	  with your local host.  All data and settings are sent and
+	  received through the network.
+
+	  If unsure, say N.
+
 config DEVPTS_MULTIPLE_INSTANCES
 	bool "Support multiple instances of devpts"
 	depends on UNIX98_PTYS
drivers/char/Makefile +1 -0
index ba53ec9..7deba37 100644
@@ -4,6 +4,7 @@
 
 obj-y				+= mem.o random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
+obj-$(CONFIG_NVT_TTY)		+= nvtty.o
 obj-y				+= misc.o
 obj-$(CONFIG_BFIN_JTAG_COMM)	+= bfin_jtag_comm.o
 obj-$(CONFIG_MVME147_SCC)	+= generic_serial.o vme_scc.o
drivers/char/nvtty.c new file +1557 -0

1,557 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/1] char nvtty: Network Virtual Terminal support

Quoted 4 lines

By using these devices and a proper compatible server (not included here but you can use sredird) you can get access to a remote tty device as the tty device itself was conneted with your local host. All data and settings are sent and received through the network.

And this is still something that should be done in userspace if necessary by fixing up the tty layer to support pty/tty pair modem lines and termios change reporting, or some kind of *generic* vt that can also expose all the config other net protocols might need.

drivers/char/nvtty.c line 409

Quoted 2 lines
drivers/char/nvtty.c new file +2 -0
+	default:
+		tty->termios->c_cflag = B0;

This btw is wrong - if you don't recognize the baud rate you want to force a new one. Also you shouldn't be writing all of c_cflag here just the baud bits, also you shouldn't in fact ever be hand mangling the baud bits but using the helpers.

Quoted 9 lines
drivers/char/nvtty.c new file +9 -0
+	}
+}
+#undef TEST_SET_BAUDRATE
+
+#define TEST_SET_DATASIZE(b)	case b: tty->termios->c_cflag |= CS ## b ; break
+static void nvtty_set_datasize(struct nvtty_serial *info, unsigned int datasize)
+{
+	struct tty_struct *tty = info->tty;
+

drivers/char/nvtty.c line 428

Quoted 10 lines
drivers/char/nvtty.c new file +10 -0
+	nvtty_dbg(info, "datasize=%d", datasize);
+
+	tty->termios->c_cflag &= ~CSIZE;
+	switch (datasize) {
+	TEST_SET_DATASIZE(5);
+	TEST_SET_DATASIZE(6);
+	TEST_SET_DATASIZE(7);
+	TEST_SET_DATASIZE(8);
+	default:
+		tty->termios->c_cflag = CS5;

Should be |=

drivers/char/nvtty.c line 439

Quoted 9 lines
drivers/char/nvtty.c new file +7 -0
+static void nvtty_set_parity(struct nvtty_serial *info, unsigned int parity)
+{
+	struct tty_struct *tty = info->tty;
+
+	nvtty_dbg(info, "parity=%d", parity);
+
+	tty->termios->c_cflag &= ~(PARENB | PARODD);

Needs to consider the CMSPAR bit.

Otherwise its a very nice implementation of something I don't think we should have implemented in the kernel.

#3 lore raw

Re: [PATCH 1/1] char nvtty: Network Virtual Terminal support

Quoted 9 lines · Alan Cox
Quoted 4 lines

By using these devices and a proper compatible server (not included here but you can use sredird) you can get access to a remote tty device as the tty device itself was conneted with your local host. All data and settings are sent and received through the network.

And this is still something that should be done in userspace if necessary by fixing up the tty layer to support pty/tty pair modem lines and termios change reporting, or some kind of *generic* vt that can also expose all the config other net protocols might need.

If I well understood the pty/tty pair modem lines they can be used to send receive serial data but they cannot be used to set the serial parameters since the slave doesn't send to the master the serial settings a userland application does on it, doesn't it?

Quoted 7 lines

drivers/char/nvtty.c line 409

Quoted 2 lines
drivers/char/nvtty.c new file +2 -0
+	default:
+		tty->termios->c_cflag = B0;

This btw is wrong - if you don't recognize the baud rate you want to force a new one. Also you shouldn't be writing all of c_cflag here just the baud bits, also you shouldn't in fact ever be hand mangling the baud bits but using the helpers.

Ok.

Quoted 14 lines
Quoted 14 lines
drivers/char/nvtty.c new file +13 -0
+	}
+}
+#undef TEST_SET_BAUDRATE
+
+#define TEST_SET_DATASIZE(b)	case b: tty->termios->c_cflag |= CS ## b ; break
+static void nvtty_set_datasize(struct nvtty_serial *info, unsigned int datasize)
+{
+	struct tty_struct *tty = info->tty;
+
+	nvtty_dbg(info, "datasize=%d", datasize);
+
+	tty->termios->c_cflag &= ~CSIZE;
+	switch (datasize) {
Quoted 8 lines

drivers/char/nvtty.c line 428

Quoted 6 lines
drivers/char/nvtty.c new file +6 -0
+	TEST_SET_DATASIZE(5);
+	TEST_SET_DATASIZE(6);
+	TEST_SET_DATASIZE(7);
+	TEST_SET_DATASIZE(8);
+	default:
+		tty->termios->c_cflag = CS5;

Should be |=

Ok.

Quoted 9 lines

drivers/char/nvtty.c line 439

Quoted 7 lines
drivers/char/nvtty.c new file +7 -0
+static void nvtty_set_parity(struct nvtty_serial *info, unsigned int parity)
+{
+	struct tty_struct *tty = info->tty;
+
+	nvtty_dbg(info, "parity=%d", parity);
+
+	tty->termios->c_cflag &= ~(PARENB | PARODD);

Needs to consider the CMSPAR bit.

Ok.

I'm going to fix these issues ASAP.

Quoted 2 lines

Otherwise its a very nice implementation of something I don't think we should have implemented in the kernel.

Thanks, but I still don't understand how I can set the serial settings without a specific tty driver and just using the pty/tty pair modem lines... :'(

Ciao,

Rodolfo

Signature · 5 lines
GNU/Linux Solutions                  e-mail: [email protected]
Linux Device Driver                          [email protected]
Embedded Systems                     phone:  +39 349 2432127
UNIX programming                     skype:  rodolfo.giometti
Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
#4 lore raw

Re: [PATCH 1/1] char nvtty: Network Virtual Terminal support

Quoted 4 lines

If I well understood the pty/tty pair modem lines they can be used to send receive serial data but they cannot be used to set the serial parameters since the slave doesn't send to the master the serial settings a userland application does on it, doesn't it?

Currently this is the case.

Quoted 6 lines
Quoted 2 lines

Otherwise its a very nice implementation of something I don't think we should have implemented in the kernel.

Thanks, but I still don't understand how I can set the serial settings without a specific tty driver and just using the pty/tty pair modem lines... :'(

I'd rather see either tweaks to the pty/tty code to support this and modem line setting, or something like your nvt which can be used for arbitary protocols rather than being tied to the nvt telnet protocol limits.

Alan

#5 lore raw

Re: [PATCH 1/1] char nvtty: Network Virtual Terminal support

Quoted 10 lines · Alan Cox
Quoted 4 lines

If I well understood the pty/tty pair modem lines they can be used to send receive serial data but they cannot be used to set the serial parameters since the slave doesn't send to the master the serial settings a userland application does on it, doesn't it?

Currently this is the case.

Quoted 3 lines
Quoted 2 lines

Otherwise its a very nice implementation of something I don't think we should have implemented in the kernel.

Quoted 8 lines
Quoted 3 lines

Thanks, but I still don't understand how I can set the serial settings without a specific tty driver and just using the pty/tty pair modem lines... :'(

I'd rather see either tweaks to the pty/tty code to support this and modem line setting, or something like your nvt which can be used for arbitary protocols rather than being tied to the nvt telnet protocol limits.

I also agree with this, we don't want to force the protocol to be this one, userspace has access to many good, secure protocols, that should be able to be used instead if they want to.

thanks,

greg k-h

#6 lore raw

Re: [PATCH 1/1] char nvtty: Network Virtual Terminal support

In reply to Rodolfo Giometti
Quoted 5 lines · Rodolfo Giometti

A Network Virtual terminal (NVT tty) is a software device consisting of one halves: a client device, which is identical to a physical terminal, who, is turn, get connected with a remote server where real tty devices are located.

Quoted 7 lines

These devices are specified by RFC 854 and RFC 2217 and ther name into the system is /dev/nvttyX (by default you have 4 devices).

By using these devices and a proper compatible server (not included here but you can use sredird) you can get access to a remote tty device as the tty device itself was conneted with your local host. All data and settings are sent and received through the network.

Oops! I forgot to update the patch message... attached the correct patch.

Sorry, :'(

Rodolfo

Signature · 5 lines
GNU/Linux Solutions                  e-mail: [email protected]
Linux Device Driver                          [email protected]
Embedded Systems                     phone:  +39 349 2432127
UNIX programming                     skype:  rodolfo.giometti
Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
Quoted 1 line

From 41b111aaee2b5c96a56bd6f2aa32aa460e1dd182 Mon Sep 17 00:00:00 2001

From: Rodolfo Giometti <[email protected]>
Date: Sun, 2 Jan 2011 13:04:07 +0100
Subject: [PATCH 1/1] char nvtty: Network Virtual Terminal support

A Network Virtual terminal (NVT tty) is a software device consisting of one halve: a client device, which is identical to a physical terminal, who, in turn, gets connected with a remote server where real tty devices are located.

These devices are specified by RFC 854 and RFC 2217 and their name into the system is /dev/nvttyX (by default there are 4 devices).

By using these devices and a proper compatible server (not included here but you can use sredird) you can get access to a remote tty device as though the tty device itself was connected with your local host. All data and settings are sent and received through the network.

---
 Documentation/ABI/testing/sysfs-nvtty |   35 +
 drivers/char/Kconfig                  |   22 +
 drivers/char/Makefile                 |    1 +
 drivers/char/nvtty.c                  | 1557 +++++++++++++++++++++++++++++++++
 4 files changed, 1615 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-nvtty
 create mode 100644 drivers/char/nvtty.c
Documentation/ABI/testing/sysfs-nvtty new file +35 -0
new file mode 100644
index 0000000..a52d319
@@ -0,0 +1,35 @@
+What:		/sys/class/tty/nvttyX/
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/ directory is related to X-th
+		NVT tty device into the system. Each directory will
+		contain files to manage and control its NVT tty device.
+
+What:		/sys/class/tty/nvttyX/connection
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/connection file reports 1 if the
+		related NVT tty device is connected with remote server and
+		0 otherwise.
+
+What:		/sys/class/tty/nvttyX/ip
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/ip file reports the IP address
+		of the remote server where to connecto to.
+		User should change this value, when no connection is active,
+		in order to select a different remote server.
+		Default is localhost (127.0.0.1).
+
+What:		/sys/class/tty/nvttyX/port
+Date:		January 2011
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/tty/nvttyX/port file reports the IP port number
+		of the remote server where to connecto to.
+		User should change this value, when no connection is active,
+		in order to select a different port.
+		Default is 32769.
drivers/char/Kconfig +22 -0
index 43d3395..439d7c3 100644
@@ -451,6 +451,28 @@ config UNIX98_PTYS
 	  All modern Linux systems use the Unix98 ptys.  Say Y unless
 	  you're on an embedded system and want to conserve memory.
 
+config NVT_TTY
+	tristate "Network Virtual Terminal"
+	default n
+	---help---
+	  A Network Virtual terminal (NVT tty) is a software device
+	  consisting of one halve: a client device, which is
+	  identical to a physical terminal, who, in turn, gets
+	  connected to a remote server where real tty devices are
+	  located.
+
+	  These devices are specified by RFC 854 and RFC 2217 and their
+	  name into the system is /dev/nvttyX (by default there are 4
+	  devices).
+
+	  By using these devices and a proper compatible server (not
+	  included here but you can use sredird) you can get access to
+	  a remote tty device as though the tty device itself was connected
+	  with your local host.  All data and settings are sent and
+	  received through the network.
+
+	  If unsure, say N.
+
 config DEVPTS_MULTIPLE_INSTANCES
 	bool "Support multiple instances of devpts"
 	depends on UNIX98_PTYS
drivers/char/Makefile +1 -0
index ba53ec9..7deba37 100644
@@ -4,6 +4,7 @@
 
 obj-y				+= mem.o random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
+obj-$(CONFIG_NVT_TTY)		+= nvtty.o
 obj-y				+= misc.o
 obj-$(CONFIG_BFIN_JTAG_COMM)	+= bfin_jtag_comm.o
 obj-$(CONFIG_MVME147_SCC)	+= generic_serial.o vme_scc.o
drivers/char/nvtty.c new file +1557 -0

1,557 lines not on this page · raw message

Signature · 1 line
1.7.0.4