Add ICMP flow filter

Closes #2498
This commit is contained in:
emanuele-f 2019-05-14 16:39:36 +02:00
parent d7765bb32d
commit 359d359d09
8 changed files with 121 additions and 73 deletions

View file

@ -38,6 +38,8 @@ local vhost = _GET["vhost"]
local flowhosts_type = _GET["flowhosts_type"]
local ipversion = _GET["version"]
local vlan = _GET["vlan"]
local icmp_type = _GET["icmp_type"]
local icmp_code = _GET["icmp_cod"]
-- remote exporters address and interfaces
local deviceIP = _GET["deviceIP"]
@ -140,6 +142,11 @@ if(flowhosts_type ~= nil) then
page_params["flowhosts_type"] = flowhosts_type
end
if((icmp_type ~= nil) and (icmp_code ~= nil)) then
page_params["icmp_type"] = icmp_type
page_params["icmp_cod"] = icmp_code
end
print(getPageUrl(ntop.getHttpPrefix().."/lua/get_flows_data.lua", page_params))
print ('";')

View file

@ -35,6 +35,8 @@ local uid = _GET["uid"]
local pid = _GET["pid"]
local container = _GET["container"]
local pod = _GET["pod"]
local icmp_type = _GET["icmp_type"]
local icmp_code = _GET["icmp_cod"]
local deviceIP = _GET["deviceIP"]
local inIfIdx = _GET["inIfIdx"]
@ -196,6 +198,9 @@ if not isEmptyString(asn) then
pageinfo["asnFilter"] = tonumber(asn)
end
pageinfo["icmp_type"] = tonumber(icmp_type)
pageinfo["icmp_code"] = tonumber(icmp_code)
if not isEmptyString(tcp_state) then
pageinfo["tcpFlowStateFilter"] = tcp_state
end

View file

@ -7,6 +7,7 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
require "graph_utils"
require "flow_utils"
require "historical_utils"
sendHTTPContentTypeHeader('text/html')
@ -15,77 +16,6 @@ host_info = url2hostinfo(_GET)
-- #####################################################################
local icmp_v4_msgs = {
{ 0, 0, i18n("icmp_v4_msgs.type_0_0_echo_reply") },
{ 3, 0, i18n("icmp_v4_msgs.type_3_0_destination_network_unreachable") },
{ 3, 1, i18n("icmp_v4_msgs.type_3_1_destination_host_unreachable") },
{ 3, 2, i18n("icmp_v4_msgs.type_3_2_destination_protocol_unreachable") },
{ 3, 3, i18n("icmp_v4_msgs.type_3_3_destination_port_unreachable") },
{ 3, 4, i18n("icmp_v4_msgs.type_3_4_fragmentation_required") },
{ 3, 6, i18n("icmp_v4_msgs.type_3_6_destination_network_unknown") },
{ 3, 7, i18n("icmp_v4_msgs.type_3_7_destination_host_unknown") },
{ 3, 0, i18n("icmp_v4_msgs.type_3_0_destination_unreachable") },
{ 4, 0, i18n("icmp_v4_msgs.type_4_0_source_quench") },
{ 5, 0, i18n("icmp_v4_msgs.type_5_0_redirect") },
{ 8, 0, i18n("icmp_v4_msgs.type_8_0_echo_request") },
{ 9, 0, i18n("icmp_v4_msgs.type_9_0_router_advertisement") },
{ 10, 0, i18n("icmp_v4_msgs.type_10_0_router_selection") },
{ 11, 0, i18n("icmp_v4_msgs.type_11_0_ttl_expired_in_transit") },
{ 11, 1, i18n("icmp_v4_msgs.type_11_1_fragment_reassembly_time_exceeded") },
{ 12, 0, i18n("icmp_v4_msgs.type_12_0_parameter_problem") },
{ 13, 0, i18n("icmp_v4_msgs.type_13_0_timestamp_request") },
{ 14, 0, i18n("icmp_v4_msgs.type_14_0_timestamp_reply") },
{ 15, 0, i18n("icmp_v4_msgs.type_15_0_information_request") },
{ 16, 0, i18n("icmp_v4_msgs.type_16_0_information_reply") },
{ 17, 0, i18n("icmp_v4_msgs.type_17_0_address_mask_request") },
{ 18, 0, i18n("icmp_v4_msgs.type_18_0_address_mask_reply") },
{ 30, 0, i18n("icmp_v4_msgs.type_30_0_traceroute") },
}
local icmp_v6_msgs = {
{ 1, 0, i18n("icmp_v6_msgs.type_1_0_destination_unreachable") },
{ 2, 0, i18n("icmp_v6_msgs.type_2_0_packet_too_big") },
{ 3, 0, i18n("icmp_v6_msgs.type_3_0_hop_limit_exceeded_in_transit") },
{ 3, 1, i18n("icmp_v6_msgs.type_3_1_fragment_reassembly_time_exceeded") },
{ 4, 0, i18n("icmp_v6_msgs.type_4_0_parameter_problem") },
{ 128, 0, i18n("icmp_v6_msgs.type_128_0_echo_request") },
{ 129, 0, i18n("icmp_v6_msgs.type_129_0_echo_reply") },
{ 133, 0, i18n("icmp_v6_msgs.type_133_0_router_solicitation") },
{ 134, 0, i18n("icmp_v6_msgs.type_134_0_router_advertisement") },
{ 135, 0, i18n("icmp_v6_msgs.type_135_0_neighbor_solicitation") },
{ 136, 0, i18n("icmp_v6_msgs.type_136_0_neighbor_advertisement") },
}
function get_icmp_label(icmp_type, icmp_value, is_v4, is_host)
local what, label
if(is_v4) then
what = icmp_v4_msgs
label = "ICMPv4"
else
what = icmp_v6_msgs
label = "ICMPv6"
end
for _, k in pairs(what) do
local i_type = tostring(k[1])
local i_value = tostring(k[2])
local i_msg = k[3]
-- print(i_type.."/"..icmp_type.."<br>\n")
if(i_type == icmp_type) then
-- print("))"..i_type.."/"..icmp_type.."<br>\n")
if(i_value == icmp_value) then
return(i_msg)
end
end
end
return(label.." [type: "..icmp_type.."][value: "..icmp_value.."]")
end
-- #####################################################################
function formatPeer(peer)
return '<A HREF="'..ntop.getHttpPrefix()..'/lua/host_details.lua?host='..peer..'">'..peer..'</A>'
end
@ -118,7 +48,9 @@ if(stats ~= nil) then
local keys = string.split(key, ",")
local icmp_type = keys[1]
local icmp_value = keys[2]
print('<tr><td>'..get_icmp_label(icmp_type, icmp_value, is_v4, is_host))
print('<tr><td><a href="'..ntop.getHttpPrefix()..'/lua/flows_stats.lua?icmp_type='..
icmp_type..'&icmp_cod='..icmp_value..'&version='.. ternary(is_v4, "4", "6") ..'">'..
get_icmp_label(icmp_type, icmp_value, is_v4)..'</a>')
if(is_host) then
print('<td>')

View file

@ -1084,6 +1084,77 @@ end
-- #######################
local icmp_v4_msgs = {
{ 0, 0, i18n("icmp_v4_msgs.type_0_0_echo_reply") },
{ 3, 0, i18n("icmp_v4_msgs.type_3_0_destination_network_unreachable") },
{ 3, 1, i18n("icmp_v4_msgs.type_3_1_destination_host_unreachable") },
{ 3, 2, i18n("icmp_v4_msgs.type_3_2_destination_protocol_unreachable") },
{ 3, 3, i18n("icmp_v4_msgs.type_3_3_destination_port_unreachable") },
{ 3, 4, i18n("icmp_v4_msgs.type_3_4_fragmentation_required") },
{ 3, 6, i18n("icmp_v4_msgs.type_3_6_destination_network_unknown") },
{ 3, 7, i18n("icmp_v4_msgs.type_3_7_destination_host_unknown") },
{ 3, 0, i18n("icmp_v4_msgs.type_3_0_destination_unreachable") },
{ 4, 0, i18n("icmp_v4_msgs.type_4_0_source_quench") },
{ 5, 0, i18n("icmp_v4_msgs.type_5_0_redirect") },
{ 8, 0, i18n("icmp_v4_msgs.type_8_0_echo_request") },
{ 9, 0, i18n("icmp_v4_msgs.type_9_0_router_advertisement") },
{ 10, 0, i18n("icmp_v4_msgs.type_10_0_router_selection") },
{ 11, 0, i18n("icmp_v4_msgs.type_11_0_ttl_expired_in_transit") },
{ 11, 1, i18n("icmp_v4_msgs.type_11_1_fragment_reassembly_time_exceeded") },
{ 12, 0, i18n("icmp_v4_msgs.type_12_0_parameter_problem") },
{ 13, 0, i18n("icmp_v4_msgs.type_13_0_timestamp_request") },
{ 14, 0, i18n("icmp_v4_msgs.type_14_0_timestamp_reply") },
{ 15, 0, i18n("icmp_v4_msgs.type_15_0_information_request") },
{ 16, 0, i18n("icmp_v4_msgs.type_16_0_information_reply") },
{ 17, 0, i18n("icmp_v4_msgs.type_17_0_address_mask_request") },
{ 18, 0, i18n("icmp_v4_msgs.type_18_0_address_mask_reply") },
{ 30, 0, i18n("icmp_v4_msgs.type_30_0_traceroute") },
}
local icmp_v6_msgs = {
{ 1, 0, i18n("icmp_v6_msgs.type_1_0_destination_unreachable") },
{ 2, 0, i18n("icmp_v6_msgs.type_2_0_packet_too_big") },
{ 3, 0, i18n("icmp_v6_msgs.type_3_0_hop_limit_exceeded_in_transit") },
{ 3, 1, i18n("icmp_v6_msgs.type_3_1_fragment_reassembly_time_exceeded") },
{ 4, 0, i18n("icmp_v6_msgs.type_4_0_parameter_problem") },
{ 128, 0, i18n("icmp_v6_msgs.type_128_0_echo_request") },
{ 129, 0, i18n("icmp_v6_msgs.type_129_0_echo_reply") },
{ 133, 0, i18n("icmp_v6_msgs.type_133_0_router_solicitation") },
{ 134, 0, i18n("icmp_v6_msgs.type_134_0_router_advertisement") },
{ 135, 0, i18n("icmp_v6_msgs.type_135_0_neighbor_solicitation") },
{ 136, 0, i18n("icmp_v6_msgs.type_136_0_neighbor_advertisement") },
}
function get_icmp_label(icmp_type, icmp_value, is_v4)
local what, label
if(is_v4) then
what = icmp_v4_msgs
label = "ICMPv4"
else
what = icmp_v6_msgs
label = "ICMPv6"
end
for _, k in pairs(what) do
local i_type = tostring(k[1])
local i_value = tostring(k[2])
local i_msg = k[3]
-- print(i_type.."/"..icmp_type.."<br>\n")
if(i_type == icmp_type) then
-- print("))"..i_type.."/"..icmp_type.."<br>\n")
if(i_value == icmp_value) then
return(i_msg)
end
end
end
return(label.." [type: "..icmp_type.."][value: "..icmp_value.."]")
end
-- #######################
function extractSIPCaller(caller)
local i
local j
@ -2257,6 +2328,16 @@ function getFlowsTableTitle()
active_msg = active_msg .. " ["..i18n("containers_stats.pod").." ".. shortenString(_GET["pod"]) .."]"
end
if((_GET["icmp_type"] ~= nil) and (_GET["icmp_cod"] ~= nil)) then
local is_v4 = true
if(_GET["version"] ~= nil) then
is_v4 = (_GET["version"] == "4")
end
local icmo_label = get_icmp_label(_GET["icmp_type"], _GET["icmp_cod"], is_v4)
active_msg = active_msg .. " ["..icmo_label.."]"
end
if(_GET["tcp_flow_state"] ~= nil) then
active_msg = active_msg .. " ["..tcp_flow_state_utils.state2i18n(_GET["tcp_flow_state"]).."]"
end

View file

@ -1460,6 +1460,8 @@ local known_parameters = {
["list_enabled"] = validateOnOff,
["list_update"] = validateNumber,
["dhcp_ranges"] = validateListOfTypeInline(validateIpRange),
["icmp_type"] = validateNumber,
["icmp_cod"] = validateNumber,
-- Containers
["pod"] = validateSingleWord,