From 272e4669fe1b093991692b13b4ae945563b47ca3 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Sun, 18 Apr 2021 23:28:35 +0200 Subject: [PATCH 1/3] Implement __jool type. --- type/__jool/man.rst | 76 ++++++++++++++++++++++++++++++++++ type/__jool/manifest | 76 ++++++++++++++++++++++++++++++++++ type/__jool/parameter/boolean | 1 + type/__jool/parameter/optional | 3 ++ type/__jool/singleton | 0 5 files changed, 156 insertions(+) create mode 100644 type/__jool/man.rst create mode 100755 type/__jool/manifest create mode 100644 type/__jool/parameter/boolean create mode 100644 type/__jool/parameter/optional create mode 100644 type/__jool/singleton diff --git a/type/__jool/man.rst b/type/__jool/man.rst new file mode 100644 index 0000000..9b47a21 --- /dev/null +++ b/type/__jool/man.rst @@ -0,0 +1,76 @@ +cdist-type__jool(7) +=================== + +NAME +---- +cdist-type__jool - Configures a NAT64 instance using jool. + + +DESCRIPTION +----------- +This type configures an instance of a NAT64 using jool. This type **does not** +configure anything related to the other capacities of the jool project, such as +SIIT (see the `jool_siit` daemon / `__jool_siit` type - unimplemented at this +time). See https://jool.mx + +Note that this type is only implemented for the Alpine Linux operating system. + +Note that this type currently does not implement running several parallel +instances of jool NAT64. Please contribute your implementation if you do so. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +instance + The instance name, `default` if unspecified. + +framework + The used translation framework, `netfilter` if unspecified. + +pool6 + The IPv6 prefix used to map IPv4 addresses, `64:ff9b::/96` if unspecified. + + +BOOLEAN PARAMETERS +------------------ +vm + Wether this instance is running in a VM or not: configures the kernel + modules that will be installed. + + +EXAMPLES +-------- + +.. code-block:: sh + + __jool # Everything default + + # or, if you're feeling contrary + + __jool --instance "prettysoup" \ + --framework "iptables" \ + --pool6 "2001:DB8:dead:beef::/96" + + +SEE ALSO +-------- +`cdist-type__jool_siit(7)` - yet to be written +`cdist-type__joold(7)` - yet to be written + + +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/__jool/manifest b/type/__jool/manifest new file mode 100755 index 0000000..b116363 --- /dev/null +++ b/type/__jool/manifest @@ -0,0 +1,76 @@ +#!/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') + : + ;; +*) + printf "This type has no implementation for %s. Please contribute one if you can.\n" "$os" + exit 1 + ;; +esac + + +if [ -f "${__object:?}/parameter/vm" ]; +then + kernel_modules="jool-modules-virt" +else + kernel_modules="jool-modules-lts" +fi + +for pkg in jool-tools jool-tools-openrc "$kernel_modules"; +do + __package "$pkg" +done + +instance="default" +if [ -f "${__object:?}/parameter/instance" ]; +then + instance="$(cat "${__object:?}/parameter/instance")" +fi + +framework="netfilter" +if [ -f "${__object:?}/parameter/framework" ]; +then + framework="$(cat "${__object:?}/parameter/framework")" +fi + +pool6="64:ff9b::/96" +if [ -f "${__object:?}/parameter/pool6" ]; +then + pool6="$(cat "${__object:?}/parameter/pool6")" +fi + +require='__package/jool-tools' __file /etc/jool/jool.conf \ + --source - <<- EOF + { + "instance": "$instance", + "framework": "$framework", + "global": { + "pool6": "$pool6" + } + } + EOF + +__start_on_boot 'jool' diff --git a/type/__jool/parameter/boolean b/type/__jool/parameter/boolean new file mode 100644 index 0000000..73b3d4e --- /dev/null +++ b/type/__jool/parameter/boolean @@ -0,0 +1 @@ +vm diff --git a/type/__jool/parameter/optional b/type/__jool/parameter/optional new file mode 100644 index 0000000..822afd9 --- /dev/null +++ b/type/__jool/parameter/optional @@ -0,0 +1,3 @@ +instance +framework +pool6 diff --git a/type/__jool/singleton b/type/__jool/singleton new file mode 100644 index 0000000..e69de29 From 40d19f0ad6058487642a6f629ebd02d4667e91c1 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Wed, 21 Apr 2021 11:03:00 +0200 Subject: [PATCH 2/3] [__jool] Use explorer to determine alpine kernel version. --- type/__jool/explorer/alpine-kernel-modules | 13 +++++++++++++ type/__jool/man.rst | 7 ------- type/__jool/manifest | 12 ++---------- 3 files changed, 15 insertions(+), 17 deletions(-) create mode 100755 type/__jool/explorer/alpine-kernel-modules diff --git a/type/__jool/explorer/alpine-kernel-modules b/type/__jool/explorer/alpine-kernel-modules new file mode 100755 index 0000000..e3a1a35 --- /dev/null +++ b/type/__jool/explorer/alpine-kernel-modules @@ -0,0 +1,13 @@ +#!/bin/sh +# Explorer for the __jool type to determine if we need the -virt or the -lts modules. + +[ "$(sh -e "${__explorer:?}"/os)" = 'alpine' ] || exit 0 + +case $(uname -r) in +*-virt) + printf "jool-modules-virt" + ;; +*-lts) + printf "jool-modules-lts" + ;; +esac diff --git a/type/__jool/man.rst b/type/__jool/man.rst index 9b47a21..3220bc2 100644 --- a/type/__jool/man.rst +++ b/type/__jool/man.rst @@ -36,13 +36,6 @@ pool6 The IPv6 prefix used to map IPv4 addresses, `64:ff9b::/96` if unspecified. -BOOLEAN PARAMETERS ------------------- -vm - Wether this instance is running in a VM or not: configures the kernel - modules that will be installed. - - EXAMPLES -------- diff --git a/type/__jool/manifest b/type/__jool/manifest index b116363..a0ff4ce 100755 --- a/type/__jool/manifest +++ b/type/__jool/manifest @@ -23,7 +23,7 @@ os=$(cat "${__global:?}/explorer/os") case "$os" in 'alpine') - : + packages="jool-tools jool-tools-openrc $(cat "${__object:?}"/explorer/alpine-kernel-modules)" ;; *) printf "This type has no implementation for %s. Please contribute one if you can.\n" "$os" @@ -31,15 +31,7 @@ case "$os" in ;; esac - -if [ -f "${__object:?}/parameter/vm" ]; -then - kernel_modules="jool-modules-virt" -else - kernel_modules="jool-modules-lts" -fi - -for pkg in jool-tools jool-tools-openrc "$kernel_modules"; +for pkg in $packages; do __package "$pkg" done From 6a0647cd909256565d8f7525d61823dfd96de90f Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Wed, 21 Apr 2021 15:35:13 +0200 Subject: [PATCH 3/3] [__jool]: fail on unkown alpine kernel. --- type/__jool/explorer/alpine-kernel-modules | 6 ++++++ type/__jool/parameter/boolean | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) delete mode 100644 type/__jool/parameter/boolean diff --git a/type/__jool/explorer/alpine-kernel-modules b/type/__jool/explorer/alpine-kernel-modules index e3a1a35..581d63a 100755 --- a/type/__jool/explorer/alpine-kernel-modules +++ b/type/__jool/explorer/alpine-kernel-modules @@ -10,4 +10,10 @@ case $(uname -r) in *-lts) printf "jool-modules-lts" ;; +*) + cat <<- EOF >&2 + Incompatible kernel version found - could not install jool kernel + modules. Please use one of linux-lts or linux-virt. + EOF + exit 1 esac diff --git a/type/__jool/parameter/boolean b/type/__jool/parameter/boolean deleted file mode 100644 index 73b3d4e..0000000 --- a/type/__jool/parameter/boolean +++ /dev/null @@ -1 +0,0 @@ -vm