From 594ca80f50fa1caf7d21e5d7f442eb146d0c48ad Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Fri, 5 May 2023 20:20:12 -0700 Subject: [PATCH] frontend: fix whois lookup & only show bgpmap nexthop info on the first hop --- frontend/asn_cache.go | 9 +++++---- frontend/bgpmap.go | 6 +++++- frontend/bgpmap_graph.go | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/asn_cache.go b/frontend/asn_cache.go index f21e931..1da558e 100644 --- a/frontend/asn_cache.go +++ b/frontend/asn_cache.go @@ -9,9 +9,8 @@ import ( type ASNCache map[string]string func (cache ASNCache) _lookup(asn string) string { - + // Try to get ASN representation using DNS if setting.dnsInterface != "" { - // get ASN representation using DNS records, err := net.LookupTXT(fmt.Sprintf("AS%s.%s", asn, setting.dnsInterface)) if err == nil { result := strings.Join(records, " ") @@ -20,8 +19,10 @@ func (cache ASNCache) _lookup(asn string) string { } return fmt.Sprintf("AS%s\n%s", asn, result) } - } else if setting.whoisServer != "" { - // get ASN representation using WHOIS + } + + // Try to get ASN representation using WHOIS + if setting.whoisServer != "" { if setting.bgpmapInfo == "" { setting.bgpmapInfo = "asn,as-name,ASName,descr" } diff --git a/frontend/bgpmap.go b/frontend/bgpmap.go index 95feb98..e6ffd09 100644 --- a/frontend/bgpmap.go +++ b/frontend/bgpmap.go @@ -90,14 +90,18 @@ func birdRouteToGraph(servers []string, responses []string, target string) Route // Edges between AS for i := range paths { var src string + var label string + // Only show nexthop information on the first hop if i == 0 { src = server + label = strings.TrimSpace(protocolName + "\n" + via) } else { src = paths[i-1] + label = "" } dst := paths[i] - graph.AddEdge(src, dst, strings.TrimSpace(protocolName+"\n"+via), makeEdgeAttrs(routePreferred)) + graph.AddEdge(src, dst, label, makeEdgeAttrs(routePreferred)) // Only set color for next step, origin color is set to blue above graph.AddPoint(dst, true, makePointAttrs(routePreferred)) } diff --git a/frontend/bgpmap_graph.go b/frontend/bgpmap_graph.go index 1981196..03e5c46 100644 --- a/frontend/bgpmap_graph.go +++ b/frontend/bgpmap_graph.go @@ -89,7 +89,9 @@ func (graph *RouteGraph) AddEdge(src string, dest string, label string, attrs Ro newValue = makeRouteEdgeValue() } - newValue.label = append(newValue.label, label) + if len(label) != 0 { + newValue.label = append(newValue.label, label) + } for k, v := range attrs { newValue.attrs[k] = v }