diff --git a/cmd/cnetflow/cnetflow.go b/cmd/cnetflow/cnetflow.go index 7ce8a48..291eca7 100644 --- a/cmd/cnetflow/cnetflow.go +++ b/cmd/cnetflow/cnetflow.go @@ -18,8 +18,9 @@ var ( buildinfos = "" AppVersion = "GoFlow NetFlow " + version + " " + buildinfos - Addr = flag.String("addr", "", "NetFlow/IPFIX listening address") - Port = flag.Int("port", 2055, "NetFlow/IPFIX listening port") + Addr = flag.String("addr", "", "NetFlow/IPFIX listening address") + Port = flag.Int("port", 2055, "NetFlow/IPFIX listening port") + Reuse = flag.Bool("reuse", false, "Enable so_reuseport for NetFlow/IPFIX listening port") Workers = flag.Int("workers", 1, "Number of NetFlow workers") LogLevel = flag.String("loglevel", "info", "Log level") @@ -80,7 +81,7 @@ func main() { "Type": "NetFlow"}). Infof("Listening on UDP %v:%v", *Addr, *Port) - err := s.FlowRoutine(*Workers, *Addr, *Port) + err := s.FlowRoutine(*Workers, *Addr, *Port, *Reuse) if err != nil { log.Fatalf("Fatal error: could not listen to UDP (%v)", err) } diff --git a/cmd/cnflegacy/cnflegacy.go b/cmd/cnflegacy/cnflegacy.go index 60ea52a..10bbf82 100644 --- a/cmd/cnflegacy/cnflegacy.go +++ b/cmd/cnflegacy/cnflegacy.go @@ -18,8 +18,9 @@ var ( buildinfos = "" AppVersion = "GoFlow NetFlowV5 " + version + " " + buildinfos - Addr = flag.String("addr", "", "NetFlow v5 listening address") - Port = flag.Int("port", 2055, "NetFlow v5 listening port") + Addr = flag.String("addr", "", "NetFlow v5 listening address") + Port = flag.Int("port", 2055, "NetFlow v5 listening port") + Reuse = flag.Bool("reuse", false, "Enable so_reuseport for NetFlow v5 listening port") Workers = flag.Int("workers", 1, "Number of NetFlow v5 workers") LogLevel = flag.String("loglevel", "info", "Log level") @@ -78,7 +79,7 @@ func main() { "Type": "NetFlowLegacy"}). Infof("Listening on UDP %v:%v", *Addr, *Port) - err := s.FlowRoutine(*Workers, *Addr, *Port) + err := s.FlowRoutine(*Workers, *Addr, *Port, *Reuse) if err != nil { log.Fatalf("Fatal error: could not listen to UDP (%v)", err) } diff --git a/cmd/csflow/csflow.go b/cmd/csflow/csflow.go index 2b29808..70e2c5e 100644 --- a/cmd/csflow/csflow.go +++ b/cmd/csflow/csflow.go @@ -18,8 +18,9 @@ var ( buildinfos = "" AppVersion = "GoFlow sFlow " + version + " " + buildinfos - Addr = flag.String("addr", "", "sFlow listening address") - Port = flag.Int("port", 6343, "sFlow listening port") + Addr = flag.String("addr", "", "sFlow listening address") + Port = flag.Int("port", 6343, "sFlow listening port") + Reuse = flag.Bool("reuse", false, "Enable so_reuseport for sFlow listening port") Workers = flag.Int("workers", 1, "Number of sFlow workers") LogLevel = flag.String("loglevel", "info", "Log level") @@ -78,7 +79,7 @@ func main() { "Type": "sFlow"}). Infof("Listening on UDP %v:%v", *Addr, *Port) - err := s.FlowRoutine(*Workers, *Addr, *Port) + err := s.FlowRoutine(*Workers, *Addr, *Port, *Reuse) if err != nil { log.Fatalf("Fatal error: could not listen to UDP (%v)", err) } diff --git a/cmd/goflow/goflow.go b/cmd/goflow/goflow.go index 0f7ece6..e5d53df 100644 --- a/cmd/goflow/goflow.go +++ b/cmd/goflow/goflow.go @@ -23,14 +23,17 @@ var ( SFlowEnable = flag.Bool("sflow", true, "Enable sFlow") SFlowAddr = flag.String("sflow.addr", "", "sFlow listening address") SFlowPort = flag.Int("sflow.port", 6343, "sFlow listening port") + SFlowReuse = flag.Bool("sflow.reuserport", false, "Enable so_reuseport for sFlow") NFLEnable = flag.Bool("nfl", true, "Enable NetFlow v5") NFLAddr = flag.String("nfl.addr", "", "NetFlow v5 listening address") NFLPort = flag.Int("nfl.port", 2056, "NetFlow v5 listening port") + NFLReuse = flag.Bool("nfl.reuserport", false, "Enable so_reuseport for NetFlow v5") NFEnable = flag.Bool("nf", true, "Enable NetFlow/IPFIX") NFAddr = flag.String("nf.addr", "", "NetFlow/IPFIX listening address") NFPort = flag.Int("nf.port", 2055, "NetFlow/IPFIX listening port") + NFReuse = flag.Bool("nf.reuserport", false, "Enable so_reuseport for NetFlow/IPFIX") Workers = flag.Int("workers", 1, "Number of workers per collector") LogLevel = flag.String("loglevel", "info", "Log level") @@ -109,7 +112,7 @@ func main() { "Type": "sFlow"}). Infof("Listening on UDP %v:%v", *SFlowAddr, *SFlowPort) - err := sSFlow.FlowRoutine(*Workers, *SFlowAddr, *SFlowPort) + err := sSFlow.FlowRoutine(*Workers, *SFlowAddr, *SFlowPort, *SFlowReuse) if err != nil { log.Fatalf("Fatal error: could not listen to UDP (%v)", err) } @@ -123,7 +126,7 @@ func main() { "Type": "NetFlow"}). Infof("Listening on UDP %v:%v", *NFAddr, *NFPort) - err := sNF.FlowRoutine(*Workers, *NFAddr, *NFPort) + err := sNF.FlowRoutine(*Workers, *NFAddr, *NFPort, *NFReuse) if err != nil { log.Fatalf("Fatal error: could not listen to UDP (%v)", err) } @@ -137,7 +140,7 @@ func main() { "Type": "NetFlowLegacy"}). Infof("Listening on UDP %v:%v", *NFLAddr, *NFLPort) - err := sNFL.FlowRoutine(*Workers, *NFLAddr, *NFLPort) + err := sNFL.FlowRoutine(*Workers, *NFLAddr, *NFLPort, *NFLReuse) if err != nil { log.Fatalf("Fatal error: could not listen to UDP (%v)", err) } diff --git a/utils/netflow.go b/utils/netflow.go index a24a1d7..2a2107a 100644 --- a/utils/netflow.go +++ b/utils/netflow.go @@ -343,7 +343,7 @@ func (s *StateNetFlow) InitTemplates() { s.samplinglock = &sync.RWMutex{} } -func (s *StateNetFlow) FlowRoutine(workers int, addr string, port int) error { +func (s *StateNetFlow) FlowRoutine(workers int, addr string, port int, reuseport bool) error { s.InitTemplates() - return UDPRoutine("NetFlow", s.DecodeFlow, workers, addr, port, false, s.Logger) + return UDPRoutine("NetFlow", s.DecodeFlow, workers, addr, port, reuseport, s.Logger) } diff --git a/utils/nflegacy.go b/utils/nflegacy.go index 88a4fe6..60f7e7d 100644 --- a/utils/nflegacy.go +++ b/utils/nflegacy.go @@ -78,6 +78,6 @@ func (s *StateNFLegacy) DecodeFlow(msg interface{}) error { return nil } -func (s *StateNFLegacy) FlowRoutine(workers int, addr string, port int) error { - return UDPRoutine("NetFlowV5", s.DecodeFlow, workers, addr, port, false, s.Logger) +func (s *StateNFLegacy) FlowRoutine(workers int, addr string, port int, reuseport bool) error { + return UDPRoutine("NetFlowV5", s.DecodeFlow, workers, addr, port, reuseport, s.Logger) } diff --git a/utils/sflow.go b/utils/sflow.go index 632045e..76f3624 100644 --- a/utils/sflow.go +++ b/utils/sflow.go @@ -130,6 +130,6 @@ func (s *StateSFlow) DecodeFlow(msg interface{}) error { return nil } -func (s *StateSFlow) FlowRoutine(workers int, addr string, port int) error { - return UDPRoutine("sFlow", s.DecodeFlow, workers, addr, port, false, s.Logger) +func (s *StateSFlow) FlowRoutine(workers int, addr string, port int, reuseport bool) error { + return UDPRoutine("sFlow", s.DecodeFlow, workers, addr, port, reuseport, s.Logger) }