From 59290415a00380ebe47cb72f46e3bb3154a4a0cf Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Mon, 21 Sep 2020 23:59:24 +0200 Subject: [PATCH 1/4] batman executor: Allow settings the B.A.T.M.A.N. adv. routing algorithm Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/batman | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/executor-scripts/linux/batman b/executor-scripts/linux/batman index c041634..dd8dd2d 100644 --- a/executor-scripts/linux/batman +++ b/executor-scripts/linux/batman @@ -13,6 +13,7 @@ # 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_IFACE_PENALTY Set the hop penalty of this B.A.T.M.A.N. adv. interface @@ -54,6 +55,15 @@ set_batman_params () { [ "${IF_BATMAN_GW_MODE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" gw_mode "${IF_BATMAN_GW_MODE}" } +set_routing_algo () { + if [ "${IF_BATMAN_ROUTING_ALGO}" != "BATMAN_IV" -a "${IF_BATMAN_ROUTING_ALGO}" != "BATMAN_V" ]; then + echo "Invalid routing algorithm \"$1\"." + return + fi + + batctl ra "${IF_BATMAN_ROUTING_ALGO}" +} + # # Functions to manage B.A.T.M.A.N. adv. underlying interfaces set_iface_penalty () { @@ -71,6 +81,10 @@ case "${PHASE}" in create) # Main B.A.T.M.A.N. adv. interface if [ "${IF_BATMAN_IFACES}" ]; then + if [ "${IF_BATMAN_ROUTING_ALGO}" ]; then + set_routing_algo + fi + if [ ! -d "/sys/class/net/${IFACE}" ]; then batctl "${mesh_if_param}" "${IFACE}" interface create || true fi From 332ea7c7d37271d164da154e168057e56bbd2249 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sun, 4 Oct 2020 18:11:38 +0200 Subject: [PATCH 2/4] Stick to upstream naming of hop-penalty instead of interface penalty for hardifs. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/batman | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/executor-scripts/linux/batman b/executor-scripts/linux/batman index dd8dd2d..33bb7d9 100644 --- a/executor-scripts/linux/batman +++ b/executor-scripts/linux/batman @@ -16,7 +16,7 @@ # 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_IFACE_PENALTY Set the hop penalty of this B.A.T.M.A.N. adv. interface +# IF_BATMAN_HOP_PENALTY Set the hop penalty of this B.A.T.M.A.N. adv. underlay interface # set -e @@ -67,7 +67,7 @@ set_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_IFACE_PENALTY}" + ${MOCK} batctl hardif "${IFACE}" hop_penalty "${IF_BATMAN_HOP_PENALTY}" } @@ -98,7 +98,7 @@ case "${PHASE}" in set_batman_params # B.A.T.M.A.N. adv. underlying interface - elif [ "${IF_BATMAN_IFACE_PENALTY}" ]; then + elif [ "${IF_BATMAN_HOP_PENALTY}" ]; then set_iface_penalty fi ;; From 27a7201b45ae57046956b742df8525cb65ecfda2 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sun, 4 Oct 2020 20:05:42 +0200 Subject: [PATCH 3/4] 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 ;; From 13a8daf96e121d9ab5cb9a36555490f9cf7ff117 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Tue, 6 Oct 2020 05:17:48 +0200 Subject: [PATCH 4/4] batman executor: Work around excution order limitations for now. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/batman | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/executor-scripts/linux/batman b/executor-scripts/linux/batman index 62f4f6e..dd984ec 100644 --- a/executor-scripts/linux/batman +++ b/executor-scripts/linux/batman @@ -68,13 +68,18 @@ set_routing_algo () { # # 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 + # Query hardif parameter manually for now + for hardif in ${IF_BATMAN_IFACES}; do + penalty=$(ifquery -p "batman-hop-penalty" "${hardif}") + if [ "${penalty}" ]; then + ${MOCK} batctl hardif "${hardif}" hop_penalty "${penalty}" + fi - if [ "${IF_BATMAN_THROUGHPUT_OVERRIDE}" ]; then - ${MOCK} batctl hardif "${IFACE}" throughput_override "${IF_BATMAN_THROUGHPUT_OVERRIDE}" - fi + throughput=$(ifquery -p "batman-throughput-override" "${hardif}") + if [ "${throughput}" ]; then + ${MOCK} batctl hardif "${hardif}" throughput_override "${througput}" + fi + done } @@ -103,9 +108,6 @@ case "${PHASE}" in if [ "${IF_BATMAN_IFACES}" ]; then batctl_if add set_meshif_options - - # 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 ;;