diff --git a/src/apps/ipfix/maps.lua b/src/apps/ipfix/maps.lua index 01c37239c5..8b4326af5e 100644 --- a/src/apps/ipfix/maps.lua +++ b/src/apps/ipfix/maps.lua @@ -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 diff --git a/src/apps/ipfix/template.lua b/src/apps/ipfix/template.lua index 7ac6df4e27..6269e538bb 100644 --- a/src/apps/ipfix/template.lua +++ b/src/apps/ipfix/template.lua @@ -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) @@ -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 @@ -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 @@ -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) diff --git a/src/program/ipfix/probe/README b/src/program/ipfix/probe/README index b2a167d541..c37a994c24 100644 --- a/src/program/ipfix/probe/README +++ b/src/program/ipfix/probe/README @@ -44,11 +44,14 @@ Available options: The interval at which template records are sent in seconds. Defaults to 600. --pfx-to-as 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 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 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 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. diff --git a/src/program/ipfix/probe/probe.lua b/src/program/ipfix/probe/probe.lua index a2af992224..548f0d2a93 100644 --- a/src/program/ipfix/probe/probe.lua +++ b/src/program/ipfix/probe/probe.lua @@ -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,