summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packet/bgp.go25
-rw-r--r--server/fsm.go9
2 files changed, 16 insertions, 18 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 8bff8485..37d19b3e 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -2096,7 +2096,7 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error {
// check withdrawn route length
if len(data) < 2 {
msg := "message length isn't enough for withdrawn route length"
- e := NewPacketParseError(eCode, eSubCode, msg)
+ e := NewMessageError(eCode, eSubCode, nil, msg)
return e
}
@@ -2106,7 +2106,7 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error {
// check withdrawn route
if len(data) < int(msg.WithdrawnRoutesLen) {
msg := "withdrawn route length exceeds message length"
- e := NewPacketParseError(eCode, eSubCode, msg)
+ e := NewMessageError(eCode, eSubCode, nil, msg)
return e
}
@@ -2121,7 +2121,7 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error {
// check path total attribute length
if len(data) < 2 {
msg := "message length isn't enough for path total attribute length"
- e := NewPacketParseError(eCode, eSubCode, msg)
+ e := NewMessageError(eCode, eSubCode, nil, msg)
return e
}
@@ -2131,7 +2131,7 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error {
// check path attribute
if len(data) < int(msg.TotalPathAttributeLen) {
msg := "path total attribute length exceeds message length"
- e := NewPacketParseError(eCode, eSubCode, msg)
+ e := NewMessageError(eCode, eSubCode, nil, msg)
return e
}
@@ -2698,21 +2698,22 @@ func ParseBMPMessage(data []byte) (*BMPMessage, error) {
return msg, nil
}
-type PacketParseError struct {
+type MessageError struct {
TypeCode uint8
SubTypeCode uint8
- Message string
+ Data []byte
+ message string
}
-func NewPacketParseError(typeCode, subTypeCode uint8, msg string) error {
- e := &PacketParseError{
+func NewMessageError(typeCode, subTypeCode uint8, data []byte, msg string) error {
+ return &MessageError{
TypeCode: typeCode,
SubTypeCode: subTypeCode,
- Message: msg,
+ Data: data,
+ message: msg,
}
- return e
}
-func (e *PacketParseError) Error() string {
- return e.Message
+func (e *MessageError) Error() string {
+ return e.message
}
diff --git a/server/fsm.go b/server/fsm.go
index ee3d221e..c6e03e8f 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -347,12 +347,9 @@ func (h *FSMHandler) recvMessageloop() error {
for {
err := h.recvMessageWithError()
if err != nil {
- switch e := err.(type) {
- case *bgp.PacketParseError:
- // enqueue notification message
- n := bgp.NewBGPNotificationMessage(e.TypeCode, e.SubTypeCode, nil)
- h.fsm.outgoing <- n
- }
+ e := err.(*bgp.MessageError)
+ m := bgp.NewBGPNotificationMessage(e.TypeCode, e.SubTypeCode, e.Data)
+ h.fsm.outgoing <- m
return nil
}
}