CaptureBytes

The CaptureBytes filter's job is to find a series of bytes within a packet, and capture it into Filter Dynamic Metadata, so that it can be utilised by filters further down the chain.

This is often used as a way of retrieving authentication tokens from a packet, and used in combination with ConcatenateBytes and TokenRouter filter to provide common packet routing utilities.

Capture strategies

There are multiple strategies for capturing bytes from the packet.

Suffix

Captures bytes from the end of the packet.

Prefix

Captures bytes from the start of the packet.

Regex

Captures bytes using a regular expression. Unlike other capture strategies, the regular expression can return one or many values if there are multiple matches.

Filter name

quilkin.filters.capture.v1alpha1.Capture

Configuration Examples


#![allow(unused)]
fn main() {
let yaml = "
version: v1alpha1
static:
  filters:
    - name: quilkin.filters.capture.v1alpha1.Capture
      config:
          metadataKey: myapp.com/myownkey
          prefix:
            size: 3
            remove: false
  endpoints:
    - address: 127.0.0.1:7001
";
let config = quilkin::config::Config::from_reader(yaml.as_bytes()).unwrap();
assert_eq!(config.source.get_static_filters().unwrap().len(), 1);
quilkin::Builder::from(std::sync::Arc::new(config)).validate().unwrap();
}

Configuration Options (Rust Doc)

---
$schema: "http://json-schema.org/draft-07/schema#"
title: Config
type: object
required:
  - metadata_key
  - strategy
properties:
  metadata_key:
    description: "The key to use when storing the captured value in the filter context. If a match was found it is available under `{{metadata_key}}/is_present`."
    type: string
  strategy:
    description: The capture strategy.
    allOf:
      - $ref: "#/definitions/Strategy"
definitions:
  Strategy:
    description: Strategy to apply for acquiring a set of bytes in the UDP packet
    oneOf:
      - description: Looks for the set of bytes at the beginning of the packet
        type: object
        required:
          - kind
          - size
        properties:
          kind:
            type: string
            enum:
              - PREFIX
          remove:
            description: Whether captured bytes are removed from the original packet.
            default: false
            type: boolean
          size:
            description: The number of bytes to capture.
            type: integer
            format: uint32
            minimum: 0.0
      - description: Look for the set of bytes at the end of the packet
        type: object
        required:
          - kind
          - size
        properties:
          kind:
            type: string
            enum:
              - SUFFIX
          remove:
            description: The number of bytes to capture.
            default: false
            type: boolean
          size:
            description: Whether captured bytes are removed from the original packet.
            type: integer
            format: uint32
            minimum: 0.0
      - description: Look for the set of bytes at the end of the packet
        type: object
        required:
          - kind
          - pattern
        properties:
          kind:
            type: string
            enum:
              - REGEX
          pattern:
            description: The regular expression to use for capture.
            type: string

Metrics

  • quilkin_filter_Capture_packets_dropped A counter of the total number of packets that have been dropped due to their length being less than the configured size.