From 18cfc4be7bf0bf5bb275b39721dd7ab9eb875d20 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Wed, 17 Mar 2021 01:03:06 +0300 Subject: [PATCH] Adds udp6 support for ingest servers (#1134) with flag -enableUDP6 https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1131 --- lib/ingestserver/graphite/server.go | 2 +- lib/ingestserver/influx/server.go | 2 +- lib/ingestserver/opentsdb/server.go | 2 +- lib/netutil/udp.go | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 lib/netutil/udp.go diff --git a/lib/ingestserver/graphite/server.go b/lib/ingestserver/graphite/server.go index 8bd685954..90c0a055e 100644 --- a/lib/ingestserver/graphite/server.go +++ b/lib/ingestserver/graphite/server.go @@ -44,7 +44,7 @@ func MustStart(addr string, insertHandler func(r io.Reader) error) *Server { } logger.Infof("starting UDP Graphite server at %q", addr) - lnUDP, err := net.ListenPacket("udp4", addr) + lnUDP, err := net.ListenPacket(netutil.GetUDPNetwork(), addr) if err != nil { logger.Fatalf("cannot start UDP Graphite server at %q: %s", addr, err) } diff --git a/lib/ingestserver/influx/server.go b/lib/ingestserver/influx/server.go index 9ed428f27..48ead76a9 100644 --- a/lib/ingestserver/influx/server.go +++ b/lib/ingestserver/influx/server.go @@ -44,7 +44,7 @@ func MustStart(addr string, insertHandler func(r io.Reader) error) *Server { } logger.Infof("starting UDP Influx server at %q", addr) - lnUDP, err := net.ListenPacket("udp4", addr) + lnUDP, err := net.ListenPacket(netutil.GetUDPNetwork(), addr) if err != nil { logger.Fatalf("cannot start UDP Influx server at %q: %s", addr, err) } diff --git a/lib/ingestserver/opentsdb/server.go b/lib/ingestserver/opentsdb/server.go index b25251410..178f3ddb6 100644 --- a/lib/ingestserver/opentsdb/server.go +++ b/lib/ingestserver/opentsdb/server.go @@ -51,7 +51,7 @@ func MustStart(addr string, telnetInsertHandler func(r io.Reader) error, httpIns httpServer := opentsdbhttp.MustServe(lnHTTP, httpInsertHandler) logger.Infof("starting UDP OpenTSDB collector at %q", addr) - lnUDP, err := net.ListenPacket("udp4", addr) + lnUDP, err := net.ListenPacket(netutil.GetUDPNetwork(), addr) if err != nil { logger.Fatalf("cannot start UDP OpenTSDB collector at %q: %s", addr, err) } diff --git a/lib/netutil/udp.go b/lib/netutil/udp.go new file mode 100644 index 000000000..96f11eb6f --- /dev/null +++ b/lib/netutil/udp.go @@ -0,0 +1,14 @@ +package netutil + +import "flag" + +var enableUDP6 = flag.Bool("enableUDP6", false, "Whether to enable IPv6 for listening. By default only IPv4 UDP is used") + +// GetUDPNetwork returns current udp network. +func GetUDPNetwork() string { + if *enableUDP6 { + // Enable both udp4 and udp6 + return "udp" + } + return "udp4" +}