mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
added exported routes to peer
This commit is contained in:
parent
87252032bf
commit
27d9ada6eb
8 changed files with 33 additions and 5 deletions
1
Makefile
1
Makefile
|
@ -1,4 +1,3 @@
|
|||
|
||||
#
|
||||
# Ecix Birdseye Makefile
|
||||
#
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.7.5
|
||||
1.7.7
|
||||
|
|
|
@ -213,3 +213,7 @@ func RoutesLookupProtocol(net string, protocol string) (Parsed, bool) {
|
|||
return RunAndParse("route for '"+net+"' protocol '"+protocol+"' all",
|
||||
parseRoutes)
|
||||
}
|
||||
|
||||
func RoutesPeer(peer string) (Parsed, bool) {
|
||||
return RunAndParse("route export '"+peer+"'", parseRoutes)
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ func parseRoutes(input []byte) Parsed {
|
|||
|
||||
route := Parsed{}
|
||||
start_def_rx := regexp.MustCompile(`^([0-9a-f\.\:\/]+)\s+via\s+([0-9a-f\.\:]+)\s+on\s+(\w+)\s+\[([\w\.:]+)\s+([0-9\-\:\s]+)(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*`)
|
||||
second_rx := regexp.MustCompile(`^\s+via\s+([0-9a-f\.\:]+)\s+on\s+([\w+)\s+\[([\w\.]+)\s+([0-9\-\:\s]+)(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$`)
|
||||
second_rx := regexp.MustCompile(`^\s+via\s+([0-9a-f\.\:]+)\s+on\s+([\w+)\s+\[([\w\.]+)\s+([0-9\-\:\s]+)(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$`)
|
||||
type_rx := regexp.MustCompile(`^\s+Type:\s+(.*)\s*$`)
|
||||
bgp_rx := regexp.MustCompile(`^\s+BGP.(\w+):\s+(.+)\s*$`)
|
||||
community_rx := regexp.MustCompile(`^\((\d+),(\d+)\)`)
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
//go:generate versionize
|
||||
var VERSION = "1.7.5"
|
||||
var VERSION = "1.7.7"
|
||||
|
||||
func isModuleEnabled(module string, modulesEnabled []string) bool {
|
||||
for _, enabled := range modulesEnabled {
|
||||
|
@ -29,6 +29,7 @@ func makeRouter(config endpoints.ServerConfig) *httprouter.Router {
|
|||
|
||||
r := httprouter.New()
|
||||
if isModuleEnabled("status", whitelist) {
|
||||
r.GET("/version", endpoints.Version(VERSION))
|
||||
r.GET("/status", endpoints.Endpoint(endpoints.Status))
|
||||
}
|
||||
if isModuleEnabled("protocols", whitelist) {
|
||||
|
@ -68,6 +69,9 @@ 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("routes_peer", whitelist) {
|
||||
r.GET("/routes/peer", endpoints.Endpoint(endpoints.RoutesPeer))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
|
|
|
@ -70,3 +70,10 @@ func Endpoint(wrapped endpoint) httprouter.Handle {
|
|||
w.Write(js)
|
||||
}
|
||||
}
|
||||
|
||||
func Version(version string) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte(version))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,3 +61,17 @@ func RouteNet(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
|||
func RouteNetTable(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
return bird.RoutesLookupTable(ps.ByName("net"), ps.ByName("table"))
|
||||
}
|
||||
|
||||
func RoutesPeer(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
||||
qs := r.URL.Query()
|
||||
peerl := qs["peer"]
|
||||
if len(peerl) != 1 {
|
||||
return bird.Parsed{"error": "need a peer as single query parameter"}, false
|
||||
}
|
||||
|
||||
peer, err := ValidateProtocolParam(peerl[0])
|
||||
if err != nil {
|
||||
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
||||
}
|
||||
return bird.RoutesPeer(peer)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ allow_from = []
|
|||
# routes_filtered
|
||||
# routes_prefixed
|
||||
#
|
||||
modules_enabled = ["status", "protocols_bgp", "routes_protocol"]
|
||||
modules_enabled = ["status", "protocols_bgp", "routes_protocol", "routes_peer"]
|
||||
|
||||
[status]
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue