summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-16 19:13:32 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-16 19:13:32 +0900
commit1ee4e65bc9ed53887c9c835dfbb22d3b7817d71c (patch)
treea564456c286dbc48003830cdbf6915f48857022d
parent63908917a29f27e2edd0ad43fa25decf5164e038 (diff)
server: handle over 4096 byte size message
send notification. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-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",