From f33148428ac2c035e526303742983db8428236b1 Mon Sep 17 00:00:00 2001 From: Kirill Smorodinnikov Date: Wed, 24 Feb 2021 15:23:38 +0300 Subject: Extend LsLinkDescriptor.String Cover additional cases when only one part of the link is presented. --- pkg/packet/bgp/bgp.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index 5112e7ae..cb28bd7f 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -5046,19 +5046,34 @@ func (l *LsLinkDescriptor) ParseTLVs(tlvs []LsTLVInterface) { } func (l *LsLinkDescriptor) String() string { - if l.InterfaceAddrIPv4 != nil && l.NeighborAddrIPv4 != nil { + switch { + case l.InterfaceAddrIPv4 != nil && l.NeighborAddrIPv4 != nil: return fmt.Sprintf("%v->%v", l.InterfaceAddrIPv4, l.NeighborAddrIPv4) - } - if l.InterfaceAddrIPv6 != nil && l.NeighborAddrIPv6 != nil { + case l.InterfaceAddrIPv6 != nil && l.NeighborAddrIPv6 != nil: return fmt.Sprintf("%v->%v", l.InterfaceAddrIPv6, l.NeighborAddrIPv6) - } - if l.LinkLocalID != nil && l.LinkRemoteID != nil { + case l.LinkLocalID != nil && l.LinkRemoteID != nil: return fmt.Sprintf("%v->%v", *l.LinkLocalID, *l.LinkRemoteID) - } - return "UNKNOWN" + case l.InterfaceAddrIPv4 != nil: + return fmt.Sprintf("%v->UNKNOWN", l.InterfaceAddrIPv4) + case l.NeighborAddrIPv4 != nil: + return fmt.Sprintf("UNKNOWN->%v", l.NeighborAddrIPv4) + + case l.InterfaceAddrIPv6 != nil: + return fmt.Sprintf("%v->UNKNOWN", l.InterfaceAddrIPv6) + case l.NeighborAddrIPv6 != nil: + return fmt.Sprintf("UNKNOWN->%v", l.NeighborAddrIPv6) + + case l.LinkLocalID != nil: + return fmt.Sprintf("%v->UNKNOWN", *l.LinkLocalID) + case l.LinkRemoteID != nil: + return fmt.Sprintf("UNKNOWN->%v", *l.LinkRemoteID) + + default: + return "UNKNOWN" + } } type LsLinkNLRI struct { -- cgit v1.2.3