Author: quozl
Date: Wed Feb 20 03:46:23 2013
New Revision: 3563
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3563
Log:
inet - add remote diagnosis console feature, increase verbosity of telnet and telnetd, include telnetd in build rather than autoload from source, and allow other port numbers for outbound telnet.
Added:
ofw/inet/rdc.fth
Modified:
ofw/inet/loadtcp.fth
ofw/inet/telnet.fth
ofw/inet/telnetd.fth
Modified: ofw/inet/loadtcp.fth
==============================================================================
--- ofw/inet/loadtcp.fth Wed Feb 20 03:43:47 2013 (r3562)
+++ ofw/inet/loadtcp.fth Wed Feb 20 03:46:23 2013 (r3563)
@@ -20,10 +20,8 @@
fload ${BP}/ofw/inet/finger.fth
fload ${BP}/ofw/inet/telnet.fth
fload ${BP}/ofw/inet/loadmail.fth
-
-warning @ warning off
-autoload: telnetd defines: telnetd
-warning !
+fload ${BP}/ofw/inet/telnetd.fth
+fload ${BP}/ofw/inet/rdc.fth
also forth definitions
" " d# 64 config-string http-proxy
Added: ofw/inet/rdc.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ ofw/inet/rdc.fth Wed Feb 20 03:46:23 2013 (r3563)
@@ -0,0 +1,115 @@
+\ See license at end of file
+purpose: Remote diagnosis console - shares the interpreter with a remote host
+
+\
+\ rdc - a telnetd that makes rather than accepting a connection.
+\ rdcd - a telnet that accepts rather than making a connection.
+\
+
+\
+\ Instructions for use over internet:
+\
+\ 1. set up a TCP relay on ports 8024 and 8023 of a host that is
+\ accessible to the user over the internet,
+\
+\ % socat \
+\ TCP-LISTEN:8024,fork,reuseaddr,nodelay,bind=127.0.0.1 \
+\ TCP-LISTEN:8023,reuseaddr,nodelay
+\
+\ 2. start your telnet client and connect to port 8024,
+\
+\ % telnet -- 127.0.0.1 -8024
+\
+\ (the odd arguments are to force automatic initiation of TELNET options
+\ which would otherwise be omitted due to the non-standard port number).
+\
+\ 3. ask the user to type "rdc IP" on the remote system, where IP is the IP
+\ address of the host running socat,
+\
+\ ok rdc IP
+\
+\ 4. use the remote system via the connection. When done, type
+\ "exit-rdc" or just close the connection.
+\
+
+\
+\ Instructions for use over a local network:
+\
+\ 1. on the host firmware system, start rdcd to listen for
+\ connections, and note the IP address shown,
+\
+\ ok rdcd
+\
+\ 2. on the target firmware system, type "rdc IP",
+\
+\ ok rdc IP
+\
+\ 3. use the remote system via the connection. When done, type
+\ "exit-rdc" or close the connection with ctrl-].
+\
+
+\needs telnet fload ${BP}/ofw/inet/telnet.fth
+\needs telnetd fload ${BP}/ofw/inet/telnetd.fth
+
+: exit-rdc
+ telnet-ih 0= if exit then
+ demux
+ close-telnet
+ ." rdc: off" cr
+;
+
+: $rdc ( host$ port# -- )
+ " tcp//telnet:passive" open-telnet
+ " connect?" telnet-ih $call-method 0= if
+ close-telnet true abort" Can't connect to host"
+ then
+ ." rdc: connected" cr
+ mux banner
+;
+
+: parse-port ( ["port"] -- port# )
+ parse-word dup if ( port$ )
+ push-decimal $number pop-base abort" Bad port" ( port# )
+ else
+ 2drop d# 8023
+ then ( port# )
+;
+
+: rdc ( "host" ["port"] -- ) \ share this console with remote host
+ safe-parse-word parse-port $rdc
+;
+
+: rdcd ( ["port"] -- ) \ wait for a shared console connection
+ parse-port
+ open-tcp
+ ." rdcd: listening for a connection" cr
+ tcp-accept
+ ." rdcd: connected" cr
+ (telnet)
+ close-tcp
+ ." rdcd: disconnected" cr
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2013 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Modified: ofw/inet/telnet.fth
==============================================================================
--- ofw/inet/telnet.fth Wed Feb 20 03:43:47 2013 (r3562)
+++ ofw/inet/telnet.fth Wed Feb 20 03:46:23 2013 (r3563)
@@ -111,8 +111,22 @@
telnet-out
repeat
;
-: $telnet ( hostname$ -- ) d# 23 open-tcp-connection (telnet) close-tcp ;
-: telnet ( "hostname" -- ) safe-parse-word $telnet ;
+: $telnet ( host$ port# -- )
+ open-tcp-connection
+ ." telnet: connected" cr
+ (telnet)
+ close-tcp
+ ." telnet: disconnected" cr
+;
+: telnet ( "host" ["port"] -- )
+ safe-parse-word ( host$ )
+ parse-word dup if ( host$ port$ )
+ push-decimal $number pop-base abort" Bad port" ( host$ port# )
+ else
+ 2drop d# 23
+ then ( host$ port# )
+ $telnet
+;
hex
\ LICENSE_BEGIN
Modified: ofw/inet/telnetd.fth
==============================================================================
--- ofw/inet/telnetd.fth Wed Feb 20 03:43:47 2013 (r3562)
+++ ofw/inet/telnetd.fth Wed Feb 20 03:46:23 2013 (r3563)
@@ -5,10 +5,13 @@
\ use telnet on the remote host to connect to the firmware system.
\ When done, execute "exit-telnet" or just close the connection.
+\needs telnet fload ${BP}/ofw/inet/telnet.fth \ for protocol constants
+
support-package: telnet
-false value debug-options?
+false value debug-options? \ display telnet option negotiation
false value verbose?
-false value listening?
+false value passive? \ package is not to try accept or connect
+false value listening? \ package is to try accept
: (read) ( adr len -- actual ) " read" $call-parent ;
: (write) ( adr len -- actual ) " write" $call-parent ;
@@ -49,17 +52,17 @@
: send-option ( option request -- ) #iac putbyte putbyte putbyte ;
-: send-will ( option -- ) " WILL" .sent d# 251 send-option ;
-: send-wont ( option -- ) " WONT" .sent d# 252 send-option ;
-: send-do ( option -- ) " DO" .sent d# 253 send-option ;
-: send-dont ( option -- ) " DONT" .sent d# 254 send-option ;
+: send-will ( option -- ) " WILL" .sent #will send-option ;
+: send-wont ( option -- ) " WONT" .sent #wont send-option ;
+: send-do ( option -- ) " DO" .sent #do send-option ;
+: send-dont ( option -- ) " DONT" .sent #dont send-option ;
: will ( rem$ -- rem$' )
next-cmd-byte " WILL" .got
dup case
\ Since we have already sent "do binary", there is no need to re-ack it
\ 0 of send-do endof
- 0 of drop endof \ Suppress go-ahead
+ 0 of drop endof \ Suppress binary
\ Since we have already sent "do suppressGA", there is no need to re-ack it
\ 3 of send-do endof \ Suppress go-ahead
@@ -120,11 +123,11 @@
d# 247 of control h reinsert endof \ erase character
d# 248 of control u reinsert endof \ erase line
d# 249 of endof \ go-ahead
- d# 250 of subnegotiate endof
- d# 251 of will endof
- d# 252 of wont endof
- d# 253 of tdo endof
- d# 254 of dont endof
+ #sb of subnegotiate endof
+ #will of will endof
+ #wont of wont endof
+ #do of tdo endof
+ #dont of dont endof
#iac of #iac reinsert endof
endcase
;
@@ -155,14 +158,27 @@
" his-ip-addr" $call-parent .ipaddr
;
+: negotiate ( -- )
+ 3 send-do \ You suppress go-ahead
+ 0 send-do \ Be binary
+ 1 send-will \ I will echo
+;
+
: accept? ( -- connected? )
d# 23 " accept" $call-parent 0= if false exit then
verbose? if ." telnetd: connection from " .his-ip-addr cr then
+ negotiate
+ false to listening?
+ false to last-was-cr?
+ true
+;
- 3 send-do \ You suppress go-ahead
- 0 send-do \ Be binary
- 1 send-will \ I will echo
+: connect? ( $host port# -- connected? )
+ >r " $set-host" $call-parent r> ( port )
+ " connect" $call-parent 0= if false exit then ( )
+
+ negotiate
false to listening?
false to last-was-cr?
true
@@ -175,7 +191,7 @@
;
: read ( adr len -- actual|-1|-2 )
- listening? if accept? drop 2drop -2 exit then
+ listening? passive? 0= and if accept? drop 2drop -2 exit then
over swap (read) ( adr actual )
dup case ( adr actual )
-1 of disconnect nip exit endof
@@ -196,9 +212,18 @@
2drop (write) drop ( len )
;
+: parse-args ( $ -- )
+ begin ?dup while
+ ascii , left-parse-string
+ 2dup " verbose" $= if true to verbose? then
+ " passive" $= if true to passive? then
+ repeat drop
+;
+
: open ( -- flag )
true to listening?
- my-args " verbose" $= to verbose?
+ my-args parse-args
+ passive? if true exit then
verbose? if
." telnet://" " my-ip-addr" $call-parent .ipaddr cr
@@ -206,36 +231,39 @@
begin accept? until
- verbose? if ." Connected" cr then
-
true
;
: close ( -- ) ;
end-support-package
-
0 value telnet-ih
+: mux ( -- ) telnet-ih " add-console" evaluate ;
+: demux ( -- ) telnet-ih " remove-console" evaluate ;
+
+: open-telnet ( name$ -- )
+ open-dev dup 0= abort" Can't open telnet" ( ih )
+ to telnet-ih
+;
+
+: close-telnet
+ telnet-ih close-dev
+ 0 to telnet-ih
+;
+
: exit-telnet ( -- )
telnet-ih 0= if exit then
" verbose?" telnet-ih $call-method ( verbose? )
- telnet-ih remove-output ( verbose? )
- telnet-ih remove-input ( verbose? )
- telnet-ih close-dev ( verbose? )
- 0 to telnet-ih ( verbose? )
+ demux
+ close-telnet ( verbose? )
if ." telnetd: off" cr then ( )
;
-devalias telnetd tcp//telnet:verbose
-
: telnetd ( -- )
- " telnetd" open-dev dup 0= abort" Can't open telnet" ( ih )
- to telnet-ih
- telnet-ih add-output
- telnet-ih add-input
- \ hint: use " screen-ih remove-output " to speed up your telnet output
+ " tcp//telnet:verbose" open-telnet mux banner
;
+
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\