list_match ${proto} ${IP_SUPPORTED_PROTOCOLS}
}
+# Returns true if all IP addresses are of the same protocol
+ip_protocol_match() {
+ local address="${1}"
+ shift
+
+ # Get protocol of the first address
+ local protocol="$(ip_detect_protocol "${address}")"
+
+ # Check if all other addresses match the protocol
+ for address in $@; do
+ local p="$(ip_detect_protocol "${address}")"
+
+ if [ "${p}" != "${protocol}" ]; then
+ return ${EXIT_FALSE}
+ fi
+ done
+
+ return ${EXIT_TRUE}
+}
+
ip_is_valid() {
local address=${1}
assert isset address
return ${EXIT_ERROR}
fi
- # Detect the IP protocol, which is important to decide which mode we have to use
- local remote_address_protocol="$(ip_detect_protocol "${remote_address}")"
-
- # If we could not detect the IP protocol something with
- # ${remote_address} is wrong
- if ! isset remote_address_protocol; then
- log ERROR "Could not determine remote address IP protocol"
- return ${EXIT_ERROR}
- fi
-
# We cannot mix IPv6 and IPv4
- if isset local_address && \
- [[ "${remote_address_protocol}" != "$(ip_detect_protocol "${local_address}")" ]] ; then
- log ERROR "Local and remote address\
- are not from the same IP protocol"
+ if isset local_address && ! ip_protocol_match "${remote_address}" "${local_address}"; then
+ log ERROR "Local and remote address are not of the same IP protocol"
return ${EXIT_ERROR}
fi
fi
# Determine the mode based on the IP protocol
+ local remote_address_protocol="$(ip_detect_protocol "${remote_address}")"
mode=$(ip_tunnel_convert_mode_to_iproute2_mode "${mode}" "${remote_address_protocol}")
log DEBUG "Creating tunnel device '${device}' (mode=${mode})..."