log syslog all; router id A.B.C.D; define myas = myASN; define linka = ASN1; define linkb = ASN2; define gatewaya = X.X.X.A; define gatewayb = X.X.X.B; table ispa; table ispb; protocol device { scan time 10; } protocol static static_bgp { import all; route A.A.A.A/22 reject; route Y.Y.Y.A/29 reject; route Y.Y.Y.B/29 reject; } function net_local() { return net ~ [ A.A.A.A/22+ ]; } # Generic / Helper Functions / filters function net_martian() { return net ~ [ 169.254.0.0/16+, 172.16.0.0/12+, 192.168.0.0/16+, 10.0.0.0/8+, 127.0.0.0/8+, 224.0.0.0/4+, 240.0.0.0/4+, 0.0.0.0/32-, 0.0.0.0/0{25,32}, 0.0.0.0/0{0,7} ]; } function rt_import() int asn; int set peer_asns; prefix set peer_nets; { if ! (net ~ peer_nets) then return false; if ! (bgp_path.last ~ peer_asns) then return false; if bgp_path.first != asn then return false; if bgp_path.len > 64 then return false; if bgp_next_hop != from then return false; return true; } function rt_import_all(int asn) { if net_martian() || net_local() then return false; if bgp_path.first != asn then return false; if bgp_path.len > 64 then return false; if bgp_next_hop != from then return false; return true; } function rt_export() { if proto = "static_bgp" then return true; if source != RTS_BGP then return false; if net_martian() then return false; if bgp_path.len > 64 then return false; return bgp_path.first ~ [ myas ]; } function rt_export_all() { if proto = "static_bgp" then return true; if source != RTS_BGP then return false; if net_martian() then return false; if bgp_path.len > 64 then return false; return true; } ### End Helper Functions ### BGP uplink A protocol kernel k_a { table ispa; export all; kernel table 1; scan time 15; } filter bgp_in_uplink_a { if ! rt_import_all(linka) then reject; accept; } filter bgp_out_uplink_a { if ! rt_export() then reject; # Routing policy: penalize routes that other people would # get to me through isp A bgp_path.prepend(myas); bgp_path.prepend(myas); bgp_path.prepend(myas); accept; } protocol pipe p_a { table master; peer table ispa; import filter bgp_in_uplink_a; export filter bgp_out_uplink_a; } protocol bgp bgp_a { table ispa; import all; export all; local as myas; neighbor gatewaya as linka; # Routing policy: make routes from uplinks less prefered default bgp_local_pref 50; } ### BGP uplink B protocol kernel k_b { table ispb; export all; kernel table 2; scan time 15; } filter bgp_in_uplink_b { if ! rt_import_all(linkb) then reject; accept; } filter bgp_out_uplink_b { if ! rt_export() then reject; accept; } protocol pipe p_b { table master; peer table ispb; import filter bgp_in_uplink_b; export filter bgp_out_uplink_b; } protocol bgp bgp_b { table ispb; import all; export all; local as myas; neighbor gatewayb as linkb; } protocol static static_ospf { import all; route 0.0.0.0/0 reject; } protocol ospf { import all; export where proto = "static_ospf"; export filter { ospf_metric1 = 1000; if source = RTS_STATIC then accept; else reject; }; area 0 { interface "eth2" { cost 200; type pointopoint; hello 5; retransmit 2; wait 10; dead 20; }; interface "eth5" { cost 5; type pointopoint; hello 5; retransmit 2; wait 10; dead 20; }; interface "*" { cost 1000; stub; }; }; }