Skip to content

NetFlow

Turn captured NetFlow v5/v9, IPFIX, and sFlow v5 datagrams into normalized, queryable flow rows

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/netflow/index.md to help me query NetFlow with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

See what you can query

Example output Β· captured
Connector release
v0.6.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT netflow.main.flow_version(content) AS version, count(*)
FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v5.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v9.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/ipfix.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/sflow.dat'])
GROUP BY version
ORDER BY version
Result
version count_star()
10 1
5 1
9 1
sflow5 1

Quick start

Choose where to run NetFlow, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'netflow' AS netflow (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-netflow'
);

3. Run a query

query.sql
SELECT netflow.main.flow_version(content) AS version, count(*)
FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v5.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v9.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/ipfix.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/sflow.dat'])
GROUP BY version
ORDER BY version
More example queries β†’
Technical details
Verified connector release
v0.6.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'netflow' AS netflow (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Decode captured NetFlow v5/v9, IPFIX, and sFlow v5 flow-export datagrams into normalized flow rows β€” template-stateful, in-engine, no collector stack.

Catalog

Everything netflow exposes once attached β€” read straight from the worker's released build.

netflow 1 schema
main 1 view Β· 16 functions

NetFlow / IPFIX / sFlow flow-export decode functions and template-cache introspection.

Schema examples (8)
Examples (8)

Route a mixed set of captured datagrams (sample NetFlow v5/v9, IPFIX, and sFlow captures fetched by URL): label each by its flow-export version before decoding.

SELECT netflow.main.flow_version(content) AS version, count(*)
FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v5.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v9.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/ipfix.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/sflow.dat'])
GROUP BY version
ORDER BY version;
Result
version count_star()
10 1
5 1
9 1
sflow5 1

Decode a set of captures (sample datagrams fetched by URL; point read_blob at your own capture archive) to normalized flow rows and keep the flows whose source address falls in 10.0.0.0/8 via INET containment.

SELECT f.src_addr::INET AS src, f.dst_port, f.bytes
FROM netflow.main.flows((FROM (SELECT content AS datagram, filename AS exporter FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v5.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v9.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/ipfix.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/sflow.dat'])))) f
WHERE f.diagnostics IS NULL AND f.src_addr::INET <<= '10.0.0.0/8'::INET;

After decoding, inspect which v9/IPFIX templates the worker learned in this session, per exporter.

SELECT exporter, template_id, kind, field_count
FROM netflow.main.templates()
ORDER BY exporter, template_id;

Decode a mixed batch of NetFlow v5, NetFlow v9, IPFIX and sFlow datagrams with flows(), then join each decoded row's flow_version to the supported_formats reference table to count decoded rows and bytes per format and defining spec (sFlow counter samples count as rows but carry no bytes).

SELECT s.format, s.rfc, count(*) AS decoded_rows,
  sum(f.bytes) AS total_bytes
FROM netflow.main.flows((SELECT from_hex(h) AS datagram FROM (VALUES ('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000'), ('00090002000186a06553f1000000001400000001000000240100000700080004000c000400070002000b000200040001000200040001000401000019ac100001ac100002045700160600000003000000b4'), ('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10'), ('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')) AS t(h))) AS f
JOIN netflow.main.supported_formats AS s ON s.flow_version = f.flow_version
GROUP BY s.format, s.rfc
ORDER BY s.format, s.rfc;
4 more examples

Route a mixed set of captured datagrams: probe each one's wire version with flow_version() and look it up in supported_formats to find the decode function that handles it β€” the unrecognized junk blob gets a NULL version and no decoder.

SELECT c.capture, netflow.main.flow_version(c.datagram) AS version,
  s.format, s.decoder
FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-b', from_hex('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10')), ('switch-c', from_hex('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')), ('junk', '\xde\xad'::BLOB)) AS c(capture, datagram)
LEFT JOIN netflow.main.supported_formats AS s ON s.flow_version = netflow.main.flow_version(c.datagram)
ORDER BY c.capture;

Triage before decoding: keep only the captures that well_formed() validates (the truncated router-t datagram fails as short-record), decode those with flows(), and total the clean flows and bytes per capture.

SELECT f.exporter, count(*) AS flows, sum(f.bytes) AS total_bytes
FROM netflow.main.flows((SELECT c.datagram, c.capture AS exporter FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-t', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d20050')), ('router-9', from_hex('00090002000186a06553f1000000001400000001000000240100000700080004000c000400070002000b000200040001000200040001000401000019ac100001ac100002045700160600000003000000b4'))) AS c(capture, datagram) WHERE netflow.main.well_formed(c.datagram).ok)) AS f
GROUP BY f.exporter
ORDER BY f.exporter;

Reconcile NetFlow v5 captures: compare the record count each export header declares (header().count) with the clean rows netflow_decode() actually produced for that capture β€” the truncated router-b datagram declares 2 records but decodes 0 clean ones.

WITH caps AS (SELECT exporter, datagram FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-b', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d20050'))) AS t(exporter, datagram)) SELECT c.exporter, netflow.main.header(c.datagram).count AS declared_records, coalesce(d.clean_rows, 0) AS clean_rows
FROM caps AS c
LEFT JOIN (SELECT exporter, count(*) FILTER (WHERE diagnostics IS NULL) AS clean_rows FROM netflow.main.netflow_decode((SELECT datagram, exporter FROM caps)) GROUP BY exporter) AS d ON d.exporter = c.exporter
ORDER BY c.exporter;

Enrich decoded IPFIX flows with Layer-2 identity: take each flow's sourceMacAddress from raw_fields, normalize it, look up its IEEE-registered vendor with oui_vendor(), and flag randomized (locally administered) MACs with mac_is_local() β€” the randomized phone MAC has no vendor.

SELECT netflow.main.mac_normalize(f.raw_fields['sourceMacAddress']) AS src_mac,
  netflow.main.oui_vendor(f.raw_fields['sourceMacAddress']) AS vendor,
  netflow.main.mac_is_local(f.raw_fields['sourceMacAddress']) AS randomized,
  f.bytes
FROM netflow.main.flows((SELECT from_hex('000a00846553f100000000070000002a0002001c0103000500080004000c000400380006005000060001000801030058c0a8010ac0a80101001b638445e6fcfbfb01020300000000000003e8c0a8010bc0a80101daa119123456fcfbfb01020300000000000007d0c0a8010cc0a80101b827eb0a0b0cffffffffffff0000000000000bb8') AS datagram)) AS f
ORDER BY src_mac;
Views
supported_formats 2 examples7 cols

One row per flow-export format the worker decodes, with its version, defining spec, whether decoding is template-stateful, and the decode function that handles it.

Columns
format VARCHAR
Flow-export protocol family: 'NetFlow', 'IPFIX', or 'sFlow'.
version VARCHAR
Protocol version as it appears on the wire (e.g. '5', '9', '10').
rfc VARCHAR
The RFC or vendor specification that defines the format.
template_stateful BOOLEAN
TRUE when decoding needs a previously-seen template (NetFlow v9, IPFIX); FALSE for self-contained formats (NetFlow v5, sFlow).
decoder VARCHAR
The netflow.main table function that decodes this format (the unified `flows` handles all of them).
flow_version VARCHAR
The value this format produces in the decoded rows' `flow_version` column.
notes VARCHAR
One-line summary of the format's decoding characteristics.
Examples (2)

List the template-stateful formats (the ones whose decode needs a learned template) and which function decodes each.

SELECT format, version, decoder
FROM netflow.main.supported_formats
WHERE template_stateful
ORDER BY version;

Look up which decode function handles IPFIX and the flow_version value it emits.

SELECT decoder, flow_version, rfc
FROM netflow.main.supported_formats
WHERE format = 'IPFIX';
Link
Scalar functions
eui48_to_eui64 (mac ANY) 2 examples

Modified EUI-64 IPv6 interface identifier for a MAC

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsVARCHAR
Examples (2)

Derive the modified EUI-64 interface identifier of a MAC.

SELECT netflow.main.eui48_to_eui64('00:1b:63:84:45:e6') AS iid;

Build the SLAAC link-local IPv6 address for a MAC.

SELECT 'fe80::' || netflow.main.eui48_to_eui64('34-56-78-9A-BC-DE') AS link_local;
Link
flow_version (datagram BLOB) 4 examples

Probe a flow-export datagram's wire version

Arguments
datagram BLOB
The raw captured bytes of one flow-export datagram β€” a single exporter UDP payload.
ReturnsVARCHAR
Examples (4)

Detect a datagram's flow-export version before routing it to a decoder.

SELECT netflow.main.flow_version(from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')::BLOB) AS flow_version;

Route a mixed set of captured datagrams: probe each one's wire version with flow_version() and look it up in supported_formats to find the decode function that handles it β€” the unrecognized junk blob gets a NULL version and no decoder.

SELECT c.capture, netflow.main.flow_version(c.datagram) AS version,
  s.format, s.decoder
FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-b', from_hex('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10')), ('switch-c', from_hex('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')), ('junk', '\xde\xad'::BLOB)) AS c(capture, datagram)
LEFT JOIN netflow.main.supported_formats AS s ON s.flow_version = netflow.main.flow_version(c.datagram)
ORDER BY c.capture;
SELECT netflow.main.flow_version(from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')::BLOB) AS version;
1 more example
SELECT netflow.main.flow_version('\x00'::BLOB) AS version;
Link
header (datagram BLOB) 4 examples

Decode a flow datagram's export header

Arguments
datagram BLOB
The raw captured bytes of one flow-export datagram whose export header you want read.
ReturnsSTRUCT of 6 fields
STRUCT 6 fields
  • versionUSMALLINT
  • countUSMALLINT
  • sys_uptimeUINTEGER
  • export_timeTIMESTAMP WITH TIME ZONE
  • sequenceUBIGINT
  • obs_domainUINTEGER
Examples (4)

Read a datagram's export sequence number (for gap / dedup analysis).

SELECT netflow.main.header(from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')::BLOB).sequence AS sequence;

Reconcile NetFlow v5 captures: compare the record count each export header declares (header().count) with the clean rows netflow_decode() actually produced for that capture β€” the truncated router-b datagram declares 2 records but decodes 0 clean ones.

WITH caps AS (SELECT exporter, datagram FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-b', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d20050'))) AS t(exporter, datagram)) SELECT c.exporter, netflow.main.header(c.datagram).count AS declared_records, coalesce(d.clean_rows, 0) AS clean_rows
FROM caps AS c
LEFT JOIN (SELECT exporter, count(*) FILTER (WHERE diagnostics IS NULL) AS clean_rows FROM netflow.main.netflow_decode((SELECT datagram, exporter FROM caps)) GROUP BY exporter) AS d ON d.exporter = c.exporter
ORDER BY c.exporter;
SELECT netflow.main.header(from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')::BLOB) AS hdr;
1 more example
SELECT netflow.main.header('\x00'::BLOB) AS hdr;
Link
mac_from_ipv6 (address VARCHAR) 2 examples

MAC embedded in a modified-EUI-64 IPv6 address

Arguments
address VARCHAR
An IPv6 address as text (optionally with a /prefix length), e.g. 'fe80::21b:63ff:fe84:45e6'.
ReturnsVARCHAR
Examples (2)

Extract the MAC from a SLAAC link-local address.

SELECT netflow.main.mac_from_ipv6('fe80::21b:63ff:fe84:45e6') AS mac;

A privacy-extension address embeds no MAC β€” NULL.

SELECT netflow.main.mac_from_ipv6('2001:db8::1') AS mac;
Link
mac_is_broadcast (mac ANY) 2 examples

Whether a MAC is the all-ones broadcast address

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsBOOLEAN
Examples (2)

The all-ones address is broadcast.

SELECT netflow.main.mac_is_broadcast('FF-FF-FF-FF-FF-FF') AS broadcast;

A multicast address is not broadcast.

SELECT netflow.main.mac_is_broadcast('01:00:5e:00:00:fb') AS broadcast;
Link
mac_is_local (mac ANY) 3 examples

Whether a MAC is locally administered (e.g. randomized)

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsBOOLEAN
Examples (3)

A randomized phone MAC is locally administered.

SELECT netflow.main.mac_is_local('da:a1:19:12:34:56') AS randomized;

A burned-in Apple NIC MAC is universally administered.

SELECT netflow.main.mac_is_local('00:1b:63:84:45:e6') AS randomized;

Enrich decoded IPFIX flows with Layer-2 identity: take each flow's sourceMacAddress from raw_fields, normalize it, look up its IEEE-registered vendor with oui_vendor(), and flag randomized (locally administered) MACs with mac_is_local() β€” the randomized phone MAC has no vendor.

SELECT netflow.main.mac_normalize(f.raw_fields['sourceMacAddress']) AS src_mac,
  netflow.main.oui_vendor(f.raw_fields['sourceMacAddress']) AS vendor,
  netflow.main.mac_is_local(f.raw_fields['sourceMacAddress']) AS randomized,
  f.bytes
FROM netflow.main.flows((SELECT from_hex('000a00846553f100000000070000002a0002001c0103000500080004000c000400380006005000060001000801030058c0a8010ac0a80101001b638445e6fcfbfb01020300000000000003e8c0a8010bc0a80101daa119123456fcfbfb01020300000000000007d0c0a8010cc0a80101b827eb0a0b0cffffffffffff0000000000000bb8') AS datagram)) AS f
ORDER BY src_mac;
Link
mac_is_multicast (mac ANY) 2 examples

Whether a MAC is a group (multicast/broadcast) address

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsBOOLEAN
Examples (2)

An IPv4 multicast (mDNS) destination MAC is a group address.

SELECT netflow.main.mac_is_multicast('01:00:5e:00:00:fb') AS multicast;

An ordinary NIC MAC is unicast.

SELECT netflow.main.mac_is_multicast('00:1b:63:84:45:e6') AS multicast;
Link
mac_normalize (mac ANY) 2 examples

Canonical lowercase colon form of a MAC address

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsVARCHAR
Examples (2)

Normalize a Cisco dotted-notation MAC.

SELECT netflow.main.mac_normalize('001B.6384.45E6') AS mac;

Text that is not a MAC normalizes to NULL.

SELECT netflow.main.mac_normalize('00:1b:63:84:45') AS mac;
Link
oui_lookup (mac ANY) 2 examples

IEEE registry assignment (prefix, block, organization) for a MAC

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsSTRUCT of 3 fields
STRUCT 3 fields
  • prefixVARCHAR
  • blockVARCHAR
  • organizationVARCHAR
Examples (2)

Show which IEEE block and prefix an Apple MAC belongs to.

SELECT netflow.main.oui_lookup('00:1b:63:84:45:e6') AS assignment;

A MAC inside a 28-bit MA-M block reports that block's holder.

SELECT netflow.main.oui_lookup('a4:58:0f:d0:00:01').block AS block;
Link
oui_vendor (mac ANY) 3 examples

Registered IEEE organization for a MAC address

Arguments
mac ANY
The MAC address to inspect β€” text in colon, dash, Cisco dotted (aabb.ccdd.eeff) or bare-hex notation, its six raw address bytes (e.g. raw_fields['sourceMacAddress'] from flows()), or the 48-bit address as a number.
ReturnsVARCHAR
Examples (3)

Look up the vendor of an Apple NIC's MAC address.

SELECT netflow.main.oui_vendor('00-1B-63-84-45-E6') AS vendor;

A randomized (locally administered) MAC has no registered vendor β€” NULL.

SELECT netflow.main.oui_vendor('da:a1:19:12:34:56') AS vendor;

Enrich decoded IPFIX flows with Layer-2 identity: take each flow's sourceMacAddress from raw_fields, normalize it, look up its IEEE-registered vendor with oui_vendor(), and flag randomized (locally administered) MACs with mac_is_local() β€” the randomized phone MAC has no vendor.

SELECT netflow.main.mac_normalize(f.raw_fields['sourceMacAddress']) AS src_mac,
  netflow.main.oui_vendor(f.raw_fields['sourceMacAddress']) AS vendor,
  netflow.main.mac_is_local(f.raw_fields['sourceMacAddress']) AS randomized,
  f.bytes
FROM netflow.main.flows((SELECT from_hex('000a00846553f100000000070000002a0002001c0103000500080004000c000400380006005000060001000801030058c0a8010ac0a80101001b638445e6fcfbfb01020300000000000003e8c0a8010bc0a80101daa119123456fcfbfb01020300000000000007d0c0a8010cc0a80101b827eb0a0b0cffffffffffff0000000000000bb8') AS datagram)) AS f
ORDER BY src_mac;
Link
well_formed (datagram BLOB) 4 examples

Validate a flow datagram's structure (never panics)

Arguments
datagram BLOB
The raw captured bytes to structurally validate as a flow-export datagram.
ReturnsSTRUCT of 4 fields
STRUCT 4 fields
  • okBOOLEAN
  • versionVARCHAR
  • errorVARCHAR
  • kindVARCHAR
Examples (4)

Triage a captured datagram β€” STRUCT(ok, version, error, kind) β€” before decoding.

SELECT netflow.main.well_formed(from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')::BLOB) AS validation;

Triage before decoding: keep only the captures that well_formed() validates (the truncated router-t datagram fails as short-record), decode those with flows(), and total the clean flows and bytes per capture.

SELECT f.exporter, count(*) AS flows, sum(f.bytes) AS total_bytes
FROM netflow.main.flows((SELECT c.datagram, c.capture AS exporter FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-t', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d20050')), ('router-9', from_hex('00090002000186a06553f1000000001400000001000000240100000700080004000c000400070002000b000200040001000200040001000401000019ac100001ac100002045700160600000003000000b4'))) AS c(capture, datagram) WHERE netflow.main.well_formed(c.datagram).ok)) AS f
GROUP BY f.exporter
ORDER BY f.exporter;
SELECT netflow.main.well_formed(from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')::BLOB) AS check;
1 more example
SELECT netflow.main.well_formed('\xde\xad'::BLOB).kind AS kind;
Link
Table functions
templates (exporter := VARCHAR) 1 example

Project the live v9/IPFIX template cache

Named arguments
exporter := VARCHAR
Filter to templates learned from this exporter (source device id). Omit for all.
Returns columns
exporter VARCHAR
Source device the template was learned from.
obs_domain UINTEGER
Observation domain (v9 source-id / IPFIX) the template id is scoped to.
template_id USMALLINT
The template id a Data Set references.
kind VARCHAR
'data' for a data template or 'options' for an options template.
field_count UINTEGER
Number of field specifiers in the template.
fields STRUCT of 5 fields[]
The ordered field specifiers (ie_id, enterprise PEN, length, IE name, IE type).
STRUCT[] 5 fields
  • ie_idUSMALLINT
  • enterpriseUINTEGER
  • lengthUSMALLINT
  • nameVARCHAR
  • ie_typeVARCHAR
scope_field_count USMALLINT
Leading scope fields on an options template; 0 for a data template.
first_seen TIMESTAMP WITH TIME ZONE
When this template id was first seen.
last_seen TIMESTAMP WITH TIME ZONE
When this template was most recently seen / used.
use_count UBIGINT
How many data records have been decoded against it.
Example

The template cache is populated by decoding: first decode an IPFIX datagram scoped to an exporter, then introspect the cache for that exporter to see the learned template's id, kind (data/options), and field count. Reads the same session's cache, so run the decode first.

SELECT count(*)
FROM netflow.main.ipfix_decode((SELECT from_hex('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10') AS datagram, 'doc-exporter' AS exporter)); SELECT exporter,
     template_id,
     kind,
     field_count
FROM netflow.main.templates(exporter => 'doc-exporter');
Link
Table in-out functions
flows (relation TABLE) 3 examples

Decode captured flow-export datagrams (NetFlow v5/v9, IPFIX, sFlow v5) to normalized flow rows

Arguments
relation TABLE
A relation carrying a `datagram` column of raw captured bytes (exporter datagrams or UDP payloads carved out of pcap), and optionally an `exporter` column (cache scope / source device id, read per row so template ids never collide across exporters), an `obs_domain` column (override the header observation domain), and a `mode` column ('auto' / 'flows-only' / 'all'). Feed datagrams in capture order so a Template Set is seen before the Data Sets that reference it.
Returns columns
exporter VARCHAR
Cache key / source device (as supplied via the exporter column or derived).
flow_version VARCHAR
Wire format of the source datagram: '5', '9', '10' (IPFIX), or 'sflow5'.
obs_domain UINTEGER
v9 source-id / IPFIX observation domain (the template-id namespace).
template_id USMALLINT
v9/IPFIX template id the record decoded against; NULL for v5 / sFlow.
export_time TIMESTAMP WITH TIME ZONE
Datagram export time taken from the export header.
sequence UBIGINT
Export sequence number (used for gap / loss detection).
src_addr STRUCT of 3 fields
Source IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
dst_addr STRUCT of 3 fields
Destination IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
src_port USMALLINT
Layer-4 source port.
dst_port USMALLINT
Layer-4 destination port.
protocol UTINYINT
IP protocol number (6 = TCP, 17 = UDP, ...).
tcp_flags UTINYINT
Cumulative TCP control flags observed for the flow.
bytes UBIGINT
Octet count (for sFlow, scaled by the sampling rate).
packets UBIGINT
Packet count (for sFlow, the sampling rate).
flow_start TIMESTAMP WITH TIME ZONE
Flow start time, resolved to an absolute timestamp.
flow_end TIMESTAMP WITH TIME ZONE
Flow end time, resolved to an absolute timestamp.
src_as UINTEGER
Origin autonomous-system number (when the exporter reports it).
dst_as UINTEGER
Peer autonomous-system number (when the exporter reports it).
input_snmp UINTEGER
Ingress interface ifIndex.
output_snmp UINTEGER
Egress interface ifIndex.
next_hop STRUCT of 3 fields
BGP / IP next hop; cast ::INET to use it.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
tos UTINYINT
IP type-of-service / DSCP byte.
src_mask UTINYINT
Source prefix length in bits (v5 / v9).
dst_mask UTINYINT
Destination prefix length in bits (v5 / v9).
sampling_rate UINTEGER
sFlow sampling N / IPFIX samplingInterval; NULL when none.
direction UTINYINT
flowDirection (0 = ingress, 1 = egress) when present.
raw_fields MAP(VARCHAR, BLOB)
Every Information Element not mapped to a named column, keyed by IE name -> raw bytes.
diagnostics VARCHAR
NULL on a clean decode; else missing-template / truncated / decode-error / ...
Examples (3)

Decode a datagram with a per-row exporter id (cache scope) and aggregate the decoded flows by exporter.

SELECT exporter, count(*) AS flows, sum(bytes) AS total_bytes
FROM netflow.main.flows((SELECT from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000') AS datagram, 'router-1' AS exporter))
GROUP BY exporter;

Decode a mixed batch of NetFlow v5, NetFlow v9, IPFIX and sFlow datagrams with flows(), then join each decoded row's flow_version to the supported_formats reference table to count decoded rows and bytes per format and defining spec (sFlow counter samples count as rows but carry no bytes).

SELECT s.format, s.rfc, count(*) AS decoded_rows,
  sum(f.bytes) AS total_bytes
FROM netflow.main.flows((SELECT from_hex(h) AS datagram FROM (VALUES ('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000'), ('00090002000186a06553f1000000001400000001000000240100000700080004000c000400070002000b000200040001000200040001000401000019ac100001ac100002045700160600000003000000b4'), ('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10'), ('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')) AS t(h))) AS f
JOIN netflow.main.supported_formats AS s ON s.flow_version = f.flow_version
GROUP BY s.format, s.rfc
ORDER BY s.format, s.rfc;
SELECT flow_version, dst_port, protocol, bytes, packets
FROM netflow.main.flows((SELECT from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000') AS datagram))
ORDER BY dst_port;
Link
ipfix_decode (relation TABLE) 2 examples

Decode IPFIX (v10) datagrams to normalized flow rows

Arguments
relation TABLE
A relation carrying a `datagram` column of raw captured bytes (exporter datagrams or UDP payloads carved out of pcap), and optionally an `exporter` column (cache scope / source device id, read per row so template ids never collide across exporters), an `obs_domain` column (override the header observation domain), and a `mode` column ('auto' / 'flows-only' / 'all'). Feed datagrams in capture order so a Template Set is seen before the Data Sets that reference it.
Returns columns
exporter VARCHAR
Cache key / source device (as supplied via the exporter column or derived).
flow_version VARCHAR
Wire format of the source datagram: '5', '9', '10' (IPFIX), or 'sflow5'.
obs_domain UINTEGER
v9 source-id / IPFIX observation domain (the template-id namespace).
template_id USMALLINT
v9/IPFIX template id the record decoded against; NULL for v5 / sFlow.
export_time TIMESTAMP WITH TIME ZONE
Datagram export time taken from the export header.
sequence UBIGINT
Export sequence number (used for gap / loss detection).
src_addr STRUCT of 3 fields
Source IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
dst_addr STRUCT of 3 fields
Destination IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
src_port USMALLINT
Layer-4 source port.
dst_port USMALLINT
Layer-4 destination port.
protocol UTINYINT
IP protocol number (6 = TCP, 17 = UDP, ...).
tcp_flags UTINYINT
Cumulative TCP control flags observed for the flow.
bytes UBIGINT
Octet count (for sFlow, scaled by the sampling rate).
packets UBIGINT
Packet count (for sFlow, the sampling rate).
flow_start TIMESTAMP WITH TIME ZONE
Flow start time, resolved to an absolute timestamp.
flow_end TIMESTAMP WITH TIME ZONE
Flow end time, resolved to an absolute timestamp.
src_as UINTEGER
Origin autonomous-system number (when the exporter reports it).
dst_as UINTEGER
Peer autonomous-system number (when the exporter reports it).
input_snmp UINTEGER
Ingress interface ifIndex.
output_snmp UINTEGER
Egress interface ifIndex.
next_hop STRUCT of 3 fields
BGP / IP next hop; cast ::INET to use it.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
tos UTINYINT
IP type-of-service / DSCP byte.
src_mask UTINYINT
Source prefix length in bits (v5 / v9).
dst_mask UTINYINT
Destination prefix length in bits (v5 / v9).
sampling_rate UINTEGER
sFlow sampling N / IPFIX samplingInterval; NULL when none.
direction UTINYINT
flowDirection (0 = ingress, 1 = egress) when present.
raw_fields MAP(VARCHAR, BLOB)
Every Information Element not mapped to a named column, keyed by IE name -> raw bytes.
diagnostics VARCHAR
NULL on a clean decode; else missing-template / truncated / decode-error / ...
Examples (2)

Decode an IPFIX datagram and read the mapped 5-tuple plus byte/packet counters.

SELECT flow_version, src_port, dst_port, bytes, packets
FROM netflow.main.ipfix_decode((SELECT from_hex('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10') AS datagram));
SELECT flow_version, dst_port, protocol, bytes, packets
FROM netflow.main.ipfix_decode((SELECT from_hex('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10') AS datagram));
Link
netflow_decode (relation TABLE) 2 examples

Decode NetFlow v5 / v9 datagrams to normalized flow rows

Arguments
relation TABLE
A relation carrying a `datagram` column of raw captured bytes (exporter datagrams or UDP payloads carved out of pcap), and optionally an `exporter` column (cache scope / source device id, read per row so template ids never collide across exporters), an `obs_domain` column (override the header observation domain), and a `mode` column ('auto' / 'flows-only' / 'all'). Feed datagrams in capture order so a Template Set is seen before the Data Sets that reference it.
Returns columns
exporter VARCHAR
Cache key / source device (as supplied via the exporter column or derived).
flow_version VARCHAR
Wire format of the source datagram: '5', '9', '10' (IPFIX), or 'sflow5'.
obs_domain UINTEGER
v9 source-id / IPFIX observation domain (the template-id namespace).
template_id USMALLINT
v9/IPFIX template id the record decoded against; NULL for v5 / sFlow.
export_time TIMESTAMP WITH TIME ZONE
Datagram export time taken from the export header.
sequence UBIGINT
Export sequence number (used for gap / loss detection).
src_addr STRUCT of 3 fields
Source IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
dst_addr STRUCT of 3 fields
Destination IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
src_port USMALLINT
Layer-4 source port.
dst_port USMALLINT
Layer-4 destination port.
protocol UTINYINT
IP protocol number (6 = TCP, 17 = UDP, ...).
tcp_flags UTINYINT
Cumulative TCP control flags observed for the flow.
bytes UBIGINT
Octet count (for sFlow, scaled by the sampling rate).
packets UBIGINT
Packet count (for sFlow, the sampling rate).
flow_start TIMESTAMP WITH TIME ZONE
Flow start time, resolved to an absolute timestamp.
flow_end TIMESTAMP WITH TIME ZONE
Flow end time, resolved to an absolute timestamp.
src_as UINTEGER
Origin autonomous-system number (when the exporter reports it).
dst_as UINTEGER
Peer autonomous-system number (when the exporter reports it).
input_snmp UINTEGER
Ingress interface ifIndex.
output_snmp UINTEGER
Egress interface ifIndex.
next_hop STRUCT of 3 fields
BGP / IP next hop; cast ::INET to use it.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
tos UTINYINT
IP type-of-service / DSCP byte.
src_mask UTINYINT
Source prefix length in bits (v5 / v9).
dst_mask UTINYINT
Destination prefix length in bits (v5 / v9).
sampling_rate UINTEGER
sFlow sampling N / IPFIX samplingInterval; NULL when none.
direction UTINYINT
flowDirection (0 = ingress, 1 = egress) when present.
raw_fields MAP(VARCHAR, BLOB)
Every Information Element not mapped to a named column, keyed by IE name -> raw bytes.
diagnostics VARCHAR
NULL on a clean decode; else missing-template / truncated / decode-error / ...
Examples (2)

Decode a NetFlow v9 datagram, scoping the template cache to exporter 'router-1' so template ids never collide across devices.

SELECT exporter, flow_version, src_port, dst_port, packets
FROM netflow.main.netflow_decode((SELECT from_hex('00090002000186a06553f1000000001400000001000000240100000700080004000c000400070002000b000200040001000200040001000401000019ac100001ac100002045700160600000003000000b4') AS datagram, 'router-1' AS exporter));
SELECT flow_version, dst_port, protocol, packets
FROM netflow.main.netflow_decode((SELECT from_hex('00090002000186a06553f1000000001400000001000000240100000700080004000c000400070002000b000200040001000200040001000401000019ac100001ac100002045700160600000003000000b4') AS datagram));
Link
sflow_decode (relation TABLE) 2 examples

Decode sFlow v5 datagrams to normalized flow rows

Arguments
relation TABLE
A relation carrying a `datagram` column of raw captured sFlow v5 bytes (exporter datagrams or UDP payloads carved out of pcap), and optionally an `exporter` column used purely as a source-device label copied onto each output row. sFlow v5 is self-contained per datagram β€” there is no template cache and no observation domain β€” so datagrams may be decoded in any order and independently of one another.
Returns columns
exporter VARCHAR
Cache key / source device (as supplied via the exporter column or derived).
flow_version VARCHAR
Wire format of the source datagram: '5', '9', '10' (IPFIX), or 'sflow5'.
obs_domain UINTEGER
v9 source-id / IPFIX observation domain (the template-id namespace).
template_id USMALLINT
v9/IPFIX template id the record decoded against; NULL for v5 / sFlow.
export_time TIMESTAMP WITH TIME ZONE
Datagram export time taken from the export header.
sequence UBIGINT
Export sequence number (used for gap / loss detection).
src_addr STRUCT of 3 fields
Source IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
dst_addr STRUCT of 3 fields
Destination IP; cast ::INET for `<<=` containment joins.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
src_port USMALLINT
Layer-4 source port.
dst_port USMALLINT
Layer-4 destination port.
protocol UTINYINT
IP protocol number (6 = TCP, 17 = UDP, ...).
tcp_flags UTINYINT
Cumulative TCP control flags observed for the flow.
bytes UBIGINT
Octet count (for sFlow, scaled by the sampling rate).
packets UBIGINT
Packet count (for sFlow, the sampling rate).
flow_start TIMESTAMP WITH TIME ZONE
Flow start time, resolved to an absolute timestamp.
flow_end TIMESTAMP WITH TIME ZONE
Flow end time, resolved to an absolute timestamp.
src_as UINTEGER
Origin autonomous-system number (when the exporter reports it).
dst_as UINTEGER
Peer autonomous-system number (when the exporter reports it).
input_snmp UINTEGER
Ingress interface ifIndex.
output_snmp UINTEGER
Egress interface ifIndex.
next_hop STRUCT of 3 fields
BGP / IP next hop; cast ::INET to use it.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
tos UTINYINT
IP type-of-service / DSCP byte.
src_mask UTINYINT
Source prefix length in bits (v5 / v9).
dst_mask UTINYINT
Destination prefix length in bits (v5 / v9).
sampling_rate UINTEGER
sFlow sampling N / IPFIX samplingInterval; NULL when none.
direction UTINYINT
flowDirection (0 = ingress, 1 = egress) when present.
raw_fields MAP(VARCHAR, BLOB)
Every Information Element not mapped to a named column, keyed by IE name -> raw bytes.
diagnostics VARCHAR
NULL on a clean decode; else missing-template / truncated / decode-error / ...
Examples (2)

Decode an sFlow v5 datagram; flow-sample rows carry the sampled 5-tuple (counter samples have NULL ports).

SELECT flow_version, src_port, dst_port, protocol
FROM netflow.main.sflow_decode((SELECT from_hex('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') AS datagram))
WHERE dst_port IS NOT NULL;
SELECT flow_version, dst_port, protocol
FROM netflow.main.sflow_decode((SELECT from_hex('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') AS datagram))
WHERE dst_port IS NOT NULL;
Link

Try these queries

Decode a set of captures (sample datagrams fetched by URL; point read_blob at your own capture archive) to normalized flow rows and keep the flows whose source address falls in 10.0.0.0/8 via INET containment.

SELECT f.src_addr::INET AS src, f.dst_port, f.bytes
FROM netflow.main.flows((FROM (SELECT content AS datagram, filename AS exporter FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v5.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/v9.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/ipfix.dat', 'https://raw.githubusercontent.com/Query-farm/vgi-netflow/v0.4.0/test/data/sflow.dat'])))) f
WHERE f.diagnostics IS NULL AND f.src_addr::INET <<= '10.0.0.0/8'::INET

Uses flows

After decoding, inspect which v9/IPFIX templates the worker learned in this session, per exporter.

SELECT exporter, template_id, kind, field_count
FROM netflow.main.templates()
ORDER BY exporter, template_id

Uses templates

Route a mixed set of captured datagrams: probe each one's wire version with flow_version() and look it up in supported_formats to find the decode function that handles it β€” the unrecognized junk blob gets a NULL version and no decoder.

SELECT c.capture, netflow.main.flow_version(c.datagram) AS version,
  s.format, s.decoder
FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-b', from_hex('000a006d6553f100000000070000002a0002002c0100000900080004000c000400070002000b0002000400010001000800020008009800080099000801000031cb007105c633640980e801bb06000000000016e36000000000000004b00000018bcfe568000000018bcfe58f10')), ('switch-c', from_hex('00000005000000010a0000090000000000000001000003e8000000020000000100000048000000640000000000001000000000000000000000000005000000060000000100000003000000200000004000000006c000020ac00002140000c738000000500000001800000000000000020000006c000000c80000000000000001000000010000005800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')), ('junk', '\xde\xad'::BLOB)) AS c(capture, datagram)
LEFT JOIN netflow.main.supported_formats AS s ON s.flow_version = netflow.main.flow_version(c.datagram)
ORDER BY c.capture

Uses flow_versionsupported_formats

Reconcile NetFlow v5 captures: compare the record count each export header declares (header().count) with the clean rows netflow_decode() actually produced for that capture β€” the truncated router-b datagram declares 2 records but decodes 0 clean ones.

WITH caps AS (SELECT exporter, datagram FROM (VALUES ('router-a', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d2005000180600fbf4fbf518180000c0a80101080808080a0000fe0001000200000002000000c800015f900001731814e900350000110000003b4118180000')), ('router-b', from_hex('00050002000186a06553f100000000000000000a000100000a0000010a0000020a0000fe000100020000000a000003e800015f900001731804d20050'))) AS t(exporter, datagram)) SELECT c.exporter, netflow.main.header(c.datagram).count AS declared_records, coalesce(d.clean_rows, 0) AS clean_rows
FROM caps AS c
LEFT JOIN (SELECT exporter, count(*) FILTER (WHERE diagnostics IS NULL) AS clean_rows FROM netflow.main.netflow_decode((SELECT datagram, exporter FROM caps)) GROUP BY exporter) AS d ON d.exporter = c.exporter
ORDER BY c.exporter

Uses headernetflow_decode

Enrich decoded IPFIX flows with Layer-2 identity: take each flow's sourceMacAddress from raw_fields, normalize it, look up its IEEE-registered vendor with oui_vendor(), and flag randomized (locally administered) MACs with mac_is_local() β€” the randomized phone MAC has no vendor.

SELECT netflow.main.mac_normalize(f.raw_fields['sourceMacAddress']) AS src_mac,
  netflow.main.oui_vendor(f.raw_fields['sourceMacAddress']) AS vendor,
  netflow.main.mac_is_local(f.raw_fields['sourceMacAddress']) AS randomized,
  f.bytes
FROM netflow.main.flows((SELECT from_hex('000a00846553f100000000070000002a0002001c0103000500080004000c000400380006005000060001000801030058c0a8010ac0a80101001b638445e6fcfbfb01020300000000000003e8c0a8010bc0a80101daa119123456fcfbfb01020300000000000007d0c0a8010cc0a80101b827eb0a0b0cffffffffffff0000000000000bb8') AS datagram)) AS f
ORDER BY src_mac

Uses mac_normalizeoui_vendormac_is_localflows

List the template-stateful formats (the ones whose decode needs a learned template) and which function decodes each.

SELECT format, version, decoder
FROM netflow.main.supported_formats
WHERE template_stateful
ORDER BY version

Uses supported_formats

37 more examples in the Catalog, each listed under the table or function it uses.

NetFlow is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.