mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-30 00:00:17 +01:00
Add support for uncached queries
The cache is still updated with new information on every request.
This commit is contained in:
parent
c6e717bc61
commit
116f03fed4
8 changed files with 126 additions and 108 deletions
126
bird/bird.go
126
bird/bird.go
|
@ -159,12 +159,15 @@ func checkRateLimit() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func RunAndParse(key string, cmd string, parser func(io.Reader) Parsed, updateCache func(*Parsed)) (Parsed, bool) {
|
||||
if val, ok := fromCache(cmd); ok {
|
||||
return val, true
|
||||
func RunAndParse(useCache bool, key string, cmd string, parser func(io.Reader) Parsed, updateCache func(*Parsed)) (Parsed, bool) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
if useCache {
|
||||
if val, ok := fromCache(cmd); ok {
|
||||
return val, true
|
||||
}
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
if queueGroup, queueLoaded := RunQueue.LoadOrStore(cmd, &wg); queueLoaded {
|
||||
(*queueGroup.(*sync.WaitGroup)).Wait()
|
||||
|
@ -200,13 +203,12 @@ func RunAndParse(key string, cmd string, parser func(io.Reader) Parsed, updateCa
|
|||
toCache(cmd, parsed)
|
||||
|
||||
wg.Done()
|
||||
|
||||
RunQueue.Delete(cmd)
|
||||
|
||||
return parsed, false
|
||||
}
|
||||
|
||||
func Status() (Parsed, bool) {
|
||||
func Status(useCache bool) (Parsed, bool) {
|
||||
updateParsedCache := func(p *Parsed) {
|
||||
status := (*p)["status"].(Parsed)
|
||||
|
||||
|
@ -235,16 +237,16 @@ func Status() (Parsed, bool) {
|
|||
}
|
||||
}
|
||||
|
||||
birdStatus, from_cache := RunAndParse(GetCacheKey("Status"), "status", parseStatus, updateParsedCache)
|
||||
birdStatus, from_cache := RunAndParse(useCache, GetCacheKey("Status"), "status", parseStatus, updateParsedCache)
|
||||
return birdStatus, from_cache
|
||||
}
|
||||
|
||||
func ProtocolsShort() (Parsed, bool) {
|
||||
res, from_cache := RunAndParse(GetCacheKey("ProtocolsShort"), "protocols", parseProtocolsShort, nil)
|
||||
func ProtocolsShort(useCache bool) (Parsed, bool) {
|
||||
res, from_cache := RunAndParse(useCache, GetCacheKey("ProtocolsShort"), "protocols", parseProtocolsShort, nil)
|
||||
return res, from_cache
|
||||
}
|
||||
|
||||
func Protocols() (Parsed, bool) {
|
||||
func Protocols(useCache bool) (Parsed, bool) {
|
||||
createMetaCache := func(p *Parsed) {
|
||||
metaProtocol := Parsed{"protocols": Parsed{"bird_protocol": Parsed{}}}
|
||||
|
||||
|
@ -263,12 +265,12 @@ func Protocols() (Parsed, bool) {
|
|||
toCache(GetCacheKey("metaProtocol"), metaProtocol)
|
||||
}
|
||||
|
||||
res, from_cache := RunAndParse(GetCacheKey("metaProtocol"), "protocols all", parseProtocols, createMetaCache)
|
||||
res, from_cache := RunAndParse(useCache, GetCacheKey("Protocols"), "protocols all", parseProtocols, createMetaCache)
|
||||
return res, from_cache
|
||||
}
|
||||
|
||||
func ProtocolsBgp() (Parsed, bool) {
|
||||
protocols, from_cache := Protocols()
|
||||
func ProtocolsBgp(useCache bool) (Parsed, bool) {
|
||||
protocols, from_cache := Protocols(useCache)
|
||||
if IsSpecial(protocols) {
|
||||
return protocols, from_cache
|
||||
}
|
||||
|
@ -287,92 +289,92 @@ func ProtocolsBgp() (Parsed, bool) {
|
|||
"cached_at": protocols["cached_at"]}, from_cache
|
||||
}
|
||||
|
||||
func Symbols() (Parsed, bool) {
|
||||
return RunAndParse(GetCacheKey("Symbols"), "symbols", parseSymbols, nil)
|
||||
func Symbols(useCache bool) (Parsed, bool) {
|
||||
return RunAndParse(useCache, GetCacheKey("Symbols"), "symbols", parseSymbols, nil)
|
||||
}
|
||||
|
||||
func RoutesPrefixed(prefix string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route " + prefix + " all")
|
||||
return RunAndParse(GetCacheKey("RoutesPrefixed", prefix), cmd, parseRoutes, nil)
|
||||
func RoutesPrefixed(useCache bool, prefix string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route "+prefix+" all")
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesPrefixed", prefix), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesProto(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route all protocol " + protocol)
|
||||
return RunAndParse(GetCacheKey("RoutesProto", protocol), cmd, parseRoutes, nil)
|
||||
func RoutesProto(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route all protocol "+protocol)
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesProto", protocol), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesPeer(peer string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route all where from=" + peer)
|
||||
return RunAndParse(GetCacheKey("RoutesPeer", peer), cmd, parseRoutes, nil)
|
||||
func RoutesPeer(useCache bool, peer string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route all where from="+peer)
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesPeer", peer), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesTableAndPeer(table string, peer string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route table " + table + " all where from=" + peer)
|
||||
return RunAndParse(GetCacheKey("RoutesTableAndPeer", table, peer), cmd, parseRoutes, nil)
|
||||
func RoutesTableAndPeer(useCache bool, table string, peer string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route table "+table+" all where from="+peer)
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesTableAndPeer", table, peer), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesProtoCount(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route protocol "+protocol) + " count"
|
||||
return RunAndParse(GetCacheKey("RoutesProtoCount", protocol), cmd, parseRoutesCount, nil)
|
||||
func RoutesProtoCount(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route protocol "+protocol) + " count"
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesProtoCount", protocol), cmd, parseRoutesCount, nil)
|
||||
}
|
||||
|
||||
func RoutesProtoPrimaryCount(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route primary protocol "+protocol) + " count"
|
||||
return RunAndParse(GetCacheKey("RoutesProtoPrimaryCount", protocol), cmd, parseRoutesCount, nil)
|
||||
func RoutesProtoPrimaryCount(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route primary protocol "+protocol) + " count"
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesProtoPrimaryCount", protocol), cmd, parseRoutesCount, nil)
|
||||
}
|
||||
|
||||
func PipeRoutesFilteredCount(pipe string, table string, neighborAddress string) (Parsed, bool) {
|
||||
func PipeRoutesFilteredCount(useCache bool, pipe string, table string, neighborAddress string) (Parsed, bool) {
|
||||
cmd := "route table " + table + " noexport " + pipe + " where from=" + neighborAddress + " count"
|
||||
return RunAndParse(GetCacheKey("PipeRoutesFilteredCount", table, pipe, neighborAddress), cmd, parseRoutesCount, nil)
|
||||
return RunAndParse(useCache, GetCacheKey("PipeRoutesFilteredCount", table, pipe, neighborAddress), cmd, parseRoutesCount, nil)
|
||||
}
|
||||
|
||||
func PipeRoutesFiltered(pipe string, table string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route table '" + table + "' noexport '" + pipe + "' all")
|
||||
return RunAndParse(GetCacheKey("PipeRoutesFiltered", table, pipe), cmd, parseRoutes, nil)
|
||||
func PipeRoutesFiltered(useCache bool, pipe string, table string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route table '"+table+"' noexport '"+pipe+"' all")
|
||||
return RunAndParse(useCache, GetCacheKey("PipeRoutesFiltered", table, pipe), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesFiltered(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route all filtered protocol " + protocol)
|
||||
return RunAndParse(GetCacheKey("RoutesFiltered", protocol), cmd, parseRoutes, nil)
|
||||
func RoutesFiltered(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route all filtered protocol "+protocol)
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesFiltered", protocol), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesExport(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route all export " + protocol)
|
||||
return RunAndParse(GetCacheKey("RoutesExport", protocol), cmd, parseRoutes, nil)
|
||||
func RoutesExport(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route all export "+protocol)
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesExport", protocol), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesNoExport(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route all noexport " + protocol)
|
||||
return RunAndParse(GetCacheKey("RoutesNoExport", protocol), cmd, parseRoutes, nil)
|
||||
func RoutesNoExport(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route all noexport "+protocol)
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesNoExport", protocol), cmd, parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesExportCount(protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel("route export "+protocol) + " count"
|
||||
return RunAndParse(GetCacheKey("RoutesExportCount", protocol), cmd, parseRoutesCount, nil)
|
||||
func RoutesExportCount(useCache bool, protocol string) (Parsed, bool) {
|
||||
cmd := routeQueryForChannel(useCache, "route export "+protocol) + " count"
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesExportCount", protocol), cmd, parseRoutesCount, nil)
|
||||
}
|
||||
|
||||
func RoutesTable(table string) (Parsed, bool) {
|
||||
return RunAndParse(GetCacheKey("RoutesTable", table), "route table "+table+" all", parseRoutes, nil)
|
||||
func RoutesTable(useCache bool, table string) (Parsed, bool) {
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesTable", table), "route table "+table+" all", parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesTableFiltered(table string) (Parsed, bool) {
|
||||
return RunAndParse(GetCacheKey("RoutesTableFiltered", table), "route table "+table+" filtered", parseRoutes, nil)
|
||||
func RoutesTableFiltered(useCache bool, table string) (Parsed, bool) {
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesTableFiltered", table), "route table "+table+" filtered", parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesTableCount(table string) (Parsed, bool) {
|
||||
return RunAndParse(GetCacheKey("RoutesTableCount", table), "route table "+table+" count", parseRoutesCount, nil)
|
||||
func RoutesTableCount(useCache bool, table string) (Parsed, bool) {
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesTableCount", table), "route table "+table+" count", parseRoutesCount, nil)
|
||||
}
|
||||
|
||||
func RoutesLookupTable(net string, table string) (Parsed, bool) {
|
||||
return RunAndParse(GetCacheKey("RoutesLookupTable", net, table), "route for "+net+" table "+table+" all", parseRoutes, nil)
|
||||
func RoutesLookupTable(useCache bool, net string, table string) (Parsed, bool) {
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesLookupTable", net, table), "route for "+net+" table "+table+" all", parseRoutes, nil)
|
||||
}
|
||||
|
||||
func RoutesLookupProtocol(net string, protocol string) (Parsed, bool) {
|
||||
return RunAndParse(GetCacheKey("RoutesLookupProtocol", net, protocol), "route for "+net+" protocol "+protocol+" all", parseRoutes, nil)
|
||||
func RoutesLookupProtocol(useCache bool, net string, protocol string) (Parsed, bool) {
|
||||
return RunAndParse(useCache, GetCacheKey("RoutesLookupProtocol", net, protocol), "route for "+net+" protocol "+protocol+" all", parseRoutes, nil)
|
||||
}
|
||||
|
||||
func routeQueryForChannel(cmd string) string {
|
||||
status, _ := Status()
|
||||
func routeQueryForChannel(useCache bool, cmd string) string {
|
||||
status, _ := Status(useCache)
|
||||
if IsSpecial(status) {
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ package endpoints
|
|||
type ServerConfig struct {
|
||||
AllowFrom []string `toml:"allow_from"`
|
||||
ModulesEnabled []string `toml:"modules_enabled"`
|
||||
AllowUncached bool `toml:"allow_uncached"`
|
||||
|
||||
EnableTLS bool `toml:"enable_tls"`
|
||||
Crt string `toml:"crt"`
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
type endpoint func(*http.Request, httprouter.Params) (bird.Parsed, bool)
|
||||
type endpoint func(*http.Request, httprouter.Params, bool) (bird.Parsed, bool)
|
||||
|
||||
var Conf ServerConfig
|
||||
|
||||
|
@ -42,6 +42,17 @@ func CheckAccess(req *http.Request) error {
|
|||
return fmt.Errorf("%s is not allowed to access this service.", ip)
|
||||
}
|
||||
|
||||
func CheckUseCache(req *http.Request) bool {
|
||||
qs := req.URL.Query()
|
||||
|
||||
if Conf.AllowUncached &&
|
||||
len(qs["uncached"]) == 1 && qs["uncached"][0] == "true" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func Endpoint(wrapped endpoint) httprouter.Handle {
|
||||
return func(w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
|
@ -54,7 +65,9 @@ func Endpoint(wrapped endpoint) httprouter.Handle {
|
|||
}
|
||||
|
||||
res := make(map[string]interface{})
|
||||
ret, from_cache := wrapped(r, ps)
|
||||
|
||||
useCache := CheckUseCache(r)
|
||||
ret, from_cache := wrapped(r, ps, useCache)
|
||||
|
||||
if reflect.DeepEqual(ret, bird.NilParse) {
|
||||
w.WriteHeader(http.StatusTooManyRequests)
|
||||
|
|
|
@ -7,14 +7,14 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func Protocols(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
return bird.Protocols()
|
||||
func Protocols(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
return bird.Protocols(useCache)
|
||||
}
|
||||
|
||||
func Bgp(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
return bird.ProtocolsBgp()
|
||||
func Bgp(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
return bird.ProtocolsBgp(useCache)
|
||||
}
|
||||
|
||||
func ProtocolsShort(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
return bird.ProtocolsShort()
|
||||
func ProtocolsShort(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
return bird.ProtocolsShort(useCache)
|
||||
}
|
||||
|
|
|
@ -8,34 +8,34 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func ProtoRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func ProtoRoutes(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesProto(protocol)
|
||||
return bird.RoutesProto(useCache, protocol)
|
||||
}
|
||||
|
||||
func RoutesFiltered(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func RoutesFiltered(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesFiltered(protocol)
|
||||
return bird.RoutesFiltered(useCache, protocol)
|
||||
}
|
||||
|
||||
func RoutesNoExport(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func RoutesNoExport(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesNoExport(protocol)
|
||||
return bird.RoutesNoExport(useCache, protocol)
|
||||
}
|
||||
|
||||
func RoutesPrefixed(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func RoutesPrefixed(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
qs := r.URL.Query()
|
||||
prefixl := qs["prefix"]
|
||||
if len(prefixl) != 1 {
|
||||
|
@ -47,28 +47,28 @@ func RoutesPrefixed(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
|||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesPrefixed(prefix)
|
||||
return bird.RoutesPrefixed(useCache, prefix)
|
||||
}
|
||||
|
||||
func TableRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func TableRoutes(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
table, err := ValidateProtocolParam(ps.ByName("table"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesTable(table)
|
||||
return bird.RoutesTable(useCache, table)
|
||||
}
|
||||
|
||||
func TableRoutesFiltered(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func TableRoutesFiltered(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
table, err := ValidateProtocolParam(ps.ByName("table"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesTableFiltered(table)
|
||||
return bird.RoutesTableFiltered(useCache, table)
|
||||
}
|
||||
|
||||
func TableAndPeerRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func TableAndPeerRoutes(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
table, err := ValidateProtocolParam(ps.ByName("table"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
|
@ -79,45 +79,45 @@ func TableAndPeerRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, boo
|
|||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesTableAndPeer(table, peer)
|
||||
return bird.RoutesTableAndPeer(useCache, table, peer)
|
||||
}
|
||||
|
||||
func ProtoCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func ProtoCount(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesProtoCount(protocol)
|
||||
return bird.RoutesProtoCount(useCache, protocol)
|
||||
}
|
||||
|
||||
func ProtoPrimaryCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func ProtoPrimaryCount(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
return bird.RoutesProtoPrimaryCount(protocol)
|
||||
return bird.RoutesProtoPrimaryCount(useCache, protocol)
|
||||
}
|
||||
|
||||
func TableCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func TableCount(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
table, err := ValidateProtocolParam(ps.ByName("table"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesTableCount(table)
|
||||
return bird.RoutesTableCount(useCache, table)
|
||||
}
|
||||
|
||||
func RouteNet(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func RouteNet(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(net, "master")
|
||||
return bird.RoutesLookupTable(useCache, net, "master")
|
||||
}
|
||||
|
||||
func RouteNetTable(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
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
|
||||
|
@ -128,10 +128,10 @@ func RouteNetTable(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
|||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesLookupTable(net, table)
|
||||
return bird.RoutesLookupTable(useCache, net, table)
|
||||
}
|
||||
|
||||
func PipeRoutesFiltered(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func PipeRoutesFiltered(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
qs := r.URL.Query()
|
||||
|
||||
if len(qs["table"]) != 1 {
|
||||
|
@ -150,10 +150,10 @@ func PipeRoutesFiltered(r *http.Request, ps httprouter.Params) (bird.Parsed, boo
|
|||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.PipeRoutesFiltered(pipe, table)
|
||||
return bird.PipeRoutesFiltered(useCache, pipe, table)
|
||||
}
|
||||
|
||||
func PipeRoutesFilteredCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func PipeRoutesFilteredCount(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
qs := r.URL.Query()
|
||||
|
||||
if len(qs["table"]) != 1 {
|
||||
|
@ -180,14 +180,14 @@ func PipeRoutesFilteredCount(r *http.Request, ps httprouter.Params) (bird.Parsed
|
|||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.PipeRoutesFilteredCount(pipe, table, address)
|
||||
return bird.PipeRoutesFilteredCount(useCache, pipe, table, address)
|
||||
}
|
||||
|
||||
func PeerRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
func PeerRoutes(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
peer, err := ValidatePrefixParam(ps.ByName("peer"))
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
|
||||
return bird.RoutesPeer(peer)
|
||||
return bird.RoutesPeer(useCache, peer)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func Status(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
return bird.Status()
|
||||
func Status(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
return bird.Status(useCache)
|
||||
}
|
||||
|
|
|
@ -7,20 +7,20 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func Symbols(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
return bird.Symbols()
|
||||
func Symbols(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
return bird.Symbols(useCache)
|
||||
}
|
||||
|
||||
func SymbolTables(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
val, from_cache := bird.Symbols()
|
||||
func SymbolTables(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
val, from_cache := bird.Symbols(useCache)
|
||||
if bird.IsSpecial(val) {
|
||||
return val, from_cache
|
||||
}
|
||||
return bird.Parsed{"symbols": val["symbols"].(bird.Parsed)["routing table"]}, from_cache
|
||||
}
|
||||
|
||||
func SymbolProtocols(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
val, from_cache := bird.Symbols()
|
||||
func SymbolProtocols(r *http.Request, ps httprouter.Params, useCache bool) (bird.Parsed, bool) {
|
||||
val, from_cache := bird.Symbols(useCache)
|
||||
if bird.IsSpecial(val) {
|
||||
return val, from_cache
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
[server]
|
||||
# Restrict access to certain IPs. Leave empty to allow from all.
|
||||
allow_from = []
|
||||
# Allow queries that bypass the cache
|
||||
allow_uncached = false
|
||||
|
||||
# Available modules:
|
||||
## low-level modules (translation from birdc output to JSON objects)
|
||||
|
|
Loading…
Add table
Reference in a new issue