diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-19 02:36:04 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-20 13:28:45 +0900 |
commit | 51f1c2b644e8fac485db45b571520b31a6cb0da0 (patch) | |
tree | e16b53e86495d54ebfebcd40ca01012458b5a119 /packet/bgp.go | |
parent | caeea100653522090d36ece22e80a945d59742fd (diff) |
packet: store path attr flag as type BGPAttrFlag
also add more meaningful debug message to ValidateFlags()
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp.go')
-rw-r--r-- | packet/bgp.go | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 79a03aac..0797465b 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1715,13 +1715,32 @@ func routeFamilyPrefix(afi uint16, safi uint8) (prefix AddrPrefixInterface, err return prefix, nil } +type BGPAttrFlag uint8 + const ( - BGP_ATTR_FLAG_EXTENDED_LENGTH = 1 << 4 - BGP_ATTR_FLAG_PARTIAL = 1 << 5 - BGP_ATTR_FLAG_TRANSITIVE = 1 << 6 - BGP_ATTR_FLAG_OPTIONAL = 1 << 7 + BGP_ATTR_FLAG_EXTENDED_LENGTH BGPAttrFlag = 1 << 4 + BGP_ATTR_FLAG_PARTIAL BGPAttrFlag = 1 << 5 + BGP_ATTR_FLAG_TRANSITIVE BGPAttrFlag = 1 << 6 + BGP_ATTR_FLAG_OPTIONAL BGPAttrFlag = 1 << 7 ) +func (f BGPAttrFlag) String() string { + var strs []string = make([]string, 0, 4) + if f&BGP_ATTR_FLAG_EXTENDED_LENGTH > 0 { + strs = append(strs, "EXTENDED_LENGTH") + } + if f&BGP_ATTR_FLAG_PARTIAL > 0 { + strs = append(strs, "PARTIAL") + } + if f&BGP_ATTR_FLAG_TRANSITIVE > 0 { + strs = append(strs, "TRANSITIVE") + } + if f&BGP_ATTR_FLAG_OPTIONAL > 0 { + strs = append(strs, "OPTIONAL") + } + return strings.Join(strs, "|") +} + type BGPAttrType uint8 const ( @@ -1822,7 +1841,7 @@ const ( BGP_ERROR_SUB_OUT_OF_RESOURCES ) -var pathAttrFlags map[BGPAttrType]uint8 = map[BGPAttrType]uint8{ +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, @@ -1845,13 +1864,13 @@ type PathAttributeInterface interface { DecodeFromBytes([]byte) error Serialize() ([]byte, error) Len() int - getFlags() uint8 + getFlags() BGPAttrFlag getType() BGPAttrType ToApiStruct() *api.PathAttr } type PathAttribute struct { - Flags uint8 + Flags BGPAttrFlag Type BGPAttrType Length uint16 Value []byte @@ -1867,7 +1886,7 @@ func (p *PathAttribute) Len() int { return int(l) } -func (p *PathAttribute) getFlags() uint8 { +func (p *PathAttribute) getFlags() BGPAttrFlag { return p.Flags } @@ -1882,7 +1901,7 @@ func (p *PathAttribute) DecodeFromBytes(data []byte) error { if len(data) < 2 { return NewMessageError(eCode, eSubCode, data, "attribute header length is short") } - p.Flags = data[0] + p.Flags = BGPAttrFlag(data[0]) p.Type = BGPAttrType(data[1]) if p.Flags&BGP_ATTR_FLAG_EXTENDED_LENGTH != 0 { @@ -1918,7 +1937,7 @@ func (p *PathAttribute) Serialize() ([]byte, error) { p.Flags &^= BGP_ATTR_FLAG_EXTENDED_LENGTH } buf := make([]byte, p.Len()) - buf[0] = p.Flags + buf[0] = uint8(p.Flags) buf[1] = uint8(p.Type) if p.Flags&BGP_ATTR_FLAG_EXTENDED_LENGTH != 0 { binary.BigEndian.PutUint16(buf[2:4], p.Length) |