summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp.go3
-rw-r--r--packet/validate.go10
2 files changed, 12 insertions, 1 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 3e11bf8c..c11cc25c 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -2584,7 +2584,8 @@ type BGPBody interface {
}
const (
- BGP_HEADER_LENGTH = 19
+ BGP_HEADER_LENGTH = 19
+ BGP_MAX_MESSAGE_LENGTH = 4096
)
type BGPHeader struct {
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
+}