Merge pull request #101 from BarbarossaTM/feature/batman-options
Generalize B.A.T.M.A.N. .adv. option handling
This commit is contained in:
commit
a67d518ea9
1 changed files with 52 additions and 29 deletions
|
@ -6,16 +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
|
|
||||||
#
|
|
||||||
# Known options for underlying interfaces are:
|
|
||||||
# IF_BATMAN_IFACE_PENALTY Set the hop penalty of this B.A.T.M.A.N. adv. interface
|
|
||||||
#
|
#
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
@ -23,12 +14,10 @@ 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
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Compatiblity glue: Newer versions of batctl print a deprecation
|
# Compatiblity glue: Newer versions of batctl print a deprecation
|
||||||
|
@ -47,17 +36,50 @@ 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 () {
|
||||||
|
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
|
# 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_IFACE_PENALTY}"
|
# 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
|
||||||
|
|
||||||
|
throughput=$(ifquery -p "batman-throughput-override" "${hardif}")
|
||||||
|
if [ "${throughput}" ]; then
|
||||||
|
${MOCK} batctl hardif "${hardif}" throughput_override "${througput}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,6 +93,10 @@ case "${PHASE}" in
|
||||||
create)
|
create)
|
||||||
# Main B.A.T.M.A.N. adv. interface
|
# Main B.A.T.M.A.N. adv. interface
|
||||||
if [ "${IF_BATMAN_IFACES}" ]; then
|
if [ "${IF_BATMAN_IFACES}" ]; then
|
||||||
|
if [ "${IF_BATMAN_ROUTING_ALGO}" ]; then
|
||||||
|
set_routing_algo
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -d "/sys/class/net/${IFACE}" ]; then
|
if [ ! -d "/sys/class/net/${IFACE}" ]; then
|
||||||
batctl "${mesh_if_param}" "${IFACE}" interface create || true
|
batctl "${mesh_if_param}" "${IFACE}" interface create || true
|
||||||
fi
|
fi
|
||||||
|
@ -78,14 +104,11 @@ 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
|
||||||
|
set_hardif_options
|
||||||
# B.A.T.M.A.N. adv. underlying interface
|
|
||||||
elif [ "${IF_BATMAN_IFACE_PENALTY}" ]; then
|
|
||||||
set_iface_penalty
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue