Support for netmasks in route net queries

This commit is contained in:
Vasileios Kotronis 2023-12-21 17:45:00 +02:00
parent fc7cf5be16
commit 680b93052e
3 changed files with 42 additions and 1 deletions

View File

@ -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))
}

View File

@ -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")
}

View File

@ -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, table)
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+"/"+mask, table)
}
func PipeRoutesFiltered(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {