forked from jwhited/corebgp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification_error.go
96 lines (83 loc) · 2.65 KB
/
notification_error.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package corebgp
import "fmt"
type notificationError struct {
notification *Notification
out bool
}
func newNotificationError(n *Notification, out bool) *notificationError {
return ¬ificationError{
notification: n,
out: out,
}
}
func (n *notificationError) dampPeer() bool {
return n.notification.Code != NotifCodeCease
}
func (n *notificationError) Error() string {
direction := "received"
if n.out {
direction = "sent"
}
desc := lookupNotifDesc(n.notification.Code, n.notification.Subcode)
return fmt.Sprintf("notification %s '%s' code: %d subcode: %d",
direction, desc, n.notification.Code, n.notification.Subcode)
}
func lookupNotifDesc(code, subcode uint8) string {
for _, desc := range notifDescs {
if desc.code == code && desc.subcode == subcode {
return desc.description
}
}
return "Unknown description"
}
var (
// most descriptions come from https://tools.ietf.org/html/rfc4271#section-4.5
notifDescs = []struct {
code uint8
subcode uint8
description string
}{
{1, 0, "Invalid message header"},
{1, 1, "Connection not synchronized"},
{1, 2, "Bad message length"},
{1, 3, "Bad message type"},
{2, 0, "Invalid OPEN message"},
{2, 1, "Unsupported version number"},
{2, 2, "Bad peer AS"},
{2, 3, "Bad BGP identifier"},
{2, 4, "Unsupported optional parameter"},
{2, 6, "Unacceptable hold time"},
// https://tools.ietf.org/html/rfc5492#section-5
{2, 7, "Required capability missing"},
{3, 0, "Invalid UPDATE message"},
{3, 1, "Malformed attribute list"},
{3, 2, "Unrecognized well-known attribute"},
{3, 3, "Missing mandatory attribute"},
{3, 4, "Invalid attribute flags"},
{3, 5, "Invalid attribute length"},
{3, 6, "Invalid ORIGIN attribute"},
{3, 8, "Invalid NEXT_HOP attribute"},
{3, 9, "Optional attribute error"},
{3, 10, "Invalid network field"},
{3, 11, "Malformed AS_PATH"},
{4, 0, "Hold timer expired"},
{5, 0, "Finite state machine error"},
// https://tools.ietf.org/html/rfc6608#section-3
{5, 1, "Unexpected message in OpenSent state"},
{5, 2, "Unexpected message in OpenConfirm state"},
{5, 3, "Unexpected message in Established state"},
{6, 0, "Cease"},
// https://tools.ietf.org/html/rfc4486#section-3
{6, 1, "Maximum number of prefixes reached"},
{6, 2, "Administrative shutdown"},
{6, 3, "Peer de-configured"},
{6, 4, "Administrative reset"},
{6, 5, "Connection rejected"},
{6, 6, "Other configuration change"},
{6, 7, "Connection collision resolution"},
{6, 8, "Out of Resources"},
// https://tools.ietf.org/html/rfc7313#section-5
{7, 0, "Invalid ROUTE-REFRESH message"},
{7, 1, "Invalid ROUTE-REFRESH message length"},
}
)