From ca2cbd9f0e19b24ec4886cab048d6c3d9ccbad24 Mon Sep 17 00:00:00 2001 From: Jonathan Lassoff Date: Mon, 12 Feb 2024 21:17:13 -0800 Subject: [PATCH] Add a `dualstack` config option to enable dualstack BIRD 2.x operation --- bird/bird.go | 7 ++++++- bird/config.go | 1 + bird/parser.go | 2 +- etc/birdwatcher/birdwatcher.conf | 6 +++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bird/bird.go b/bird/bird.go index 3e1ba17..0867bf3 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -311,7 +311,12 @@ func Symbols(useCache bool) (Parsed, bool) { func routesQuery(filter string) string { cmd := "route " + filter - return cmd + + if getBirdVersion() < 2 || ClientConf.Dualstack { + return cmd + } + + return cmd + " where net.type = NET_IP" + IPVersion } func remapTable(table string) string { diff --git a/bird/config.go b/bird/config.go index 7f2babb..b0f77a4 100644 --- a/bird/config.go +++ b/bird/config.go @@ -14,6 +14,7 @@ type BirdConfig struct { ConfigFilename string `toml:"config"` BirdCmd string `toml:"birdc"` CacheTtl int `toml:"ttl"` + Dualstack bool `toml:"dualstack"` } type ParserConfig struct { diff --git a/bird/parser.go b/bird/parser.go index de47ee2..1e0527b 100644 --- a/bird/parser.go +++ b/bird/parser.go @@ -568,7 +568,7 @@ func parseProtocol(lines string) Parsed { ipVersion = m[1] } - if isCorrectChannel(ipVersion) { + if isCorrectChannel(ipVersion) || ClientConf.Dualstack { parseLine(line, handlers) } } diff --git a/etc/birdwatcher/birdwatcher.conf b/etc/birdwatcher/birdwatcher.conf index ac0bfee..993aaa3 100755 --- a/etc/birdwatcher/birdwatcher.conf +++ b/etc/birdwatcher/birdwatcher.conf @@ -66,12 +66,16 @@ filter_fields = [] enabled = true requests_per_minute = 10 - [bird] listen = "0.0.0.0:29184" config = "/etc/bird.conf" birdc = "birdc" ttl = 5 # time to live (in minutes) for caching of cli output +# When dualstack is set to true, birdwatcher will combine queries for both +# protocol versions into a single API. +# When dualstack is set to false, birdwatcher will use the presence or absense +# of the "-6" CLI flag to set a protocol stack to query for +dualstack = false [bird6] listen = "0.0.0.0:29186"