Skip to content

Commit

Permalink
Merge pull request #53 from kotronis-te/netmask-support
Browse files Browse the repository at this point in the history
Support for netmasks in route net queries
  • Loading branch information
annikahannig authored Jan 17, 2024
2 parents 7d5962e + f2aabce commit 70eb549
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions birdwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 4 additions & 0 deletions endpoints/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
33 changes: 33 additions & 0 deletions endpoints/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()

Expand Down
1 change: 1 addition & 0 deletions etc/birdwatcher/birdwatcher.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ allow_uncached = false
# route_net
# routes_pipe_filtered_count
# routes_pipe_filtered
# route_net_mask


modules_enabled = ["status",
Expand Down

0 comments on commit 70eb549

Please sign in to comment.