mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
added prefixes
This commit is contained in:
parent
47e514e9ed
commit
e6b7d14c23
5 changed files with 29 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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.:/")
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue