diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-15 21:12:40 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-20 10:33:10 +0900 |
commit | 7937d8ddb6f8f82c593fb3b019d1fc618dc89f48 (patch) | |
tree | 853aa4860dd2a392cb7692c4b13741e2db1a0e26 /packet | |
parent | 473f5b6ff32be2829dac2a19bd63df19a7efd4ec (diff) |
policy: clean up
remove redundant api structures and shorten valiable names
re-implement *ToApiStruct functions as a method of each structures
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 3687d817..2d049543 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -4473,8 +4473,8 @@ func NewFourOctetAsSpecificExtended(subtype ExtendedCommunityAttrSubType, as uin } } -func ParseRouteTarget(rt string) (ExtendedCommunityInterface, error) { - elems, err := parseRdAndRt(rt) +func ParseExtendedCommunity(subtype ExtendedCommunityAttrSubType, com string) (ExtendedCommunityInterface, error) { + elems, err := parseRdAndRt(com) if err != nil { return nil, err } @@ -4483,18 +4483,22 @@ func ParseRouteTarget(rt string) (ExtendedCommunityInterface, error) { isTransitive := true switch { case ip.To4() != nil: - return NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, elems[1], uint16(localAdmin), isTransitive), nil + return NewIPv4AddressSpecificExtended(subtype, elems[1], uint16(localAdmin), isTransitive), nil case elems[6] == "" && elems[7] == "": asn, _ := strconv.Atoi(elems[8]) - return NewTwoOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, uint16(asn), uint32(localAdmin), isTransitive), nil + return NewTwoOctetAsSpecificExtended(subtype, uint16(asn), uint32(localAdmin), isTransitive), nil default: fst, _ := strconv.Atoi(elems[7]) snd, _ := strconv.Atoi(elems[8]) asn := fst<<16 | snd - return NewFourOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, uint32(asn), uint16(localAdmin), isTransitive), nil + return NewFourOctetAsSpecificExtended(subtype, uint32(asn), uint16(localAdmin), isTransitive), nil } } +func ParseRouteTarget(rt string) (ExtendedCommunityInterface, error) { + return ParseExtendedCommunity(EC_SUBTYPE_ROUTE_TARGET, rt) +} + type OpaqueExtendedValueInterface interface { Serialize() ([]byte, error) String() string |