diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-06-13 20:22:55 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-06-13 20:22:55 +0900 |
commit | c8d69a3906dc9a6ea9a7257805fbb7682362c367 (patch) | |
tree | 6b2963401bf25159f5619d545641d5801fd29c49 /packet | |
parent | f2cea556c18da0419ee64a47653455c3c4dc6811 (diff) |
packet: export pathAttrFlags
Used to check if an attribute is known or unknown.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp/bgp.go | 42 | ||||
-rw-r--r-- | packet/bgp/validate.go | 2 | ||||
-rw-r--r-- | packet/bgp/validate_test.go | 10 |
3 files changed, 27 insertions, 27 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 49a7cc01..9d0a2855 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -3756,7 +3756,7 @@ func NewNotificationErrorCode(code, subcode uint8) NotificationErrorCode { return NotificationErrorCode(uint16(code)<<8 | uint16(subcode)) } -var pathAttrFlags map[BGPAttrType]BGPAttrFlag = map[BGPAttrType]BGPAttrFlag{ +var PathAttrFlags map[BGPAttrType]BGPAttrFlag = map[BGPAttrType]BGPAttrFlag{ BGP_ATTR_TYPE_ORIGIN: BGP_ATTR_FLAG_TRANSITIVE, BGP_ATTR_TYPE_AS_PATH: BGP_ATTR_FLAG_TRANSITIVE, BGP_ATTR_TYPE_NEXT_HOP: BGP_ATTR_FLAG_TRANSITIVE, @@ -3919,7 +3919,7 @@ func NewPathAttributeOrigin(value uint8) *PathAttributeOrigin { return &PathAttributeOrigin{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Value: []byte{byte(value)}, }, @@ -4247,7 +4247,7 @@ func NewPathAttributeAsPath(value []AsPathParamInterface) *PathAttributeAsPath { t := BGP_ATTR_TYPE_AS_PATH return &PathAttributeAsPath{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: value, @@ -4300,7 +4300,7 @@ func NewPathAttributeNextHop(value string) *PathAttributeNextHop { t := BGP_ATTR_TYPE_NEXT_HOP return &PathAttributeNextHop{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: net.ParseIP(value).To4(), @@ -4351,7 +4351,7 @@ func NewPathAttributeMultiExitDisc(value uint32) *PathAttributeMultiExitDisc { t := BGP_ATTR_TYPE_MULTI_EXIT_DISC return &PathAttributeMultiExitDisc{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: value, @@ -4402,7 +4402,7 @@ func NewPathAttributeLocalPref(value uint32) *PathAttributeLocalPref { t := BGP_ATTR_TYPE_LOCAL_PREF return &PathAttributeLocalPref{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: value, @@ -4429,7 +4429,7 @@ func NewPathAttributeAtomicAggregate() *PathAttributeAtomicAggregate { t := BGP_ATTR_TYPE_ATOMIC_AGGREGATE return &PathAttributeAtomicAggregate{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, } @@ -4506,7 +4506,7 @@ func NewPathAttributeAggregator(as interface{}, address string) *PathAttributeAg t := BGP_ATTR_TYPE_AGGREGATOR return &PathAttributeAggregator{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: PathAttributeAggregatorParam{ @@ -4626,7 +4626,7 @@ func NewPathAttributeCommunities(value []uint32) *PathAttributeCommunities { t := BGP_ATTR_TYPE_COMMUNITIES return &PathAttributeCommunities{ PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Length: 0, Value: nil}, @@ -4678,7 +4678,7 @@ func NewPathAttributeOriginatorId(value string) *PathAttributeOriginatorId { t := BGP_ATTR_TYPE_ORIGINATOR_ID return &PathAttributeOriginatorId{ PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Length: 0, Value: nil}, @@ -4744,7 +4744,7 @@ func NewPathAttributeClusterList(value []string) *PathAttributeClusterList { t := BGP_ATTR_TYPE_CLUSTER_LIST return &PathAttributeClusterList{ PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Length: 0, Value: nil}, @@ -4910,7 +4910,7 @@ func NewPathAttributeMpReachNLRI(nexthop string, nlri []AddrPrefixInterface) *Pa } p := &PathAttributeMpReachNLRI{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Nexthop: ip, @@ -4995,7 +4995,7 @@ func NewPathAttributeMpUnreachNLRI(nlri []AddrPrefixInterface) *PathAttributeMpU t := BGP_ATTR_TYPE_MP_UNREACH_NLRI p := &PathAttributeMpUnreachNLRI{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Length: 0, }, @@ -6024,7 +6024,7 @@ func NewPathAttributeExtendedCommunities(value []ExtendedCommunityInterface) *Pa t := BGP_ATTR_TYPE_EXTENDED_COMMUNITIES return &PathAttributeExtendedCommunities{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: value, @@ -6089,7 +6089,7 @@ func NewPathAttributeAs4Path(value []*As4PathParam) *PathAttributeAs4Path { t := BGP_ATTR_TYPE_AS4_PATH return &PathAttributeAs4Path{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: value, @@ -6128,7 +6128,7 @@ func NewPathAttributeAs4Aggregator(as uint32, address string) *PathAttributeAs4A t := BGP_ATTR_TYPE_AS4_AGGREGATOR return &PathAttributeAs4Aggregator{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: PathAttributeAggregatorParam{ @@ -6330,7 +6330,7 @@ func NewPathAttributeTunnelEncap(value []*TunnelEncapTLV) *PathAttributeTunnelEn t := BGP_ATTR_TYPE_TUNNEL_ENCAP return &PathAttributeTunnelEncap{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Value: value, @@ -6451,7 +6451,7 @@ func NewPathAttributePmsiTunnel(typ PmsiTunnelType, isLeafInfoRequired bool, lab t := BGP_ATTR_TYPE_PMSI_TUNNEL return &PathAttributePmsiTunnel{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, IsLeafInfoRequired: isLeafInfoRequired, @@ -6624,7 +6624,7 @@ func NewPathAttributeAigp(values []AigpTLV) *PathAttributeAigp { t := BGP_ATTR_TYPE_AIGP return &PathAttributeAigp{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, }, Values: values, @@ -6653,7 +6653,7 @@ func NewPathAttributeOpaqueValue(value []byte) *PathAttributeOpaqueValue { t := BGP_ATTR_TYPE_OPAQUE_VALUE return &PathAttributeOpaqueValue{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Value: value, }, @@ -6865,7 +6865,7 @@ func NewEndOfRib(family RouteFamily) *BGPMessage { t := BGP_ATTR_TYPE_MP_UNREACH_NLRI unreach := &PathAttributeMpUnreachNLRI{ PathAttribute: PathAttribute{ - Flags: pathAttrFlags[t], + Flags: PathAttrFlags[t], Type: t, Length: 0, }, diff --git a/packet/bgp/validate.go b/packet/bgp/validate.go index 2c743c44..84a82c87 100644 --- a/packet/bgp/validate.go +++ b/packet/bgp/validate.go @@ -196,7 +196,7 @@ func ValidateFlags(t BGPAttrType, flags BGPAttrFlag) (bool, string) { } // check flags are correct - if f, ok := pathAttrFlags[t]; ok { + if f, ok := PathAttrFlags[t]; ok { if f != flags & ^BGP_ATTR_FLAG_EXTENDED_LENGTH & ^BGP_ATTR_FLAG_PARTIAL { eMsg := fmt.Sprintf("flags are invalid. attribute type: %s, expect: %s, actual: %s", t, f, flags) return false, eMsg diff --git a/packet/bgp/validate_test.go b/packet/bgp/validate_test.go index 490c6402..66eb56d5 100644 --- a/packet/bgp/validate_test.go +++ b/packet/bgp/validate_test.go @@ -146,7 +146,7 @@ func Test_Validate_duplicate_attribute(t *testing.T) { assert := assert.New(t) message := bgpupdate().Body.(*BGPUpdate) // duplicate origin path attribute - originBytes := []byte{byte(pathAttrFlags[BGP_ATTR_TYPE_ORIGIN]), 1, 1, 1} + originBytes := []byte{byte(PathAttrFlags[BGP_ATTR_TYPE_ORIGIN]), 1, 1, 1} origin := &PathAttributeOrigin{} origin.DecodeFromBytes(originBytes) message.PathAttributes = append(message.PathAttributes, origin) @@ -189,7 +189,7 @@ func Test_Validate_invalid_origin(t *testing.T) { assert := assert.New(t) message := bgpupdate().Body.(*BGPUpdate) // origin needs to be well-known - originBytes := []byte{byte(pathAttrFlags[BGP_ATTR_TYPE_ORIGIN]), 1, 1, 5} + originBytes := []byte{byte(PathAttrFlags[BGP_ATTR_TYPE_ORIGIN]), 1, 1, 5} origin := &PathAttributeOrigin{} origin.DecodeFromBytes(originBytes) message.PathAttributes[0] = origin @@ -209,7 +209,7 @@ func Test_Validate_invalid_nexthop_zero(t *testing.T) { // invalid nexthop addr := net.ParseIP("0.0.0.1").To4() - nexthopBytes := []byte{byte(pathAttrFlags[BGP_ATTR_TYPE_NEXT_HOP]), 3, 4} + nexthopBytes := []byte{byte(PathAttrFlags[BGP_ATTR_TYPE_NEXT_HOP]), 3, 4} nexthopBytes = append(nexthopBytes, addr...) nexthop := &PathAttributeNextHop{} nexthop.DecodeFromBytes(nexthopBytes) @@ -230,7 +230,7 @@ func Test_Validate_invalid_nexthop_lo(t *testing.T) { // invalid nexthop addr := net.ParseIP("127.0.0.1").To4() - nexthopBytes := []byte{byte(pathAttrFlags[BGP_ATTR_TYPE_NEXT_HOP]), 3, 4} + nexthopBytes := []byte{byte(PathAttrFlags[BGP_ATTR_TYPE_NEXT_HOP]), 3, 4} nexthopBytes = append(nexthopBytes, addr...) nexthop := &PathAttributeNextHop{} nexthop.DecodeFromBytes(nexthopBytes) @@ -251,7 +251,7 @@ func Test_Validate_invalid_nexthop_de(t *testing.T) { // invalid nexthop addr := net.ParseIP("224.0.0.1").To4() - nexthopBytes := []byte{byte(pathAttrFlags[BGP_ATTR_TYPE_NEXT_HOP]), 3, 4} + nexthopBytes := []byte{byte(PathAttrFlags[BGP_ATTR_TYPE_NEXT_HOP]), 3, 4} nexthopBytes = append(nexthopBytes, addr...) nexthop := &PathAttributeNextHop{} nexthop.DecodeFromBytes(nexthopBytes) |