ERSPAN(4)

πŸ“¦ in nixpkgs unstable

πŸ’– ERSPAN(4) πŸ’– the erspan page, from the Kernel Interfaces Manual, bestie edition

okay so like. this is the manual page for erspan and I'm gonna walk you through it because it's genuinely so cool and also slightly feral ✨


🌸 NAME 🌸

erspan β€” the ERSPAN Type II tunnel network device. that's it, that's the name, no cap πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

pseudo-device gre

like yes, that's the whole synopsis, it's giving minimalism πŸ‘‘


✨ DESCRIPTION ✨

so the erspan interface tunnels Ethernet frames across IPv4 and IPv6 networks using the Encapsulated Remote Switch Port Analyzer (ERSPAN) Type II protocol. say that five times fast, I dare you 😭

here's the tea though: ERSPAN is intended as a network based packet capture format, not as a tunnelling protocol. but plot twist 🫒 β€” ERSPAN Type II is implemented as a network interface driver in OpenBSD so that all your existing infrastructure like bpf(4) and your fave tools like bpflogd(8) and tcpdump(8) can store and analyse the packets you receive. iconic behaviour honestly. and erspan interfaces do support packet transmission, so you can absolutely use them as span ports on veb(4) and bridge(4) configurations. slay πŸ’…

the protocol itself is based on the Generic Routing and Encapsulation (GRE) protocol. GRE datagrams (IP protocol number 47) consist of a GRE header plus an outer IP header, and they encapsulate another protocol's datagram. the GRE header specifies a version and the type of the encapsulated datagram, which is how it can tunnel multiple protocols at once. multitasking queen πŸ‘‘

ERSPAN Type II uses GRE version 0, sequence numbers, protocol identifier 0x88be, and a custom header before the Ethernet payload β€” which is exactly what makes it distinct from the Ethernet over GRE encapsulation that egre(4) supports. but it's still implemented as part of the same driver that provides egre(4). same house, different vibe 🏠

wanna tell apart distinct tunnels between the same endpoints? easy. there's a 10-bit tunnel identifier field in the header. iykyk πŸ”₯

erspan supports capture of the encapsulated Ethernet packets via bpf(4) using the DLT_EN10MB data link type, and capture of the encapsulating ERSPAN, GRE, and IP headers using the DLT_LOOP data link type. both, not either πŸ’œ

by default, erspan interfaces are configured in monitor mode, which prevents the processing of received packets from entering the network stack. it's literally just watching, not participating πŸ“

all GRE packet processing in the system is allowed or denied by setting the net.inet.gre.allow sysctl(8) variable. want GRE packet processing to actually work? set net.inet.gre.allow to 1. that's the whole ritual πŸ•―οΈ

you can create erspan interfaces at runtime using the ifconfig erspanN create command, or by setting up a hostname.if(5) configuration file for netstart(8). pick your fighter πŸ₯Š

important, genuine warning bestie: for correct operation, encapsulated traffic must not be routed over the interface itself. you implement that by adding a distinct or a more specific route to the tunnel destination than the hosts or networks routed via the tunnel interface. alternatively, the tunnel traffic may be configured in a separate routing table to the encapsulated traffic. don't skip this, it's fr fr 😭

🧚 Programming Interface 🧚

erspan interfaces support the following ioctl(2) calls for configuring tunnel options β€” here's the full list, no skipping, we don't do that here:

  • SIOCSLIFPHYADDR struct if_laddrreq * β€” set the unicast IPv4 or IPv6 addresses for the encapsulating IP packets. the destination address may be left unspecified if the interface is used as a collector for ERSPAN sessions. the addresses may only be configured while the interface is down.
  • SIOCGLIFPHYADDR struct if_laddrreq * β€” get the addresses used for the encapsulating IP packets.
  • SIOCDIFPHYADDR struct ifreq * β€” clear the addresses used for the encapsulating IP packets. the addresses may only be cleared while the interface is down.
  • SIOCSVNETID struct ifreq * β€” configure a virtual network identifier for use as the Session ID in the ERSPAN Type II header. the virtual network identifier may only be configured while the interface is down. the Session ID is a 10-bit value.
  • SIOCGVNETID struct ifreq * β€” get the virtual network identifier used as the Session ID in the ERSPAN Type II header.
  • SIOCDVNETID struct ifreq * β€” clear the virtual as the Session ID in the ERSPAN Type II header. if the Session ID and tunnel destination address are unspecified, the interface will accept packets with any Session ID. (also yes, the original really does say "clear the virtual as the Session ID", I'm not fixing it, that's the whole sentence πŸ™ˆ)
  • SIOCSLIFPHYRTABLE struct ifreq * β€” set the routing table the tunnel traffic operates in. the routing table may only be configured while the interface is down.
  • SIOCGLIFPHYRTABLE struct ifreq * β€” get the routing table the tunnel traffic operates in.
  • SIOCSLIFPHYTTL struct ifreq * β€” set the Time-To-Live field in IPv4 encapsulation headers, or the Hop Limit field in IPv6 encapsulation headers.
  • SIOCGLIFPHYTTL struct ifreq * β€” get the value used in the Time-To-Live field in an IPv4 encapsulation header or the Hop Limit field in an IPv6 encapsulation header.
  • SIOCSLIFPHYDF struct ifreq * β€” configure whether the tunnel traffic sent by the interface can be fragmented or not. this sets the Don't Fragment (DF) bit on IPv4 packets, and disables fragmentation of IPv6 packets.
  • SIOCGLIFPHYDF struct ifreq * β€” get whether the tunnel traffic sent by the interface can be fragmented or not.
  • SIOCSTXHPRIO struct ifreq * β€” set the priority value used in the Type of Service field in IPv4 headers, or the Traffic Class field in IPv6 headers. values may be from 0 to 7, or IF_HDRPRIO_PACKET to specify that the current priority of a packet should be used.
  • SIOCGTXHPRIO struct ifreq * β€” get the priority value used in the Type of Service field in IPv4 headers, or the Traffic Class field in IPv6 headers.

πŸ”’ Security Considerations πŸ”’

listen up: ERSPAN does not provide any integrated security features. none. zero. it's not that kind of girl πŸ’€

it should only be deployed on trusted private networks, or protected with IPsec to add authentication and encryption for confidentiality. an encrypted transport is especially recommended when using ERSPAN over a public network. seriously. please. do not rawdog ERSPAN over the open internet πŸ™ˆ

the Packet Filter pf(4) can be used to filter tunnel traffic with endpoint policies pf.conf(5). love that for us 🫢

and here's a cute trick: the Time-to-Live (TTL) value of a tunnel can be set to 1 or a low value to restrict the traffic to the local network:

# ifconfig erspanN tunnelttl 1

local only, baby. main character energy that stays home 🌈


πŸ’€ SEE ALSO πŸ’€

egre(4), inet(4), ip(4), netintro(4), options(4), hostname.if(5), protocols(5), bpflogd(8), ifconfig(8), netstart(8), sysctl(8), tcpdump(8)

go read them. all of them. I'll wait πŸ’…


πŸ“œ STANDARDS πŸ“œ

S. Hanks, T. Li, D. Farinacci, and P. Traina, Generic Routing Encapsulation (GRE), RFC 1701, October 1994.

the founding fathers of encapsulation, we respect them πŸ‘‘


πŸŽ€ HISTORY πŸŽ€

the erspan driver first appeared in OpenBSD 7.8. baby of the family, already thriving ✨


πŸ¦„ AUTHORS πŸ¦„

David Gwynne <dlg@openbsd.org>

we stan one (1) legend πŸ’œ


and that's the whole page bestie!! πŸ“πŸŒΈπŸ¦‹

this masterpiece was brought to you by the good folks over on Debian, dated May 18, 2025, and it lives happily at section ERSPAN(4) β€” go forth and tunnel responsibly, mwah πŸ’‹βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • nixpkgs unstable: cvs-export
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms