log "/var/log/bird.log" all; debug protocols all;

# The Device protocol is not a real routing protocol. It does not generate any
# routes and it only serves as a module for getting information about network
# interfaces from the kernel. It is necessary in almost any configuration.
protocol device {
}

# The direct protocol is not a real routing protocol. It automatically generates
# direct routes to all network interfaces. Can exist in as many instances as you
# wish if you want to populate multiple routing tables with direct routes.
protocol direct {
  disabled;		# Disable by default
  ipv4;			# Connect to default IPv4 table
}

function is_valid_network() {
  return net !~ [
    141.80.181.40/32
  ];
}

function guixsd_networks() {
  return net ~ [
    192.168.154.0/24
  ];
}

# The Kernel protocol is not a real routing protocol. Instead of communicating
# with other routers in the network, it performs synchronization of BIRD
# routing tables with the OS kernel. One instance per table.
protocol kernel {
  ipv4 {			# Connect protocol to IPv4 table by channel
    # table master4;	# Default IPv4 table is master4
    import all;
    export filter {
      if is_valid_network()
      then {
        accept;
      }
      else {
        reject;
      }
    };
  };
  # learn;			# Learn alien routes from the kernel
  # kernel table 10;	# Kernel table to synchronize with (default: main)
}


# Static routes (Again, there can be multiple instances, for different address
# families and to disable/enable various groups of static routes on the fly).
protocol static {
  ipv4; # Again, IPv4 channel with default options
  route 141.80.181.40/32 via "tapvpn1";
  # route 0.0.0.0/0 via 198.51.100.10;
  # route 192.0.2.0/24 blackhole;
  # route 10.0.0.0/8 unreachable;
  # route 10.2.0.0/24 via "eth0";
  # # Static routes can be defined with optional attributes
  # route 10.1.1.0/24 via 198.51.100.3 { rip_metric = 3; };
  # route 10.1.2.0/24 via 198.51.100.3 { ospf_metric1 = 100; };
  # route 10.1.3.0/24 via 198.51.100.4 { ospf_metric2 = 100; };
}

protocol bgp uplink1 {
  strict bind;
  description "My BGP uplink";
  local 192.168.25.2 as 64513;
  neighbor 192.168.25.3 as 64514;
  ipv4 {
    import filter {
      if guixsd_networks()
      then {
        accept;
      }
      else {
        reject;
      }
    };
    export filter { accept; };
  };
}
