1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Merge pull request #53 from kotronis-te/netmask-support

Support for netmasks in route net queries
This commit is contained in:
Annika Hannig 2024-01-17 11:07:37 +01:00 committed by GitHub
commit 70eb549c3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 0 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,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()

View file

@ -32,6 +32,7 @@ allow_uncached = false
# route_net
# routes_pipe_filtered_count
# routes_pipe_filtered
# route_net_mask
modules_enabled = ["status",