From 27d9ada6eb5f19ae66fb47af66ab90819f3bf368 Mon Sep 17 00:00:00 2001 From: hellerve Date: Wed, 15 Feb 2017 12:20:55 +0100 Subject: [PATCH] added exported routes to peer --- Makefile | 1 - VERSION | 2 +- bird/bird.go | 4 ++++ bird/parser.go | 2 +- birdwatcher.go | 6 +++++- endpoints/endpoint.go | 7 +++++++ endpoints/routes.go | 14 ++++++++++++++ etc/ecix/birdwatcher.conf | 2 +- 8 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5a10620..98ac2de 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ - # # Ecix Birdseye Makefile # diff --git a/VERSION b/VERSION index 6a126f4..91c74a5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.5 +1.7.7 diff --git a/bird/bird.go b/bird/bird.go index 6d3bc26..ab0da44 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -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) +} diff --git a/bird/parser.go b/bird/parser.go index a7e935f..4facb13 100644 --- a/bird/parser.go +++ b/bird/parser.go @@ -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+)\)`) diff --git a/birdwatcher.go b/birdwatcher.go index b86a4be..1932b60 100644 --- a/birdwatcher.go +++ b/birdwatcher.go @@ -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 } diff --git a/endpoints/endpoint.go b/endpoints/endpoint.go index 587bb9d..dfe07b7 100644 --- a/endpoints/endpoint.go +++ b/endpoints/endpoint.go @@ -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)) + } +} diff --git a/endpoints/routes.go b/endpoints/routes.go index 36debdc..0ceff26 100644 --- a/endpoints/routes.go +++ b/endpoints/routes.go @@ -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) +} diff --git a/etc/ecix/birdwatcher.conf b/etc/ecix/birdwatcher.conf index 3f3d7e6..0f184e7 100644 --- a/etc/ecix/birdwatcher.conf +++ b/etc/ecix/birdwatcher.conf @@ -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] #