diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-07-31 16:16:56 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-09-29 15:05:43 +0900 |
commit | 4158d82bf6129e49b7fbc40809a54ca44820f581 (patch) | |
tree | a11353da6f2a36db4a535b90af6e1460096276c2 /packet/bgp | |
parent | f662b657abc3341d32eeba302d776ecada28e852 (diff) |
server/bgp: Extend MessageError for Revised Error Handling
This patch extends MessageError to contain error handling level
and error path attribute.
These informations are needed to Revised Error Handling (RFC7606).
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'packet/bgp')
-rw-r--r-- | packet/bgp/bgp.go | 98 |
1 files changed, 90 insertions, 8 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index f7d39a30..c8050ab5 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -8162,19 +8162,91 @@ func (msg *BGPMessage) Serialize(options ...*MarshallingOption) ([]byte, error) return append(h, b...), nil } +type ErrorHandling int + +const ( + ERROR_HANDLING_NONE ErrorHandling = iota + ERROR_HANDLING_ATTRIBUTE_DISCARD + ERROR_HANDLING_TREAT_AS_WITHDRAW + ERROR_HANDLING_AFISAFI_DISABLE + ERROR_HANDLING_SESSION_RESET +) + +func getErrorHandlingFromPathAttribute(t BGPAttrType) ErrorHandling { + switch t { + case BGP_ATTR_TYPE_ORIGIN: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_AS_PATH: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_AS4_PATH: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_NEXT_HOP: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_MULTI_EXIT_DISC: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_LOCAL_PREF: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_ATOMIC_AGGREGATE: + return ERROR_HANDLING_ATTRIBUTE_DISCARD + case BGP_ATTR_TYPE_AGGREGATOR: + return ERROR_HANDLING_ATTRIBUTE_DISCARD + case BGP_ATTR_TYPE_AS4_AGGREGATOR: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_COMMUNITIES: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_ORIGINATOR_ID: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_CLUSTER_LIST: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_MP_REACH_NLRI: + return ERROR_HANDLING_AFISAFI_DISABLE + case BGP_ATTR_TYPE_MP_UNREACH_NLRI: + return ERROR_HANDLING_AFISAFI_DISABLE + case BGP_ATTR_TYPE_EXTENDED_COMMUNITIES: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_IP6_EXTENDED_COMMUNITIES: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_PMSI_TUNNEL: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_LARGE_COMMUNITY: + return ERROR_HANDLING_TREAT_AS_WITHDRAW + case BGP_ATTR_TYPE_TUNNEL_ENCAP: + return ERROR_HANDLING_ATTRIBUTE_DISCARD + case BGP_ATTR_TYPE_AIGP: + return ERROR_HANDLING_ATTRIBUTE_DISCARD + default: + return ERROR_HANDLING_ATTRIBUTE_DISCARD + } +} + type MessageError struct { - TypeCode uint8 - SubTypeCode uint8 - Data []byte - Message string + TypeCode uint8 + SubTypeCode uint8 + Data []byte + Message string + ErrorHandling ErrorHandling + ErrorAttribute *PathAttributeInterface } func NewMessageError(typeCode, subTypeCode uint8, data []byte, msg string) error { return &MessageError{ - TypeCode: typeCode, - SubTypeCode: subTypeCode, - Data: data, - Message: msg, + TypeCode: typeCode, + SubTypeCode: subTypeCode, + Data: data, + ErrorHandling: ERROR_HANDLING_SESSION_RESET, + ErrorAttribute: nil, + Message: msg, + } +} + +func NewMessageErrorWithErrorHandling(typeCode, subTypeCode uint8, data []byte, errorHandling ErrorHandling, errorAttribute *PathAttributeInterface, msg string) error { + return &MessageError{ + TypeCode: typeCode, + SubTypeCode: subTypeCode, + Data: data, + ErrorHandling: errorHandling, + ErrorAttribute: errorAttribute, + Message: msg, } } @@ -8182,6 +8254,16 @@ func (e *MessageError) Error() string { return e.Message } +func (e *MessageError) Stronger(err error) bool { + if err == nil { + return true + } + if msgErr, ok := err.(*MessageError); ok { + return e.ErrorHandling > msgErr.ErrorHandling + } + return false +} + func (e *TwoOctetAsSpecificExtended) Flat() map[string]string { if e.SubType == EC_SUBTYPE_ROUTE_TARGET { return map[string]string{"routeTarget": e.String()} |