added support for ndpi-protocols ipv6 rules (#8531)

* added netbox documentation

* Update asset_inventory.rst

* added ndpi-protocols ipv6 rules

* updated ipv6 check for custom rule

* fix typo
This commit is contained in:
Luca Ferretti 2024-07-19 12:22:29 +02:00 committed by GitHub
parent b3bc336625
commit 7192cff076
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 4 deletions

View file

@ -113,7 +113,7 @@ function protos_utils.parseProtosTxt()
for _, rule in ipairs(rules) do
parts = string.split(rule, ":")
if ((parts ~= nil) and (#parts == 2 or #parts == 3)) then
if ((parts ~= nil) and (#parts >= 2)) then
local filter = parts[1]
local value = rule:gsub(filter .. ":", "")
@ -139,6 +139,11 @@ function protos_utils.parseProtosTxt()
match = "ip",
value = value
})
elseif (filter == "ipv6") then
addRule(proto, {
match = "ipv6",
value = value
})
else
traceError(TRACE_WARNING, TRACE_CONSOLE,
string.format("[protos.txt] Ignoring unknown filter '%s' in rule: %s", filter, line))
@ -167,7 +172,7 @@ end
function protos_utils.getProtosTxtRule(line)
local http_lint = require "http_lint"
line = trimString(line)
if isIPv4(line) or http_lint.validateNetwork(line) then
@ -177,7 +182,7 @@ function protos_utils.getProtosTxtRule(line)
}
else
local parts = string.split(line, ":")
if ((parts ~= nil) and (#parts >= 2)) then
local filter = parts[1]
local value = parts[2]
@ -192,6 +197,14 @@ function protos_utils.getProtosTxtRule(line)
match = "ip",
value = value
}
elseif filter == 'ipv6' then
-- Add each value after 'ipv6:', so accept both cases, [ipv6] and [ipv6]:port :
-- e.g. ipv6:[1:1:1:1:1:1:1:1] and ipv6:[1:1:1:1:1:1:1:1]:5466
value = line:gsub(filter .. ":", "")
return {
match = "ipv6",
value = value
}
elseif filter == 'host' then
-- Domain name filter
-- e.g. host:google
@ -374,6 +387,8 @@ function protos_utils.generateProtosTxt(rules, defined_protos)
writeRule(string.format("host:\"%s\"@%s=%s", rule.value, proto_name, proto_id))
elseif rule.match == "ip" then
writeRule(string.format("ip:%s@%s=%s", rule.value, proto_name, proto_id))
elseif rule.match == "ipv6" then
writeRule(string.format("ipv6:%s@%s=%s", rule.value, proto_name, proto_id))
end
end