From a78ad8c83e97f71f7bfa221570be68d17c5af7c5 Mon Sep 17 00:00:00 2001 From: Jonathan Lassoff Date: Mon, 12 Feb 2024 20:30:41 -0800 Subject: [PATCH 1/2] BIRD 2.x: Support dual-stack route queries --- bird/bird.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bird/bird.go b/bird/bird.go index b9039e0..3e1ba17 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -311,12 +311,7 @@ func Symbols(useCache bool) (Parsed, bool) { func routesQuery(filter string) string { cmd := "route " + filter - if getBirdVersion() < 2 { - return cmd - } - - // Add ipversion filter - return cmd + " where net.type = NET_IP" + IPVersion + return cmd } func remapTable(table string) string { From ca2cbd9f0e19b24ec4886cab048d6c3d9ccbad24 Mon Sep 17 00:00:00 2001 From: Jonathan Lassoff Date: Mon, 12 Feb 2024 21:17:13 -0800 Subject: [PATCH 2/2] 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"