From ad706a62aba6c98c1a0a5ca39759e37c774d9775 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Mon, 26 Jan 2015 00:24:49 +0900 Subject: table: validate path attribute flag BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR is preferred than BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR so after parsing a message then validating the flag does't work. With this patch, bmp doesn't parse a message having incorrect path attribute flag. It's not ideal so need to fix later. Signed-off-by: FUJITA Tomonori --- packet/bgp.go | 5 +++++ packet/bgp_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'packet') diff --git a/packet/bgp.go b/packet/bgp.go index 5131a284..a5fd715c 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1134,6 +1134,7 @@ func (p *PathAttribute) getType() BGPAttrType { } func (p *PathAttribute) DecodeFromBytes(data []byte) error { + odata := data eCode := uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR) eSubCode := uint8(BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR) if len(data) < 2 { @@ -1160,6 +1161,10 @@ func (p *PathAttribute) DecodeFromBytes(data []byte) error { } p.Value = data[:p.Length] + ok, eMsg := ValidateFlags(p.Type, p.Flags) + if !ok { + return NewMessageError(eCode, BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR, odata[:p.Len()], eMsg) + } return nil } diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 5b2e1736..8fd734eb 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -108,7 +108,7 @@ func update() *BGPMessage { NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}), &PathAttributeUnknown{ PathAttribute: PathAttribute{ - Flags: 1, + Flags: BGP_ATTR_FLAG_TRANSITIVE, Type: 100, Value: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, }, -- cgit v1.2.3