diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-15 20:41:30 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-15 20:41:30 +0900 |
commit | 7743748a1559c722f4a1c7870978fa7d07cfe6cb (patch) | |
tree | 6a9b442e801fbf03e6bef8e708cdc1a923151de3 /packet/bgp.go | |
parent | d815c3143d982fece79937fc27d74cabf3601cf9 (diff) |
packet: check routefamily in MP_REACH/UNREACH attributes
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp.go')
-rw-r--r-- | packet/bgp.go | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 819169c9..c001686f 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -18,6 +18,7 @@ package bgp import ( "encoding/binary" "encoding/json" + "errors" "fmt" "math" "net" @@ -957,7 +958,7 @@ const ( RF_RTC_UC RouteFamily = AFI_IP<<16 | SAFI_ROUTE_TARGET_CONSTRTAINS ) -func routeFamilyPrefix(afi uint16, safi uint8) (prefix AddrPrefixInterface) { +func routeFamilyPrefix(afi uint16, safi uint8) (prefix AddrPrefixInterface, err error) { switch rfshift(afi, safi) { case RF_IPv4_UC: prefix = NewIPAddrPrefix(0, "") @@ -973,8 +974,10 @@ func routeFamilyPrefix(afi uint16, safi uint8) (prefix AddrPrefixInterface) { prefix = NewLabelledIPv6AddrPrefix(0, "", *NewLabel()) case RF_RTC_UC: prefix = &RouteTargetMembershipNLRI{} + default: + return nil, errors.New("unknown route family") } - return prefix + return prefix, nil } const ( @@ -1890,8 +1893,11 @@ func (p *PathAttributeMpReachNLRI) DecodeFromBytes(data []byte) error { } value = value[1:] for len(value) > 0 { - prefix := routeFamilyPrefix(afi, safi) - err := prefix.DecodeFromBytes(value) + prefix, err := routeFamilyPrefix(afi, safi) + if err != nil { + return NewMessageError(eCode, BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR, data[:p.PathAttribute.Len()], err.Error()) + } + err = prefix.DecodeFromBytes(value) if err != nil { return err } @@ -1978,10 +1984,16 @@ func (p *PathAttributeMpUnreachNLRI) DecodeFromBytes(data []byte) error { safi := value[2] value = value[3:] for len(value) > 0 { - prefix := routeFamilyPrefix(afi, safi) - prefix.DecodeFromBytes(value) + prefix, err := routeFamilyPrefix(afi, safi) + if err != nil { + return NewMessageError(eCode, BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR, data[:p.PathAttribute.Len()], err.Error()) + } + err = prefix.DecodeFromBytes(value) + if err != nil { + return err + } if prefix.Len() > len(value) { - return NewMessageError(eCode, eSubCode, value, "prefix length is incorrect") + return NewMessageError(eCode, eSubCode, data[:p.PathAttribute.Len()], "prefix length is incorrect") } value = value[prefix.Len():] p.Value = append(p.Value, prefix) |