Add query AS info via DNS interface
This commit is contained in:
parent
ad17c52bb9
commit
7794ec7bcb
@ -1,9 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getASNRepresentation(asn string) string {
|
||||||
|
if records, err := net.LookupTXT(fmt.Sprintf("AS%s.%s", asn, setting.dnsInterface)); err != nil {
|
||||||
|
return fmt.Sprintf("AS%s", asn)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("AS%s\\n%s", asn, strings.Join(records, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func birdRouteToGraphviz(servers []string, responses []string, target string) string {
|
func birdRouteToGraphviz(servers []string, responses []string, target string) string {
|
||||||
graph := make(map[string]string)
|
graph := make(map[string]string)
|
||||||
// Helper to add an edge
|
// Helper to add an edge
|
||||||
@ -64,12 +74,12 @@ func birdRouteToGraphviz(servers []string, responses []string, target string) st
|
|||||||
// Edge from originating server to nexthop
|
// Edge from originating server to nexthop
|
||||||
addEdge(server, "Nexthop:\\n"+routeNexthop, (map[bool]string{true: "[color=red]"})[routePreferred])
|
addEdge(server, "Nexthop:\\n"+routeNexthop, (map[bool]string{true: "[color=red]"})[routePreferred])
|
||||||
// and from nexthop to AS
|
// and from nexthop to AS
|
||||||
addEdge("Nexthop:\\n"+routeNexthop, "AS"+paths[0], (map[bool]string{true: "[color=red]"})[routePreferred])
|
addEdge("Nexthop:\\n"+routeNexthop, getASNRepresentation(paths[0]), (map[bool]string{true: "[color=red]"})[routePreferred])
|
||||||
addPoint("Nexthop:\\n"+routeNexthop, "[shape=diamond]")
|
addPoint("Nexthop:\\n"+routeNexthop, "[shape=diamond]")
|
||||||
routeFound = true
|
routeFound = true
|
||||||
} else {
|
} else {
|
||||||
// Edge from originating server to AS
|
// Edge from originating server to AS
|
||||||
addEdge(server, "AS"+paths[0], (map[bool]string{true: "[color=red]"})[routePreferred])
|
addEdge(server, getASNRepresentation(paths[0]), (map[bool]string{true: "[color=red]"})[routePreferred])
|
||||||
routeFound = true
|
routeFound = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,10 +89,10 @@ func birdRouteToGraphviz(servers []string, responses []string, target string) st
|
|||||||
if pathIndex == 0 {
|
if pathIndex == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addEdge("AS"+paths[pathIndex-1], "AS"+paths[pathIndex], (map[bool]string{true: "[color=red]"})[routePreferred])
|
addEdge(getASNRepresentation(paths[pathIndex-1]), getASNRepresentation(paths[pathIndex]), (map[bool]string{true: "[color=red]"})[routePreferred])
|
||||||
}
|
}
|
||||||
// Last AS to destination
|
// Last AS to destination
|
||||||
addEdge("AS"+paths[len(paths)-1], "Target: "+target, (map[bool]string{true: "[color=red]"})[routePreferred])
|
addEdge(getASNRepresentation(paths[len(paths)-1]), "Target: "+target, (map[bool]string{true: "[color=red]"})[routePreferred])
|
||||||
}
|
}
|
||||||
|
|
||||||
if !routeFound {
|
if !routeFound {
|
||||||
|
@ -8,37 +8,46 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type settingType struct {
|
type settingType struct {
|
||||||
servers []string
|
servers []string
|
||||||
domain string
|
domain string
|
||||||
proxyPort int
|
proxyPort int
|
||||||
whoisServer string
|
whoisServer string
|
||||||
listen string
|
listen string
|
||||||
|
dnsInterface string
|
||||||
}
|
}
|
||||||
|
|
||||||
var setting settingType
|
var setting settingType
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var settingDefault = settingType{
|
var settingDefault = settingType{
|
||||||
[]string{""}, "", 8000, "whois.verisign-grs.com", ":5000",
|
[]string{""},
|
||||||
|
"",
|
||||||
|
8000,
|
||||||
|
"whois.verisign-grs.com",
|
||||||
|
":5000",
|
||||||
|
"asn.cymru.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
if serversEnv := os.Getenv("BIRDLG_SERVERS"); serversEnv != "" {
|
if env := os.Getenv("BIRDLG_SERVERS"); env != "" {
|
||||||
settingDefault.servers = strings.Split(serversEnv, ",")
|
settingDefault.servers = strings.Split(env, ",")
|
||||||
}
|
}
|
||||||
if domainEnv := os.Getenv("BIRDLG_DOMAIN"); domainEnv != "" {
|
if env := os.Getenv("BIRDLG_DOMAIN"); env != "" {
|
||||||
settingDefault.domain = domainEnv
|
settingDefault.domain = env
|
||||||
}
|
}
|
||||||
if proxyPortEnv := os.Getenv("BIRDLG_PROXY_PORT"); proxyPortEnv != "" {
|
if env := os.Getenv("BIRDLG_PROXY_PORT"); env != "" {
|
||||||
var err error
|
var err error
|
||||||
if settingDefault.proxyPort, err = strconv.Atoi(proxyPortEnv); err != nil {
|
if settingDefault.proxyPort, err = strconv.Atoi(env); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if whoisEnv := os.Getenv("BIRDLG_WHOIS"); whoisEnv != "" {
|
if env := os.Getenv("BIRDLG_WHOIS"); env != "" {
|
||||||
settingDefault.whoisServer = whoisEnv
|
settingDefault.whoisServer = env
|
||||||
}
|
}
|
||||||
if listenEnv := os.Getenv("BIRDLG_LISTEN"); listenEnv != "" {
|
if env := os.Getenv("BIRDLG_LISTEN"); env != "" {
|
||||||
settingDefault.listen = listenEnv
|
settingDefault.listen = env
|
||||||
|
}
|
||||||
|
if env := os.Getenv("BIRDLG_DNS_INTERFACE"); env != "" {
|
||||||
|
settingDefault.dnsInterface = env
|
||||||
}
|
}
|
||||||
|
|
||||||
serversPtr := flag.String("servers", strings.Join(settingDefault.servers, ","), "server name prefixes, separated by comma")
|
serversPtr := flag.String("servers", strings.Join(settingDefault.servers, ","), "server name prefixes, separated by comma")
|
||||||
@ -46,6 +55,7 @@ func main() {
|
|||||||
proxyPortPtr := flag.Int("proxy-port", settingDefault.proxyPort, "port bird-lgproxy is running on")
|
proxyPortPtr := flag.Int("proxy-port", settingDefault.proxyPort, "port bird-lgproxy is running on")
|
||||||
whoisPtr := flag.String("whois", settingDefault.whoisServer, "whois server for queries")
|
whoisPtr := flag.String("whois", settingDefault.whoisServer, "whois server for queries")
|
||||||
listenPtr := flag.String("listen", settingDefault.listen, "address bird-lg is listening on")
|
listenPtr := flag.String("listen", settingDefault.listen, "address bird-lg is listening on")
|
||||||
|
dnsInterfacePtr := flag.String("dns-interface", settingDefault.dnsInterface, "dns zone to query ASN information")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *serversPtr == "" {
|
if *serversPtr == "" {
|
||||||
@ -60,6 +70,7 @@ func main() {
|
|||||||
*proxyPortPtr,
|
*proxyPortPtr,
|
||||||
*whoisPtr,
|
*whoisPtr,
|
||||||
*listenPtr,
|
*listenPtr,
|
||||||
|
*dnsInterfacePtr,
|
||||||
}
|
}
|
||||||
|
|
||||||
webServerStart()
|
webServerStart()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user