summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packet/bgp.go3
-rw-r--r--packet/validate.go10
-rw-r--r--server/fsm.go3
3 files changed, 15 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
+}
diff --git a/server/fsm.go b/server/fsm.go
index fcc4adfb..606ebbf9 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -225,6 +225,9 @@ func (h *FSMHandler) recvMessageWithError() error {
var fmsg *fsmMsg
m, err := bgp.ParseBGPBody(hd, bodyBuf)
+ if err == nil {
+ err = bgp.ValidateBGPMessage(m)
+ }
if err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",