diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-08 09:47:36 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-08 09:47:36 +0100 |
commit | de3d2c7ed173d6a3478f2432dea441a7e2e1088a (patch) | |
tree | 4b07256544e2eb4c915662a1ae2c53c3b885b077 | |
parent | 47c6e8907818d2238c4e9d29511d923710438e44 (diff) | |
download | prolog-firewall-de3d2c7ed173d6a3478f2432dea441a7e2e1088a.tar.gz prolog-firewall-de3d2c7ed173d6a3478f2432dea441a7e2e1088a.tar.bz2 prolog-firewall-de3d2c7ed173d6a3478f2432dea441a7e2e1088a.tar.xz prolog-firewall-de3d2c7ed173d6a3478f2432dea441a7e2e1088a.zip |
wip
-rw-r--r-- | 6/bgp.pl | 25 | ||||
-rw-r--r-- | 6/hosts.pl | 2 | ||||
-rw-r--r-- | 6/main.pl | 21 |
3 files changed, 24 insertions, 24 deletions
@@ -13,8 +13,6 @@ router_link/3, attached_network/2]). -:- discontiguous bgp:to_dict/2. - %host(H) :- router_link(H, _, _). %host(H) :- router_link(_, H, _). % host(H). @@ -22,13 +20,6 @@ router(R) :- host(R), hosts:host_config(R, _). routers(Routers) :- setof(router(R), router(R), Routers). -to_dict(router(R), Dict) :- - bgp:neighbors(R, Neighbors), - maplist(bgp:to_dict(), Neighbors, NeighborDicts), - Dict = _{ - host: R, - neighbors: NeighborDicts}. - neighbor(H, R) :- router(H), router(R), router_link(H, _, R), @@ -38,7 +29,7 @@ warning(Msg) :- host(H), host(R), router_link(H, _, R), \+ router_link(R, _, H), - format(string(Msg), "Missing router_link from ~w to ~w", [R, H]). + format(string(Msg), "Missing router_link from '~w' to '~w'", [R, H]). neighbors(H, Cs) :- findall(neighbor(H, Name), neighbor(H, Name), Cs). @@ -75,8 +66,16 @@ router_path(X, Y) :- router_path(X, Y, []). router_path(X, Y, _) :- router_link(X, _, Y). router_path(X, Y, V) :- \+ member(X, V), router_link(X, _, Z), router_path(Z, Y, [X|V]). -to_yaml(neighbor(H, Remote), Dict) :- Dict = yaml(router(H), remote(Remote)). -to_json(neighbor(H, Remote), Dict) :- Dict = json(router(H), remote(Remote)). +%to_yaml(neighbor(H, Remote), Dict) :- Dict = yaml(router(H), remote(Remote)). +%to_json(neighbor(H, Remote), Dict) :- Dict = json(router(H), remote(Remote)). + +to_dict(router(R), Dict) :- + neighbors(R, Neighbors), + maplist(to_dict(), Neighbors, NeighborDicts), + Dict = _{ + host: R, + neighbors: NeighborDicts}. + to_dict(neighbor(_, Remote), Dict) :- host_config(Remote, RC), Dict = neighbor{ neighbor:_{ @@ -91,7 +90,7 @@ routers_entry(router(R), Dict) :- dict_create(Dict, _, Data). bird_config(Dict) :- - bgp:routers(Routers), + routers(Routers), maplist(to_dict(), Routers, RouterDicts), % maplist(routers_entry(), Routers, RouterDicts), Dict = _{routers:RouterDicts}. @@ -40,7 +40,7 @@ router_link(kv24ix, "1::5", hash). router_link(lhn2ix, "1::9", hash). router_link(lhn2ix, "1::4", knot). router_link(conflatorio, "1::11", lhn2ix). -router_link(lhn2ix, "1::12", conflatorio). +%router_link(lhn2ix, "1::12", conflatorio). % network(R, address, range) attached_network(conflatorio, ipv6_net("1:78e1::", 64)). @@ -1,16 +1,17 @@ :- use_module(bgp). -% :- use_module(tnet). -% H=knot, -% bgp:bgp_connections(H, BgpConnections), -% maplist(bgp:to_dict(), BgpConnections, BgpConnectionDicts), -% yaml_write(current_output, _{bgp_connections:BgpConnectionDicts}). +print_warnings([]). +print_warnings([W|Ws]) :- format("Warning: ~w~n", [W]), print_warnings(Ws). -warnings :- - bgp:warning(Ws), - writeln("Warnings: ~w", [length(Ws)]). +print_warnings :- + findall(W, bgp:warning(W), Ws), + length(Ws, L), + ( L > 0 + ->format("Found ~w warning(s):~n", [L]), + print_warnings(Ws) + ; format("No warnings!~n") + ). main :- bgp:bird_config(BirdDict), - yaml_write(current_output, BirdDict), - true. + yaml_write(current_output, BirdDict). |