diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-07-01 17:43:18 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-01 21:33:39 +0900 |
commit | d43b77e0ec0f3f51cff9317db312d97a98f1df8f (patch) | |
tree | 2e05a95be9cd4b116e53bbf418fe7437c5787517 /packet/validate.go | |
parent | 1db97a53022a02ff3bf355909b54eb6be8dc286e (diff) |
packet: add AS_PATH validator
Diffstat (limited to 'packet/validate.go')
-rw-r--r-- | packet/validate.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/packet/validate.go b/packet/validate.go index 2afd53c4..e82113ee 100644 --- a/packet/validate.go +++ b/packet/validate.go @@ -8,7 +8,7 @@ import ( ) // Validator for BGPUpdate -func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]bool) (bool, error) { +func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]bool, doConfedCheck bool) (bool, error) { eCode := uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR) eSubCodeAttrList := uint8(BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST) eSubCodeMissing := uint8(BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE) @@ -31,7 +31,7 @@ func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]bool) (bool, error) { } //check specific path attribute - ok, e := ValidateAttribute(a, rfs) + ok, e := ValidateAttribute(a, rfs, doConfedCheck) if !ok { return false, e } @@ -58,12 +58,13 @@ func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]bool) (bool, error) { return true, nil } -func ValidateAttribute(a PathAttributeInterface, rfs map[RouteFamily]bool) (bool, error) { +func ValidateAttribute(a PathAttributeInterface, rfs map[RouteFamily]bool, doConfedCheck bool) (bool, error) { eCode := uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR) eSubCodeBadOrigin := uint8(BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE) eSubCodeBadNextHop := uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE) eSubCodeUnknown := uint8(BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE) + eSubCodeMalformedAspath := uint8(BGP_ERROR_SUB_MALFORMED_AS_PATH) checkPrefix := func(l []AddrPrefixInterface) bool { for _, prefix := range l { @@ -119,6 +120,23 @@ func ValidateAttribute(a PathAttributeInterface, rfs map[RouteFamily]bool) (bool data, _ := a.Serialize() return false, NewMessageError(eCode, eSubCodeBadNextHop, data, eMsg) } + case *PathAttributeAsPath: + if doConfedCheck { + for _, paramIf := range p.Value { + var segType uint8 + asParam, y := paramIf.(*As4PathParam) + if y { + segType = asParam.Type + } else { + segType = paramIf.(*AsPathParam).Type + } + + if segType == BGP_ASPATH_ATTR_TYPE_CONFED_SET || segType == BGP_ASPATH_ATTR_TYPE_CONFED_SEQ { + return false, NewMessageError(eCode, eSubCodeMalformedAspath, nil, fmt.Sprintf("segment type confederation(%d) found", segType)) + } + } + } + case *PathAttributeUnknown: if p.getFlags()&BGP_ATTR_FLAG_OPTIONAL == 0 { eMsg := "unrecognized well-known attribute" |