<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aleksey Budaev</title>
    <description>The latest articles on DEV Community by Aleksey Budaev (@aibudaevv).</description>
    <link>https://dev.to/aibudaevv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1610749%2F1d3c11ea-e759-47ec-8495-b146c62b1d1a.jpg</url>
      <title>DEV Community: Aleksey Budaev</title>
      <link>https://dev.to/aibudaevv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aibudaevv"/>
    <language>en</language>
    <item>
      <title>Building an eBPF-based SIP Monitor in Go</title>
      <dc:creator>Aleksey Budaev</dc:creator>
      <pubDate>Sun, 05 Apr 2026 11:25:32 +0000</pubDate>
      <link>https://dev.to/aibudaevv/building-an-ebpf-based-sip-monitor-in-go-3igk</link>
      <guid>https://dev.to/aibudaevv/building-an-ebpf-based-sip-monitor-in-go-3igk</guid>
      <description>&lt;p&gt;I recently built a SIP monitoring service that uses eBPF to capture SIP traffic directly in the Linux kernel and export metrics to Prometheus. The entire pipeline from packet to Prometheus metric takes ~3μs in userspace.&lt;/p&gt;

&lt;p&gt;Here's how it works and what I learned along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Monitoring SIP/VoIP infrastructure at scale requires tracking call success rates, active dialogs, and response codes — without adding latency to the signaling path.&lt;/p&gt;

&lt;p&gt;I wanted something that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Processes packets in kernel space&lt;/li&gt;
&lt;li&gt;Exports standard Prometheus metrics&lt;/li&gt;
&lt;li&gt;Runs as a single container&lt;/li&gt;
&lt;li&gt;Tracks SIP dialogs per RFC 3261&lt;/li&gt;
&lt;li&gt;Implements RFC 6076 performance metrics (Session Establishment Ratio)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SIP Traffic → NIC → eBPF socket filter → ringbuf → Go poller → SIP parser → Prometheus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The eBPF program (written in C) attaches as a socket filter via &lt;code&gt;AF_PACKET&lt;/code&gt;. It intercepts UDP packets on configurable SIP ports (default 5060/5061), copies them to a ring buffer, and the Go userspace process polls and parses them.&lt;/p&gt;

&lt;p&gt;The C program does three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Parse Ethernet/IP/UDP headers&lt;/strong&gt; — handles both regular and VLAN-tagged frames&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filter SIP traffic&lt;/strong&gt; — checks UDP ports (configurable via environment variables)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Copy to ringbuf&lt;/strong&gt; — pushes matching packets to userspace&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Loaded via &lt;code&gt;cilium/ebpf&lt;/code&gt; — the Go library handles BPF map creation, program loading, and ringbuf polling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Known limitation:&lt;/strong&gt; The eBPF verifier doesn't allow variable-length &lt;code&gt;bpf_skb_load_bytes&lt;/code&gt;, so I copy packets in 64-byte blocks. Planning to migrate to &lt;code&gt;AF_PACKET&lt;/code&gt; with &lt;code&gt;PACKET_RX_RING&lt;/code&gt; (mmap) for arbitrary sizes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Go Part
&lt;/h2&gt;

&lt;p&gt;The Go side is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Poll ringbuf for new packets&lt;/li&gt;
&lt;li&gt;Parse raw SIP messages (method/status, headers, Call-ID, tags)&lt;/li&gt;
&lt;li&gt;Update Prometheus counters&lt;/li&gt;
&lt;li&gt;Track SIP dialog lifecycle&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Dialog Tracking
&lt;/h3&gt;

&lt;p&gt;SIP dialogs are identified by &lt;code&gt;{Call-ID, From tag, To tag}&lt;/code&gt;. Tags are sorted lexicographically for consistent IDs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dialog &lt;strong&gt;created&lt;/strong&gt; on &lt;code&gt;200 OK&lt;/code&gt; response to &lt;code&gt;INVITE&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Dialog &lt;strong&gt;terminated&lt;/strong&gt; on &lt;code&gt;200 OK&lt;/code&gt; response to &lt;code&gt;BYE&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Expired dialogs cleaned up every 1 second (based on &lt;code&gt;Session-Expires&lt;/code&gt; header, default 30 min)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Metrics Exported
&lt;/h3&gt;

&lt;p&gt;~30 Prometheus counters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Per-method:&lt;/strong&gt; &lt;code&gt;sip_exporter_invite_total&lt;/code&gt;, &lt;code&gt;sip_exporter_bye_total&lt;/code&gt;, &lt;code&gt;sip_exporter_register_total&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Per-status:&lt;/strong&gt; &lt;code&gt;sip_exporter_200_total&lt;/code&gt;, &lt;code&gt;sip_exporter_404_total&lt;/code&gt;, &lt;code&gt;sip_exporter_500_total&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session count:&lt;/strong&gt; &lt;code&gt;sip_exporter_sessions&lt;/code&gt; (active dialogs gauge)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RFC 6076 SER:&lt;/strong&gt; &lt;code&gt;sip_exporter_ser&lt;/code&gt; — Session Establishment Ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The SER metric is interesting because it follows RFC 6076 exactly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SER = (INVITE → 200 OK) / (Total INVITE - INVITE → 3xx) × 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3xx redirects are excluded from the denominator — they're routing instructions, not failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;Benchmarks on Intel i7-8665U (userspace only):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Latency&lt;/th&gt;
&lt;th&gt;Throughput&lt;/th&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Packet parsing (L2→SIP)&lt;/td&gt;
&lt;td&gt;~124 ns&lt;/td&gt;
&lt;td&gt;8M pkt/sec&lt;/td&gt;
&lt;td&gt;32 B/op&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SIP header parsing&lt;/td&gt;
&lt;td&gt;~1.2 μs&lt;/td&gt;
&lt;td&gt;800k pkt/sec&lt;/td&gt;
&lt;td&gt;350 B/op&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full processing (with metrics)&lt;/td&gt;
&lt;td&gt;~3 μs&lt;/td&gt;
&lt;td&gt;300k pkt/sec&lt;/td&gt;
&lt;td&gt;1000 B/op&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are userspace numbers. Actual latency depends on kernel eBPF overhead and system load.&lt;/p&gt;

&lt;h2&gt;
  
  
  E2E Testing
&lt;/h2&gt;

&lt;p&gt;E2E tests use SIPp via &lt;code&gt;testcontainers-go&lt;/code&gt; to generate real SIP traffic and verify that metrics match expected values. Tests cover success/failure scenarios and validate proper dialog cleanup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Start
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;sip-exporter&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frzq/sip-exporter:0.5.0&lt;/span&gt;
    &lt;span class="na"&gt;privileged&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="na"&gt;network_mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;host&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;SIP_EXPORTER_INTERFACE=eth0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up &lt;span class="nt"&gt;-d&lt;/span&gt;
curl http://localhost:2112/metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;More RFC 6076 metrics (Session Setup Time, Response Time)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/aibudaevv/sip-exporter" rel="noopener noreferrer"&gt;https://github.com/aibudaevv/sip-exporter&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker:&lt;/strong&gt; &lt;code&gt;docker pull frzq/sip-exporter:0.5.0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy to answer questions about the eBPF integration, SIP dialog state machine, or Prometheus metric design. Drop a comment below!&lt;/p&gt;

</description>
      <category>go</category>
      <category>monitoring</category>
      <category>voip</category>
      <category>prometheus</category>
    </item>
  </channel>
</rss>
