MaeBPFC.Plugs.TLSSNI (maebpf_c v0.1.0)

Copy Markdown View Source

C CO-RE TLS ClientHello SNI filter (bpf_iter_num up to 64 extensions, IPv4 + IPv6, 802.1Q/802.1ad VLANs, ECH detection, optional tproxy_port punt for split PQ ClientHello reassembly, reversed-FQDN LPM_TRIE, and 5-tuple LRU_HASH flow cache) for use MaeBPFC tcx and cgroup hooks.

defmodule MyEdge.FullSNI do
  use MaeBPFC

  blocklist :blocked_domains, type: :lpm_domain, max_entries: 10_000
  counter   :sni_blocked
  stream    :sni_alerts, ringbuf_kb: 256

  tcx :egress, direction: :egress do
    plug MaeBPFC.Plugs.TLSSNI,
      domains: :blocked_domains,
      mode: :blocklist,
      max_extensions: 64,
      ipv6: true,
      vlan: true,
      ech_action: :drop,
      split_action: :drop,
      count: :sni_blocked,
      emit: :sni_alerts

    default :pass
  end
end

With userspace TPROXY punt on split PQ ClientHello:

plug MaeBPFC.Plugs.TLSSNI,
  domains: :blocked_domains,
  split_action: {:tproxy, 15001},
  tproxy_mark: 0x1501,
  emit: :sni_alerts

Requires use MaeBPFC (:maebpf_c). Using this plug inside a pure-Elixir use MaeBPF module fails cleanly at compile time with an actionable hint.

Options:

  • :domains (or :map / :list) - required type: :lpm_domain map atom
  • :mode - :blocklist (default, drop on match) or :allowlist (drop on miss)
  • :max_extensions - bpf_iter_num TLS extension scan cap (1..64, default 64)
  • :ipv6 - enable IPv6 TCP parsing alongside IPv4 (default true)
  • :vlan - strip up to two 802.1Q/802.1ad VLAN headers on tcx (default true)
  • :ech_action - :pass (default) or :drop when TLS extension 0xFE0D (ECH) is seen
  • :split_action - :pass (default), :drop, :alert, :tproxy, or {:tproxy, port} when a ClientHello is truncated before SNI
  • :tproxy_port - optional userspace TPROXY port (1..65535); implied when split_action: {:tproxy, port} is used
  • :tproxy_mark - optional u32 skb->mark set when punting split flows to TPROXY (defaults to tproxy_port when set, otherwise 1)
  • :flow_entries - capacity of the hidden 5-tuple LRU_HASH flow cache (default 65_536)
  • :count - optional counter map incremented on drop
  • :emit - optional RingBuf stream emitted on drop (and on :alert/:tproxy split events)
  • :max_entries - optional domain map capacity when auto-declaring standalone maps

Emits .rodata globals (tlssni_mode, tlssni_ech_action, tlssni_split_action, tlssni_tproxy_port, tlssni_tproxy_mark) so policy flags can be inspected via MaeBPF.get_global/2 or overridden pre-load via globals:.