diff --git a/bird/bird.go b/bird/bird.go index 3cc3b4b..fa0abc0 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -109,6 +109,10 @@ func Symbols() (Parsed, bool) { return RunAndParse("symbols", parseSymbols) } +func RoutesPrefixed(prefix string) (Parsed, bool) { + return RunAndParse("route all '"+prefix+"'", parseRoutes) +} + func RoutesProto(protocol string) (Parsed, bool) { return RunAndParse("route protocol '"+protocol+"' all", parseRoutes) diff --git a/birdwatcher.go b/birdwatcher.go index e9b9d2e..1c2a8d1 100644 --- a/birdwatcher.go +++ b/birdwatcher.go @@ -58,6 +58,9 @@ func makeRouter(config endpoints.ServerConfig) *httprouter.Router { if isModuleEnabled("routes_filtered", whitelist) { r.GET("routes/filtered/:protocol", endpoints.Endpoint(endpoints.RoutesFiltered)) } + if isModuleEnabled("routes_prefixed", whitelist) { + r.GET("routes/prefix/:prefix", endpoints.Endpoint(endpoints.RoutesPrefixed)) + } if isModuleEnabled("route_net", whitelist) { r.GET("/route/net/:net", endpoints.Endpoint(endpoints.RouteNet)) r.GET("/route/net/:net/table/:table", endpoints.Endpoint(endpoints.RouteNetTable)) diff --git a/endpoints/filter.go b/endpoints/filter.go index 4dfa2d5..6386cb3 100644 --- a/endpoints/filter.go +++ b/endpoints/filter.go @@ -32,18 +32,24 @@ func ValidateCharset(value string, alphabet string) error { return nil } -func ValidateProtocolParam(value string) (string, error) { - +func ValidateLengthAndCharset(value string, maxLength int, alphabet string) (string, error) { // Check length - if err := ValidateLength(value, 80); err != nil { + if err := ValidateLength(value, maxLength); err != nil { return "", err } // Check input - allowed := "ID_AS:.abcdef1234567890" - if err := ValidateCharset(value, allowed); err != nil { + if err := ValidateCharset(value, alphabet); err != nil { return "", err } return value, nil } + +func ValidateProtocolParam(value string) (string, error) { + return ValidateLengthAndCharset(value, 80, "ID_AS:.abcdef1234567890") +} + +func ValidatePrefixParam(value string) (string, error) { + return ValidateLengthAndCharset(value, 80, "1234567890abcdef.:/") +} diff --git a/endpoints/routes.go b/endpoints/routes.go index a398ce9..c8a95a4 100644 --- a/endpoints/routes.go +++ b/endpoints/routes.go @@ -23,6 +23,14 @@ func RoutesFiltered(ps httprouter.Params) (bird.Parsed, bool) { return bird.RoutesFiltered(protocol) } +func RoutesPrefixed(ps httprouter.Params) (bird.Parsed, bool) { + prefix, err := ValidatePrefixParam(ps.ByName("prefix")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + return bird.RoutesPrefixed(prefix) +} + func TableRoutes(ps httprouter.Params) (bird.Parsed, bool) { return bird.RoutesTable(ps.ByName("table")) } diff --git a/etc/ecix/birdwatcher.conf b/etc/ecix/birdwatcher.conf index 8ab6659..93cc840 100644 --- a/etc/ecix/birdwatcher.conf +++ b/etc/ecix/birdwatcher.conf @@ -20,7 +20,9 @@ allow_from = [] # routes_count_protocol # routes_count_table # route_net -# +# routes_filtered +# routes_prefixed +# modules_enabled = ["status", "protocols_bgp", "routes_protocol"] [status]