types

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelClusterConfig = "bgp_cluster_config"
	LabelVRouter       = "vrouter"
	LabelNeighbor      = "neighbor"
	LabelNeighborAsn   = "neighbor_asn"
	LabelAfi           = "afi"
	LabelSafi          = "safi"
	LabelResourceKind  = "resource_kind"
	LabelResourceName  = "resource_name"

	MetricsSubsystem                  = "bgp_control_plane"
	MetricReconcileErrorsTotal        = "reconcile_errors_total"
	MetricReconcileRunDurationSeconds = "reconcile_run_duration_seconds"
)

BGP metric labels

View Source
const (
	// ReconcilerLogField is used as key for reconciler name in the log field.
	ReconcilerLogField = "reconciler"

	// BGPNodeConfigLogField is used as key for BGP node config resource
	BGPNodeConfigLogField = "bgp_node_config"

	// InstanceLogField is used as key for BGP instance.
	InstanceLogField = "instance"

	// LocalASNLogField is used as key for BGP instance AS number
	LocalASNLogField = "asn"

	// ListenPortLogField is used as key for local port of BGP instance
	ListenPortLogField = "listen_port"

	// RouterIDLogField is used as key for BGP instance router ID
	RouterIDLogField = "router_id"

	// PeerLogField is used as key for BGP peer in the log field.
	PeerLogField = "peer"

	// FamilyLogField is used as key for BGP peer address family in the log field.
	FamilyLogField = "family"

	// PathLogField is used as key for BGP path in the log field.
	PathLogField = "path"

	// PrefixLogField is used as key for BGP prefix in the log field.
	PrefixLogField = "prefix"

	// AdvertTypeLogField is used as key for BGP advertisement type in the log field.
	AdvertTypeLogField = "advertisement_type"

	// PodIPPoolLogField is used as key for Pod IP pool in the log field.
	PodIPPoolLogField = "pod_ip_pool"

	// PolicyLogField is used as key for BGP policy in the log field.
	PolicyLogField = "policy"

	// ResourceLogField is used as key for k8s resource in the log field.
	ResourceLogField = "resource"

	// ComponentLogField ...
	ComponentLogField = "component"

	// NodeLabelsLogField ...
	NodeLabelsLogField = "nodeLabels"

	// PolicyNodeSelectorLogField ...
	PolicyNodeSelectorLogField = "policyNodeSelector"

	// SubsysLogField ...
	SubsysLogField = "subsys"

	// NameLogField ...
	NameLogField = "name"

	// NLRILogField ...
	NLRILogField = "NLRI"

	// PeerASNLogField ...
	PeerASNLogField = "peer_asn"

	// SecretRefLogField ...
	SecretRefLogField = "secret_ref"

	// FromPortLogField ...
	FromPortLogField = "from_port"

	// ToPortLogField ...
	ToPortLogField = "to_port"

	// FromRouterIDLogField ...
	FromRouterIDLogField = "from_router_id"

	// ToRouterIDLogField ...
	ToRouterIDLogField = "to_router_id"

	// PriorityLogField ...
	PriorityLogField = "priority"

	// ExistingPriorityLogField ...
	ExistingPriorityLogField = "existing_priority"

	// PeerEventLogField ...
	PeerEventLogField = "peer_event"

	// RouteLogField ...
	RouteLogField = "route_event"

	// PodCIDRAnnouncementsLogField ...
	PodCIDRAnnouncementsLogField = "pod_cidr_announcements"

	// PodCIDRUpdatedLogField ...
	PodCIDRUpdatedLogField = "pod_cidr_updated"

	// PodIPPoolLogFieldUpdatedLogField ...
	PodIPPoolLogFieldUpdatedLogField = "pod_ip_pool_updated"

	// ServicesAnnouncementsLogField ...
	ServicesAnnouncementsLogField = "services_announcements"

	// ServicesUpdatedLogField ...
	ServicesUpdatedLogField = "services_updated"

	// DiffLogField ...
	DiffLogField = "diff"

	// UpdatedInstancesLogField ...
	UpdatedInstancesLogField = "updated_instances"

	// DirectionLogField is a log field for direction of BGP reset
	DirectionLogField = "direction"
)

Variables

View Source
var (

	// CommonPaths contains common path structure values appearing in the agent code
	CommonPaths = []struct {
		Name string
		Path Path
	}{
		{
			Name: "IPv4 unicast advertisement",
			Path: Path{
				NLRI: prefixV4,
				PathAttributes: []bgp.PathAttributeInterface{
					originAttribute,
					nextHopAttribute,
				},
			},
		},
		{
			Name: "IPv6 unicast advertisement",
			Path: Path{
				NLRI: prefixV6,
				PathAttributes: []bgp.PathAttributeInterface{
					originAttribute,
					mpReachNLRIAttribute,
				},
			},
		},
	}

	// TestCommonRoutePolicies contains common route policy values to be used in tests
	TestCommonRoutePolicies = []struct {
		Name   string
		Policy *RoutePolicy
		Valid  bool
	}{
		{
			Name: "simple policy",
			Policy: &RoutePolicy{
				Name: "testpolicy1",
				Type: RoutePolicyTypeExport,
				Statements: []*RoutePolicyStatement{
					{
						Conditions: RoutePolicyConditions{
							MatchNeighbors: &RoutePolicyNeighborMatch{
								Type:      RoutePolicyMatchAny,
								Neighbors: []netip.Addr{netip.MustParseAddr("172.16.0.1")},
							},
							MatchPrefixes: &RoutePolicyPrefixMatch{
								Type: RoutePolicyMatchAny,
								Prefixes: []RoutePolicyPrefix{
									{
										CIDR:         netip.MustParsePrefix("1.2.3.0/24"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
								},
							},
						},
						Actions: RoutePolicyActions{
							RouteAction:         RoutePolicyActionNone,
							AddCommunities:      []string{"65000:100"},
							AddLargeCommunities: []string{"4294967295:0:100"},
							SetLocalPreference:  ptr.To[int64](150),
							NextHop: &RoutePolicyActionNextHop{
								Self: true,
							},
						},
					},
				},
			},
			Valid: true,
		},
		{
			Name: "complex policy",
			Policy: &RoutePolicy{
				Name: "testpolicy1",
				Type: RoutePolicyTypeExport,
				Statements: []*RoutePolicyStatement{
					{
						Conditions: RoutePolicyConditions{
							MatchNeighbors: &RoutePolicyNeighborMatch{
								Type:      RoutePolicyMatchInvert,
								Neighbors: []netip.Addr{netip.MustParseAddr("172.16.0.1"), netip.MustParseAddr("10.10.10.10")},
							},
							MatchPrefixes: &RoutePolicyPrefixMatch{
								Type: RoutePolicyMatchAny,
								Prefixes: []RoutePolicyPrefix{
									{
										CIDR:         netip.MustParsePrefix("1.2.3.0/24"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
									{
										CIDR:         netip.MustParsePrefix("192.188.0.0/16"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
								},
							},
							MatchFamilies: []Family{
								{
									Afi:  AfiIPv4,
									Safi: SafiUnicast,
								},
							},
						},
						Actions: RoutePolicyActions{
							RouteAction:        RoutePolicyActionNone,
							AddCommunities:     []string{"65000:100", "65000:101"},
							SetLocalPreference: ptr.To[int64](150),
							NextHop: &RoutePolicyActionNextHop{
								Unchanged: true,
							},
						},
					},
					{
						Conditions: RoutePolicyConditions{
							MatchNeighbors: &RoutePolicyNeighborMatch{
								Type:      RoutePolicyMatchAny,
								Neighbors: []netip.Addr{netip.MustParseAddr("fe80::210:5aff:feaa:20a2")},
							},
							MatchPrefixes: &RoutePolicyPrefixMatch{
								Type: RoutePolicyMatchInvert,
								Prefixes: []RoutePolicyPrefix{
									{
										CIDR:         netip.MustParsePrefix("2001:0DB8::/64"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
									{
										CIDR:         netip.MustParsePrefix("2002::/16"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
								},
							},
							MatchFamilies: []Family{
								{
									Afi:  AfiIPv6,
									Safi: SafiUnicast,
								},
							},
						},
						Actions: RoutePolicyActions{
							RouteAction:        RoutePolicyActionNone,
							AddCommunities:     []string{"65000:100", "65000:101"},
							SetLocalPreference: ptr.To[int64](150),
						},
					},
				},
			},
			Valid: true,
		},
		{
			Name: "invalid policy",
			Policy: &RoutePolicy{
				Name: "testpolicy1",
				Type: RoutePolicyTypeExport,
				Statements: []*RoutePolicyStatement{

					{
						Conditions: RoutePolicyConditions{
							MatchNeighbors: &RoutePolicyNeighborMatch{
								Type:      RoutePolicyMatchAny,
								Neighbors: []netip.Addr{netip.MustParseAddr("172.16.0.1")},
							},
							MatchPrefixes: &RoutePolicyPrefixMatch{
								Type: RoutePolicyMatchAny,
								Prefixes: []RoutePolicyPrefix{
									{
										CIDR:         netip.MustParsePrefix("1.2.3.0/24"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
								},
							},
						},
						Actions: RoutePolicyActions{
							RouteAction:        RoutePolicyActionNone,
							AddCommunities:     []string{"65000:100"},
							SetLocalPreference: ptr.To[int64](150),
						},
					},

					{
						Conditions: RoutePolicyConditions{
							MatchNeighbors: &RoutePolicyNeighborMatch{
								Type:      RoutePolicyMatchAny,
								Neighbors: []netip.Addr{{}},
							},
							MatchPrefixes: &RoutePolicyPrefixMatch{
								Type: RoutePolicyMatchAny,
								Prefixes: []RoutePolicyPrefix{
									{
										CIDR:         netip.MustParsePrefix("192.188.0.0/16"),
										PrefixLenMin: 24,
										PrefixLenMax: 32,
									},
								},
							},
						},
						Actions: RoutePolicyActions{
							RouteAction: RoutePolicyActionNone,
						},
					},
				},
			},
			Valid: false,
		},
	}
)

Functions

func CanAdvertisePodCIDR

func CanAdvertisePodCIDR(ipam string) bool

CanAdvertisePodCIDR returns true if the provided IPAM mode is supported for advertising PodCIDR

Types

type Afi

type Afi uint32

Afi is address family identifier

const (
	AfiUnknown Afi = 0
	AfiIPv4    Afi = 1
	AfiIPv6    Afi = 2
	AfiL2VPN   Afi = 25
	AfiLS      Afi = 16388
	AfiOpaque  Afi = 16397
)

func ParseAfi

func ParseAfi(s string) Afi

ParseAfi parses s as an address family identifier. If s is unknown, AfiUnknown is returned.

func (*Afi) FromString

func (a *Afi) FromString(s string) error

FromString assigns s to a. An error is returned if s is an unknown address family indicator.

func (Afi) MarshalJSON

func (a Afi) MarshalJSON() ([]byte, error)

func (Afi) MarshalYAML

func (a Afi) MarshalYAML() (any, error)

func (Afi) String

func (a Afi) String() string

String returns the stringified form of a.

type BGPGlobal

type BGPGlobal struct {
	ASN                   uint32
	RouterID              string
	ListenPort            int32 // When -1 gobgp won't listen on tcp:179
	RouteSelectionOptions *RouteSelectionOptions
}

BGPGlobal contains high level BGP configuration for given instance.

type FakeRouter

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

func (*FakeRouter) AddNeighbor

func (f *FakeRouter) AddNeighbor(ctx context.Context, n *Neighbor) error

func (*FakeRouter) AddRoutePolicy

func (f *FakeRouter) AddRoutePolicy(ctx context.Context, p RoutePolicyRequest) error

func (*FakeRouter) AdvertisePath

func (f *FakeRouter) AdvertisePath(ctx context.Context, p PathRequest) (PathResponse, error)

func (*FakeRouter) GetBGP

func (f *FakeRouter) GetBGP(ctx context.Context) (GetBGPResponse, error)

func (*FakeRouter) GetPeerState

func (f *FakeRouter) GetPeerState(ctx context.Context) (GetPeerStateResponse, error)

func (*FakeRouter) GetRoutePolicies

func (f *FakeRouter) GetRoutePolicies(ctx context.Context) (*GetRoutePoliciesResponse, error)

func (*FakeRouter) GetRoutes

func (*FakeRouter) RemoveNeighbor

func (f *FakeRouter) RemoveNeighbor(ctx context.Context, n *Neighbor) error

func (*FakeRouter) RemoveRoutePolicy

func (f *FakeRouter) RemoveRoutePolicy(ctx context.Context, p RoutePolicyRequest) error

func (*FakeRouter) ResetAllNeighbors

func (f *FakeRouter) ResetAllNeighbors(ctx context.Context, r ResetAllNeighborsRequest) error

func (*FakeRouter) ResetNeighbor

func (f *FakeRouter) ResetNeighbor(ctx context.Context, r ResetNeighborRequest) error

func (*FakeRouter) Stop

func (f *FakeRouter) Stop(ctx context.Context, r StopRequest)

func (*FakeRouter) UpdateNeighbor

func (f *FakeRouter) UpdateNeighbor(ctx context.Context, n *Neighbor) error

func (*FakeRouter) WithdrawPath

func (f *FakeRouter) WithdrawPath(ctx context.Context, p PathRequest) error

type Family

type Family struct {
	Afi  Afi
	Safi Safi
}

Family holds Address Family Indicator (AFI) and Subsequent Address Family Indicator for Multi-Protocol BGP

+deepequal-gen=true

func ToAgentFamily

func ToAgentFamily(fam v2.CiliumBGPFamily) Family

func (*Family) DeepEqual

func (in *Family) DeepEqual(other *Family) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

func (Family) String

func (f Family) String() string

type GetBGPResponse

type GetBGPResponse struct {
	Global BGPGlobal
}

GetBGPResponse contains BGP global parameters

type GetPeerStateResponse

type GetPeerStateResponse struct {
	Peers []*models.BgpPeer
}

GetPeerStateResponse contains state of peers configured in given instance

type GetRoutePoliciesResponse

type GetRoutePoliciesResponse struct {
	Policies []*RoutePolicy
}

GetRoutePoliciesResponse contains route policies retrieved from the underlying router

type GetRoutesRequest

type GetRoutesRequest struct {
	// TableType specifies a table type to retrieve
	TableType TableType

	// Family specifies an address family of the table
	Family Family

	// Neighbor specifies which neighbor's table to retrieve. Must be
	// specified when TableTypeAdjRIBIn/Out is specified in TableType.
	Neighbor netip.Addr
}

GetRoutesRequest contains parameters for retrieving routes from the RIB of underlying router

type GetRoutesResponse

type GetRoutesResponse struct {
	Routes []*Route
}

GetRoutesResponse contains routes retrieved from the RIB of underlying router

type Neighbor

type Neighbor struct {
	Address         netip.Addr
	ASN             uint32
	AuthPassword    string
	EbgpMultihop    *NeighborEbgpMultihop
	RouteReflector  *NeighborRouteReflector
	Timers          *NeighborTimers
	Transport       *NeighborTransport
	GracefulRestart *NeighborGracefulRestart
	AfiSafis        []*Family
}

Neighbor is an object representing a single BGP neighbor. It is an analogue of GoBGP's Peer object, but only contains minimal fields required for Cilium usecases.

func ToNeighborV2

func ToNeighborV2(np *v2.CiliumBGPNodePeer, pc *v2.CiliumBGPPeerConfigSpec, password string) *Neighbor

ToNeighborV2 converts a CiliumBGPNodePeer to Neighbor which can be used with Router API. The caller must ensure that the np, np.PeerAddress, np.PeerASN and pc are not nil.

type NeighborEbgpMultihop

type NeighborEbgpMultihop struct {
	TTL uint32
}

type NeighborGracefulRestart

type NeighborGracefulRestart struct {
	Enabled     bool
	RestartTime uint32
}

type NeighborRouteReflector

type NeighborRouteReflector struct {
	Client    bool
	ClusterID string
}

type NeighborTimers

type NeighborTimers struct {
	ConnectRetry      uint64
	HoldTime          uint64
	KeepaliveInterval uint64
}

type NeighborTransport

type NeighborTransport struct {
	LocalAddress string
	LocalPort    uint32
	RemotePort   uint32
}

type Path

type Path struct {
	// read/write
	NLRI           bgp.AddrPrefixInterface
	PathAttributes []bgp.PathAttributeInterface
	Family         Family // can be empty, in which case it will be inferred from NLRI

	// readonly
	AgeNanoseconds int64 // time duration in nanoseconds since the Path was created
	Best           bool
	UUID           []byte // path identifier in underlying implementation
	SourceASN      uint32
}

Path is an object representing a single routing Path. It is an analogue of GoBGP's Path object, but only contains minimal fields required for Cilium usecases.

func NewPathForPrefix

func NewPathForPrefix(prefix netip.Prefix) (path *Path)

NewPathForPrefix returns a Path that can be used to advertise the provided IP prefix by the underlying BGP implementation.

The prefix can be either IPv4 or IPv6 and this function will handle the differences between MP BGP and BGP.

The next hop of the path will always be set to "0.0.0.0" for IPv4 and "::" for IPv6, so the underlying BGP implementation selects appropriate actual nexthop address when advertising it.

func SetPathOriginAttrIncomplete

func SetPathOriginAttrIncomplete(path *Path) *Path

SetPathOriginAttrIncomplete ensures the given path has an ORIGIN path attribute set to INCOMPLETE, replacing the existing one if present or appending it if missing.

type PathRequest

type PathRequest struct {
	Path *Path
}

PathRequest contains parameters for advertising or withdrawing a Path

type PathResponse

type PathResponse struct {
	Path *Path
}

PathResponse contains response after advertising the Path, the returned Path can be used for withdrawing the Path (based on UUID set by the underlying implementation)

type PolicyPrefixList

type PolicyPrefixList []RoutePolicyPrefix

func (PolicyPrefixList) Less

func (l PolicyPrefixList) Less(i, j int) bool

Less is a comparator of two RoutePolicyPrefixMatch rules to be used for sorting purposes

type ResetAllNeighborsRequest

type ResetAllNeighborsRequest struct {
	Soft               bool
	SoftResetDirection SoftResetDirection
	AdminCommunication string
}

ResetAllNeighborsRequest contains parameters used when resetting all BGP peers

type ResetNeighborRequest

type ResetNeighborRequest struct {
	PeerAddress        netip.Addr
	Soft               bool
	SoftResetDirection SoftResetDirection
	AdminCommunication string
}

ResetNeighborRequest contains parameters used when resetting a BGP peer

type Route

type Route struct {
	Prefix string
	Paths  []*Path
}

Route represents a single route in the RIB of underlying router

type RoutePolicy

type RoutePolicy struct {
	// Name is a unique string identifier of the policy for the given router.
	Name string
	// RoutePolicyType is the type of the policy.
	Type RoutePolicyType
	// Statements is an ordered list of policy statements.
	Statements []*RoutePolicyStatement
}

RoutePolicy represents a BGP routing policy, also called "route map" in some BGP implementations. It can contain multiple Statements that are evaluated in the given order. Each Statement contains conditions for matching a route and actions taken if a route matches the conditions. Whenever a Statement matches a route and the action taken on it is to either accept or reject the route, the policy evaluation for the given route stops, and no further Statements nor other RoutePolicies are evaluated.

+deepequal-gen=true

func (*RoutePolicy) DeepEqual

func (in *RoutePolicy) DeepEqual(other *RoutePolicy) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

type RoutePolicyAction

type RoutePolicyAction int

RoutePolicyAction defines the action taken on a route matched by a routing policy.

const (
	// RoutePolicyActionNone does not affect processing of a route.
	// The policy evaluation continues with the next policy statements / other policies.
	RoutePolicyActionNone RoutePolicyAction = iota
	// RoutePolicyActionAccept accepts a route into the RIB / adjacency RIB.
	// No further policy statements / policies are evaluated for the route.
	RoutePolicyActionAccept
	// RoutePolicyActionReject rejects a route from the RIB / adjacency RIB.
	// No further policy statements / policies are evaluated for the route.
	RoutePolicyActionReject
)

func (RoutePolicyAction) MarshalJSON

func (a RoutePolicyAction) MarshalJSON() ([]byte, error)

func (RoutePolicyAction) MarshalYAML

func (a RoutePolicyAction) MarshalYAML() (any, error)

func (RoutePolicyAction) String

func (a RoutePolicyAction) String() string

type RoutePolicyActionNextHop

type RoutePolicyActionNextHop struct {
	// Set nexthop to the self address of the router
	Self bool
	// Don't change the nexthop of the route
	Unchanged bool
}

RoutingPolicyActionNextHop defines the action taken on the next hop of a route matched by a routing policy.

+deepequal-gen=true

func (*RoutePolicyActionNextHop) DeepEqual

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

type RoutePolicyActions

type RoutePolicyActions struct {
	// RouteAction defines an action taken on the matched route.
	RouteAction RoutePolicyAction
	// AddCommunities defines a list of BGP standard community values to be added to the matched route.
	// If empty, no communities will be added.
	AddCommunities []string
	// AddLargeCommunities defines a list of BGP large community values to be added to the matched route.
	// If empty, no communities will be added.
	AddLargeCommunities []string
	// SetLocalPreference defines a BGP local preference value to be set on the matched route.
	// If nil, no local preference is set.
	SetLocalPreference *int64
	// NextHop sets (or doesn't set) a next hop value on the matched route.
	NextHop *RoutePolicyActionNextHop
}

RoutePolicyActions define policy actions taken on route matched by a routing policy.

+deepequal-gen=true

func (*RoutePolicyActions) DeepEqual

func (in *RoutePolicyActions) DeepEqual(other *RoutePolicyActions) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

type RoutePolicyConditions

type RoutePolicyConditions struct {
	// MatchNeighbors matches BGP neighbor IP address with the provided match rules.
	MatchNeighbors *RoutePolicyNeighborMatch
	// MatchPrefixes matches CIDR prefix with the provided match rules.
	MatchPrefixes *RoutePolicyPrefixMatch
	// MatchFamilies matches ANY of the provided address families. If empty, matches all address families.
	// (Note: the underlying GoBGP infrastructure does not support any other matching criteria for families).
	MatchFamilies []Family
}

RoutePolicyConditions represent conditions of a policy statement.

+deepequal-gen=true

func (*RoutePolicyConditions) DeepEqual

func (in *RoutePolicyConditions) DeepEqual(other *RoutePolicyConditions) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

func (RoutePolicyConditions) String

func (r RoutePolicyConditions) String() string

String() constructs a string identifier

type RoutePolicyMatchType

type RoutePolicyMatchType int

RoutePolicyMatchType defines the route policy matching logic in case of multiple match elements.

const (
	RoutePolicyMatchAny RoutePolicyMatchType = iota
	RoutePolicyMatchAll
	RoutePolicyMatchInvert
)

func (RoutePolicyMatchType) MarshalJSON

func (t RoutePolicyMatchType) MarshalJSON() ([]byte, error)

func (RoutePolicyMatchType) MarshalYAML

func (t RoutePolicyMatchType) MarshalYAML() (any, error)

func (RoutePolicyMatchType) String

func (t RoutePolicyMatchType) String() string

type RoutePolicyNeighborMatch

type RoutePolicyNeighborMatch struct {
	Type RoutePolicyMatchType
	// +deepequal-gen=false
	Neighbors []netip.Addr
}

RoutePolicyNeighborMatch matches BGP neighbor IP address with the provided IPs using the provided match logic type.

+deepequal-gen=true +deepequal-gen:private-method=true

func (*RoutePolicyNeighborMatch) DeepEqual

DeepEqual is a manually created deepequal function, deeply comparing the receiver with another. It compares fields with types that do not implement the `DeepEqual` method and calls the generated private `deepEqual` method which compares the rest of the fields.

type RoutePolicyPrefix

type RoutePolicyPrefix struct {
	// CIDR is a prefix to match with.
	// +deepequal-gen=false
	CIDR netip.Prefix
	// PrefixLenMin is the minimal prefix length that will match if it falls under CIDR.
	PrefixLenMin int
	// PrefixLenMax is the maximal prefix length that will match if it falls under CIDR.
	PrefixLenMax int
}

RoutePolicyPrefix can be used to match a CIDR prefix in a routing policy. It can be used to perform exact prefix length matches (if CIDR.Bits() == PrefixLenMin == PrefixLenMax), or variable prefix length matches.

+deepequal-gen=true +deepequal-gen:private-method=true

func (*RoutePolicyPrefix) DeepEqual

func (p *RoutePolicyPrefix) DeepEqual(other *RoutePolicyPrefix) bool

DeepEqual is a manually created deepequal function, deeply comparing the receiver with another. It compares fields with types that do not implement the `DeepEqual` method and calls the generated private `deepEqual` method which compares the rest of the fields.

type RoutePolicyPrefixMatch

type RoutePolicyPrefixMatch struct {
	Type     RoutePolicyMatchType
	Prefixes []RoutePolicyPrefix
}

RoutePolicyPrefixMatch matches CIDR prefix with the provided prefixes using the provided match logic type.

+deepequal-gen=true

func (*RoutePolicyPrefixMatch) DeepEqual

func (in *RoutePolicyPrefixMatch) DeepEqual(other *RoutePolicyPrefixMatch) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

type RoutePolicyRequest

type RoutePolicyRequest struct {
	DefaultExportAction RoutePolicyAction
	Policy              *RoutePolicy
}

RoutePolicyRequest contains parameters for adding or removing a routing policy.

type RoutePolicyStatement

type RoutePolicyStatement struct {
	// Conditions of the statement. If ALL of them match a route, the Actions are taken on the route.
	Conditions RoutePolicyConditions
	// Actions define actions taken on a matched route.
	Actions RoutePolicyActions
}

RoutePolicyStatement represents a single statement of a routing RoutePolicy. It contains conditions for matching a route and actions taken if a route matches the conditions.

+deepequal-gen=true

func (*RoutePolicyStatement) DeepEqual

func (in *RoutePolicyStatement) DeepEqual(other *RoutePolicyStatement) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

type RoutePolicyType

type RoutePolicyType int

RoutePolicyType defines the type of routing policy.

const (
	// RoutePolicyTypeExport represents export routing policy type (affecting how the routes from RIB are advertised to peers).
	RoutePolicyTypeExport RoutePolicyType = iota
	// RoutePolicyTypeImport represents import routing policy type (affecting how the routes are imported into RIB).
	RoutePolicyTypeImport
)

func (RoutePolicyType) MarshalJSON

func (t RoutePolicyType) MarshalJSON() ([]byte, error)

func (RoutePolicyType) MarshalYAML

func (t RoutePolicyType) MarshalYAML() (any, error)

func (RoutePolicyType) String

func (t RoutePolicyType) String() string

type RouteSelectionOptions

type RouteSelectionOptions struct {
	// AdvertiseInactiveRoutes when set will advertise route even if it is not present in RIB
	AdvertiseInactiveRoutes bool
}

RouteSelectionOptions contains generic BGP route selection tuning parameters

type Router

type Router interface {
	// Stop stops the router
	Stop(ctx context.Context, r StopRequest)

	// AddNeighbor configures BGP peer
	AddNeighbor(ctx context.Context, n *Neighbor) error

	// UpdateNeighbor updates BGP peer
	UpdateNeighbor(ctx context.Context, n *Neighbor) error

	// RemoveNeighbor removes BGP peer
	RemoveNeighbor(ctx context.Context, n *Neighbor) error

	// ResetNeighbor resets BGP peering with the provided neighbor address
	ResetNeighbor(ctx context.Context, r ResetNeighborRequest) error

	// ResetAllNeighbors resets BGP peering with all configured neighbors
	ResetAllNeighbors(ctx context.Context, r ResetAllNeighborsRequest) error

	// AdvertisePath advertises BGP Path to all configured peers
	AdvertisePath(ctx context.Context, p PathRequest) (PathResponse, error)

	// WithdrawPath  removes BGP Path from all peers
	WithdrawPath(ctx context.Context, p PathRequest) error

	// AddRoutePolicy adds a new routing policy into the underlying router.
	AddRoutePolicy(ctx context.Context, p RoutePolicyRequest) error

	// RemoveRoutePolicy removes a routing policy from the underlying router.
	RemoveRoutePolicy(ctx context.Context, p RoutePolicyRequest) error

	// GetPeerState returns status of BGP peers
	GetPeerState(ctx context.Context) (GetPeerStateResponse, error)

	// GetRoutes retrieves routes from the RIB of underlying router
	GetRoutes(ctx context.Context, r *GetRoutesRequest) (*GetRoutesResponse, error)

	// GetRoutePolicies retrieves route policies from the underlying router
	GetRoutePolicies(ctx context.Context) (*GetRoutePoliciesResponse, error)

	// GetBGP returns configured BGP global parameters
	GetBGP(ctx context.Context) (GetBGPResponse, error)
}

Router is vendor-agnostic cilium bgp configuration layer. Parameters of this layer are standard BGP RFC complaint and not specific to any underlying implementation.

func NewFakeRouter

func NewFakeRouter() Router

type RouterProvider

type RouterProvider interface {
	NewRouter(ctx context.Context, log *slog.Logger, params ServerParameters) (Router, error)
}

RouterProvider provides instances of underlying BGP router implementation.

type Safi

type Safi uint32

Safi is subsequent address family identifier

const (
	SafiUnknown                Safi = 0
	SafiUnicast                Safi = 1
	SafiMulticast              Safi = 2
	SafiMplsLabel              Safi = 4
	SafiEncapsulation          Safi = 7
	SafiVpls                   Safi = 65
	SafiEvpn                   Safi = 70
	SafiLs                     Safi = 71
	SafiSrPolicy               Safi = 73
	SafiMup                    Safi = 85
	SafiMplsVpn                Safi = 128
	SafiMplsVpnMulticast       Safi = 129
	SafiRouteTargetConstraints Safi = 132
	SafiFlowSpecUnicast        Safi = 133
	SafiFlowSpecVpn            Safi = 134
	SafiKeyValue               Safi = 241
)

func ParseSafi

func ParseSafi(s string) Safi

ParseSafi parses s as a subsequent address family identifier. If s is unknown, SafiUnknown is returned.

func (*Safi) FromString

func (s *Safi) FromString(safi string) error

FromString assigns safi to s. An error is returned if safi is an unknown subsequent address family indicator.

func (Safi) MarshalJSON

func (s Safi) MarshalJSON() ([]byte, error)

func (Safi) MarshalYAML

func (s Safi) MarshalYAML() (any, error)

func (Safi) String

func (s Safi) String() string

String returns the stringified form of s.

type ServerParameters

type ServerParameters struct {
	Global            BGPGlobal
	StateNotification StateNotificationCh
}

ServerParameters contains information for underlying bgp implementation layer to initializing BGP process.

type SessionState

type SessionState uint32

SessionState as defined in rfc4271#section-8.2.2

const (
	SessionUnknown SessionState = iota
	SessionIdle
	SessionConnect
	SessionActive
	SessionOpenSent
	SessionOpenConfirm
	SessionEstablished
)

func (SessionState) String

func (s SessionState) String() string

type SoftResetDirection

type SoftResetDirection int

SoftResetDirection defines the direction in which a BGP soft reset should be performed

const (
	SoftResetDirectionNone SoftResetDirection = iota
	SoftResetDirectionIn
	SoftResetDirectionOut
	SoftResetDirectionBoth
)

func (SoftResetDirection) String

func (d SoftResetDirection) String() string

type StateNotificationCh

type StateNotificationCh chan struct{}

StateNotificationCh is a channel used to notify the state of the BGP instance has changed

type StopRequest

type StopRequest struct {
	// FullDestroy should be set to true if full destroy of the router instance should be performed.
	// Note that this causes sending a Cease notification to BGP peers, which terminates Graceful Restart progress.
	FullDestroy bool
}

StopRequest contains parameters for stopping the underlying router

type TableType

type TableType int

TableType specifies the routing table type of underlying router

const (
	TableTypeUnknown TableType = iota
	TableTypeLocRIB
	TableTypeAdjRIBIn
	TableTypeAdjRIBOut
)

func ParseTableType

func ParseTableType(s string) TableType

ParseTableType parses s as a routing table type. If s is unknown, TableTypeUnknown is returned.

Jump to

Keyboard shortcuts

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