From 27a7201b45ae57046956b742df8525cb65ecfda2 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sun, 4 Oct 2020 20:05:42 +0200 Subject: [PATCH] batman executor: Generalize option handling. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/batman | 65 +++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/executor-scripts/linux/batman b/executor-scripts/linux/batman index 33bb7d9..62f4f6e 100644 --- a/executor-scripts/linux/batman +++ b/executor-scripts/linux/batman @@ -6,17 +6,7 @@ # This executor is responsible for setting up the main B.A.T.M.A.N. adv. interface (eg. bat0) # as well as managing settings of the underlying interfaces (hardifs). # -# Known options for the main interface are: -# IF_BATMAN_IFACES Space separated list of interfaces to be part of this B.A.T.M.A.N. adv. instance -# IF_BATMAN_IFACES_IGNORE_REGEX Interfaces to ignore when verifying configuration (regexp) -# IF_BATMAN_DISTRIBUTED_ARP_TABLE 'enable' or 'disable' DAT of this B.A.T.M.A.N. adv. instance -# IF_BATMAN_MULTICAST_MODE 'enable' or 'disable' the multicast mode of this B.A.T.M.A.N. adv. instance -# IF_BATMAN_GW_MODE Set the gateway mode of this B.A.T.M.A.N. adv. instance -# IF_BATMAN_HOP_PENALTY Set the hop penalty of this B.A.T.M.A.N. adv. instance -# IF_BATMAN_ROUTING_ALGO Set the B.A.T.M.A.N. adv. routing algorithm (BATMAN_IV, BATMAN_V) -# -# Known options for underlying interfaces are: -# IF_BATMAN_HOP_PENALTY Set the hop penalty of this B.A.T.M.A.N. adv. underlay interface +# See interfaces-batman(5) for a list of supported options for hardifs as well as meshifs. # set -e @@ -24,11 +14,9 @@ if [ "$VERBOSE" ]; then set -x fi -if [ "${IF_BATMAN_IFACES}" -o "${IF_BATMAN_IFACE_PENALTY}" ]; then - if ! which batctl >/dev/null 2>&1; then - echo "Error: batctl utility not found!" >&2 - exit 1 - fi +if ! which batctl >/dev/null 2>&1; then + echo "Error: batctl utility not found!" >&2 + exit 1 fi # @@ -48,11 +36,23 @@ batctl_if () { done } -set_batman_params () { - [ "${IF_BATMAN_DISTRIBUTED_ARP_TABLE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" distributed_arp_table "${IF_BATMAN_DISTRIBUTED_ARP_TABLE}" - [ "${IF_BATMAN_MULTICAST_MODE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" multicast_mode "${IF_BATMAN_MULTICAST_MODE}" - [ "${IF_BATMAN_HOP_PENALTY}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" hop_penalty "${IF_BATMAN_HOP_PENALTY}" - [ "${IF_BATMAN_GW_MODE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" gw_mode "${IF_BATMAN_GW_MODE}" +set_meshif_options () { + # We only care for options of format IF_BATMAN_ + env | grep '^IF_BATMAN_[A-Z0-9_]\+' | while IFS="=" read opt value; do + # Members, ignore-regex, routing-algo, and throughput_override are handled seperately + if [ "${opt}" = "IF_BATMAN_IFACES" -o \ + "${opt}" = "IF_BATMAN_IFACES_IGNORE_REGEX" -o \ + "${opt}" = "IF_BATMAN_ROUTING_ALGO" -o \ + "${opt}" = "IF_BATMAN_THROUGHPUT_OVERRIDE" ]; then + continue + fi + + # Convert options for the actual name + real_opt=$(echo "${opt}" | sed -e 's/^IF_BATMAN_\([A-Z0-9_]\+\)/\1/' | tr '[A-Z]' '[a-z]') + + ${MOCK} batctl "${mesh_if_param}" "${IFACE}" "${real_opt}" "${value}" + done + } set_routing_algo () { @@ -64,10 +64,17 @@ set_routing_algo () { batctl ra "${IF_BATMAN_ROUTING_ALGO}" } + # -# Functions to manage B.A.T.M.A.N. adv. underlying interfaces -set_iface_penalty () { - ${MOCK} batctl hardif "${IFACE}" hop_penalty "${IF_BATMAN_HOP_PENALTY}" +# Functions to manage B.A.T.M.A.N. adv. underlay interfaces (hardifs) +set_hardif_options () { + if [ "${IF_BATMAN_HOP_PENALTY}" ]; then + ${MOCK} batctl hardif "${IFACE}" hop_penalty "${IF_BATMAN_HOP_PENALTY}" + fi + + if [ "${IF_BATMAN_THROUGHPUT_OVERRIDE}" ]; then + ${MOCK} batctl hardif "${IFACE}" throughput_override "${IF_BATMAN_THROUGHPUT_OVERRIDE}" + fi } @@ -92,14 +99,14 @@ case "${PHASE}" in ;; pre-up) - # Main B.A.T.M.A.N. adv. interface + # Main B.A.T.M.A.N. adv. interface (meshif) if [ "${IF_BATMAN_IFACES}" ]; then batctl_if add - set_batman_params + set_meshif_options - # B.A.T.M.A.N. adv. underlying interface - elif [ "${IF_BATMAN_HOP_PENALTY}" ]; then - set_iface_penalty + # B.A.T.M.A.N. adv. underlay interface (hardif) + elif [ "${IF_BATMAN_HOP_PENALTY}" -o "${IF_BATMAN_THROUGHPUT_OVERRIDE}" ]; then + set_hardif_options fi ;;