summaryrefslogtreecommitdiffhomepage
path: root/packet/validate.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-29 19:43:56 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-29 19:43:56 +0900
commita34228410e645d6e53c9752d8a9122cfa67310b9 (patch)
treed4bdacc7005dd469aaa75f58cc9834c37e209662 /packet/validate.go
parentcbcc16c65b75be7af2a6c3e227107cce3795b33f (diff)
server: verify OpenMessage
- BGP version (must be 4) - AS number - holdtime (0 or 3 <= or <= 65535) Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/validate.go')
-rw-r--r--packet/validate.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/packet/validate.go b/packet/validate.go
index 80bc426d..668552ba 100644
--- a/packet/validate.go
+++ b/packet/validate.go
@@ -183,3 +183,31 @@ func ValidateBGPMessage(m *BGPMessage) error {
return nil
}
+
+func ValidateOpenMsg(m *BGPOpen, expectedAS uint32) error {
+ if m.Version != 4 {
+ return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER, nil, fmt.Sprintf("upsuppored version %d", m.Version))
+ }
+
+ as := uint32(m.MyAS)
+ for _, p := range m.OptParams {
+ paramCap, y := p.(*OptionParameterCapability)
+ if !y {
+ continue
+ }
+ for _, c := range paramCap.Capability {
+ if c.Code() == BGP_CAP_FOUR_OCTET_AS_NUMBER {
+ cap := c.(*CapFourOctetASNumber)
+ as = cap.CapValue
+ }
+ }
+ }
+ if as != expectedAS {
+ return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_BAD_PEER_AS, nil, fmt.Sprintf("as number mismatch expected %u, received %u", expectedAS, as))
+ }
+
+ if m.HoldTime < 3 && m.HoldTime != 0 {
+ return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME, nil, fmt.Sprintf("unacceptable hold time %u", m.HoldTime))
+ }
+ return nil
+}