flowsearch
Matches network traffic records against flow rules defined in a subquery. Compares source/destination IP, port, and protocol information from input records against the flow rules in the subquery result, and assigns the list of matching rules to the _flow field.
Command properties
| Item | Description |
|---|---|
| Command type | Transforming |
| Required permission | None |
| License usage | N/A |
| Parallel execution | Supported |
| Distributed execution | Runs on Data Node (mapper) |
Syntax
Options
timeout=INT{s|m|h|d|mon}- Subquery execution time limit. If the subquery does not complete within the specified time, it is canceled and an error message is assigned to the
_flowsearch_errorfield.
Target
[ SUBQUERY ]- Subquery enclosed in square brackets (
[]). The subquery result is used as flow rules. The subquery result must contain the following fields:
src_ip(ipaddr, required): Source network addressdst_ip(ipaddr, required): Destination network addresssrc_cidr(integer, required): Source CIDR prefix length (0–32)dst_cidr(integer, required): Destination CIDR prefix length (0–32)src_port(integer, optional): Source port number (0–65535). Matches all ports if not specified.dst_port(integer, optional): Destination port number (0–65535). Matches all ports if not specified.protocol(string, optional): Protocol name. Matches all protocols if not specified (case-insensitive).flow(any, required): Rule identifier. This value is included in the matching result. If null, the rule is ignored.
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
src_ip | ipaddr | Required | Source IP address. If not an IP address type, invalid-ip-type is assigned to the _flowsearch_error field. |
dst_ip | ipaddr | Required | Destination IP address. If not an IP address type, invalid-ip-type is assigned to the _flowsearch_error field. |
src_port | integer | Optional | Source port number. If not a numeric type, invalid-src-port-type is assigned to the _flowsearch_error field. |
dst_port | integer | Optional | Destination port number. If not a numeric type, invalid-dst-port-type is assigned to the _flowsearch_error field. |
protocol | string | Optional | Protocol name |
Output fields
| Field | Type | Description |
|---|---|---|
_flow | array | List of flow field values from matched flow rules. An empty array is assigned if no rules match. |
_flowsearch_error | string | Error message when an error occurs. Assigned on subquery errors or input field type errors. Not assigned during normal processing. |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 90204 | [가 짝이 맞지 않습니다. | Square brackets are not balanced |
| 90206 | 서브 쿼리가 없습니다. | The subquery is not specified or is empty |
Runtime errors
N/A
Description
The flowsearch command loads the subquery result as a flow rule table, then compares the network address information of each input record against the rules. The subquery runs before the main query, and loads up to 10,000 rules.
The matching process is as follows:
- The
src_ipanddst_ipof the input record are masked with the CIDR prefix length of each rule to calculate the network address. - The rule's network address is compared against the input record's network address.
- If the network addresses match, port and protocol conditions are additionally checked.
- The
flowvalues of all matching rules are added to the_flowarray.
Rules from the subquery result that are missing required fields (src_ip, dst_ip, src_cidr, dst_cidr, flow) or have incorrect types are ignored.
If the src_ip or dst_ip of the input record is not an IP address type, or if port fields are not numeric, an error message is assigned to the _flowsearch_error field and the _flow field is not assigned.
Examples
-
Match with inline flow rules
json "[{'src_ip': ip('192.0.2.1'), 'dst_ip': ip('198.51.100.1'), 'src_port': 12345, 'dst_port': 80, 'protocol': 'TCP'}]" | flowsearch [ json "[{'src_ip': ip('192.0.2.0'), 'dst_ip': ip('198.51.100.0'), 'src_cidr': 24, 'dst_cidr': 24, 'dst_port': 80, 'protocol': 'TCP', 'flow': 'web-traffic'}]" ]Matches against a rule where the source is in the
192.0.2.0/24range, destination is in the198.51.100.0/24range, destination port is 80, and protocol is TCP.["web-traffic"]is assigned to the_flowfield. -
Set a subquery time limit
table duration=1h netflow_logs | flowsearch timeout=10s [ table duration=1d flow_rules ]Loads flow rules from the
flow_rulestable, but cancels the subquery if it does not complete within 10 seconds. If the subquery times out,sub query timeoutis assigned to the_flowsearch_errorfield of all input records. -
Match without port and protocol conditions
json "[{'src_ip': ip('192.0.2.10'), 'dst_ip': ip('203.0.113.5')}]" | flowsearch [ json "[{'src_ip': ip('192.0.2.0'), 'dst_ip': ip('203.0.113.0'), 'src_cidr': 24, 'dst_cidr': 24, 'flow': 'internal-to-external'}]" ]Matches based on network ranges only, without port and protocol conditions. If
src_port,dst_port, andprotocolfields are not specified in the rule, those conditions are not checked.