Help us shape the future of Go! Take the 2026 Go Developer Survey

apiutil

package
v4.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrOrEmpty added in v4.10.0

func AddrOrEmpty(addr netip.Addr) string

AddrOrEmpty renders an optional address. An absent address must come out as an empty string, not as the zero Addr's "invalid IP" text, which would be rejected as a malformed address if the value were fed back in.

func GetNativeNlri

func GetNativeNlri(p *api.Path) (bgp.NLRI, error)

func GetNativePathAttributes

func GetNativePathAttributes(p *api.Path) ([]bgp.PathAttributeInterface, error)

func MarshalCapabilities

func MarshalCapabilities(values []bgp.ParameterCapabilityInterface) ([]*api.Capability, error)

func MarshalCapability

func MarshalCapability(value bgp.ParameterCapabilityInterface) (*api.Capability, error)

func MarshalFlowSpecRules

func MarshalFlowSpecRules(values []bgp.FlowSpecComponentInterface) ([]*api.FlowSpecRule, error)

func MarshalLsAttributeSrPolicy added in v4.10.0

func MarshalLsAttributeSrPolicy(sp *bgp.LsAttributeSrPolicy) *api.LsAttributeSrPolicy

func MarshalLsBgpPeerSegmentSid

func MarshalLsBgpPeerSegmentSid(n *bgp.LsBgpPeerSegmentSID) (*api.LsBgpPeerSegmentSID, error)

func MarshalLsLinkDescriptor

func MarshalLsLinkDescriptor(n *bgp.LsLinkDescriptor) (*api.LsLinkDescriptor, error)

func MarshalLsLinkNLRI

func MarshalLsLinkNLRI(n *bgp.LsLinkNLRI) (*api.LsAddrPrefix_LsNLRI, error)

func MarshalLsNodeDescriptor

func MarshalLsNodeDescriptor(d *bgp.LsNodeDescriptor) (*api.LsNodeDescriptor, error)

func MarshalLsNodeNLRI

func MarshalLsNodeNLRI(n *bgp.LsNodeNLRI) (*api.LsAddrPrefix_LsNLRI, error)

func MarshalLsPrefixDescriptor

func MarshalLsPrefixDescriptor(d *bgp.LsPrefixDescriptor) (*api.LsPrefixDescriptor, error)

func MarshalLsPrefixV4NLRI

func MarshalLsPrefixV4NLRI(n *bgp.LsPrefixV4NLRI) (*api.LsAddrPrefix_LsNLRI, error)

func MarshalLsPrefixV6NLRI

func MarshalLsPrefixV6NLRI(n *bgp.LsPrefixV6NLRI) (*api.LsAddrPrefix_LsNLRI, error)

func MarshalLsSRv6SIDNLRI

func MarshalLsSRv6SIDNLRI(n *bgp.LsSrv6SIDNLRI) (*api.LsAddrPrefix_LsNLRI, error)

func MarshalLsSrBindingSID added in v4.10.0

func MarshalLsSrBindingSID(b *bgp.LsSrBindingSID) *api.LsSrBindingSID

func MarshalLsSrCandidatePathConstraints added in v4.10.0

func MarshalLsSrCandidatePathConstraints(c *bgp.LsSrCandidatePathConstraints) *api.LsSrCandidatePathConstraints

func MarshalLsSrCandidatePathState added in v4.10.0

func MarshalLsSrCandidatePathState(s *bgp.LsSrCandidatePathState) *api.LsSrCandidatePathState

func MarshalLsSrPolicyCandidatePathDescriptor added in v4.10.0

func MarshalLsSrPolicyCandidatePathDescriptor(d *bgp.LsSrPolicyCandidatePathDescriptor) *api.LsSrPolicyCandidatePathDescriptor

func MarshalLsSrPolicyCandidatePathNLRI added in v4.10.0

func MarshalLsSrPolicyCandidatePathNLRI(n *bgp.LsSrPolicyCandidatePathNLRI) (*api.LsAddrPrefix_LsNLRI, error)

func MarshalLsSrSegment added in v4.10.0

func MarshalLsSrSegment(s *bgp.LsSrSegment) *api.LsSrSegment

func MarshalLsSrSegmentList added in v4.10.0

func MarshalLsSrSegmentList(sl *bgp.LsSrSegmentList) *api.LsSrSegmentList

func MarshalLsSrSegmentListMetric added in v4.10.0

func MarshalLsSrSegmentListMetric(m *bgp.LsSrSegmentListMetric) *api.LsSrSegmentListMetric

func MarshalLsSrv6BindingSID added in v4.10.0

func MarshalLsSrv6BindingSID(b *bgp.LsSrv6BindingSID) *api.LsSrv6BindingSID

func MarshalLsTLVMultiTopoID

func MarshalLsTLVMultiTopoID(mti *bgp.LsTLVMultiTopoID) (*api.LsMultiTopologyIdentifier, error)

func MarshalLsTLVSrv6SIDInfo

func MarshalLsTLVSrv6SIDInfo(info *bgp.LsTLVSrv6SIDInfo) (*api.LsSrv6SIDInformation, error)

func MarshalMUPTLVs added in v4.8.0

func MarshalMUPTLVs(tlvs []bgp.MUPTLVInterface) ([]*api.MUPTLV, error)

func MarshalNLRI

func MarshalNLRI(value bgp.NLRI) (*api.NLRI, error)

func MarshalNLRIs

func MarshalNLRIs(values []bgp.NLRI) ([]*api.NLRI, error)

func MarshalPathAttributes

func MarshalPathAttributes(attrList []bgp.PathAttributeInterface) ([]*api.Attribute, error)

func MarshalRTs

func MarshalRTs(values []bgp.ExtendedCommunityInterface) ([]*api.RouteTarget, error)

func MarshalSRBSID

func MarshalSRBSID(bsid *bgp.TunnelEncapSubTLVSRBSID) (*api.SRBindingSID, error)

MarshalSRBSID marshals SR Policy Binding SID Sub TLV structure

func MarshalSRSegments

MarshalSRSegments marshals a slice of SR Policy Segment List

func MarshalSRv6SubSubTLVs

func MarshalSRv6SubSubTLVs(tlvs []bgp.PrefixSIDTLVInterface) (map[uint32]*api.SRv6SubSubTLVs, error)

func MarshalSRv6SubTLVs

func MarshalSRv6SubTLVs(tlvs []bgp.PrefixSIDTLVInterface) (map[uint32]*api.SRv6SubTLVs, error)

func MarshalSRv6TLVs

func MarshalSRv6TLVs(tlvs []bgp.PrefixSIDTLVInterface) ([]*api.PrefixSID_TLV, error)

func NewAddPathCapability

func NewAddPathCapability(a *bgp.CapAddPath) *api.AddPathCapability

func NewAggregatorAttributeFromNative

func NewAggregatorAttributeFromNative(a *bgp.PathAttributeAggregator) (*api.AggregatorAttribute, error)

func NewAigpAttributeFromNative

func NewAigpAttributeFromNative(a *bgp.PathAttributeAigp) (*api.AigpAttribute, error)

func NewAs4PathAttributeFromNative

func NewAs4PathAttributeFromNative(a *bgp.PathAttributeAs4Path) (*api.As4PathAttribute, error)

func NewAsPathAttributeFromNative

func NewAsPathAttributeFromNative(a *bgp.PathAttributeAsPath) (*api.AsPathAttribute, error)

func NewClusterListAttributeFromNative

func NewClusterListAttributeFromNative(a *bgp.PathAttributeClusterList) (*api.ClusterListAttribute, error)

func NewCommunitiesAttributeFromNative

func NewCommunitiesAttributeFromNative(a *bgp.PathAttributeCommunities) (*api.CommunitiesAttribute, error)

func NewExtendedMessageCapability added in v4.7.0

func NewExtendedMessageCapability(a *bgp.CapExtendedMessage) *api.ExtendedMessageCapability

NewExtendedMessageCapability mirrors the empty-TLV shape RFC 8654 gives the BGP Extended Message capability. There is no payload to project; the API consumer just needs to know the peer advertised the capability.

func NewFQDNCapability

func NewFQDNCapability(a *bgp.CapFQDN) *api.FqdnCapability

func NewLocalPrefAttributeFromNative

func NewLocalPrefAttributeFromNative(a *bgp.PathAttributeLocalPref) (*api.LocalPrefAttribute, error)

func NewLsAttributeFromNative

func NewLsAttributeFromNative(a *bgp.PathAttributeLs) (*api.LsAttribute, error)

func NewMpReachNLRIAttributeFromNative

func NewMpReachNLRIAttributeFromNative(a *bgp.PathAttributeMpReachNLRI) (*api.MpReachNLRIAttribute, error)

func NewMultiProtocolCapability

func NewMultiProtocolCapability(a *bgp.CapMultiProtocol) *api.MultiProtocolCapability

func NewNextHopAttributeFromNative

func NewNextHopAttributeFromNative(a *bgp.PathAttributeNextHop) (*api.NextHopAttribute, error)

func NewOriginAttributeFromNative

func NewOriginAttributeFromNative(a *bgp.PathAttributeOrigin) (*api.OriginAttribute, error)

func NewPath

func NewPath(family bgp.Family, nlri bgp.NLRI, isWithdraw bool, attrs []bgp.PathAttributeInterface, age time.Time) (*api.Path, error)

func NewPmsiTunnelAttributeFromNative

func NewPmsiTunnelAttributeFromNative(a *bgp.PathAttributePmsiTunnel) (*api.PmsiTunnelAttribute, error)

func NewPrefixSIDAttributeFromNative

func NewPrefixSIDAttributeFromNative(a *bgp.PathAttributePrefixSID) (*api.PrefixSID, error)

func NewRouteRefreshCapability

func NewRouteRefreshCapability(a *bgp.CapRouteRefresh) *api.RouteRefreshCapability

func NewTunnelEncapAttributeFromNative

func NewTunnelEncapAttributeFromNative(a *bgp.PathAttributeTunnelEncap) (*api.TunnelEncapAttribute, error)

func NewUnknownAttributeFromNative

func NewUnknownAttributeFromNative(a *bgp.PathAttributeUnknown) (*api.UnknownAttribute, error)

func NewUnknownCapability

func NewUnknownCapability(a *bgp.CapUnknown) *api.UnknownCapability

func StringToNetIPLsTLVSrv6SIDInfo

func StringToNetIPLsTLVSrv6SIDInfo(s []string) ([]netip.Addr, uint16, error)

func ToApiFamily

func ToApiFamily(afi uint16, safi uint8) *api.Family

func ToFamily

func ToFamily(f *api.Family) bgp.Family

func UnmarshalAttribute

func UnmarshalAttribute(attr *api.Attribute) (bgp.PathAttributeInterface, error)

func UnmarshalCapabilities

func UnmarshalCapabilities(values []*api.Capability) ([]bgp.ParameterCapabilityInterface, error)

func UnmarshalFlowSpecRules

func UnmarshalFlowSpecRules(values []*api.FlowSpecRule) ([]bgp.FlowSpecComponentInterface, error)

func UnmarshalLsAttribute

func UnmarshalLsAttribute(a *api.LsAttribute) (*bgp.LsAttribute, error)

func UnmarshalLsAttributeSrPolicy added in v4.10.0

func UnmarshalLsAttributeSrPolicy(sp *api.LsAttributeSrPolicy) (*bgp.LsAttributeSrPolicy, error)

func UnmarshalLsBgpPeerSegmentSid

func UnmarshalLsBgpPeerSegmentSid(a *api.LsBgpPeerSegmentSID) (*bgp.LsBgpPeerSegmentSID, error)

func UnmarshalLsLinkDescriptor

func UnmarshalLsLinkDescriptor(ld *api.LsLinkDescriptor) (*bgp.LsLinkDescriptor, error)

func UnmarshalLsNodeDescriptor

func UnmarshalLsNodeDescriptor(nd *api.LsNodeDescriptor) (*bgp.LsNodeDescriptor, error)

func UnmarshalLsSrBindingSID added in v4.10.0

func UnmarshalLsSrBindingSID(b *api.LsSrBindingSID) (*bgp.LsSrBindingSID, error)

func UnmarshalLsSrCandidatePathConstraints added in v4.10.0

func UnmarshalLsSrCandidatePathConstraints(c *api.LsSrCandidatePathConstraints) (*bgp.LsSrCandidatePathConstraints, error)

func UnmarshalLsSrCandidatePathState added in v4.10.0

func UnmarshalLsSrCandidatePathState(s *api.LsSrCandidatePathState) (*bgp.LsSrCandidatePathState, error)

func UnmarshalLsSrPolicyCandidatePathDescriptor added in v4.10.0

func UnmarshalLsSrPolicyCandidatePathDescriptor(d *api.LsSrPolicyCandidatePathDescriptor) (*bgp.LsSrPolicyCandidatePathDescriptor, error)

func UnmarshalLsSrPolicyCandidatePathNLRI added in v4.10.0

func UnmarshalLsSrPolicyCandidatePathNLRI(n *api.LsSrPolicyCandidatePathNLRI, protocolID bgp.LsProtocolID, identifier uint64) (*bgp.LsAddrPrefix, error)

UnmarshalLsSrPolicyCandidatePathNLRI builds the native NLRI. The NLRI length is computed from the descriptors, so callers need not provide it. The conversion accepts whatever the wire decoder accepts (RFC 9552 section 8.2.2), so a route learned from a peer always converts back; the RFC 9857 rules for originating a candidate path are enforced by the gobgp command instead.

func UnmarshalLsSrSegment added in v4.10.0

func UnmarshalLsSrSegment(s *api.LsSrSegment) (*bgp.LsSrSegment, error)

func UnmarshalLsSrSegmentList added in v4.10.0

func UnmarshalLsSrSegmentList(sl *api.LsSrSegmentList) (*bgp.LsSrSegmentList, error)

func UnmarshalLsSrSegmentListMetric added in v4.10.0

func UnmarshalLsSrSegmentListMetric(m *api.LsSrSegmentListMetric) (*bgp.LsSrSegmentListMetric, error)

func UnmarshalLsSrv6BindingSID added in v4.10.0

func UnmarshalLsSrv6BindingSID(b *api.LsSrv6BindingSID) (*bgp.LsSrv6BindingSID, error)

func UnmarshalLsTLVMultiTopoID

func UnmarshalLsTLVMultiTopoID(mti *api.LsMultiTopologyIdentifier) (*bgp.LsTLVMultiTopoID, error)

func UnmarshalLsTLVSrv6SIDInfo

func UnmarshalLsTLVSrv6SIDInfo(ssi *api.LsSrv6SIDInformation) (*bgp.LsTLVSrv6SIDInfo, error)

func UnmarshalMUPTLVs added in v4.8.0

func UnmarshalMUPTLVs(tlvs []*api.MUPTLV) ([]bgp.MUPTLVInterface, error)

func UnmarshalNLRI

func UnmarshalNLRI(rf bgp.Family, an *api.NLRI) (bgp.NLRI, error)

func UnmarshalNLRIs

func UnmarshalNLRIs(rf bgp.Family, values []*api.NLRI) ([]bgp.NLRI, error)

func UnmarshalPathAttributes

func UnmarshalPathAttributes(values []*api.Attribute) ([]bgp.PathAttributeInterface, error)

func UnmarshalPrefixDescriptor

func UnmarshalPrefixDescriptor(pd *api.LsPrefixDescriptor) (*bgp.LsPrefixDescriptor, error)

func UnmarshalPrefixSID

func UnmarshalPrefixSID(psid *api.PrefixSID) (*bgp.PathAttributePrefixSID, error)

func UnmarshalRTs

func UnmarshalRTs(values []*api.RouteTarget) ([]bgp.ExtendedCommunityInterface, error)

func UnmarshalSRBSID

UnmarshalSRBSID unmarshals SR Policy Binding SID Sub TLV and returns native TunnelEncapSubTLVInterface interface

func UnmarshalSRSegments

UnmarshalSRSegments unmarshals SR Policy Segments slice of structs

func UnmarshalSubSubTLVs

func UnmarshalSubSubTLVs(stlvs map[uint32]*api.SRv6SubSubTLVs) (uint16, []bgp.PrefixSIDTLVInterface, error)

func UnmarshalSubTLVs

func UnmarshalSubTLVs(stlvs map[uint32]*api.SRv6SubTLVs) (uint16, []bgp.PrefixSIDTLVInterface, error)

Types

type AddPathRequest

type AddPathRequest struct {
	VRFID string
	Paths []*Path
}

AddPathRequest is used by server.AddPath API

type AddPathResponse

type AddPathResponse struct {
	UUID  uuid.UUID
	Error error
}

AddPathResponse is used by server.AddPath API

type DeletePathRequest

type DeletePathRequest struct {
	VRFID        string
	UUIDs        []uuid.UUID
	DeleteAll    bool
	DeleteFamily *bgp.Family
	Paths        []*Path
}

type Destination

type Destination struct {
	Paths []*Path
}

func NewDestination

func NewDestination(dst *api.Destination) *Destination

func (*Destination) MarshalJSON

func (d *Destination) MarshalJSON() ([]byte, error)

type ListPathRequest

type ListPathRequest struct {
	TableType      api.TableType
	Name           string
	Family         bgp.Family
	Prefixes       []*LookupPrefix
	SortType       api.ListPathRequest_SortType
	EnableFiltered bool
}

ListPathRequest is used by server.ListPath API

type LookupOption

type LookupOption uint8
const (
	LOOKUP_EXACT LookupOption = iota
	LOOKUP_LONGER
	LOOKUP_SHORTER
)

func LookupOptionFromAPI added in v4.5.0

func LookupOptionFromAPI(t api.TableLookupPrefix_Type) LookupOption

LookupOptionFromAPI converts a protobuf TableLookupPrefix_Type to a LookupOption. A direct cast is wrong because the proto enum reserves 0 for UNSPECIFIED and starts meaningful values at 1, while LookupOption's iota starts at 0 (EXACT).

type LookupPrefix

type LookupPrefix struct {
	Prefix string
	RD     string
	LookupOption
}

type Path

type Path struct {
	Family             bgp.Family
	Nlri               bgp.NLRI                     `json:"nlri"`
	Age                int64                        `json:"age"`
	Best               bool                         `json:"best"`
	Attrs              []bgp.PathAttributeInterface `json:"attrs"`
	Stale              bool                         `json:"stale"`
	Withdrawal         bool                         `json:"withdrawal,omitempty"`
	PeerASN            uint32                       `json:"peer-asn,omitempty"`
	PeerID             netip.Addr                   `json:"peer-id,omitzero"`
	PeerAddress        netip.Addr                   `json:"peer-address,omitzero"`
	IsFromExternal     bool                         `json:"is-from-external,omitempty"`
	NoImplicitWithdraw bool                         `json:"no-implicit-withdraw,omitempty"`
	IsNexthopInvalid   bool                         `json:"is-nexthop-invalid,omitempty"`
	// the following fields are used only repoted by GetList() API
	SendMaxFiltered bool            `json:"send-max-filtered,omitempty"` // true if the path has been filtered out due to max path count reached
	Filtered        bool            `json:"filtered,omitempty"`
	Validation      *api.Validation `json:"validation,omitempty"`
	RemoteID        uint32
	LocalID         uint32
}

used by server.WatchEventMessages API

type Peer

type Peer struct {
	Conf      PeerConf
	State     PeerState
	Transport Transport
}

type PeerConf

type PeerConf struct {
	PeerASN           uint32
	LocalASN          uint32
	NeighborAddress   netip.Addr
	NeighborInterface string
	PeerGroup         string
	Description       string
}

type PeerEventType

type PeerEventType uint32
const (
	PEER_EVENT_UNKNOWN     PeerEventType = 0
	PEER_EVENT_INIT        PeerEventType = 1
	PEER_EVENT_END_OF_INIT PeerEventType = 2
	PEER_EVENT_STATE       PeerEventType = 3
)

type PeerState

type PeerState struct {
	PeerASN           uint32
	LocalASN          uint32
	NeighborAddress   netip.Addr
	SessionState      bgp.FSMState
	AdminState        api.PeerState_AdminState
	RouterID          netip.Addr
	PeerGroup         string
	RemoteCap         []bgp.ParameterCapabilityInterface
	LocalCap          []bgp.ParameterCapabilityInterface
	DisconnectReason  api.PeerState_DisconnectReason
	DisconnectMessage string
}

type Transport

type Transport struct {
	LocalAddress netip.Addr
	LocalPort    uint32
	RemotePort   uint32
}

type WatchEventMessage_PeerEvent

type WatchEventMessage_PeerEvent struct {
	Type PeerEventType
	Peer Peer
}

WatchEventMessages API type

Jump to

Keyboard shortcuts

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