PERFORCE change 197249 for review
Catalin Nicutar
cnicutar at FreeBSD.org
Fri Aug 5 23:43:29 UTC 2011
http://p4web.freebsd.org/@@197249?ac=10
Change 197249 by cnicutar at cnicutar_cronos on 2011/08/05 23:43:09
Forward-port telnet and telnetd UTO support to HEAD.
Affected files ...
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/commands.c#2 edit
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/externs.h#2 edit
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/main.c#2 edit
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/telnet.1#2 edit
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/telnet.c#2 edit
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnetd/telnetd.8#2 edit
.. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnetd/telnetd.c#2 edit
Differences ...
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/commands.c#2 (text+ko) ====
@@ -78,6 +78,7 @@
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
+#include <netinet/tcp.h>
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
@@ -877,6 +878,7 @@
{ "escape", "character to escape back to telnet command mode", NULL, &escape },
{ "rlogin", "rlogin escape character", 0, &rlogin },
{ "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},
+ { "timeout", "tcp timeout for this connection", set_timeout, NULL},
{ " ", "", NULL, NULL },
{ " ", "The following need 'localchars' to be toggled true", NULL, NULL },
{ "flushoutput", "character to cause an Abort Output", NULL, termFlushCharp },
@@ -919,6 +921,21 @@
}
}
+void
+set_timeout(char *s)
+{
+ if (s == NULL) {
+ uto = 0;
+ /* There is not way to "take it back". */
+ return;
+ }
+ /* Setting the timeout if net is a valid descriptor. */
+ uto = strtonum(s, 0, INT_MAX, NULL);
+ if (uto && net > 0 && setsockopt(net, IPPROTO_TCP, TCP_SNDUTO_TIMEOUT,
+ &uto, sizeof(uto)))
+ perror("setsockopt UTO");
+}
+
static int
setcmd(int argc, char *argv[])
{
@@ -976,7 +993,8 @@
return 0;
} else if (ct->handler) {
(*ct->handler)(argv[2]);
- printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);
+ if (ct->charp)
+ printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);
} else {
if (strcmp("off", argv[2])) {
value = special(argv[2]);
@@ -1042,7 +1060,8 @@
return 0;
} else if (ct->handler) {
(*ct->handler)(0);
- printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);
+ if (ct->charp)
+ printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);
} else {
*(ct->charp) = _POSIX_VDISABLE;
printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
@@ -2442,6 +2461,9 @@
goto fail;
}
#endif
+ if (uto && setsockopt(net, IPPROTO_TCP, TCP_SNDUTO_TIMEOUT, &uto,
+ sizeof(uto)))
+ perror("setsockopt UTO");
if (connect(net, res->ai_addr, res->ai_addrlen) < 0) {
struct addrinfo *next;
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/externs.h#2 (text+ko) ====
@@ -129,6 +129,7 @@
termdata, /* Print out terminal data flow */
telnet_debug, /* Debug level */
doaddrlookup, /* do a reverse lookup? */
+ uto, /* Request User Timeout. */
clienteof; /* Client received EOF */
extern cc_t escape; /* Escape to command mode */
@@ -260,6 +261,7 @@
setcommandmode(void),
set_escape_char(char *s),
setneturg(void),
+ set_timeout(char *s),
sys_telnet_init(void),
telnet(char *),
tel_enter_binary(int),
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/main.c#2 (text+ko) ====
@@ -97,7 +97,7 @@
"[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-c] [-d]",
"\n\t[-e char] [-l user] [-n tracefile] ",
#endif
- "[-r] [-s src_addr] [-u] ",
+ "[-r] [-s src_addr] [-t timeout] [-u] ",
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
"[-P policy] "
#endif
@@ -154,7 +154,7 @@
#define IPSECOPT
#endif
while ((ch = getopt(argc, argv,
- "468EKLNS:X:acde:fFk:l:n:rs:uxy" IPSECOPT)) != -1)
+ "468EKLNS:X:acde:fFk:l:n:rs:ut:xy" IPSECOPT)) != -1)
#undef IPSECOPT
{
switch(ch) {
@@ -303,6 +303,12 @@
case 's':
src_addr = optarg;
break;
+ case 't':
+ set_timeout(optarg);
+ if (!uto)
+ fprintf(stderr, "Warning: timeout `%s'"
+ " ignored\n", optarg);
+ break;
case 'u':
family = AF_UNIX;
break;
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/telnet.1#2 (text+ko) ====
@@ -50,6 +50,7 @@
.Op Fl l Ar user
.Op Fl n Ar tracefile
.Op Fl s Ar src_addr
+.Op Fl t Ar timeout
.Oo
.Ar host
.Op Ar port
@@ -203,6 +204,14 @@
connection to
.Ar src_addr ,
which can be an IP address or a host name.
+.It Fl t Ar timeout
+Sets the requested timeout (UTO) for the connection.
+If the server accepts this value, the connection will be kept for
+.Ar timeout
+seconds in the absence of network connectivity.
+.Pp
+This is server-dependent, but usually it only works with authentication,
+for security reasons.
.It Fl u
Forces
.Nm
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnet/telnet.c#2 (text+ko) ====
@@ -112,6 +112,7 @@
dontlecho, /* do we suppress local echoing right now? */
globalmode,
doaddrlookup = 1, /* do a reverse address lookup? */
+ uto = 0, /* Request User Timeout. */
clienteof = 0;
char *prompt = 0;
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnetd/telnetd.8#2 (text+ko) ====
@@ -32,7 +32,7 @@
.\" @(#)telnetd.8 8.4 (Berkeley) 6/1/94
.\" $FreeBSD: src/contrib/telnet/telnetd/telnetd.8,v 1.22 2008/08/29 00:04:37 trhodes Exp $
.\"
-.Dd August 28, 2008
+.Dd August 05, 2011
.Dt TELNETD 8
.Os
.Sh NAME
@@ -42,7 +42,7 @@
protocol server
.Sh SYNOPSIS
.Nm /usr/libexec/telnetd
-.Op Fl 46BUhlkn
+.Op Fl 46BUhlknt
.Op Fl D Ar debugmode
.Op Fl S Ar tos
.Op Fl X Ar authtype
@@ -263,6 +263,14 @@
TOS name found in the
.Pa /etc/iptos
file.
+.It Fl t
+Accepts UTO (User Timeout) suggestion from client.
+Normally a TCP connection is dropped if data is not acknowledged for a period
+of time.
+A client may influnce this period by advertising a timeout value.
+.Pp
+The value sent by the client is only accepted after successful authentication,
+for security reasons.
.It Fl u Ar len
This option is used to specify the size of the field
in the
==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/telnet/telnetd/telnetd.c#2 (text+ko) ====
@@ -49,6 +49,7 @@
#include <termcap.h>
#include <arpa/inet.h>
+#include <netinet/tcp.h> /* For UTO. */
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
@@ -80,6 +81,7 @@
static int debug = 0;
int keepalive = 1;
const char *altlogin;
+int uto = 0; /* Accept advertised timeout. */
void doit(struct sockaddr *);
int terminaltypeok(char *);
@@ -93,7 +95,7 @@
* passed off to getopt().
*/
char valid_opts[] = {
- 'd', ':', 'h', 'k', 'n', 'p', ':', 'S', ':', 'u', ':', 'U',
+ 'd', ':', 'h', 'k', 'n', 'p', ':', 'S', ':', 't', 'u', ':', 'U',
'4', '6',
#ifdef AUTHENTICATION
'a', ':', 'X', ':',
@@ -285,6 +287,11 @@
#endif
break;
+ case 't':
+ /* Enable TCP_RCVUTO_TIMEOUT after authentication.*/
+ uto = 1;
+ break;
+
case 'u':
utmp_len = (size_t)atoi(optarg);
if (utmp_len >= sizeof(remote_hostname))
@@ -445,6 +452,7 @@
#ifdef HAS_GETTOS
fprintf(stderr, " [-S tos]");
#endif
+ fprintf(stderr, " [-t]");
#ifdef AUTHENTICATION
fprintf(stderr, " [-X auth-type]");
#endif
@@ -931,6 +939,11 @@
DIAG(TD_REPORT, output_data("td: Entering processing loop\r\n"));
+ /* If authenticated we'll accept the received UTO. */
+ if (uto && level && setsockopt(net, IPPROTO_TCP, TCP_RCVUTO_TIMEOUT, &uto,
+ sizeof(uto)))
+ perror("setsockopt UTO");
+
/*
* Startup the login process on the slave side of the terminal
* now. We delay this until here to insure option negotiation
More information about the p4-projects
mailing list