# Generated by confd

{{- $block_key := printf "/calico/ipam/v2/host/%s/ipv6/block" (getenv "NODENAME")}}
{{- $static_key := "/calico/staticroutesv6"}}
{{if or (ls $block_key) (ls $static_key)}}
protocol static {
{{- if ls $block_key}}
   # IP blocks for this host.
{{- range ls $block_key}}
{{- $parts := split . "-"}}
{{- $cidr := join $parts "/"}}
{{- if not (hasSuffix $cidr "/128")}}
   route {{$cidr}} blackhole;
{{- end}}
{{- end}}
{{- end}}
{{- if ls $static_key}}
   # Static routes.
{{- range ls $static_key}}
{{- $parts := split . "-"}}
{{- $cidr := join $parts "/"}}
   route {{$cidr}} blackhole;
{{- end}}
{{- end}}
}
{{else}}# No IP blocks or static routes for this host.{{end}}

# Aggregation of routes on this host; export the block, nothing beneath it.
function calico_aggr ()
{
{{- range ls $block_key}}
{{- $parts := split . "-"}}
{{- $cidr := join $parts "/"}}
{{- $affinity := json (getv (printf "%s/%s" $block_key .))}}
  {{- if $affinity.state}}
      # Block {{$cidr}} is {{$affinity.state}}
    {{- if eq $affinity.state "confirmed"}}
      if ( net = {{$cidr}} ) then { accept; }
      if ( net ~ {{$cidr}} ) then { reject; }
    {{- end}}
  {{- else }}
      # Block {{$cidr}} is implicitly confirmed.
      if ( net = {{$cidr}} ) then { accept; }
      if ( net ~ {{$cidr}} ) then { reject; }
  {{- end }}
{{- end}}
}
