diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-15 23:34:23 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-21 10:56:23 +0900 |
commit | 794a164b8e779a1ceae0912d791e8fb5656896e6 (patch) | |
tree | 0d6209f7cde7f49920ff14be16ec8d3140c7af60 | |
parent | 2d805011dd135ce248aef64aae54c4ddeb1bc8ef (diff) |
packet/bgp: Avoid raw binary in EVPN ESI string
Currently, the value field of EVPN ESI might be corrupted when ESI type
is ARBITRARY (not "single-homed") or unknown type because the value
field will be formatted as the raw byte slice in this case.
This patch fixes to convert the byte slice into the colon separated hex
values which is corresponding to the format of the CLI input.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | packet/bgp/bgp.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 3bbb3502..2ed6adcf 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -1952,14 +1952,19 @@ func isZeroBuf(buf []byte) bool { } func (esi *EthernetSegmentIdentifier) String() string { + toHexArray := func(data []byte) string { + // Converts byte slice into the colon separated hex values and the + // number of elements are 9 at most (excluding Type field). + values := make([]string, 0, 9) + for _, v := range data { + values = append(values, fmt.Sprintf("%02x", v)) + } + return strings.Join(values, ":") + } + s := bytes.NewBuffer(make([]byte, 0, 64)) s.WriteString(fmt.Sprintf("%s | ", esi.Type.String())) switch esi.Type { - case ESI_ARBITRARY: - if isZeroBuf(esi.Value) { - return "single-homed" - } - s.WriteString(fmt.Sprintf("%s", esi.Value)) case ESI_LACP: s.WriteString(fmt.Sprintf("system mac %s, ", net.HardwareAddr(esi.Value[:6]).String())) s.WriteString(fmt.Sprintf("port key %d", binary.BigEndian.Uint16(esi.Value[6:8]))) @@ -1975,8 +1980,13 @@ func (esi *EthernetSegmentIdentifier) String() string { case ESI_AS: s.WriteString(fmt.Sprintf("as %d, ", binary.BigEndian.Uint32(esi.Value[:4]))) s.WriteString(fmt.Sprintf("local discriminator %d", binary.BigEndian.Uint32(esi.Value[4:8]))) + case ESI_ARBITRARY: + if isZeroBuf(esi.Value) { + return "single-homed" + } + fallthrough default: - s.WriteString(fmt.Sprintf("value %s", esi.Value)) + s.WriteString(toHexArray(esi.Value)) } return s.String() } |