ttynvt: Enable disabling telnet processing

Similar to suggestion by Jo Luxer:
"Make applications work, which expect a tty but the remote end is just a
network port."
https://gitlab.com/lars-thrane-as/ttynvt/-/merge_requests/9
This commit is contained in:
Kim Woelders
2023-02-16 16:47:24 +01:00
parent 20c393c053
commit d1f46f7dbe
3 changed files with 24 additions and 5 deletions
+6 -2
View File
@@ -21,7 +21,7 @@ typedef struct {
unsigned int bytes_rx; /* Rx byte count */
unsigned int off_rx; /* Rx buffer offset */
unsigned char mode_telnet; /* Telnet mode */
signed char mode_telnet; /* Telnet mode */
unsigned char mode_rfc2217; /* RFC-2217 mode */
unsigned char telnet_ack[256]; /* telnet option ack counter */
} tn_ctx_t;
@@ -29,7 +29,7 @@ typedef struct {
extern tn_ctx_t *telnet_ctx_init(void *cctx, srv_tx_f * ftx, srv_rx_f * frx,
srv_ms_f * fss);
extern int telnet_open(tn_ctx_t * tcc);
extern int telnet_open(tn_ctx_t * tcc, int mode);
extern int telnet_rx(tn_ctx_t * tcc, char *buf, int *plen);
extern int telnet_tx(tn_ctx_t * tcc, const char *buf, int len);
@@ -44,6 +44,10 @@ extern void telnet_rfc2217_cfg(tn_ctx_t * tcc, int cmd,
const void *val, int nd);
extern void telnet_rfc2217_ctl(tn_ctx_t * tcc, unsigned int val);
/* Telnet mode */
#define TN_MODE_RAW 0 /* Telnet processing off */
#define TN_MODE_TELNET 1 /* Telnet mode */
/*RFC2217 modem state*/
#define TNS_STATE_DCD 0x80
#define TNS_STATE_RI 0x40
+12 -2
View File
@@ -128,6 +128,10 @@ int telnet_rx(tn_ctx_t * tcc, char *buf, int *plen)
int np, nd;
int b1, b2;
/* Skip telnet processing entirely in raw mode */
if (tcc->mode_telnet < 0)
return 0;
len = *plen;
tcc->bytes_rx += len;
@@ -236,7 +240,7 @@ int telnet_tx(tn_ctx_t * tcc, const char *buf, int len)
for (s = buf, rem = len; rem > 0; s = p)
{
if (tcc->mode_telnet)
if (tcc->mode_telnet > 0)
p = memchr(s, TNC_FF_IAC, rem);
else
p = NULL;
@@ -259,12 +263,18 @@ int telnet_tx(tn_ctx_t * tcc, const char *buf, int len)
return 0;
}
int telnet_open(tn_ctx_t * tcc)
int telnet_open(tn_ctx_t * tcc, int mode)
{
time_t t = time(NULL);;
char buf[3];
int res;
if (mode == TN_MODE_RAW)
{
tcc->mode_telnet = -1; /* Raw mode - no telnet processing */
return 0;
}
buf[0] = TNC_FF_IAC;
buf[1] = TNC_FB_WILL;
buf[2] = TNO_CPCO;
+6 -1
View File
@@ -44,6 +44,7 @@ static struct ttynvt_param {
unsigned int quiet;
unsigned int debug;
int logstd;
int raw; /* No telnet processing */
const char *close_delay;
/* Derived */
unsigned int close_delay_us;
@@ -467,12 +468,14 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
tty->fds[FD_SLAVE].fd = fd;
tty->fds[FD_SLAVE].events = POLLIN;
res = telnet_open(tty->tn);
res =
telnet_open(tty->tn, ttynvt_param.raw ? TN_MODE_RAW : TN_MODE_TELNET);
if (res < 0)
{
errno = EPROTO;
goto open_err;
}
if ((res = pthread_mutex_init(&tty->tty_lock, NULL) < 0) ||
(res = pthread_mutex_init(&tty->poll_lock, NULL) < 0) ||
(res = pthread_create(&tty->ptid_poll, NULL, &_read_net, tty)))
@@ -1140,6 +1143,7 @@ static const struct fuse_opt ttynvt_opts[] = {
TTYNET_OPT("-n %s", dev_name, 0),
TTYNET_OPT("--name=%s", dev_name, 0),
TTYNET_OPT("-q", quiet, 1),
TTYNET_OPT("-r", raw, 1),
TTYNET_OPT("-s %s", close_delay, 0),
TTYNET_OPT("-S %s", server, 0),
TTYNET_OPT("--server=%s", server, 0),
@@ -1160,6 +1164,7 @@ static void print_help(void)
"\t-n name, --name=name (default: ttyNVT0)\n"
"\t\tDevice will be created in /dev/$name.\n"
"\t-q\t\tBe quiet (suppress informational messages)\n"
"\t-r\t\tDisable telnet processing\n"
"\t-s delay \t\tDelay at close in ms (use u suffix for us)\n"
"\t-S server, --server=host:port\n");
}