diff options
Diffstat (limited to '6/bgp.pl')
-rw-r--r-- | 6/bgp.pl | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -2,6 +2,7 @@ :- module(bgp, [ warning/1, + create_firewall/1, neighbor/2, bgp_config/2, bird_config/1, @@ -12,6 +13,9 @@ host_config/2, router_link/3, attached_network/2]). +:- use_module(firewall, [ + fw_rule/2, + retract_all_from/1]). %host(H) :- router_link(H, _, _). %host(H) :- router_link(_, H, _). @@ -69,7 +73,7 @@ router_path(X, Y, V) :- \+ member(X, V), router_link(X, _, Z), router_path(Z, Y, %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) :- +to_dict(router(R), Dict) :- neighbors(R, Neighbors), maplist(to_dict(), Neighbors, NeighborDicts), Dict = R-_{ @@ -88,3 +92,20 @@ bird_config(BirdConfig) :- routers(Routers), maplist(to_dict(), Routers, RouterDicts), dict_pairs(BirdConfig, bird_config, RouterDicts). + +create_firewall() :- + firewall:retract_all_from(bgp), + findall(fw(Host, Attrs), fw(Host, Attrs), Goals), + maplist(assert_fw, Goals). + +assert_fw(fw(Host, Attrs)) :- + R = firewall:fw_rule(Host, Attrs.put(_{from:bgp})), + writeln(R), + assert(R). + +fw(Host, attrs{src:Src, dst:Dst, family:ip6}) :- + hosts:router_link(Host, _, Remote), + hosts:host_config(Host, HostConfig), + hosts:host_config(Remote, RemoteConfig), + Src = RemoteConfig.ip, + Dst = HostConfig.ip. |