batman executor: Generalize option handling.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
This commit is contained in:
Maximilian Wilhelm 2020-10-04 20:05:42 +02:00
parent 332ea7c7d3
commit 27a7201b45

View file

@ -6,17 +6,7 @@
# This executor is responsible for setting up the main B.A.T.M.A.N. adv. interface (eg. bat0) # 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). # as well as managing settings of the underlying interfaces (hardifs).
# #
# Known options for the main interface are: # See interfaces-batman(5) for a list of supported options for hardifs as well as meshifs.
# 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
# #
set -e set -e
@ -24,11 +14,9 @@ if [ "$VERBOSE" ]; then
set -x set -x
fi fi
if [ "${IF_BATMAN_IFACES}" -o "${IF_BATMAN_IFACE_PENALTY}" ]; then if ! which batctl >/dev/null 2>&1; then
if ! which batctl >/dev/null 2>&1; then echo "Error: batctl utility not found!" >&2
echo "Error: batctl utility not found!" >&2 exit 1
exit 1
fi
fi fi
# #
@ -48,11 +36,23 @@ batctl_if () {
done done
} }
set_batman_params () { set_meshif_options () {
[ "${IF_BATMAN_DISTRIBUTED_ARP_TABLE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" distributed_arp_table "${IF_BATMAN_DISTRIBUTED_ARP_TABLE}" # We only care for options of format IF_BATMAN_<OPTION_NAME>
[ "${IF_BATMAN_MULTICAST_MODE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" multicast_mode "${IF_BATMAN_MULTICAST_MODE}" env | grep '^IF_BATMAN_[A-Z0-9_]\+' | while IFS="=" read opt value; do
[ "${IF_BATMAN_HOP_PENALTY}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" hop_penalty "${IF_BATMAN_HOP_PENALTY}" # Members, ignore-regex, routing-algo, and throughput_override are handled seperately
[ "${IF_BATMAN_GW_MODE}" ] && ${MOCK} batctl "${mesh_if_param}" "${IFACE}" gw_mode "${IF_BATMAN_GW_MODE}" 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 () { set_routing_algo () {
@ -64,10 +64,17 @@ set_routing_algo () {
batctl ra "${IF_BATMAN_ROUTING_ALGO}" batctl ra "${IF_BATMAN_ROUTING_ALGO}"
} }
# #
# Functions to manage B.A.T.M.A.N. adv. underlying interfaces # Functions to manage B.A.T.M.A.N. adv. underlay interfaces (hardifs)
set_iface_penalty () { set_hardif_options () {
${MOCK} batctl hardif "${IFACE}" hop_penalty "${IF_BATMAN_HOP_PENALTY}" 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) 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 if [ "${IF_BATMAN_IFACES}" ]; then
batctl_if add batctl_if add
set_batman_params set_meshif_options
# B.A.T.M.A.N. adv. underlying interface # B.A.T.M.A.N. adv. underlay interface (hardif)
elif [ "${IF_BATMAN_HOP_PENALTY}" ]; then elif [ "${IF_BATMAN_HOP_PENALTY}" -o "${IF_BATMAN_THROUGHPUT_OVERRIDE}" ]; then
set_iface_penalty set_hardif_options
fi fi
;; ;;