{ config, lib, ... }:

{
  networking.firewall.allowedTCPPorts = [ 179 ];

  # something doesn't work right
  services.bird2.enable = false;
  services.bird2.config = ''
  router id ${(lib.head config.networking.interfaces.ens18.ipv4.addresses).address};

  ipv6 table bgp6;

  protocol static {
    ipv6 {
      table bgp6;
    };
    route fd81:edb3:71d8::/48 via "lo";
  }

  protocol kernel {
    ipv6 {
      table bgp6;
      export filter {
        krt_prefsrc=${(lib.head config.networking.interfaces.lo.ipv6.addresses).address};
        accept;
      };
      import none;
    };
  }

  template bgp ildix {
    local as 4242422953;
    graceful restart on;
    source address fd81:edb3:71d8:ffff:2953::1;
    ipv6 {
      table bgp6;
      next hop self;
      import keep filtered;
      import filter {
        if net ~ [fd00::/8{8,64}] then accept;
        reject;
      };
      export filter {
        if net ~ [fd81:edb3:71d8::/48{48,64}] then accept;
        reject;
      };
    };
  }

  protocol bgp peer_ildix_clerie from ildix {
    neighbor fd81:edb3:71d8:ffff::13 as 4242422953;
  }

  protocol bgp peer_ildix_nex from ildix {
    neighbor fd81:edb3:71d8:ffff::14 as 4242422953;
  }

  protocol device {
    scan time 10;
  }
  '';
}