VRF_external.conf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ################################################################################
  2. # Internet table #
  3. ################################################################################
  4. {%- set ifaces = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}) %}
  5. {%- set have_vrf_external = [] %}
  6. {%- for iface, iface_config in ifaces.items () %}
  7. {%- if iface_config.get ('vrf', '') == 'vrf_external' %}
  8. {%- do have_vrf_external.append (True) %}
  9. {%- break %}
  10. {%- endif %}
  11. {%- endfor %}
  12. {%- if True not in have_vrf_external %}
  13. #
  14. # No vrf_external configured on this node. Nothing to do.
  15. #
  16. {%- else %}
  17. table t_external;
  18. protocol kernel k_external {
  19. scan time 20;
  20. learn;
  21. import filter external_IPs_to_learn;
  22. export all;
  23. table t_external;
  24. kernel table 1023;
  25. }
  26. # Add unreachable routes for RFC1918, RFC 6598, APIPA so we don't route
  27. # anything private into the internet + null route some bogons.
  28. protocol static bogon_unreach_ext {
  29. table t_external;
  30. {%- if proto == 'v4' %}
  31. route 0.0.0.0/8 unreachable; # Host-Subnet
  32. route 10.0.0.0/8 unreachable; # RFC 1918
  33. route 100.64.0.0/10 unreachable; # RFC 6598
  34. route 169.254.0.0/16 unreachable; # APIPA
  35. route 172.16.0.0/12 unreachable; # RFC 1918
  36. route 192.0.0.0/24 unreachable; # IANA RESERVED
  37. route 192.0.2.0/24 unreachable; # TEST-NET-1
  38. route 192.168.0.0/16 unreachable; # RFC 1918
  39. route 198.18.0.0/15 unreachable; # BENCHMARK
  40. route 198.51.100.0/24 unreachable; # TEST-NET-2
  41. route 203.0.113.0/24 unreachable; # TEST-NET-3
  42. route 224.0.0.0/3 unreachable; # MCast + Class E
  43. {%- else %}
  44. route ::/96 unreachable; # RFC 4291
  45. route 2001:db8::/32 unreachable; # Documentation
  46. route fec0::/10 unreachable; # Site Local
  47. route fc00::/7 unreachable; # ULA
  48. {%- endif %}
  49. }
  50. {%- if 'veth_int2ext' in ifaces and 'veth_ext2int' in ifaces %}
  51. {%- set veth_ips = {} %}
  52. {%- for iface in ifaces if iface in [ 'veth_int2ext', 'veth_ext2int' ] %}
  53. {%- do veth_ips.update ({ iface : { 'v4' : None, 'v6' : None }}) %}
  54. {%- for prefix in ifaces.get (iface, {}).get ('prefixes', []) %}
  55. {%- if "." in prefix %}
  56. {%- do veth_ips[iface].update ({ 'v4' : prefix.split ('/')[0] }) %}
  57. {%- else %}
  58. {%- do veth_ips[iface].update ({ 'v6' : prefix.split ('/')[0] }) %}
  59. {%- endif %}
  60. {%- endfor %}
  61. {%- endfor %}
  62. #
  63. # VRF glue
  64. #
  65. {%- set internal_ip = veth_ips['veth_int2ext'][proto] %}
  66. {%- set external_ip = veth_ips['veth_ext2int'][proto] %}
  67. # Learn route on external side of VEth tunnel between VRFs for recursive BGP
  68. # nexthop lookup.
  69. protocol direct d_ext2int {
  70. table t_external;
  71. interface "veth_ext2int";
  72. }
  73. template bgp ibgp_vrf_glue {
  74. local as AS_OWN;
  75. enable route refresh yes;
  76. graceful restart yes;
  77. }
  78. protocol bgp int2ext from ibgp_vrf_glue {
  79. import filter external_IPs_to_learn;
  80. export filter own_prefixes;
  81. source address {{ internal_ip }};
  82. neighbor {{ external_ip }} as AS_OWN;
  83. rr client;
  84. next hop self;
  85. }
  86. protocol bgp ext2int from ibgp_vrf_glue {
  87. table t_external;
  88. # External router!
  89. router id {{ veth_ips['veth_ext2int']['v4'] }};
  90. import filter own_prefixes;
  91. export filter {
  92. if proto = "k_external" then {
  93. bgp_community.add (EXTERNAL_ROUTE);
  94. accept;
  95. }
  96. reject;
  97. };
  98. source address {{ external_ip }};
  99. neighbor {{ internal_ip }} as AS_OWN;
  100. next hop self;
  101. }
  102. {%- endif %} {#- veth int/ext tunnel #}
  103. {%- endif %} {#- vrf_external exists #}