From 452fd637b397d245d44ed4c841989430325554af Mon Sep 17 00:00:00 2001 From: TimStallard Date: Sun, 27 Jan 2019 15:34:41 +0000 Subject: [PATCH 01/12] Allow for old style configs --- lg.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lg.py b/lg.py index f610cc8..e2591c8 100644 --- a/lg.py +++ b/lg.py @@ -145,6 +145,8 @@ def bird_proxy(host, proto, service, query): path = service proxyHost = app.config["PROXY"].get(host, "") + if isinstance(proxyHost, int): + proxyHost = "%s:%s" % (host, proxyHost) if not proxyHost: return False, 'Host "%s" invalid' % host From 4be9730746749d89663af8b34ae8f2fae65a3fe6 Mon Sep 17 00:00:00 2001 From: TimStallard Date: Sun, 27 Jan 2019 15:36:01 +0000 Subject: [PATCH 02/12] Exclude BFD protos --- lg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lg.py b/lg.py index e2591c8..f49e51a 100644 --- a/lg.py +++ b/lg.py @@ -232,7 +232,7 @@ def whois(): return jsonify(output=output, title=query) -SUMMARY_UNWANTED_PROTOS = ["Kernel", "Static", "Device"] +SUMMARY_UNWANTED_PROTOS = ["Kernel", "Static", "Device", "BFD"] @app.route("/summary/") @app.route("/summary//") From cfaf39bac7a290b6e3052814c293386bef3a7eee Mon Sep 17 00:00:00 2001 From: TimStallard Date: Sun, 27 Jan 2019 15:37:42 +0000 Subject: [PATCH 03/12] Better bgpmap handling for internal routes --- lg.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lg.py b/lg.py index f49e51a..cb79376 100644 --- a/lg.py +++ b/lg.py @@ -521,7 +521,9 @@ def show_bgpmap(): hop_label = "" - add_node(_as, fillcolor=(first and "#F5A9A9" or "white")) + add_node(_as, fillcolor=("white")) + if first: + nodes[_as].set_fillcolor("#F5A9A9") if hop_label: edge = add_edge(nodes[previous_as], nodes[_as], label=hop_label, fontsize="7") else: @@ -589,7 +591,8 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text): for rt_host, rt_ips in app.config["ROUTER_IP"].iteritems(): # Special case for internal routing if peer_ip in rt_ips: - path = [rt_host] + paths.append([peer_protocol_name, rt_host]) + path = None break else: # ugly hack for good printing @@ -605,8 +608,14 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text): if expr3.group(1).strip(): net_dest = expr3.group(1).strip() + + expr4 = re.search(r'^dev', line) + #handle on-link routes + if expr4: + paths.append([peer_protocol_name, net_dest]) + path = None - if line.startswith("BGP.as_path:"): + if line.startswith("BGP.as_path:") and path: path.extend(line.replace("BGP.as_path:", "").strip().split(" ")) if path: From 49ab7b003bd19bac4be4461ae8fffd09a060126a Mon Sep 17 00:00:00 2001 From: TimStallard Date: Sun, 27 Jan 2019 19:56:17 +0000 Subject: [PATCH 04/12] Fix for internal routes via unselected hosts --- lg.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lg.py b/lg.py index cb79376..c51613b 100644 --- a/lg.py +++ b/lg.py @@ -688,7 +688,9 @@ def show_route(request_type, hosts, proto): detail = {} errors = [] - for host in hosts.split("+"): + hosts = hosts.split("+") + allhosts = hosts[:] + for host in allhosts: ret, res = bird_command(host, proto, command) res = res.split("\n") @@ -702,6 +704,15 @@ def show_route(request_type, hosts, proto): if bgpmap: detail[host] = build_as_tree_from_raw_bird_ouput(host, proto, res) + #for internal routes via hosts not selected + #add them to the list, but only show preferred route + if host not in hosts: + detail[host] = detail[host][:1] + for path in detail[host]: + if len(path) == 2: + if (path[1] not in allhosts) and (path[1] in app.config["PROXY"]): + allhosts.append(path[1]) + else: detail[host] = add_links(res) From 3c76d1679f03d2c34fd69fd953e5818451c75473 Mon Sep 17 00:00:00 2001 From: TimStallard Date: Sun, 27 Jan 2019 23:42:16 +0000 Subject: [PATCH 05/12] Made all hosts available at /all, much shorter URLs when using many hosts --- lg.py | 28 ++++++++++++++++++---------- templates/layout.html | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lg.py b/lg.py index c51613b..3f52911 100644 --- a/lg.py +++ b/lg.py @@ -187,14 +187,12 @@ def inject_commands(): return dict(commands=commands, commands_dict=commands_dict) -@app.context_processor -def inject_all_host(): - return dict(all_hosts="+".join(app.config["PROXY"].keys())) - - @app.route("/") def hello(): - return redirect("/summary/%s/ipv4" % "+".join(app.config["PROXY"].keys())) + if app.config.get("UNIFIED_DAEMON", False): + return redirect("/summary/all") + else: + return redirect("/summary/all/ipv4") def error_page(text): @@ -237,13 +235,15 @@ SUMMARY_UNWANTED_PROTOS = ["Kernel", "Static", "Device", "BFD"] @app.route("/summary/") @app.route("/summary//") def summary(hosts, proto="ipv4"): - set_session("summary", hosts, proto, "") command = "show protocols" summary = {} errors = [] - for host in hosts.split("+"): + hosts = hosts.split("+") + if hosts == ["all"]: + hosts = app.config["PROXY"].keys() + for host in hosts: ret, res = bird_command(host, proto, command) res = res.split("\n") @@ -298,7 +298,10 @@ def detail(hosts, proto): detail = {} errors = [] - for host in hosts.split("+"): + hosts = hosts.split("+") + if hosts == ["all"]: + hosts = app.config["PROXY"].keys() + for host in hosts: ret, res = bird_command(host, proto, command) res = res.split("\n") @@ -344,7 +347,10 @@ def traceroute(hosts, proto): errors = [] infos = {} - for host in hosts.split("+"): + hosts = hosts.split("+") + if hosts == ["all"]: + hosts = app.config["PROXY"].keys() + for host in hosts: status, resultat = bird_proxy(host, proto, "traceroute", q) if status is False: errors.append("%s" % resultat) @@ -689,6 +695,8 @@ def show_route(request_type, hosts, proto): detail = {} errors = [] hosts = hosts.split("+") + if hosts == ["all"]: + hosts = app.config["PROXY"].keys() allhosts = hosts[:] for host in allhosts: ret, res = bird_command(host, proto, command) diff --git a/templates/layout.html b/templates/layout.html index 09ed813..62059e5 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -18,7 +18,7 @@