summaryrefslogtreecommitdiffhomepage
path: root/packet/validate.go
diff options
context:
space:
mode:
Diffstat (limited to 'packet/validate.go')
-rw-r--r--packet/validate.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/packet/validate.go b/packet/validate.go
index 248dbb59..20464574 100644
--- a/packet/validate.go
+++ b/packet/validate.go
@@ -1,6 +1,7 @@
package bgp
import (
+ "encoding/binary"
"github.com/osrg/gobgp/config"
"net"
"strconv"
@@ -139,3 +140,12 @@ func ValidateFlags(t BGPAttrType, flags uint8) (bool, string) {
}
return true, ""
}
+
+func ValidateBGPMessage(m *BGPMessage) error {
+ if m.Header.Len > BGP_MAX_MESSAGE_LENGTH {
+ buf := make([]byte, 2)
+ binary.BigEndian.PutUint16(buf, m.Header.Len)
+ return NewMessageError(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_LENGTH, buf, "too long length")
+ }
+ return nil
+}