From 3f0798d6450c87c668feb66c450ba39e0ebddc55 Mon Sep 17 00:00:00 2001 From: sparrowhawk Date: Mon, 19 Apr 2021 14:06:47 +0200 Subject: [PATCH] Add bird_xxx types. --- type/__bird_bgp/files/template.sh | 45 +++++++ type/__bird_bgp/man.rst | 105 +++++++++++++++ type/__bird_bgp/manifest | 123 ++++++++++++++++++ type/__bird_bgp/parameter/boolean | 3 + type/__bird_bgp/parameter/optional | 7 + type/__bird_bgp/parameter/required | 3 + type/__bird_core/man.rst | 65 +++++++++ type/__bird_core/manifest | 72 ++++++++++ type/__bird_core/parameter/optional | 1 + type/__bird_core/parameter/required | 1 + type/__bird_core/singleton | 0 type/__bird_filter/man.rst | 63 +++++++++ type/__bird_filter/manifest | 44 +++++++ type/__bird_function/man.rst | 58 +++++++++ type/__bird_function/manifest | 41 ++++++ type/__bird_kernel/man.rst | 73 +++++++++++ type/__bird_kernel/manifest | 83 ++++++++++++ type/__bird_kernel/parameter/boolean | 2 + type/__bird_kernel/parameter/optional | 1 + type/__bird_kernel/parameter/required | 3 + type/__bird_ospf/man.rst | 56 ++++++++ type/__bird_ospf/manifest | 63 +++++++++ type/__bird_ospf/parameter/optional | 2 + type/__bird_ospf/parameter/required | 3 + type/__bird_ospf/parameter/required_multiple | 1 + type/__bird_static/files/template.sh | 30 +++++ type/__bird_static/man.rst | 69 ++++++++++ type/__bird_static/manifest | 51 ++++++++ type/__bird_static/parameter/boolean | 1 + type/__bird_static/parameter/optional | 1 + .../__bird_static/parameter/required_multiple | 1 + 31 files changed, 1071 insertions(+) create mode 100755 type/__bird_bgp/files/template.sh create mode 100644 type/__bird_bgp/man.rst create mode 100755 type/__bird_bgp/manifest create mode 100644 type/__bird_bgp/parameter/boolean create mode 100644 type/__bird_bgp/parameter/optional create mode 100644 type/__bird_bgp/parameter/required create mode 100644 type/__bird_core/man.rst create mode 100755 type/__bird_core/manifest create mode 100644 type/__bird_core/parameter/optional create mode 100644 type/__bird_core/parameter/required create mode 100644 type/__bird_core/singleton create mode 100644 type/__bird_filter/man.rst create mode 100755 type/__bird_filter/manifest create mode 100644 type/__bird_function/man.rst create mode 100755 type/__bird_function/manifest create mode 100644 type/__bird_kernel/man.rst create mode 100755 type/__bird_kernel/manifest create mode 100644 type/__bird_kernel/parameter/boolean create mode 100644 type/__bird_kernel/parameter/optional create mode 100644 type/__bird_kernel/parameter/required create mode 100644 type/__bird_ospf/man.rst create mode 100755 type/__bird_ospf/manifest create mode 100644 type/__bird_ospf/parameter/optional create mode 100644 type/__bird_ospf/parameter/required create mode 100644 type/__bird_ospf/parameter/required_multiple create mode 100755 type/__bird_static/files/template.sh create mode 100644 type/__bird_static/man.rst create mode 100755 type/__bird_static/manifest create mode 100644 type/__bird_static/parameter/boolean create mode 100644 type/__bird_static/parameter/optional create mode 100644 type/__bird_static/parameter/required_multiple diff --git a/type/__bird_bgp/files/template.sh b/type/__bird_bgp/files/template.sh new file mode 100755 index 0000000..4d8f297 --- /dev/null +++ b/type/__bird_bgp/files/template.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# Template to generate a bgp protocol configuration file for bird(1). +# Required non-empty variables: +# __object_id, local_{ip,as}, neighbor_{ip,as} +# +# Required defined variables: +# description, password, ipv{4,6}_{import,export} + +# Header +echo "protocol bgp ${__object_id:?} {" + +# Optional description +[ -n "${description?}" ] && printf "\tdescription \"%s\";\n" "${description?}" + +# Mandatory session information +cat << EOF + local ${local_ip?} as ${local_as:?}; + neighbor ${neighbor_ip:?} as ${neighbor_as:?}; +EOF + +# Direct connection ? +[ -n "${direct?}" ] && printf "\tdirect;\n" + +# Password-protected session ? +[ -n "${password?}" ] && printf "\tpassword \"%s\";\n" "${password?}" + +if [ -n "${ipv4_import?}" ] || [ -n "${ipv4_export?}" ] || "${ipv4_extended_next_hop?}"; +then + printf "\tipv4 {\n" + [ -n "${ipv4_import?}" ] && printf "\t\timport %s;\n" "${ipv4_import:?}" + [ -n "${ipv4_export?}" ] && printf "\t\texport %s;\n" "${ipv4_export:?}" + [ -n "${ipv4_extended_next_hop?}" ] && printf "\t\textended next hop;\n" + printf "\t};\n" +fi +if [ -n "${ipv6_import?}" ] || [ -n "${ipv6_export?}" ] || "${ipv6_extended_next_hop?}"; +then + printf "\tipv6 {\n" + [ -n "${ipv6_import?}" ] && printf "\t\timport %s;\n" "${ipv6_import:?}" + [ -n "${ipv6_export?}" ] && printf "\t\texport %s;\n" "${ipv6_export:?}" + [ -n "${ipv6_extended_next_hop?}" ] && printf "\t\textended next hop;\n" + printf "\t};\n" +fi + +# Header close +echo "}" diff --git a/type/__bird_bgp/man.rst b/type/__bird_bgp/man.rst new file mode 100644 index 0000000..7b55ab5 --- /dev/null +++ b/type/__bird_bgp/man.rst @@ -0,0 +1,105 @@ +cdist-type__bird_bgp(7) +======================= + +NAME +---- +cdist-type__bird_bgp - configure an instance of the BGP protocol. + + +DESCRIPTION +----------- +This type writes the configuration for an instance of the BGP protocol to be +ran by the bird internet routing daemon. It **expects** to depend on the +`cdist-type__bird_core(7)` type. + + +REQUIRED PARAMETERS +------------------- +local-as + The number for the AS in which the daemon is running. + +neighbor-as + The number of the AS with which we are peering. + +neighbor-ip + The IP address of the peer we are opening a session with. + + +OPTIONAL PARAMETERS +------------------- +description + An instance desciption to be printed when `birdc show protocols` is called. + +local-ip + The IP address used as a source address for the BGP session. + +password + A password for the BGP session. + +ipv4-import + A string suitable for the bird `import` directive. Usually `all`, `none` or + a filter definition. + +ipv4-export + See ipv4-import. + +ipv4-extended-next-hop + Allow IPv6 next hop in IPv4 NLRI. + +ipv6-import + See ipv4-import. + +ipv6-export + See ipv4-import. + +ipv6-extended-next-hop + Allow IPv4 next hop in IPv6 NLRI. + + +BOOLEAN PARAMETERS +------------------ +direct + Specify that the two routers are directly connected. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Setup bird and open a BGP session. + __bird_core --router-id 198.51.100.4 + + require='__bird_core' __bird_bgp bgp4 \ + --description "a test IPv4 BGP instance" \ + --ipv4-export all \ + --ipv4-import all \ + --ipv6-export none \ + --ipv6-import none \ + --local-as 1234 \ + --local-ip 198.51.100.4 \ + --neighbor-as 4321 \ + --neighbor-ip 198.51.100.3 \ + --password hunter01 + + +SEE ALSO +-------- +cdist-type__bird_core(7) +cdist-type__bird_filter(7) +cdist-type__bird_kernel(7) +cdist-type__bird_ospf(7) +cdist-type__bird_static(7) + + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_bgp/manifest b/type/__bird_bgp/manifest new file mode 100755 index 0000000..a1d79f2 --- /dev/null +++ b/type/__bird_bgp/manifest @@ -0,0 +1,123 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +case "$os" in + "alpine"|"debian"|"ubuntu") + confdir="/etc/bird.d" + ;; + *) + printf "Your operating system (%s) is currently not supported by __bird_bgp\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +# Required parameters +local_as="$(cat "${__object:?}"/parameter/local-as)" +export local_as + +neighbor_as="$(cat "${__object:?}"/parameter/neighbor-as)" +export neighbor_as + +neighbor_ip="$(cat "${__object:?}"/parameter/neighbor-ip)" +export neighbor_ip + +# Optional parameters +description= +if [ -f "${__object:?}"/parameter/description ]; +then + description="$(cat "${__object:?}"/parameter/description)" +fi +export description + +direct= +if [ -f "${__object:?}"/parameter/direct ]; +then + direct="true" +fi +export direct + +ipv4_extended_next_hop= +if [ -f "${__object:?}"/parameter/ipv4-extended-next-hop ]; +then + ipv4_extended_next_hop="true" +fi +export ipv4_extended_next_hop + +ipv6_extended_next_hop= +if [ -f "${__object:?}"/parameter/ipv6-extended-next-hop ]; +then + ipv6_extended_next_hop="true" +fi +export ipv6_extended_next_hop + +local_ip= +if [ -f "${__object:?}"/parameter/local-ip ]; +then + local_ip="$(cat "${__object:?}"/parameter/local-ip)" +fi +export local_ip + +password= +if [ -f "${__object:?}"/parameter/password ]; +then + password="$(cat "${__object:?}"/parameter/password)" +fi +export password + +ipv4_import= +if [ -f "${__object:?}"/parameter/ipv4-import ]; +then + ipv4_import="$(cat "${__object:?}"/parameter/ipv4-import)" + echo "FOO" >&2 +fi +export ipv4_import + +ipv4_export= +if [ -f "${__object:?}"/parameter/ipv4-export ]; +then + ipv4_export="$(cat "${__object:?}"/parameter/ipv4-export)" +fi +export ipv4_export + +ipv6_import= +if [ -f "${__object:?}"/parameter/ipv6-import ]; +then + ipv6_import="$(cat "${__object:?}"/parameter/ipv6-import)" +fi +export ipv6_import + +ipv6_export= +if [ -f "${__object:?}"/parameter/ipv6-export ]; +then + ipv6_export="$(cat "${__object:?}"/parameter/ipv6-export)" +fi +export ipv6_export + +# Run template +"${__type:?}"/files/template.sh > "${__files:?}/bgp-${__object_id:?}.conf" + +# Install resulting configuration +__file "${confdir:?}"/bgp-"${__object_id:?}".conf \ + --mode 0640 --owner root --group bird \ + --source "${__files:?}/bgp-${__object_id:?}.conf" diff --git a/type/__bird_bgp/parameter/boolean b/type/__bird_bgp/parameter/boolean new file mode 100644 index 0000000..1c34b58 --- /dev/null +++ b/type/__bird_bgp/parameter/boolean @@ -0,0 +1,3 @@ +direct +ipv4-extended-next-hop +ipv6-extended-next-hop diff --git a/type/__bird_bgp/parameter/optional b/type/__bird_bgp/parameter/optional new file mode 100644 index 0000000..b9624a9 --- /dev/null +++ b/type/__bird_bgp/parameter/optional @@ -0,0 +1,7 @@ +description +ipv4-export +ipv4-import +ipv6-export +ipv6-import +local-ip +password diff --git a/type/__bird_bgp/parameter/required b/type/__bird_bgp/parameter/required new file mode 100644 index 0000000..9b82660 --- /dev/null +++ b/type/__bird_bgp/parameter/required @@ -0,0 +1,3 @@ +local-as +neighbor-as +neighbor-ip diff --git a/type/__bird_core/man.rst b/type/__bird_core/man.rst new file mode 100644 index 0000000..7bf3dc1 --- /dev/null +++ b/type/__bird_core/man.rst @@ -0,0 +1,65 @@ +cdist-type__bird-core(7) +======================== + +NAME +---- +cdist-type__bird-core - setup a skeleton bird configuration. + + +DESCRIPTION +----------- +The `bird`_ daemon is an internet routing daemon, running protocols such as +OSPF and BGP. This type creates a skeleton configuration file suitable for +running a no-op bird. It is then intended to be combined - and depended on - by +types specific to the instances of the various protocols that bird should run. + +.. _bird: https://bird.network.cz/ + +OPTIONAL PARAMETERS +------------------- +router-id + This parameter follows the format of an IPv4 address, and will be used by + bird as its router id. See `the documentation for router id`_. + +.. _the documentation for router id: https://bird.network.cz/?get_doc&v=20&f=bird-3.html#opt-router-id + +log-params + + This parameter expects a string suitable to follow the `log` bird + configuration key. If this parameter is not include, the value `syslog all` + is used. See `the documentation for log`_. + +.. _the documentation for log: https://bird.network.cz/?get_doc&v=20&f=bird-3.html#opt-log + + +EXAMPLES +-------- + +.. code-block:: sh + + __bird-core --router-id 198.51.100.4 + + require='__bird-core' __bird_bgp <...> + require='__bird-core' __bird_ospf <...> + + +SEE ALSO +-------- +cdist-type__bird_bgp(7) +cdist-type__bird_filter(7) +cdist-type__bird_kernel(7) +cdist-type__bird_ospf(7) +cdist-type__bird_static(7) + + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_core/manifest b/type/__bird_core/manifest new file mode 100755 index 0000000..be24da0 --- /dev/null +++ b/type/__bird_core/manifest @@ -0,0 +1,72 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +package= +conffile= +confdir= +case "$os" in + "alpine") + package=bird + conffile=/etc/bird.conf + confdir=/etc/bird.d + ;; + *) + printf "Your operating system (%s) is currently not supported by __bird_core\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +router_id= +if [ -f "${__object:?}/parameter/router-id" ]; +then + router_id="router id $(cat "${__object:?}"/parameter/router-id);" +fi + +log_params="syslog all" +if [ -f "${__object:?}/parameter/log-params" ]; +then + log_params="$(cat "${__object:?}"/parameter/log-params)" +fi + +__package "$package" + +__directory "$confdir" + +__file "$conffile" \ + --mode 0640 --owner root --group bird \ + --source - << EOF +# $conffile - bird(1) configuration file. +# Managed by cdist. Do not edit by hand. + +${router_id} +log ${log_params}; + +# Always include this "protocol": all it does is expose the available +# interfaces to bird. +protocol device { + description "Obtain a list of device interfaces."; +} + +include "$confdir/*.conf"; +EOF diff --git a/type/__bird_core/parameter/optional b/type/__bird_core/parameter/optional new file mode 100644 index 0000000..40d74bf --- /dev/null +++ b/type/__bird_core/parameter/optional @@ -0,0 +1 @@ +log-params diff --git a/type/__bird_core/parameter/required b/type/__bird_core/parameter/required new file mode 100644 index 0000000..8fb6ae6 --- /dev/null +++ b/type/__bird_core/parameter/required @@ -0,0 +1 @@ +router-id diff --git a/type/__bird_core/singleton b/type/__bird_core/singleton new file mode 100644 index 0000000..e69de29 diff --git a/type/__bird_filter/man.rst b/type/__bird_filter/man.rst new file mode 100644 index 0000000..a1ebf0b --- /dev/null +++ b/type/__bird_filter/man.rst @@ -0,0 +1,63 @@ +cdist-type__bird_filter(7) +========================== + +NAME +---- +cdist-type__bird_filter - Create a named filter to use in configuring bird. + + +DESCRIPTION +----------- +This type writes a configuration file defining a filter named `__object_id` for +the bird internet routing daemon. It is guaranteed that all filters defined +through this type will be loaded before any other protocol defined using the +cdist __bird_xxx types, except functions. However, note that if two filters +have a dependency, they will be loaded in alphabetical order, so some care may +need to be taken in the naming. + +This type takes it's input through stdin, expecting valid filter statements as +per the bird configuration file syntax. The standard input will be printed out +between a `filter __object_id {\n ... \n}`, so only the inner statements are +needed. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Setup bird, a filter and open a BGP session. + __bird_core --router-id 198.51.100.4 + + require='__bird_core' __bird_filter bgp_export <<- EOF + if (source = RTS_DEVICE) then accept; + reject; + EOF + + require='__bird_core' __bird_bgp bgp4 \ + --description "a test IPv4 BGP instance" \ + --ipv4-export "filter bgp_export" \ + --[...] + + +SEE ALSO +-------- +cdist-type__bird_core(7) +cdist-type__bird_bgp(7) +cdist-type__bird_function(7) +cdist-type__bird_kernel(7) +cdist-type__bird_ospf(7) +cdist-type__bird_static(7) + + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_filter/manifest b/type/__bird_filter/manifest new file mode 100755 index 0000000..9579598 --- /dev/null +++ b/type/__bird_filter/manifest @@ -0,0 +1,44 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +case "$os" in +'alpine'|'debian'|'ubuntu') + confdir=/etc/bird.d + ;; +*) + printf "Your operating system (%s) is currently not supported by __bird_filter\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +# Filters start with 1 because bird loads the config in alphanumerical order +# and we need them to be defined to be used in the rest of the stuff, but after +# functions. +__file "$confdir/1-filter-${__object_id:?}.conf" \ + --owner root --group bird --mode 0640 \ + --source - << EOF +filter ${__object_id:?} { +$(cat "${__object:?}"/stdin) +} +EOF diff --git a/type/__bird_function/man.rst b/type/__bird_function/man.rst new file mode 100644 index 0000000..b5488ec --- /dev/null +++ b/type/__bird_function/man.rst @@ -0,0 +1,58 @@ +cdist-type__bird_function(7) +============================ + +NAME +---- +cdist-type__bird_function - Create a named function to use in configuring bird. + + +DESCRIPTION +----------- + +This type writes a configuration file for the bird internet routing daemon. It +is guaranteed that all functions defined through this type will be loaded +before any other protocol defined using the cdist __bird_xxx types. However, +note that if two functions have a dependency, they will be loaded in +alphabetical order, so some care may need to be taken in the naming. + +This type takes it's input through stdin, expecting a valid function definition +as per the bird configuration file syntax. + +EXAMPLES +-------- + +.. code-block:: sh + + # Setup bird, a function and open a BGP session. + __bird_core --router-id 198.51.100.4 + + require='__bird_core' __bird_function is_device <<- EOF + function is_device (enum source) + { + if (source = RTS_DEVICE) then return true; + return false; + } + EOF + + +SEE ALSO +-------- +cdist-type__bird_core(7) +cdist-type__bird_bgp(7) +cdist-type__bird_filter(7) +cdist-type__bird_kernel(7) +cdist-type__bird_ospf(7) +cdist-type__bird_static(7) + + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_function/manifest b/type/__bird_function/manifest new file mode 100755 index 0000000..9a93f35 --- /dev/null +++ b/type/__bird_function/manifest @@ -0,0 +1,41 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +case "$os" in +'alpine'|'debian'|'ubuntu') + confdir=/etc/bird.d + ;; +*) + printf "Your operating system (%s) is currently not supported by __bird_filter\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +# Functions start with 0 because bird loads the config in alphanumerical order +# and we need them to be defined to be used in the rest of the stuff. +__file "$confdir/0-function-${__object_id:?}.conf" \ + --owner root --group bird --mode 0640 \ + --source - << EOF +$(cat "${__object:?}"/stdin) +EOF diff --git a/type/__bird_kernel/man.rst b/type/__bird_kernel/man.rst new file mode 100644 index 0000000..34f1c49 --- /dev/null +++ b/type/__bird_kernel/man.rst @@ -0,0 +1,73 @@ +cdist-type__bird_kernel(7) +========================== + +NAME +---- +cdist-type__bird_kernel - configure syncing of routes with the kernel. + + +DESCRIPTION +----------- + +This type writes the configuration for an instance of the kernel protocol to be +ran by the bird internet routing daemon. It **expects** to depend on the +`cdist-type__bird_core(7)` type. + +OPTIONAL PARAMETERS +------------------- +description + An instance desciption to be printed when `birdc show protocols` is called. + +persist + Instruct bird to leave routes in kernel table after exiting. See the bird + `persist` keyword. + +learn + Learn routes added externally to the kernel routing table. See the bird + `learn` keyword. + +channel + The channel to connect the protocol to. Usually `ipv4` or `ipv6`. + +import + A string suitable for the bird `import` directive. Usually `all`, `none` or + a filter definition. + +export + See import. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Setup bird and open a BGP session. + __bird_core --router-id 198.51.100.4 + + require='__bird_core' __bird_kernel k4 \ + --learn --persist --channel ipv4 \ + --import all \ + --export all + + +SEE ALSO +-------- +cdist-type__bird_bgp(7) +cdist-type__bird_core(7) +cdist-type__bird_filter(7) +cdist-type__bird_ospf(7) +cdist-type__bird_static(7) + + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_kernel/manifest b/type/__bird_kernel/manifest new file mode 100755 index 0000000..c5d2eac --- /dev/null +++ b/type/__bird_kernel/manifest @@ -0,0 +1,83 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +case "$os" in + "alpine"|"debian"|"ubuntu") + confdir="/etc/bird.d" + ;; + *) + printf "Your operating system (%s) is currently not supported by __bird_kernel\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +# Required parameters +channel="$(cat "${__object:?}/parameter/channel")" + +# Boolean switches +persist= +if [ -f "${__object:?}"/parameter/persist ]; +then + persist=true +fi + +learn= +if [ -f "${__object:?}"/parameter/learn ]; +then + learn=true +fi + +# Optional parameters +description= +if [ -f "${__object:?}"/parameter/description ]; +then + description="$(cat "${__object:?}/parameter/description")" +fi + +import= +if [ -f "${__object:?}"/parameter/import ]; +then + import="$(cat "${__object:?}/parameter/import")" +fi + +_export= +if [ -f "${__object:?}"/parameter/export ]; +then + _export="$(cat "${__object:?}/parameter/export")" +fi + +# Install resulting configuration +__file "${confdir:?}"/kernel-"${__object_id:?}".conf \ + --mode 0640 --owner root --group bird \ + --source - << EOF +protocol kernel ${__object_id:?} { +$([ -n "${description?}" ] && printf "\tdescription \"%s\";\n" "${description?}") +$([ -n "${persist?}" ] && printf "\tpersist;\n") +$([ -n "${learn?}" ] && printf "\tlearn;\n") + ${channel:?} { + import ${import:?}; + export ${_export:?}; + }; +} +EOF diff --git a/type/__bird_kernel/parameter/boolean b/type/__bird_kernel/parameter/boolean new file mode 100644 index 0000000..6499685 --- /dev/null +++ b/type/__bird_kernel/parameter/boolean @@ -0,0 +1,2 @@ +learn +persist diff --git a/type/__bird_kernel/parameter/optional b/type/__bird_kernel/parameter/optional new file mode 100644 index 0000000..e1b39b0 --- /dev/null +++ b/type/__bird_kernel/parameter/optional @@ -0,0 +1 @@ +description diff --git a/type/__bird_kernel/parameter/required b/type/__bird_kernel/parameter/required new file mode 100644 index 0000000..a87a501 --- /dev/null +++ b/type/__bird_kernel/parameter/required @@ -0,0 +1,3 @@ +channel +import +export diff --git a/type/__bird_ospf/man.rst b/type/__bird_ospf/man.rst new file mode 100644 index 0000000..9b9a20f --- /dev/null +++ b/type/__bird_ospf/man.rst @@ -0,0 +1,56 @@ +cdist-type__bird-ospf(7) +======================== + +NAME +---- +cdist-type__bird-ospf - Configure an instance of the OSPF protocol + + +DESCRIPTION +----------- + +This type is an *extremely rudimentary* method to configure a simple OSPF +protocol instance for bird, the internet routing daemon. Even this manpage is +pretty crude and will be fixed and expanded. + +REQUIRED PARAMETERS +------------------- +channel + The channel the protocol should connect to. Usually `ipv4` or `ipv6`. + +import + The keyword or filter to decide what to import in the above channel. + +export + The keyword or filter to decide what to export in the above channel. + + +REQUIRED MULTIPLE PARAMETERS +---------------------------- +interface + An interface to include in OSPF area 0. + +OPTIONAL PARAMETERS +------------------- +description + A description given with `show protocol all` + +instance-id + An OSPF instance ID, allowing several OSPF instances to run on the same + links. + +SEE ALSO +-------- +cdist-type__bird_core(7) + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_ospf/manifest b/type/__bird_ospf/manifest new file mode 100755 index 0000000..0e219ae --- /dev/null +++ b/type/__bird_ospf/manifest @@ -0,0 +1,63 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +case "$os" in +'alpine'|'debian'|'ubuntu') + confdir='/etc/bird.d' +;; +*) + printf "Your operating system (%s) is currently not supported by this __bird_ospf\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 +;; +esac + +description= +if [ -f "${__object:?}/parameter/description" ]; +then + description="$(cat "${__object:?}/parameter/description")" +fi + +instance_id= +if [ -f "${__object:?}/parameter/instance-id" ]; +then + instance_id="$(cat "${__object:?}/parameter/instance-id")" +fi + +__file "${confdir:?}/ospf-${__object_id:?}.conf" \ + --mode 0640 --owner root --group bird \ + --source - << EOF +protocol ospf v3 ${__object_id:?} { +$([ -n "${description?}" ] && printf "\tdescription \"%s\";\n" "${description?}") +$([ -n "${instance_id?}" ] && printf "\tinstance id %s;\n" "${instance_id?}") + + $(cat "${__object:?}/parameter/channel") { + import $(cat "${__object:?}/parameter/import"); + export $(cat "${__object:?}/parameter/export"); + }; + + area 0 { +$(sed -e 's/^/\t\tinterface "/' -e 's/$/";/' "${__object:?}/parameter/interface") + }; +} +EOF diff --git a/type/__bird_ospf/parameter/optional b/type/__bird_ospf/parameter/optional new file mode 100644 index 0000000..cf6dd53 --- /dev/null +++ b/type/__bird_ospf/parameter/optional @@ -0,0 +1,2 @@ +description +instance-id diff --git a/type/__bird_ospf/parameter/required b/type/__bird_ospf/parameter/required new file mode 100644 index 0000000..a87a501 --- /dev/null +++ b/type/__bird_ospf/parameter/required @@ -0,0 +1,3 @@ +channel +import +export diff --git a/type/__bird_ospf/parameter/required_multiple b/type/__bird_ospf/parameter/required_multiple new file mode 100644 index 0000000..b529896 --- /dev/null +++ b/type/__bird_ospf/parameter/required_multiple @@ -0,0 +1 @@ +interface diff --git a/type/__bird_static/files/template.sh b/type/__bird_static/files/template.sh new file mode 100755 index 0000000..05b5215 --- /dev/null +++ b/type/__bird_static/files/template.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Template to generate a static protocol configuration file for bird(1). +# Required non-empty variables: +# __object_id, object +# +# Required defined variables: +# description + +# Header +printf "protocol static %s {\n" "${__object_id:?}" + +# Optional description +[ -n "${description?}" ] && printf "\tdescription \"%s\";\n" "${description:?}" + +# Channel choice +if [ -f "${__object:?}/parameter/ipv4" ]; +then + printf "\tipv4;\n" +else + printf "\tipv6;\n" +fi + +# Routes +while read -r route +do + printf "\troute %s;\n" "${route?}" +done < "${__object:?}/parameter/route" + +# Header close +printf "}\n" diff --git a/type/__bird_static/man.rst b/type/__bird_static/man.rst new file mode 100644 index 0000000..f42474a --- /dev/null +++ b/type/__bird_static/man.rst @@ -0,0 +1,69 @@ +cdist-type__bird_static(7) +========================== + +NAME +---- +cdist-type__bird_static - configure an instance of the bird static protocol. + + +DESCRIPTION +----------- +This type write the configuration file for an instance of the static protocl to +be ran bu the bird internet routing daemon, allowing an administrator to inject +static routes into the daemon's routing tables. This protocol allows for only +one of two channels to be used, either `ipv4` or `ipv6`, by default `ipv6` is +used unless the `ipv4` flag is passed. This type **expects** to depend on the +`cdist-type__bird_core(7)` type. + + +REQUIRED MULTIPLE PARAMETERS +---------------------------- +route + This flag expects a valid route to be inserted between the bird `route` + keyword and the end of line. It may be specified as many times as necessary. + + +OPTIONAL PARAMETERS +------------------- +description + An instance desciption to be printed when `birdc show protocols` is called. + +BOOLEAN PARAMETERS +------------------ +ipv4 + Use the ipv4 channel instead of the default ipv6 one. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Setup bird and open a BGP session. + __bird_core --router-id 198.51.100.4 + + require='__bird_core' __bird_static static4 \ + --description "static ipv4 routes plugged into bird" \ + --route "198.51.0.0/16 via 192.51.100.1" \ + --route "192.52.0.0/16 via 192.51.100.1" + + +SEE ALSO +-------- +cdist-type__bird_core(7) +cdist-type__bird_bgp(7) +cdist-type__bird_kernel(7) +cdist-type__bird_ospf(7) + + +AUTHORS +------- +Joachim Desroches + + +COPYING +------- +Copyright \(C) 2021 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__bird_static/manifest b/type/__bird_static/manifest new file mode 100755 index 0000000..722971b --- /dev/null +++ b/type/__bird_static/manifest @@ -0,0 +1,51 @@ +#!/bin/sh -e +# +# 2021 Joachim Desroches (joachim.desroches@epfl.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "${__global:?}/explorer/os") + +case "$os" in + 'alpine'|'debian'|'ubuntu') + confdir=/etc/bird.d + ;; + *) + printf "Your operating system (%s) is currently not supported by __bird_static\n" "$os" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +# Required parameter route is directly accessed in template. +# Boolean parameter ipv4 is directly accessed in template. +# Optional parameter description +description= +if [ -f "${__object:?}/parameter/description" ]; +then + description="$(cat "${__object:?}/parameter/description")" +fi +export description + +# Run template +"${__type:?}"/files/template.sh > "${__files:?}/static-${__object_id:?}.conf" + +# Install resulting configuration +__file "${confdir:?}"/static-"${__object_id:?}".conf \ + --mode 0640 --owner root --group bird \ + --source "${__files:?}/static-${__object_id:?}.conf" diff --git a/type/__bird_static/parameter/boolean b/type/__bird_static/parameter/boolean new file mode 100644 index 0000000..53bb6dd --- /dev/null +++ b/type/__bird_static/parameter/boolean @@ -0,0 +1 @@ +ipv4 diff --git a/type/__bird_static/parameter/optional b/type/__bird_static/parameter/optional new file mode 100644 index 0000000..e1b39b0 --- /dev/null +++ b/type/__bird_static/parameter/optional @@ -0,0 +1 @@ +description diff --git a/type/__bird_static/parameter/required_multiple b/type/__bird_static/parameter/required_multiple new file mode 100644 index 0000000..6f36346 --- /dev/null +++ b/type/__bird_static/parameter/required_multiple @@ -0,0 +1 @@ +route