123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- log syslog all;
- define OSPF_tag_sourcebits = 5;
- define OSPF_tag_pathbits = 32 - OSPF_tag_sourcebits;
- define OSPF_tag_pathvalue_div = 32 ;
- function fn_tag_to_source (int tagbits) {
- return tagbits - ((tagbits / OSPF_tag_pathvalue_div) * OSPF_tag_pathvalue_div);
- }
- function fn_tag_to_path (int tagbits) {
- return tagbits / OSPF_tag_pathvalue_div;
- }
- function fn_power_of_2 (int n) {
-
- case n {
- 0: return 1;
- 1: return 2;
- 2: return 4;
- 3: return 8;
- 4: return 16;
- 5: return 32;
- 6: return 64;
- 7: return 128;
- 8: return 256;
- 9: return 512;
- 10: return 1024;
- 11: return 2048;
- 12: return 4096;
- 13: return 8192;
- 14: return 16384;
- 15: return 32768;
- 16: return 65536;
- 17: return 131072;
- 18: return 262144;
- 19: return 524288;
- 20: return 1048576;
- 21: return 2097152;
- 22: return 4194304;
- 23: return 8388608;
- 24: return 16777216;
- 25: return 33554432;
- 26: return 67108864;
- 27: return 134217728;
- 28: return 268435456;
- 29: return 536870912;
- 30: return 1073741824;
- 31: return 2147483648;
- else: return 0;
- }
- }
- function fn_instance_to_tagbit (int inst) {
- return fn_power_of_2(OSPF_tag_sourcebits - 1 + inst);
- }
- function fn_instancebit_is_set_in_ospf_tag (int inst)
- int instpathbits;
- {
- instpathbits = fn_tag_to_path(ospf_tag) / fn_power_of_2(inst-1);
- return (instpathbits / 2) * 2 != instpathbits;
- }
- function fn_reentrybit_is_set_in_ospf_tag() {
- return fn_instancebit_is_set_in_ospf_tag(fn_tag_to_source(ospf_tag));
- }
- function fn_set_reentrybit_in_ospf_tag() {
- ospf_tag = ospf_tag + fn_instance_to_tagbit(fn_tag_to_source(ospf_tag));
- }
- include "/usr/local/etc/bird.local.conf";
- define Babel_WLAN_metric_base = 1000;
- define Babel_WLAN_metric_inactive = 999;
- define OSPF_metric2_max = 16777215;
- define OSPF_preference_local = 160;
- define HOT = 0;
- define BEST = 1;
- define COLD = 2;
- include "/usr/local/etc/bird.inst.conf";
- function fn_a_Babel_WLAN_routes () {
- return ifname = "tap9";
- };
- function fn_a_Routed () {
- return net ~ Routed;
- };
- filter f_a_Routed {
- if fn_a_Routed()
- then accept;
- else reject "Routed";
- };
- function fn_r_Unrouted () {
- return ! (net ~ Unrouted_global || net ~ Unrouted_local);
- };
- filter f_r_Unrouted {
- if fn_r_Unrouted()
- then accept;
- else reject "Unrouted";
- };
- function fn_a_acceptable_routes () {
- return fn_r_Unrouted() && fn_a_Routed();
- }
-
- function fn_include_Babel_WLAN_routes () {
- case gw {
- include "/var/run/bird.babeld.conf";
- else: ospf_metric1 = ospf_metric1 + Babel_WLAN_metric_base + Babel_WLAN_metric_inactive;
- }
- }
- function fn_debug_ospf_route (string str)
- {
- print str, " ", net, " ^", scope, " *", source,
- " !", from, " :", gw, " (", preference, ") ",
- igp_metric, "/", ospf_metric1, "/", ospf_metric2,
- " [", ospf_tag, "]";
-
-
-
- }
- function fn_debug_ospf_route_before (string str)
- {
- printn str; fn_debug_ospf_route("?");
- }
- function fn_debug_ospf_route_after (string str)
- {
- printn str; fn_debug_ospf_route("!");
- }
- function fn_am_local_to_ospf_table () {
- if ! (proto ~ "ospf*") &&
- fn_a_acceptable_routes()
- then if ifname ~ "lo0"
- then return false;
- else { if preference < OSPF_preference_local
- then preference = OSPF_preference_local;
- return true; }
- else return false;
- }
- function fn_am_local_to_ospf_export () {
- if ! (proto ~ "*ospf*") &&
- fn_a_acceptable_routes()
- then { if ifname ~ "lo0"
- then return false;
- else
- if ifname ~ "lo*"
- then ospf_metric1 = 1;
- else ospf_metric1 = 10;
- ospf_metric2 = 0;
- return true; }
- else return false;
- }
- function fn_import_ospf_master (int from_instance) {
- if ! fn_a_acceptable_routes()
- then return false;
-
-
-
-
-
-
- else if ospf_tag != 0
- then {
- if fn_instance_to_potato(from_instance) = HOT
-
- then
- return false;
- else if fn_is_local_ospf_instance(fn_tag_to_source(ospf_tag)) ||
- fn_any_local_instancebit_is_set_in_ospf_tag()
- then
- if ! fn_reentrybit_is_set_in_ospf_tag()
- then
- fn_set_reentrybit_in_ospf_tag();
- }
- case from_instance {
-
-
- 2: fn_include_Babel_WLAN_routes();
- }
- return true;
- }
- function fn_import_master_ospf (string from_proto) {
- return proto = from_proto;
- }
- function fn_am_master_to_bgpospf (int dest_instance)
- int from_instance;
- {
- if fn_a_acceptable_routes()
- then { from_instance = fn_proto_to_instance(proto);
- if ospf_tag = 0
- then {
-
-
-
-
-
-
-
- ospf_tag = from_instance;
- return true;
- }
- else if fn_instance_to_potato(from_instance) = HOT
-
- then
- return false;
- else { if fn_reentrybit_is_set_in_ospf_tag() &&
- fn_instancebit_is_set_in_ospf_tag(dest_instance)
- then
- return false;
-
- if ! fn_instancebit_is_set_in_ospf_tag(from_instance)
- then ospf_tag = ospf_tag + fn_instance_to_tagbit(from_instance);
- return true;
- }
- }
- else return false;
- }
- function fn_export_master_bgpospf (string dest_proto)
- int dest_instance;
- {
- dest_instance = fn_proto_to_instance(dest_proto);
- printn "master2bgp"; fn_debug_ospf_route_before(dest_proto);
- if proto ~ "ospf*" &&
- proto != dest_proto &&
- fn_am_master_to_bgpospf(dest_instance)
- then { printn "master2bgp"; fn_debug_ospf_route_after(dest_proto);
- bgp_local_pref = preference;
- bgp_path.prepend(ospf_tag);
-
-
-
-
-
-
-
-
-
-
- if
- ospf_metric2 = OSPF_metric2_max
- then
- bgp_med = ospf_metric1;
- else
- bgp_med = ospf_metric2 + ospf_metric1;
-
- if ospf_tag != 0
- then
- if fn_reentrybit_is_set_in_ospf_tag()
- then
- bgp_origin = 2;
- else
- bgp_origin = 1;
- else
- bgp_origin = 0;
- accept;
- }
- else reject;
- }
- function fn_import_bgpospf ()
- {
- preference = bgp_local_pref;
- return true;
- }
- function fn_export_ospf (int dest_instance)
- string proto_bgpospf;
- int potato_ospf;
- {
- proto_bgpospf = fn_instance_to_bgpospf(dest_instance);
- potato_ospf = fn_instance_to_potato(dest_instance);
- printn "export-", dest_instance; fn_debug_ospf_route_before("");
- if fn_am_local_to_ospf_export()
- then return true;
- else if proto = proto_bgpospf
- then { ospf_tag = bgp_path.first;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if potato_ospf = BEST
- then {
-
-
-
- ospf_metric1 = bgp_med;
- }
- else if potato_ospf = HOT
- then {
-
-
-
- ospf_metric1 = 0;
-
-
-
- }
- else if potato_ospf = COLD
- then ospf_metric2 = bgp_med;
- printn "export-", dest_instance; fn_debug_ospf_route_after("");
- return true;
- }
- else return false;
- }
- protocol device {
- scan time 10;
- }
- protocol direct {
- }
- protocol kernel kernel0 {
- learn on;
- scan time 5;
- import filter f_r_Unrouted;
- export filter f_r_Unrouted;
- }
- table fib4table;
- protocol kernel kernel4 {
- description "babel FIB 4";
- kernel table 4;
- table fib4table;
- learn on;
- scan time 10;
- }
- include "/usr/local/etc/bird.inst.local.conf";
|