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
- Query Farm hosting
- Available Β· $10/month organization minimum
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
| 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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'netflow' AS netflow (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-netflow:0.6.0'
);
3. Run a query
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
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connectorβs deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'netflow' AS netflow
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
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
Query Farm operates NetFlow for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use netflow as the catalog alias for the query below.
4. Run a query
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
Technical details
- Verified connector release
- v0.6.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'netflow' AS netflow (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-netflow:0.6.0'
);
Overview
Decode captured NetFlow v5/v9, IPFIX, and sFlow v5 flow-export datagrams into normalized flow rows β template-stateful, in-engine, no collector stack.
Decode captured flow-export datagrams β NetFlow v5 (fixed), NetFlow v9 (RFC 3954, template-based), IPFIX (RFC 7011, template-based, enterprise + variable-length IEs), and sFlow v5 (packet sampling) β from a BLOB column of captured exporter datagrams (or UDP payloads carved out of pcap) into one normalized wide flow row per record.
The moat is correct template-stateful v9/IPFIX decode at lake scale: a Data Set carries no field descriptors, only a template id, and the Template Set that defines the layout arrives out-of-band β so the worker keeps a template cache keyed by (exporter, observation domain, template id) as serializable VGI scan state that survives scan-batch boundaries and HTTP worker rehydration (a template seen in datagram 1 decodes data in datagram 10,000). A data record that arrives before its template is buffered and retried, or emitted with diagnostics = 'missing-template:β¦' β never dropped.
Addresses are emitted as DuckDB INET (LOAD inet;), so src_addr::INET <<= '10.0.0.0/8'::INET containment joins to geoip / threat-intel work directly. The worker decodes captured bytes only β it opens no UDP socket and makes no egress (collector mode is roadmap).
MAC enrichment works on any MAC β text in any notation, the 6-byte values IPFIX exports in raw_fields['sourceMacAddress'], or a number: resolve the IEEE-registered vendor from a bundled MA-L/MA-M/MA-S snapshot (no network), canonicalize the notation, read the multicast / locally-administered (randomized) / broadcast bits, and convert to and from modified EUI-64.
Sources and references
- RFC 3954 β Cisco NetFlow Services Export Version 9
- RFC 7011 β IPFIX protocol
- IANA IPFIX Information Elements β the element ids behind
raw_fields - sFlow Version 5
- IEEE Registration Authority MAC registries β MA-L / MA-M / MA-S, the source of
oui_vendor - RFC 4291 Appendix A β modified EUI-64 interface identifiers
Catalog
Everything netflow exposes once attached β read straight from the worker's
released build.
main 1 view Β· 16 functions
NetFlow / IPFIX / sFlow flow-export decode functions and template-cache introspection.
Schema 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;
| 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;
supported_formats
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.
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';
eui48_to_eui64 (mac ANY)
Modified EUI-64 IPv6 interface identifier for a MAC
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;
flow_version (datagram BLOB)
Probe a flow-export datagram's wire version
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;
header (datagram BLOB)
Decode a flow datagram's export header
-
versionUSMALLINT
-
countUSMALLINT
-
sys_uptimeUINTEGER
-
export_timeTIMESTAMP WITH TIME ZONE
-
sequenceUBIGINT
-
obs_domainUINTEGER
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;
mac_from_ipv6 (address VARCHAR)
MAC embedded in a modified-EUI-64 IPv6 address
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;
mac_is_broadcast (mac ANY)
Whether a MAC is the all-ones broadcast address
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;
mac_is_local (mac ANY)
Whether a MAC is locally administered (e.g. randomized)
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;
mac_is_multicast (mac ANY)
Whether a MAC is a group (multicast/broadcast) address
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;
mac_normalize (mac ANY)
Canonical lowercase colon form of a MAC address
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;
oui_lookup (mac ANY)
IEEE registry assignment (prefix, block, organization) for a MAC
-
prefixVARCHAR
-
blockVARCHAR
-
organizationVARCHAR
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;
oui_vendor (mac ANY)
Registered IEEE organization for a MAC address
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;
well_formed (datagram BLOB)
Validate a flow datagram's structure (never panics)
-
okBOOLEAN
-
versionVARCHAR
-
errorVARCHAR
-
kindVARCHAR
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;
templates (exporter := VARCHAR)
Project the live v9/IPFIX template cache
-
ie_idUSMALLINT
-
enterpriseUINTEGER
-
lengthUSMALLINT
-
nameVARCHAR
-
ie_typeVARCHAR
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');
flows (relation TABLE)
Decode captured flow-export datagrams (NetFlow v5/v9, IPFIX, sFlow v5) to normalized flow rows
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
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;
ipfix_decode (relation TABLE)
Decode IPFIX (v10) datagrams to normalized flow rows
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
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));
netflow_decode (relation TABLE)
Decode NetFlow v5 / v9 datagrams to normalized flow rows
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
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));
sflow_decode (relation TABLE)
Decode sFlow v5 datagrams to normalized flow rows
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
-
ip_typeUTINYINT
-
addressHUGEINT
-
maskUSMALLINT
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;
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
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
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.
Related workers
Perf
Developer & networking
Decode Linux perf.data captures into SQL tables of samples, memory mappings, and event metadata for bulk profile analysis
pprof
Developer & networking
Decode Go, gperftools, Parca and py-spy pprof profiles into SQL rows for flamegraph diffs and CI performance-regression gates
BGP
Developer & networking
Query RouteViews and RIPE RIS MRT archives (RIB snapshots and BGP updates) as SQL rows, with AS-path and community helpers