Skip to content

Commit

Permalink
Disable map logging in extended template by default
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergall committed Mar 19, 2018
1 parent fbacffb commit 84b486a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
11 changes: 7 additions & 4 deletions src/apps/ipfix/maps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ function mk_map(name, file, log_rate, log_fh)
map = info.create_fn(file)
maps[name] = map
end
return { map = map,
logger = lib.logger_new({ rate = log_rate or 0.05,
fh = log_fh,
module = info.logger_module }) }
local map = { map = map }
if log_fh then
map.logger = lib.logger_new({ rate = log_rate or 0.05,
fh = log_fh,
module = info.logger_module })
end
return map
end
34 changes: 18 additions & 16 deletions src/apps/ipfix/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ local function DNS_accumulate(self, dst, new)
accumulate_generic(dst, new)
end

local function can_log(logger)
return logger and logger:can_log()
end

local function extended_extract(self, pkt, md, timestamp, entry, extract_addr_fn)
extract_5_tuple(pkt, timestamp, entry, md, extract_addr_fn)
local eth_hdr = ffi.cast(ether_header_ptr_t, pkt.data)
Expand All @@ -446,15 +450,17 @@ local function extended_extract(self, pkt, md, timestamp, entry, extract_addr_fn
local result = mac_to_as.map:lookup_ptr(eth_hdr.shost)
if result then
entry.value.bgpPrevAdjacentAsNumber = result.value
elseif mac_to_as.logger:can_log() then
mac_to_as.logger:log("unknown source MAC "..ethernet:ntop(eth_hdr.shost))
elseif can_log(mac_to_as.logger) then
mac_to_as.logger:log("unknown source MAC "
..ethernet:ntop(eth_hdr.shost))
end
if not ethernet:is_mcast(eth_hdr.dhost) then
local result = mac_to_as.map:lookup_ptr(eth_hdr.dhost)
if result then
entry.value.bgpNextAdjacentAsNumber = result.value
elseif mac_to_as.logger:can_log() then
mac_to_as.logger:log("unknown destination MAC "..ethernet:ntop(eth_hdr.dhost))
elseif can_log(mac_to_as.logger) then
mac_to_as.logger:log("unknown destination MAC "
..ethernet:ntop(eth_hdr.dhost))
end
end

Expand All @@ -466,10 +472,8 @@ local function extended_extract(self, pkt, md, timestamp, entry, extract_addr_fn
if result then
entry.value.ingressInterface = result.ingress
entry.value.egressInterface = result.egress
else
if vlan_to_ifindex.logger:can_log() then
vlan_to_ifindex.logger:log("unknown vlan "..vlan)
end
elseif can_log(vlan_to_ifindex.logger) then
vlan_to_ifindex.logger:log("unknown vlan "..vlan)
end
end

Expand All @@ -492,18 +496,16 @@ local function v4_extended_extract (self, pkt, timestamp, entry)
local asn = pfx_to_as.map:search_bytes(entry.key.sourceIPv4Address)
if asn ~= 0 then
entry.value.bgpSourceAsNumber = asn
else
if pfx_to_as.logger:can_log() then
pfx_to_as.logger:log("missing AS for source "..ipv4:ntop(entry.key.sourceIPv4Address))
end
elseif can_log(pfx_to_as.logger) then
pfx_to_as.logger:log("missing AS for source "
..ipv4:ntop(entry.key.sourceIPv4Address))
end
local asn = pfx_to_as.map:search_bytes(entry.key.destinationIPv4Address)
if asn ~= 0 then
entry.value.bgpDestinationAsNumber = asn
else
if pfx_to_as.logger:can_log() then
pfx_to_as.logger:log("missing AS for destination "..ipv4:ntop(entry.key.destinationIPv4Address))
end
elseif can_log(pfx_to_as.logger) then
pfx_to_as.logger:log("missing AS for destination "
..ipv4:ntop(entry.key.destinationIPv4Address))
end

entry.value.ipClassOfService = get_ipv4_tos(md.l3)
Expand Down
9 changes: 6 additions & 3 deletions src/program/ipfix/probe/README
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ Available options:
The interval at which template records are sent in
seconds. Defaults to 600.
--pfx-to-as <file> Name of the file that contains mappings from prefixes
to AS numbers from RIR data (used by SWITCH templates)
to AS numbers from RIR data (used by extended templates)
--vlan-to-ifindex <file> Name of the file that contains mappings from VLAN
tags to interface indices (used by SWITCH templates)
tags to interface indices (used by extended templates)
--mac-to-as <file> Name of the file that contains mappings from MAC
addresses to adjacent AS numbers (used by SWITCH templates)
addresses to adjacent AS numbers (used by extended templates)
--maps-log <file> Name of the file to which extended templates log
map-related messages. If not specified, logging is
disabled.
--netflow-v9 Use the Netflow V9 protocol to communicate to the
flow collector.
--ipfix Use IPFIX to communicate with the flow collector.
Expand Down
2 changes: 1 addition & 1 deletion src/program/ipfix/probe/probe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function run (args)
end
end,
["maps-log"] = function (arg)
if arg then
if arg ~= "" then
maps_log_fh = assert(io.open(arg, "a"))
end
end,
Expand Down

0 comments on commit 84b486a

Please sign in to comment.