evpn

package
v0.0.0-...-6b8ee43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Design: docs/architecture/wire/nlri-evpn.md — EVPN NLRI plugin RFC: rfc/short/rfc7432.md

Package evpn implements an EVPN family plugin for ze. It handles decoding of EVPN NLRI (RFC 7432, 9136) for the decode mode protocol.

Design: docs/architecture/wire/nlri-evpn.md — EVPN NLRI plugin RFC: rfc/short/rfc7432.md

Package evpn implements EVPN NLRI types for the evpn plugin. RFC 7432: BGP MPLS-Based Ethernet VPN RFC 9136: IP Prefix Advertisement in EVPN

Index

Constants

View Source
const (
	AFIL2VPN = family.AFIL2VPN
	SAFIEVPN = family.SAFIEVPN
)

Re-export constants from nlri for local use.

View Source
const (
	RouteNameEthernetAutoDiscovery = "ethernet-auto-discovery"
	RouteNameMACIPAdvertisement    = "mac-ip-advertisement"
	RouteNameInclusiveMulticast    = "inclusive-multicast"
	RouteNameEthernetSegment       = "ethernet-segment"
	RouteNameIPPrefix              = "ip-prefix"
)

Variables

View Source
var (
	ParseRouteDistinguisher = nlri.ParseRouteDistinguisher
	ParseLabelStack         = nlri.ParseLabelStack
	EncodeLabelStack        = nlri.EncodeLabelStack
	WriteLabelStack         = nlri.WriteLabelStack
	ParseRDString           = nlri.ParseRDString
)

Re-export parsing functions.

View Source
var (
	ErrEVPNTruncated      = errors.New("evpn: truncated data")
	ErrEVPNInvalidAddress = errors.New("evpn: invalid address")
	ErrEVPNInvalidPrefix  = errors.New("evpn: invalid prefix")
)

EVPN errors.

View Source
var L2VPNEVPN = family.MustRegister(AFIL2VPN, SAFIEVPN, "l2vpn", "evpn")

Family registration for EVPN.

Functions

func DecodeNLRIHex

func DecodeNLRIHex(family, hexStr string) (any, error)

DecodeNLRIHex decodes EVPN NLRI from hex bytes, returning a data structure. This is the in-process fast path registered in the plugin registry. Same logic as the OnDecodeNLRI SDK callback but callable without RPC.

func EVPNFamilies

func EVPNFamilies() []string

EVPNFamilies returns the address families this plugin can decode.

func EncodeNLRIHex

func EncodeNLRIHex(family string, args []string) (string, error)

EncodeNLRIHex encodes EVPN NLRI from text args, returning hex bytes. Args format: <route-type> followed by key-value pairs:

"type2" "rd" <rd> "esi" <esi> "ethernet-tag" <tag> "mac" <mac> ["ip" <ip>] ["label" <l>]...
"type3" "rd" <rd> "ethernet-tag" <tag> "ip" <ip>
"type5" "rd" <rd> ["esi" <esi>] "ethernet-tag" <tag> "prefix" <pfx> ["gateway" <gw>] ["label" <l>]...

This is the in-process fast path registered in the plugin registry.

func EncodeRoute

func EncodeRoute(routeCmd, _ string, localAS uint32, isIBGP, asn4, addPath bool) ([]byte, []byte, error)

EncodeRoute encodes an EVPN route command into UPDATE body bytes and NLRI bytes. This implements the InProcessRouteEncoder signature for the plugin registry.

func GetEVPNYANG

func GetEVPNYANG() string

GetEVPNYANG returns the embedded YANG schema for the evpn plugin. EVPN plugin doesn't augment config schema, returns empty.

func RunCLIDecode

func RunCLIDecode(hexData, family string, textOutput bool, output, errOut io.Writer) int

RunCLIDecode decodes EVPN NLRI from hex string for CLI mode. This is for direct CLI invocation: ze plugin evpn --nlri <hex> Output is plain JSON array or text (no "decoded json" prefix). Errors go to errOut (typically stderr), results go to output (typically stdout).

func RunEVPNDecode

func RunEVPNDecode(input io.Reader, output io.Writer) int

RunEVPNDecode runs the plugin in decode mode for ze bgp decode (engine protocol).

func RunEVPNPlugin

func RunEVPNPlugin(conn net.Conn) int

RunEVPNPlugin runs the EVPN plugin using the SDK RPC protocol. This is the in-process entry point called via InternalPluginRunner.

func SetEVPNLogger

func SetEVPNLogger(l *slog.Logger)

SetEVPNLogger sets the package-level logger. Called by cmd/ze/bgp/plugin_evpn.go with slogutil.PluginLogger().

Types

type ESI

type ESI [10]byte

ESI represents a 10-byte Ethernet Segment Identifier. RFC 7432 Section 5 defines the ESI format and types.

func ParseESIString

func ParseESIString(s string) (ESI, error)

ParseESIString parses an Ethernet Segment Identifier from string format.

func (ESI) IsZero

func (e ESI) IsZero() bool

IsZero returns true if ESI is all zeros.

func (ESI) String

func (e ESI) String() string

String returns hex representation.

type EVPN

type EVPN interface {
	RouteType() EVPNRouteType
	RD() RouteDistinguisher
	Family() Family
	Bytes() []byte
	Len() int
	String() string
	PathID() uint32
	HasPathID() bool
	SupportsAddPath() bool
	WriteTo(buf []byte, off int) int
}

EVPN is the interface for all EVPN route types.

func ParseEVPN

func ParseEVPN(data []byte, addpath bool) (EVPN, []byte, error)

ParseEVPN parses an EVPN NLRI from wire format. RFC 7432 Section 7: AFI 25 (L2VPN) and SAFI 70 (EVPN).

type EVPNGeneric

type EVPNGeneric struct {
	// contains filtered or unexported fields
}

EVPNGeneric holds unparsed EVPN routes.

func (*EVPNGeneric) AppendJSON

func (e *EVPNGeneric) AppendJSON(buf []byte) []byte

AppendJSON for EVPNGeneric (unparsed / unknown route type). Keys: code, parsed, raw.

func (*EVPNGeneric) Bytes

func (e *EVPNGeneric) Bytes() []byte

Bytes returns a standalone wire encoding, header included, matching every other EVPN route type. It used to return the bare body, so a caller that round-trips an unrecognized route through encode.go emitted an NLRI with no [type][length] header.

func (*EVPNGeneric) Family

func (e *EVPNGeneric) Family() Family

func (*EVPNGeneric) HasPathID

func (e *EVPNGeneric) HasPathID() bool

func (*EVPNGeneric) Len

func (e *EVPNGeneric) Len() int

func (*EVPNGeneric) PathID

func (e *EVPNGeneric) PathID() uint32

func (*EVPNGeneric) RD

func (*EVPNGeneric) RouteType

func (e *EVPNGeneric) RouteType() EVPNRouteType

func (*EVPNGeneric) String

func (e *EVPNGeneric) String() string

func (*EVPNGeneric) SupportsAddPath

func (e *EVPNGeneric) SupportsAddPath() bool

func (*EVPNGeneric) WriteTo

func (e *EVPNGeneric) WriteTo(buf []byte, off int) int

WriteTo writes the full [route-type][length][body] encoding, like every other EVPN type, and returns the total written.

It used to copy only the body, which broke the two contracts its callers rely on: Len() promised len(data)+2, so plugin.go's `make([]byte, Len())` + WriteTo left two trailing zero octets on the wire; and appendRawField (json.go) skips `scratch[:2]` to drop the header, so the JSON "raw" field lost the first two octets of the body instead.

e.data comes from ParseEVPN, where the length is a single octet, so it cannot exceed 255.

type EVPNRouteType

type EVPNRouteType uint8

EVPNRouteType identifies the EVPN route type. RFC 7432 Section 7 defines the EVPN NLRI format.

const (
	EVPNRouteType1 EVPNRouteType = 1 // Ethernet Auto-Discovery (RFC 7432 Section 7.1)
	EVPNRouteType2 EVPNRouteType = 2 // MAC/IP Advertisement (RFC 7432 Section 7.2)
	EVPNRouteType3 EVPNRouteType = 3 // Inclusive Multicast Ethernet Tag (RFC 7432 Section 7.3)
	EVPNRouteType4 EVPNRouteType = 4 // Ethernet Segment (RFC 7432 Section 7.4)
	EVPNRouteType5 EVPNRouteType = 5 // IP Prefix (RFC 9136 Section 3)
)

EVPN Route Types per RFC 7432 Section 7 and RFC 9136.

func (EVPNRouteType) String

func (t EVPNRouteType) String() string

String returns the route type name.

type EVPNType1

type EVPNType1 struct {
	// contains filtered or unexported fields
}

EVPNType1 represents an Ethernet Auto-Discovery route (RFC 7432 Section 7.1).

func NewEVPNType1

func NewEVPNType1(rd RouteDistinguisher, esi [10]byte, ethernetTag uint32, labels []uint32) *EVPNType1

NewEVPNType1 creates an Ethernet Auto-Discovery route (Type 1).

func (*EVPNType1) AppendJSON

func (e *EVPNType1) AppendJSON(buf []byte) []byte

AppendJSON for EVPNType1 (Ethernet Auto-Discovery). Keys: code, esi, ethernet-tag, label, name, parsed, raw, rd.

func (*EVPNType1) Bytes

func (e *EVPNType1) Bytes() []byte

Bytes returns a standalone wire encoding. Retained for JSON / test callers that need an owned slice; hot-path senders should call WriteTo directly into a pool buffer.

func (*EVPNType1) ESI

func (e *EVPNType1) ESI() ESI

func (*EVPNType1) EthernetTag

func (e *EVPNType1) EthernetTag() uint32

func (*EVPNType1) Family

func (e *EVPNType1) Family() Family

func (*EVPNType1) HasPathID

func (e *EVPNType1) HasPathID() bool

func (*EVPNType1) Labels

func (e *EVPNType1) Labels() []uint32

func (*EVPNType1) Len

func (e *EVPNType1) Len() int

func (*EVPNType1) PathID

func (e *EVPNType1) PathID() uint32

func (*EVPNType1) RD

func (e *EVPNType1) RD() RouteDistinguisher

func (*EVPNType1) RouteType

func (e *EVPNType1) RouteType() EVPNRouteType

func (*EVPNType1) String

func (e *EVPNType1) String() string

func (*EVPNType1) SupportsAddPath

func (e *EVPNType1) SupportsAddPath() bool

func (*EVPNType1) WriteTo

func (e *EVPNType1) WriteTo(buf []byte, off int) int

WriteTo encodes the EVPN Type 1 NLRI directly into buf at off. Returns bytes written. Zero-alloc primitive: label stack and RD are written in place via their own WriteTo helpers, never through an intermediate `make`.

type EVPNType2

type EVPNType2 struct {
	// contains filtered or unexported fields
}

EVPNType2 represents a MAC/IP Advertisement route (RFC 7432 Section 7.2).

func NewEVPNType2

func NewEVPNType2(rd RouteDistinguisher, esi [10]byte, ethernetTag uint32, mac [6]byte, ip netip.Addr, labels []uint32) *EVPNType2

NewEVPNType2 creates a MAC/IP Advertisement route (Type 2).

func (*EVPNType2) AppendJSON

func (e *EVPNType2) AppendJSON(buf []byte) []byte

AppendJSON for EVPNType2 (MAC/IP advertisement). Keys: code, esi, ethernet-tag, ip (optional), label, mac, name, parsed, raw, rd.

func (*EVPNType2) Bytes

func (e *EVPNType2) Bytes() []byte

Bytes returns a standalone wire encoding. Retained for JSON / test callers; hot-path senders should call WriteTo into a pool buffer.

func (*EVPNType2) ESI

func (e *EVPNType2) ESI() ESI

func (*EVPNType2) EthernetTag

func (e *EVPNType2) EthernetTag() uint32

func (*EVPNType2) Family

func (e *EVPNType2) Family() Family

func (*EVPNType2) HasPathID

func (e *EVPNType2) HasPathID() bool

func (*EVPNType2) IP

func (e *EVPNType2) IP() netip.Addr

func (*EVPNType2) Labels

func (e *EVPNType2) Labels() []uint32

func (*EVPNType2) Len

func (e *EVPNType2) Len() int

func (*EVPNType2) MAC

func (e *EVPNType2) MAC() [6]byte

func (*EVPNType2) PathID

func (e *EVPNType2) PathID() uint32

func (*EVPNType2) RD

func (e *EVPNType2) RD() RouteDistinguisher

func (*EVPNType2) RouteType

func (e *EVPNType2) RouteType() EVPNRouteType

func (*EVPNType2) String

func (e *EVPNType2) String() string

func (*EVPNType2) SupportsAddPath

func (e *EVPNType2) SupportsAddPath() bool

func (*EVPNType2) WriteTo

func (e *EVPNType2) WriteTo(buf []byte, off int) int

WriteTo encodes the EVPN Type 2 NLRI directly into buf at off. Zero-alloc: label stack, RD, and IP are written in place.

type EVPNType3

type EVPNType3 struct {
	// contains filtered or unexported fields
}

EVPNType3 represents an Inclusive Multicast Ethernet Tag route (RFC 7432 Section 7.3).

func NewEVPNType3

func NewEVPNType3(rd RouteDistinguisher, ethernetTag uint32, originatorIP netip.Addr) *EVPNType3

NewEVPNType3 creates an Inclusive Multicast Ethernet Tag route (Type 3).

func (*EVPNType3) AppendJSON

func (e *EVPNType3) AppendJSON(buf []byte) []byte

AppendJSON for EVPNType3 (Inclusive Multicast Ethernet Tag). Keys: code, ethernet-tag, name, originator, parsed, raw, rd.

func (*EVPNType3) Bytes

func (e *EVPNType3) Bytes() []byte

Bytes returns a standalone wire encoding. Retained for JSON / test callers; hot-path senders should call WriteTo into a pool buffer.

func (*EVPNType3) EthernetTag

func (e *EVPNType3) EthernetTag() uint32

func (*EVPNType3) Family

func (e *EVPNType3) Family() Family

func (*EVPNType3) HasPathID

func (e *EVPNType3) HasPathID() bool

func (*EVPNType3) Len

func (e *EVPNType3) Len() int

func (*EVPNType3) OriginatorIP

func (e *EVPNType3) OriginatorIP() netip.Addr

func (*EVPNType3) PathID

func (e *EVPNType3) PathID() uint32

func (*EVPNType3) RD

func (e *EVPNType3) RD() RouteDistinguisher

func (*EVPNType3) RouteType

func (e *EVPNType3) RouteType() EVPNRouteType

func (*EVPNType3) String

func (e *EVPNType3) String() string

func (*EVPNType3) SupportsAddPath

func (e *EVPNType3) SupportsAddPath() bool

func (*EVPNType3) WriteTo

func (e *EVPNType3) WriteTo(buf []byte, off int) int

WriteTo encodes the EVPN Type 3 NLRI directly into buf at off. Zero-alloc: RD and IP are written in place.

type EVPNType4

type EVPNType4 struct {
	// contains filtered or unexported fields
}

EVPNType4 represents an Ethernet Segment route (RFC 7432 Section 7.4).

func NewEVPNType4

func NewEVPNType4(rd RouteDistinguisher, esi [10]byte, originatorIP netip.Addr) *EVPNType4

NewEVPNType4 creates an Ethernet Segment route (Type 4).

func (*EVPNType4) AppendJSON

func (e *EVPNType4) AppendJSON(buf []byte) []byte

AppendJSON for EVPNType4 (Ethernet Segment). Keys: code, esi, name, originator, parsed, raw, rd.

func (*EVPNType4) Bytes

func (e *EVPNType4) Bytes() []byte

Bytes returns a standalone wire encoding. Retained for JSON / test callers; hot-path senders should call WriteTo into a pool buffer.

func (*EVPNType4) ESI

func (e *EVPNType4) ESI() ESI

func (*EVPNType4) Family

func (e *EVPNType4) Family() Family

func (*EVPNType4) HasPathID

func (e *EVPNType4) HasPathID() bool

func (*EVPNType4) Len

func (e *EVPNType4) Len() int

func (*EVPNType4) OriginatorIP

func (e *EVPNType4) OriginatorIP() netip.Addr

func (*EVPNType4) PathID

func (e *EVPNType4) PathID() uint32

func (*EVPNType4) RD

func (e *EVPNType4) RD() RouteDistinguisher

func (*EVPNType4) RouteType

func (e *EVPNType4) RouteType() EVPNRouteType

func (*EVPNType4) String

func (e *EVPNType4) String() string

func (*EVPNType4) SupportsAddPath

func (e *EVPNType4) SupportsAddPath() bool

func (*EVPNType4) WriteTo

func (e *EVPNType4) WriteTo(buf []byte, off int) int

WriteTo encodes the EVPN Type 4 NLRI directly into buf at off. Zero-alloc: RD and IP are written in place.

type EVPNType5

type EVPNType5 struct {
	// contains filtered or unexported fields
}

EVPNType5 represents an IP Prefix route (RFC 9136 Section 3).

func NewEVPNType5

func NewEVPNType5(rd RouteDistinguisher, esi [10]byte, ethernetTag uint32, prefix netip.Prefix, gateway netip.Addr, labels []uint32) *EVPNType5

NewEVPNType5 creates an IP Prefix route (Type 5).

func (*EVPNType5) AppendJSON

func (e *EVPNType5) AppendJSON(buf []byte) []byte

AppendJSON for EVPNType5 (IP Prefix). Keys: code, esi, ethernet-tag, gateway (optional), label, name, parsed, prefix, raw, rd.

func (*EVPNType5) Bytes

func (e *EVPNType5) Bytes() []byte

Bytes returns a standalone wire encoding. Retained for JSON / test callers; hot-path senders should call WriteTo into a pool buffer.

func (*EVPNType5) ESI

func (e *EVPNType5) ESI() ESI

func (*EVPNType5) EthernetTag

func (e *EVPNType5) EthernetTag() uint32

func (*EVPNType5) Family

func (e *EVPNType5) Family() Family

func (*EVPNType5) Gateway

func (e *EVPNType5) Gateway() netip.Addr

func (*EVPNType5) HasPathID

func (e *EVPNType5) HasPathID() bool

func (*EVPNType5) Labels

func (e *EVPNType5) Labels() []uint32

func (*EVPNType5) Len

func (e *EVPNType5) Len() int

func (*EVPNType5) PathID

func (e *EVPNType5) PathID() uint32

func (*EVPNType5) Prefix

func (e *EVPNType5) Prefix() netip.Prefix

func (*EVPNType5) RD

func (e *EVPNType5) RD() RouteDistinguisher

func (*EVPNType5) RouteType

func (e *EVPNType5) RouteType() EVPNRouteType

func (*EVPNType5) String

func (e *EVPNType5) String() string

func (*EVPNType5) SupportsAddPath

func (e *EVPNType5) SupportsAddPath() bool

func (*EVPNType5) WriteTo

func (e *EVPNType5) WriteTo(buf []byte, off int) int

WriteTo encodes the EVPN Type 5 NLRI directly into buf at off. Zero-alloc: label stack, RD, prefix, and gateway are written in place.

type Family

type Family = family.Family

Type aliases for nlri types used by EVPN.

type RouteDistinguisher

type RouteDistinguisher = nlri.RouteDistinguisher

Type aliases for nlri types used by EVPN.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL