-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds IPV6_NETWORK method #53
Open
ldormoy
wants to merge
4
commits into
logstash-plugins:main
Choose a base branch
from
ldormoy:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base | |
# Any current contents of that field will be overwritten. | ||
config :target, :validate => :string, :default => 'fingerprint' | ||
|
||
# When used with the `IPV4_NETWORK` method fill in the subnet prefix length. | ||
# When used with the `IPV4_NETWORK` or `IPV6_NETWORK` method fill in the subnet prefix length. | ||
# With other methods, optionally fill in the HMAC key. | ||
config :key, :validate => :string | ||
|
||
|
@@ -55,13 +55,18 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base | |
# specified in the `key` option. For example, with "1.2.3.4" as the input | ||
# and `key` set to 16, the hash becomes "1.2.0.0". | ||
# | ||
# If set to `IPV6_NETWORK` the input data needs to be a IPv6 address and | ||
# the hash value will be the masked-out address using the number of bits | ||
# specified in the `key` option. For example, with "2001:db8:85a3::8a2e:370:7334" as the input | ||
# and `key` set to 112, the hash becomes "2001:db8:85a3::8a2e:370:0". | ||
# | ||
# If set to `PUNCTUATION`, all non-punctuation characters will be removed | ||
# from the input string. | ||
# | ||
# If set to `UUID`, a | ||
# https://en.wikipedia.org/wiki/Universally_unique_identifier[UUID] will | ||
# be generated. The result will be random and thus not a consistent hash. | ||
config :method, :validate => ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5', "MURMUR3", "IPV4_NETWORK", "UUID", "PUNCTUATION"], :required => true, :default => 'SHA1' | ||
config :method, :validate => ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5', "MURMUR3", "IPV4_NETWORK", "IPV6_NETWORK", "UUID", "PUNCTUATION"], :required => true, :default => 'SHA1' | ||
|
||
# When set to `true` and `method` isn't `UUID` or `PUNCTUATION`, the | ||
# plugin concatenates the names and values of all fields given in the | ||
|
@@ -92,6 +97,16 @@ def register | |
) | ||
end | ||
class << self; alias_method :fingerprint, :fingerprint_ipv4_network; end | ||
when :IPV6_NETWORK | ||
if @key.nil? | ||
raise LogStash::ConfigurationError, I18n.t( | ||
"logstash.runner.configuration.invalid_plugin_register", | ||
:plugin => "filter", | ||
:type => "fingerprint", | ||
:error => "Key value is empty. please fill in a subnet prefix length" | ||
) | ||
end | ||
class << self; alias_method :fingerprint, :fingerprint_ipv6_network; end | ||
when :MURMUR3 | ||
class << self; alias_method :fingerprint, :fingerprint_murmur3; end | ||
when :UUID | ||
|
@@ -151,6 +166,11 @@ def fingerprint_ipv4_network(ip_string) | |
IPAddr.new(ip_string).mask(@key.to_i).to_s.force_encoding(Encoding::UTF_8) | ||
end | ||
|
||
def fingerprint_ipv6_network(ip_string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, we can remove the duplication |
||
# in JRuby 1.7.11 outputs as US-ASCII | ||
IPAddr.new(ip_string).mask(@key.to_i).to_s.force_encoding(Encoding::UTF_8) | ||
end | ||
|
||
def fingerprint_openssl(data) | ||
# since OpenSSL::Digest instances aren't thread safe, we must ensure that | ||
# each pipeline worker thread gets its own instance. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the implementation is the same as IPv4, I suggest to reuse the condition in ipv4 instead of duplicate the code
when :IPV4_NETWORK, :IPV6_NETWORK