server: handle over 4096 byte size message

send notification.

Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
FUJITA Tomonori
2015-01-16 19:13:32 +09:00
parent 63908917a2
commit 1ee4e65bc9
3 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -2584,7 +2584,8 @@ type BGPBody interface {
}
const (
BGP_HEADER_LENGTH = 19
BGP_HEADER_LENGTH = 19
BGP_MAX_MESSAGE_LENGTH = 4096
)
type BGPHeader struct {
+10
View File
@@ -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
}
+3
View File
@@ -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",