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..4d7a93d 100644 --- a/endpoints/routes.go +++ b/endpoints/routes.go @@ -126,6 +126,20 @@ 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 + } + + mask, err := ValidateNetMaskParam(ps.ByName("mask")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + + 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 { @@ -140,6 +154,25 @@ func RouteNetTable(r *http.Request, ps httprouter.Params, useCache bool) (bird.P return bird.RoutesLookupTable(useCache, net, 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+"/"+mask, table) +} + func PipeRoutesFiltered(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) { qs := r.URL.Query() 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",