From 680b93052ecbc648db6e52647d04768c33ae2805 Mon Sep 17 00:00:00 2001 From: Vasileios Kotronis Date: Thu, 21 Dec 2023 17:45:00 +0200 Subject: [PATCH 1/3] Support for netmasks in route net queries --- birdwatcher.go | 4 ++++ endpoints/filter.go | 4 ++++ endpoints/routes.go | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/birdwatcher.go b/birdwatcher.go index 68f29b8..10df647 100644 --- a/birdwatcher.go +++ b/birdwatcher.go @@ -94,6 +94,10 @@ func makeRouter(config endpoints.ServerConfig) *httprouter.Router { r.GET("/route/net/:net", endpoints.Endpoint(endpoints.RouteNet)) r.GET("/route/net/:net/table/:table", endpoints.Endpoint(endpoints.RouteNetTable)) } + if isModuleEnabled("route_net_mask", whitelist) { + r.GET("/route/net/:net/mask/:mask", endpoints.Endpoint(endpoints.RouteNetMask)) + r.GET("/route/net/:net/mask/:mask/table/:table", endpoints.Endpoint(endpoints.RouteNetMaskTable)) + } if isModuleEnabled("routes_pipe_filtered_count", whitelist) { r.GET("/routes/pipe/filtered/count", endpoints.Endpoint(endpoints.PipeRoutesFilteredCount)) } diff --git a/endpoints/filter.go b/endpoints/filter.go index a29316b..406cb87 100644 --- a/endpoints/filter.go +++ b/endpoints/filter.go @@ -53,3 +53,7 @@ func ValidateProtocolParam(value string) (string, error) { func ValidatePrefixParam(value string) (string, error) { return ValidateLengthAndCharset(value, 80, "1234567890abcdef.:/") } + +func ValidateNetMaskParam(value string) (string, error) { + return ValidateLengthAndCharset(value, 3, "1234567890") +} diff --git a/endpoints/routes.go b/endpoints/routes.go index fd3e85a..4188da1 100644 --- a/endpoints/routes.go +++ b/endpoints/routes.go @@ -126,18 +126,51 @@ func RouteNet(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed return bird.RoutesLookupTable(useCache, net, "master") } +func RouteNetMask(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { + net, err := ValidatePrefixParam(ps.ByName("net")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + + return bird.RoutesLookupTable(useCache, net, "master") +} + func RouteNetTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { net, err := ValidatePrefixParam(ps.ByName("net")) if err != nil { return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false } + mask, err := ValidateNetMaskParam(ps.ByName("mask")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + + table, err := ValidateProtocolParam(ps.ByName("table")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + + return bird.RoutesLookupTable(useCache, net+"/"+mask, table) +} + +func RouteNetMaskTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { + net, err := ValidatePrefixParam(ps.ByName("net")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + + mask, err := ValidateNetMaskParam(ps.ByName("mask")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + table, err := ValidateProtocolParam(ps.ByName("table")) if err != nil { return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false } - return bird.RoutesLookupTable(useCache, net, table) + return bird.RoutesLookupTable(useCache, net+"/"+mask, table) } func PipeRoutesFiltered(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { From 379a40285050ef196c6320079e5f596850050917 Mon Sep 17 00:00:00 2001 From: Vasileios Kotronis Date: Thu, 21 Dec 2023 18:04:53 +0200 Subject: [PATCH 2/3] fixing small issue with netmask implementation --- endpoints/routes.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/endpoints/routes.go b/endpoints/routes.go index 4188da1..4d7a93d 100644 --- a/endpoints/routes.go +++ b/endpoints/routes.go @@ -132,16 +132,16 @@ func RouteNetMask(r *http.Request, ps httprouter.Params, useCache bool) (bird.Pa return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false } - return bird.RoutesLookupTable(useCache, net, "master") -} - -func RouteNetTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { - net, err := ValidatePrefixParam(ps.ByName("net")) + mask, err := ValidateNetMaskParam(ps.ByName("mask")) if err != nil { return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false } - mask, err := ValidateNetMaskParam(ps.ByName("mask")) + return bird.RoutesLookupTable(useCache, net+"/"+mask, "master") +} + +func RouteNetTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { + net, err := ValidatePrefixParam(ps.ByName("net")) if err != nil { return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false } @@ -151,7 +151,7 @@ func RouteNetTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.P return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false } - return bird.RoutesLookupTable(useCache, net+"/"+mask, table) + return bird.RoutesLookupTable(useCache, net, table) } func RouteNetMaskTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { From f2aabce394c3f5888496c41c9dd4349e46963413 Mon Sep 17 00:00:00 2001 From: Vasileios Kotronis Date: Thu, 21 Dec 2023 18:08:51 +0200 Subject: [PATCH 3/3] adding route_net_mask endpoint --- etc/birdwatcher/birdwatcher.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/birdwatcher/birdwatcher.conf b/etc/birdwatcher/birdwatcher.conf index 3cef56b..ac0bfee 100755 --- a/etc/birdwatcher/birdwatcher.conf +++ b/etc/birdwatcher/birdwatcher.conf @@ -32,6 +32,7 @@ allow_uncached = false # route_net # routes_pipe_filtered_count # routes_pipe_filtered +# route_net_mask modules_enabled = ["status",