]> Cypherpunks.ru repositories - nncp.git/commitdiff
MCD uses regexp instead of exact interface name
authorSergey Matveev <stargrave@stargrave.org>
Tue, 25 Jan 2022 16:12:35 +0000 (19:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 25 Jan 2022 18:27:36 +0000 (21:27 +0300)
doc/cfg/general.texi
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-caller/main.go
src/cmd/nncp-cfgnew/main.go
src/cmd/nncp-daemon/main.go
src/nncp.go

index 69551a280e85521acb0a16979d14db16c2e5554a..2575779de6171bde4c9a803c3c34b79b7a61e10b 100644 (file)
@@ -13,8 +13,8 @@ noprogress: true
 nohdr: true
 
 # MultiCast Discovery
-mcd-listen: ["em0", "igb1"]
-mcd-send: {em0: 60, igb1: 5}
+mcd-listen: ["em[0-3]", "igb_.*"]
+mcd-send: {"em[0-3]": 60, igb_.*: 5}
 
 # Yggdrasil aliases
 yggdrasil-aliases: {
@@ -52,12 +52,12 @@ And optional @ref{MCD, MultiCast Discovery} options:
 @table @code
 @anchor{CfgMCDListen}
 @item mcd-listen
-Specifies list of network interfaces @ref{nncp-caller} will listen for
-incoming @ref{MCD} announcements.
+Specifies list of network interfaces regular expression
+@ref{nncp-caller} will listen for incoming @ref{MCD} announcements.
 @anchor{CfgMCDSend}
 @item mcd-send
-Specifies list of network interfaces, and intervals in seconds, where
-@ref{nncp-daemon} will send @ref{MCD} announcements.
+Specifies list of network interfaces regular expressions, and intervals
+in seconds, where @ref{nncp-daemon} will send @ref{MCD} announcements.
 @end table
 
 @anchor{CfgYggdrasilAliases}
index f271462591614ed9fdf0e0c56bd8ff634fd1ac6c..1dd64787e88409d9a168fc1d7ad572b4d78374b5 100644 (file)
@@ -1,6 +1,18 @@
 @node Новости
 @section Новости
 
+@node Релиз 8.4.0
+@subsection Релиз 8.4.0
+@itemize
+
+@item
+Имена интерфейсов относящихся к multicast (@code{mcd-listen} и
+@code{mcd-send} опции конфигурации) теперь являются регулярными
+выражениями. По умолчанию @command{nncp-cfgnew} не комментирует
+их теперь и прописывает @code{.*} имя интерфейса.
+
+@end itemize
+
 @node Релиз 8.3.0
 @subsection Релиз 8.3.0
 @itemize
index cf0e875adfd8d52daf6e4dadeafae3f63932c4aa..2101ce085c6b4b8c923b4d9eca9569c841c94a00 100644 (file)
@@ -3,6 +3,17 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 8_4_0
+@section Release 8.4.0
+@itemize
+
+@item
+Multicast related interface names (@code{mcd-listen} and @code{mcd-send}
+configuration options) are now regular expressions. By default
+@command{nncp-cfgnew} uncomments them now with @code{.*} interface name.
+
+@end itemize
+
 @node Release 8_3_0
 @section Release 8.3.0
 @itemize
index 981e42e68d204e3faadf845d25036ac32a329d55..690244141eaf87e151112c3822b7c8ff9c637ff0 100644 (file)
@@ -23,7 +23,9 @@ import (
        "flag"
        "fmt"
        "log"
+       "net"
        "os"
+       "regexp"
        "sync"
        "time"
 
@@ -125,9 +127,21 @@ func main() {
                }
        }
 
-       for _, ifiName := range ctx.MCDRxIfis {
-               if err = ctx.MCDRx(ifiName); err != nil {
-                       log.Printf("Can not run MCD reception on %s: %s", ifiName, err)
+       ifis, err := net.Interfaces()
+       if err != nil {
+               log.Fatalln("Can not get network interfaces list:", err)
+       }
+       for _, ifiReString := range ctx.MCDRxIfis {
+               ifiRe, err := regexp.CompilePOSIX(ifiReString)
+               if err != nil {
+                       log.Fatalf("Can not compile POSIX regexp \"%s\": %s", ifiReString, err)
+               }
+               for _, ifi := range ifis {
+                       if ifiRe.MatchString(ifi.Name) {
+                               if err = ctx.MCDRx(ifi.Name); err != nil {
+                                       log.Printf("Can not run MCD reception on %s: %s", ifi.Name, err)
+                               }
+                       }
                }
        }
 
index e049b444bdb87a61f9d59c0d57659a150bfee773..8e0fa9f819c48e2e4ad1801e6a106229c73a1f4a 100644 (file)
@@ -198,10 +198,11 @@ func main() {
   # nohdr: true
 
   # MultiCast Discovery:
-  # List of interfaces where to listen for MCD announcements
-  # mcd-listen: ["em0", "igb1"]
-  # Interfaces and intervals (in seconds) where to send MCD announcements
-  # mcd-send: {em0: 60, igb1: 5}
+  # List of interface regular expressions where to listen for MCD announcements
+  mcd-listen: [".*"]
+  # Interfaces regular expressions and intervals (in seconds) where to send
+  # MCD announcements
+  mcd-send: {.*: 10}
 
   # Yggdrasil related aliases:
   # yggdrasil-aliases: {
index 88f7e20fec9dfa1c5692dfb04235ccf1171f3ba4..5fd6f6d0353f5cc0e7e5e5212234e9bd4def05ea 100644 (file)
@@ -24,6 +24,7 @@ import (
        "log"
        "net"
        "os"
+       "regexp"
        "strconv"
        "strings"
        "time"
@@ -105,6 +106,31 @@ func performSP(
        close(nodeIdC)
 }
 
+func startMCDTx(ctx *nncp.Ctx, port int, zeroInterval bool) error {
+       ifis, err := net.Interfaces()
+       if err != nil {
+               return err
+       }
+       for ifiReString, secs := range ctx.MCDTxIfis {
+               ifiRe, err := regexp.CompilePOSIX(ifiReString)
+               if err != nil {
+                       return err
+               }
+               var interval time.Duration
+               if !zeroInterval {
+                       interval = time.Duration(secs) * time.Second
+               }
+               for _, ifi := range ifis {
+                       if ifiRe.MatchString(ifi.Name) {
+                               if err = ctx.MCDTx(ifi.Name, port, interval); err != nil {
+                                       return err
+                               }
+                       }
+               }
+       }
+       return nil
+}
+
 func main() {
        var (
                cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
@@ -211,10 +237,8 @@ func main() {
                }
 
                if *mcdOnce {
-                       for ifiName := range ctx.MCDTxIfis {
-                               if err = ctx.MCDTx(ifiName, port, 0); err != nil {
-                                       log.Fatalln("Can not do MCD transmission:", err)
-                               }
+                       if err = startMCDTx(ctx, port, true); err != nil {
+                               log.Fatalln("Can not do MCD transmission:", err)
                        }
                        return
                }
@@ -223,13 +247,9 @@ func main() {
                if err != nil {
                        log.Fatalln("Can not listen:", err)
                }
-
-               for ifiName, secs := range ctx.MCDTxIfis {
-                       if err = ctx.MCDTx(ifiName, port, time.Duration(secs)*time.Second); err != nil {
-                               log.Fatalln("Can not run MCD transmission:", err)
-                       }
+               if err = startMCDTx(ctx, port, false); err != nil {
+                       log.Fatalln("Can not do MCD transmission:", err)
                }
-
                ln = netutil.LimitListener(ln, *maxConn)
                go func() {
                        for {
index ce0c0d71fbc082bbf2768df5893306891606c32e..b9457d378b686e13dfbf7a47fbc95fcf0da711e5 100644 (file)
@@ -40,7 +40,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.`
 const Base32Encoded32Len = 52
 
 var (
-       Version string = "8.3.0"
+       Version string = "8.4.0"
 
        Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding)
 )