bird.conf.j2 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. ################################################
  2. # Variable header #
  3. ################################################
  4. define DN42AS = {{ dn42.asn }};
  5. define NEOAS = {{ neonetwork.asn }};
  6. # Default ASN
  7. define OWNAS = DN42AS;
  8. define DN42IP = {{ dnet.dn42 }};
  9. define DN42IPv6 = {{ dnet.dn42v6 }};
  10. define NEOIP = {{ dnet.neo }};
  11. define NEOIPv6 = {{ dnet.neov6 }};
  12. define CRXNIP = {{ dnet.crxn }};
  13. {% for net in dn42.ipv4nets %}
  14. define DN42NET{{ loop.index }} = {{ net }};
  15. {% endfor %}
  16. {% for net in dn42.ipv6nets %}
  17. define DN42NET{{ loop.index }}v6 = {{ net }};
  18. {% endfor %}
  19. {% for net in neonetwork.ipv4nets %}
  20. define NEONET{{ loop.index }} = {{ net }};
  21. {% endfor %}
  22. {% for net in neonetwork.ipv6nets %}
  23. define NEONET{{ loop.index }}v6 = {{ net }};
  24. {% endfor %}
  25. {% for net in crxn.nets %}
  26. define CRXNNET{{ loop.index }} = {{ net }};
  27. {% endfor %}
  28. {% set comma = joiner(",") %}
  29. define DN42NETSET = [{% for net in dn42.ipv4nets %}{{ comma() }}{{ net }}+{% endfor %}];
  30. {% set comma = joiner(",") %}
  31. define DN42NETSETv6 = [{% for net in dn42.ipv6nets %}{{ comma() }}{{ net }}+{% endfor %}];
  32. {% set comma = joiner(",") %}
  33. define NEONETSET = [{% for net in neonetwork.ipv4nets %}{{ comma() }}{{ net }}+{% endfor %}];
  34. {% set comma = joiner(",") %}
  35. define NEONETSETv6 = [{% for net in neonetwork.ipv6nets %}{{ comma() }}{{ net }}+{% endfor %}];
  36. {% set comma = joiner(",") %}
  37. define CRXNNETSET = [{% for net in crxn.nets %}{{ comma() }}{{ net }}+{% endfor %}];
  38. define DN_REGION_GEO = {{ dnet.region_geo }};
  39. define DN_REGION_COUNTRY = {{ dnet.region_country }};
  40. define BANDWIDTH = {{ dnet.bandwidth }};
  41. ################################################
  42. # Header end #
  43. ################################################
  44. router id DN42IP;
  45. protocol device {}
  46. include "/etc/bird/netids.conf";
  47. /*
  48. * Utility functions
  49. */
  50. function is_self_net() -> bool {
  51. return net ~ DN42NETSET || net ~ DN42NETSETv6 || net ~ NEONETSET || net ~ NEONETSETv6 || net ~ CRXNNETSET;
  52. }
  53. function is_neonetwork() -> bool {
  54. return net ~ [10.127.0.0/16+] || net ~ [fd10:127::/32+];
  55. }
  56. function is_valid_network() -> bool {
  57. return (net ~ [
  58. 172.20.0.0/14{21,29}, # dn42
  59. 172.20.0.0/24{28,32}, # dn42 Anycast
  60. 172.21.0.0/24{28,32}, # dn42 Anycast
  61. 172.22.0.0/24{28,32}, # dn42 Anycast
  62. 172.23.0.0/24{28,32}, # dn42 Anycast
  63. 172.31.0.0/16+, # ChaosVPN
  64. 10.100.0.0/14+, # ChaosVPN
  65. 10.127.0.0/16{16,32}, # neonetwork
  66. 10.0.0.0/8{15,24} # Freifunk.net
  67. ] && net !~ [10.115.0.0/16+]) # Meshtastic
  68. || (net !~ [fd7a:115c:a1e0::/96+] && net ~ [ fd00::/8{44,64} ]);
  69. }
  70. function is_notsub_self_net() -> bool {
  71. {% set comma = joiner("||") %}
  72. return (
  73. {% for net in dn42.ipv4nets %}
  74. {{ comma() }} net = DN42NET{{ loop.index }}
  75. {% endfor %}
  76. {% for net in dn42.ipv6nets %}
  77. {{ comma() }} net = DN42NET{{ loop.index }}v6
  78. {% endfor %}
  79. {% for net in neonetwork.ipv4nets %}
  80. {{ comma() }} net = NEONET{{ loop.index }}
  81. {% endfor %}
  82. {% for net in neonetwork.ipv6nets %}
  83. {{ comma() }} net = NEONET{{ loop.index }}v6
  84. {% endfor %}
  85. {% for net in crxn.nets %}
  86. {{ comma() }} net = CRXNNET{{ loop.index }}
  87. {% endfor %}
  88. );
  89. }
  90. include "/etc/bird/crxn_utilits.conf";
  91. /*
  92. * ROA dn42 & neo
  93. */
  94. roa4 table dn42_roa;
  95. roa6 table dn42_roa_v6;
  96. protocol static {
  97. roa4 { table dn42_roa; };
  98. include "/var/lib/bird/dn42-roa4.conf";
  99. };
  100. protocol static {
  101. roa6 { table dn42_roa_v6; };
  102. include "/var/lib/bird/dn42-roa6.conf";
  103. };
  104. /*
  105. * Forward plane
  106. */
  107. protocol kernel {
  108. scan time 20;
  109. metric 500;
  110. ipv4 {
  111. import none;
  112. export filter {
  113. if source = RTS_DEVICE then reject;
  114. if (has_netid(0)) then {
  115. print "Warning: Netid 0 found", net;
  116. reject;
  117. } else if (has_netid(2)) then {
  118. print "Warning: CRXN netid in IPv4", net;
  119. reject;
  120. } else if (has_netid(4)) then {
  121. krt_prefsrc = NEOIP;
  122. } else {
  123. krt_prefsrc = DN42IP;
  124. }
  125. accept;
  126. };
  127. };
  128. }
  129. protocol kernel {
  130. scan time 20;
  131. metric 500;
  132. ipv6 {
  133. import none;
  134. export filter {
  135. if source = RTS_DEVICE then reject;
  136. if (has_netid(0)) then {
  137. print "Warning: Netid 0 found", net;
  138. reject;
  139. } else if (has_netid(2)) then {
  140. krt_prefsrc = CRXNIP;
  141. } else if (has_netid(4)) then {
  142. krt_prefsrc = NEOIPv6;
  143. } else {
  144. krt_prefsrc = DN42IPv6;
  145. }
  146. accept;
  147. };
  148. };
  149. };
  150. /*
  151. * OWNNET
  152. */
  153. protocol static {
  154. {% for net in dn42.ipv4nets %}
  155. route DN42NET{{ loop.index }} reject;
  156. {% endfor %}
  157. ipv4 {
  158. import filter { preference = 100; add_netid(1); accept; };
  159. export none;
  160. };
  161. }
  162. protocol static {
  163. {% for net in dn42.ipv6nets %}
  164. route DN42NET{{ loop.index }}v6 reject;
  165. {% endfor %}
  166. ipv6 {
  167. import filter { preference = 100; add_netid(1); accept; };
  168. export none;
  169. };
  170. }
  171. protocol static {
  172. {% for net in crxn.nets %}
  173. route CRXNNET{{ loop.index }} reject;
  174. {% endfor %}
  175. ipv6 {
  176. import filter { preference = 100; add_netid(2); accept; };
  177. export none;
  178. };
  179. }
  180. protocol static {
  181. {% for net in neonetwork.ipv4nets %}
  182. route NEONET{{ loop.index }} reject;
  183. {% endfor %}
  184. ipv4 {
  185. import filter { preference = 100; add_netid(4); accept; };
  186. export none;
  187. };
  188. }
  189. protocol static {
  190. {% for net in neonetwork.ipv6nets %}
  191. route NEONET{{ loop.index }}v6 reject;
  192. {% endfor %}
  193. ipv6 {
  194. import filter { preference = 100; add_netid(4); accept; };
  195. export none;
  196. };
  197. }
  198. /*
  199. * Other configurations
  200. */
  201. protocol bfd {}
  202. include "routes.conf";
  203. include "igp.conf";
  204. include "filters.conf";
  205. include "templates.conf";
  206. include "crxn_peers.conf";
  207. include "antiddos.conf";
  208. include "bgp_clients_filter.conf";
  209. include "bgp_clients.conf";
  210. include "dnpeers.conf";
  211. include "ibgp_nodes.conf";
  212. include "collector_peers.conf";