]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-daemon's UCSPI-TCP compatibility
authorSergey Matveev <stargrave@stargrave.org>
Mon, 26 Jul 2021 11:33:56 +0000 (14:33 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 26 Jul 2021 11:35:40 +0000 (14:35 +0300)
doc/admin.texi
doc/cfg/neigh.texi
doc/cmd/nncp-daemon.texi
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-daemon/main.go

index a84c9743e1de3e6ede31f67fd2956a33a0d40d85..9a4c8e8df6fcee4453cf5120c7350dc6e5807bb4 100644 (file)
@@ -95,7 +95,7 @@ EOF
     @url{https://en.wikipedia.org/wiki/Inetd, inetd} service on UUCP's port:
 
 @example
-uucp   stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -inetd
+uucp   stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -ucspi
 @end example
 
 @item
@@ -108,8 +108,8 @@ uucp        stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -
 
 # cat > run <<EOF
 #!/bin/sh -e
-exec envuidgid nncpuser tcpserver -DHRU -l 0 0 uucp \
-       /usr/local/bin/nncp-daemon -quiet -inetd
+exec envuidgid nncpuser tcpserver -DHRU -l 0 ::0 uucp \
+       /usr/local/bin/nncp-daemon -quiet -ucspi
 EOF
 
 # cat > log/run <<EOF
index ababdf911cc7f574fb2139ea9664864afb91c45c..fb2388df4dabe98a874a9e48c138efd5087d5da7 100644 (file)
@@ -27,7 +27,7 @@ neigh: {
     addrs: {
       lan: "[fe80::1234%igb0]:5400"
       internet: alice.com:3389
-      proxied: "|ssh remote.host nncp-daemon -inetd"
+      proxied: "|ssh remote.host nncp-daemon -ucspi"
     }
     calls: [
       {
index aa11aca038544c43bb7b8f52a6390ea3ad263be7..4b5fa330cc7c351fe970a384a27a6dcbc96dd6f7 100644 (file)
@@ -3,7 +3,7 @@
 
 @example
 $ nncp-daemon [options]
-    [-maxconn INT] [-bind ADDR] [-inetd]
+    [-maxconn INT] [-bind ADDR] [-ucspi]
     [-autotoss*] [-nock] [-mcd-once]
 @end example
 
@@ -16,14 +16,21 @@ time to time.
 can handle. @option{-bind} option specifies @option{addr:port} it must
 bind to and listen.
 
-It could be run as @command{inetd} service, by specifying
-@option{-inetd} option. Pay attention that because it uses
-@code{stdin}/@code{stdout}, it can not effectively work with IO timeouts
-and connection closing can propagate up to 5 minutes in practice.
-Example inetd-entry:
+It could be run as @url{http://cr.yp.to/ucspi-tcp.html, UCSPI-TCP}
+service, by specifying @option{-ucspi} option. Pay attention that
+because it uses @code{stdin}/@code{stdout}, it can not effectively work
+with IO timeouts and connection closing can propagate up to 5 minutes in
+practice. Example startup command:
 
 @verbatim
-uucp   stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -inetd
+tcpserver -DHR -l 0 ::0 uucp nncp-daemon -quiet -ucspi
+@end verbatim
+
+Also it is some kind of backward compatible with @command{inetd}
+interface, just lacking knowledge or remote's address:
+
+@verbatim
+uucp   stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -ucspi
 @end verbatim
 
 @option{-autotoss} option runs tosser on node's spool every second
index 8d0bca9c0c072d2782cda1f739d09cf233df277d..25af628f701c10791e05f3a043b68aa48d677f85 100644 (file)
@@ -1,6 +1,18 @@
 @node Новости
 @section Новости
 
+@node Релиз 7.5.0
+@subsection Релиз 7.5.0
+@itemize
+
+@item
+@command{nncp-daemon} соблюдает UCSPI-TCP интерфейс, благодаря чему в
+журнале будет присутствовать адрес удалённой системы (при запуске под
+совместимой утилитой). Желательно применять @option{-ucspi} опцию вместо
+@option{-inetd}.
+
+@end itemize
+
 @node Релиз 7.4.0
 @subsection Релиз 7.4.0
 @itemize
index c9106f8c7b52b049abbec7ad649a60e4ba3644d1..1d8a3ee0675166243af14bca6dbe4a96c6d5c98e 100644 (file)
@@ -3,6 +3,17 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 7_5_0
+@section Release 7.5.0
+@itemize
+
+@item
+@command{nncp-daemon} is compatible with UCSPI-TCP interface, so log
+will contain remote side's address (when running under appropriate
+utility). @option{-ucspi} option should be used instead of @option{-inetd}.
+
+@end itemize
+
 @node Release 7_4_0
 @section Release 7.4.0
 @itemize
index b0628fe421a39c8ab37f21e8cb6f733d79b343c8..f27c2a371461b0dad558509be8a09f670c75b507 100644 (file)
@@ -40,28 +40,28 @@ func usage() {
        flag.PrintDefaults()
 }
 
-type InetdConn struct {
+type UCSPIConn struct {
        r *os.File
        w *os.File
 }
 
-func (c InetdConn) Read(p []byte) (n int, err error) {
+func (c UCSPIConn) Read(p []byte) (n int, err error) {
        return c.r.Read(p)
 }
 
-func (c InetdConn) Write(p []byte) (n int, err error) {
+func (c UCSPIConn) Write(p []byte) (n int, err error) {
        return c.w.Write(p)
 }
 
-func (c InetdConn) SetReadDeadline(t time.Time) error {
+func (c UCSPIConn) SetReadDeadline(t time.Time) error {
        return c.r.SetReadDeadline(t)
 }
 
-func (c InetdConn) SetWriteDeadline(t time.Time) error {
+func (c UCSPIConn) SetWriteDeadline(t time.Time) error {
        return c.w.SetWriteDeadline(t)
 }
 
-func (c InetdConn) Close() error {
+func (c UCSPIConn) Close() error {
        if err := c.r.Close(); err != nil {
                c.w.Close() // #nosec G104
                return err
@@ -138,7 +138,8 @@ func main() {
                cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                niceRaw   = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness")
                bind      = flag.String("bind", "[::]:5400", "Address to bind to")
-               inetd     = flag.Bool("inetd", false, "Is it started as inetd service")
+               ucspi     = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP server")
+               inetd     = flag.Bool("inetd", false, "Obsolete, use -ucspi")
                maxConn   = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
                noCK      = flag.Bool("nock", false, "Do no checksum checking")
                mcdOnce   = flag.Bool("mcd-once", false, "Send MCDs once and quit")
@@ -174,6 +175,9 @@ func main() {
        if err != nil {
                log.Fatalln(err)
        }
+       if *inetd {
+               *ucspi = true
+       }
 
        ctx, err := nncp.CtxFromCmdline(
                *cfgPath,
@@ -192,11 +196,20 @@ func main() {
        }
        ctx.Umask()
 
-       if *inetd {
+       if *ucspi {
                os.Stderr.Close() // #nosec G104
-               conn := &InetdConn{os.Stdin, os.Stdout}
+               conn := &UCSPIConn{os.Stdin, os.Stdout}
                nodeIdC := make(chan *nncp.NodeId)
-               go performSP(ctx, conn, "PIPE", nice, *noCK, nodeIdC)
+               addr := "PIPE"
+               if proto := os.Getenv("PROTO"); proto == "TCP" {
+                       port := os.Getenv("TCPREMOTEPORT")
+                       if host := os.Getenv("TCPREMOTEHOST"); host == "" {
+                               addr = fmt.Sprintf("[%s]:%s", os.Getenv("TCPREMOTEIP"), port)
+                       } else {
+                               addr = fmt.Sprintf("%s:%s", host, port)
+                       }
+               }
+               go performSP(ctx, conn, addr, nice, *noCK, nodeIdC)
                nodeId := <-nodeIdC
                var autoTossFinish chan struct{}
                var autoTossBadCode chan bool