-
Notifications
You must be signed in to change notification settings - Fork 11
/
plugin.go
53 lines (46 loc) · 2.2 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package corebgp
import "net/netip"
// Plugin is a BGP peer plugin.
type Plugin interface {
// GetCapabilities is fired when a peer's FSM is in the Connect state prior
// to sending an Open message. The returned capabilities are included in the
// Open message sent to the peer.
//
// The four-octet AS number space capability will be implicitly handled,
// Plugin implementations are not required to return it.
GetCapabilities(peer PeerConfig) []Capability
// OnOpenMessage is fired when an Open message is received from a peer
// during the OpenSent state. Returning a non-nil Notification will cause it
// to be sent to the peer and the FSM will transition to the Idle state.
//
// Remote peers MUST include the four-octet AS number space capability in
// their open message. corebgp will return a Notification message if a
// remote peer does not support said capability, and will not invoke
// OnOpenMessage.
//
// Per RFC5492 a BGP speaker should only send a Notification if a required
// capability is missing; unknown or unsupported capabilities should be
// ignored.
OnOpenMessage(peer PeerConfig, routerID netip.Addr, capabilities []Capability) *Notification
// OnEstablished is fired when a peer's FSM transitions to the Established
// state. The returned UpdateMessageHandler will be fired when an Update
// message is received from the peer.
//
// The provided writer can be used to send Update messages to the peer for
// the lifetime of the FSM's current, established state. It should be
// discarded once OnClose() fires.
OnEstablished(peer PeerConfig, writer UpdateMessageWriter) UpdateMessageHandler
// OnClose is fired when a peer's FSM transitions out of the Established
// state.
OnClose(peer PeerConfig)
}
// UpdateMessageHandler handles Update messages. If a non-nil Notification is
// returned it will be sent to the peer and the FSM will transition out of the
// Established state.
type UpdateMessageHandler func(peer PeerConfig, updateMessage []byte) *Notification
type UpdateMessageWriter interface {
// WriteUpdate sends an update message to the remote peer. An error is
// returned if the write fails and/or the FSM is no longer in an established
// state.
WriteUpdate([]byte) error
}