From 857b50285a0b75f03c2f2bfa5daa39901cfdf320 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 25 Jan 2022 19:12:35 +0300 Subject: [PATCH] MCD uses regexp instead of exact interface name --- doc/cfg/general.texi | 12 +++++------ doc/news.ru.texi | 12 +++++++++++ doc/news.texi | 11 ++++++++++ src/cmd/nncp-caller/main.go | 20 ++++++++++++++++--- src/cmd/nncp-cfgnew/main.go | 9 +++++---- src/cmd/nncp-daemon/main.go | 40 +++++++++++++++++++++++++++---------- src/nncp.go | 2 +- 7 files changed, 82 insertions(+), 24 deletions(-) diff --git a/doc/cfg/general.texi b/doc/cfg/general.texi index 69551a2..2575779 100644 --- a/doc/cfg/general.texi +++ b/doc/cfg/general.texi @@ -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} diff --git a/doc/news.ru.texi b/doc/news.ru.texi index f271462..1dd6478 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -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 diff --git a/doc/news.texi b/doc/news.texi index cf0e875..2101ce0 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 diff --git a/src/cmd/nncp-caller/main.go b/src/cmd/nncp-caller/main.go index 981e42e..6902441 100644 --- a/src/cmd/nncp-caller/main.go +++ b/src/cmd/nncp-caller/main.go @@ -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) + } + } } } diff --git a/src/cmd/nncp-cfgnew/main.go b/src/cmd/nncp-cfgnew/main.go index e049b44..8e0fa9f 100644 --- a/src/cmd/nncp-cfgnew/main.go +++ b/src/cmd/nncp-cfgnew/main.go @@ -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: { diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index 88f7e20..5fd6f6d 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -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 { diff --git a/src/nncp.go b/src/nncp.go index ce0c0d7..b9457d3 100644 --- a/src/nncp.go +++ b/src/nncp.go @@ -40,7 +40,7 @@ along with this program. If not, see .` const Base32Encoded32Len = 52 var ( - Version string = "8.3.0" + Version string = "8.4.0" Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding) ) -- 2.44.0