summaryrefslogtreecommitdiff
path: root/bin/mkbirdconfig.sh
blob: a7ca42edb93fe52bec8c331df7844a58e38a133d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh

. ${INET2_PREFIX}/share/inet2/inet2.sh

escapebird() {
    sed -e 's/\\/\\\\/g;s/"/\\"/g'
}

step "Creating Bird configuration"
  
touch /var/log/bird.log
chown bird:bird /var/log/bird.log

interfacelist=$(
  echo "    interface \"lo\" { stub; };"
  getval interface | while read -r inter; do
    val="$(getval "interface $inter" OSPF)"
    if [ "$?" = "0" ]; then
      echo "    interface \"$(printf "%s" "$inter" | escapebird)\" {"
      echo "      type ptp;"
      if [ -n "$val" ]; then
        echo "      $val;";
      fi
      echo "    };"
    fi
  done
)

filter4=$(getval "Subnet" | grep -v ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//')
filter6=$(getval "Subnet" | grep ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//')

(cat <<EOF
log "/var/log/bird.log" all;

$(getval RouterID | while read -r line; do echo "router id $line;"; done)

protocol kernel {
  ipv4 { export filter { if net ~ [$filter4] then accept; else reject; }; };
}

protocol kernel {
  ipv6 { export filter { if net ~ [$filter6] then accept; else reject; }; };
}

protocol device {
}

protocol direct {
  ipv4;
  ipv6;
}

protocol static {
  ipv4;
}

EOF

cat <<EOF
protocol ospf v3 ospf4 {
  ipv4 {
    import all;
    export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$filter4] then accept; else reject; };
  };
  area 0 {
$(getval "Stubnet" | grep -v ':' | while read -r net; do echo "    stubnet $net {};"; done)
$interfacelist
  };
}
protocol ospf v3 ospf6 {
  ipv6 {
    import all;
    export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$filter6] then accept; else reject; };
  };
  area 0 {
$(getval "Stubnet" | grep ':' | while read -r net; do echo "    stubnet $net {};"; done)
$interfacelist
  };
}
EOF
) > /etc/bird.conf

chown root:bird /etc/bird.conf
chmod 640 /etc/bird.conf