From ceb3d139d330724182af4084a3225890d90dee0e Mon Sep 17 00:00:00 2001 From: Arend Lapere Date: Thu, 19 Nov 2020 10:31:19 +0100 Subject: [PATCH 1/2] Support IPv6 UDP sockets --- CHANGELOG.md | 3 +++ lib/logstash/inputs/syslog.rb | 6 +++++- logstash-input-syslog.gemspec | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d1678c..2d9de35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.4.5 + - Added support for listening on IPv6 addresses + ## 3.4.4 - Refactor: avoid global side-effect + cleanup [#62](https://github.com/logstash-plugins/logstash-input-syslog/pull/62) * avoid setting `BasicSocket.do_not_reverse_lookup` as it has side effects for others diff --git a/lib/logstash/inputs/syslog.rb b/lib/logstash/inputs/syslog.rb index cfff794..9abb5da 100644 --- a/lib/logstash/inputs/syslog.rb +++ b/lib/logstash/inputs/syslog.rb @@ -138,7 +138,11 @@ def udp_listener(output_queue) @logger.info("Starting syslog udp listener", :address => "#{@host}:#{@port}") @udp.close if @udp - @udp = UDPSocket.new(Socket::AF_INET) + if IPAddr.new(@host).ipv6? + @udp = UDPSocket.new(Socket::AF_INET6) + elsif IPAddr.new(@host).ipv4? + @udp = UDPSocket.new(Socket::AF_INET) + end @udp.do_not_reverse_lookup = true @udp.bind(@host, @port) diff --git a/logstash-input-syslog.gemspec b/logstash-input-syslog.gemspec index f379bd4..affe2f3 100644 --- a/logstash-input-syslog.gemspec +++ b/logstash-input-syslog.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'logstash-input-syslog' - s.version = '3.4.4' + s.version = '3.4.5' s.licenses = ['Apache License (2.0)'] s.summary = "Reads syslog messages as events" s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" From 378c3890f065e6783e6ed203218a408f6ecd7d3b Mon Sep 17 00:00:00 2001 From: Arend Lapere Date: Mon, 11 Jan 2021 10:53:13 +0100 Subject: [PATCH 2/2] Keep backwards compatibility for host Co-authored-by: Karol Bucek --- lib/logstash/inputs/syslog.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/logstash/inputs/syslog.rb b/lib/logstash/inputs/syslog.rb index 9abb5da..5247278 100644 --- a/lib/logstash/inputs/syslog.rb +++ b/lib/logstash/inputs/syslog.rb @@ -138,11 +138,7 @@ def udp_listener(output_queue) @logger.info("Starting syslog udp listener", :address => "#{@host}:#{@port}") @udp.close if @udp - if IPAddr.new(@host).ipv6? - @udp = UDPSocket.new(Socket::AF_INET6) - elsif IPAddr.new(@host).ipv4? - @udp = UDPSocket.new(Socket::AF_INET) - end + @udp = UDPSocket.new (IPAddr.new(@host).ipv6? rescue nil) ? Socket::AF_INET6 : Socket::AF_INET @udp.do_not_reverse_lookup = true @udp.bind(@host, @port)