set_mtu_up() {
	local mtu=0 mtufound=0 endpoint output
	if [[ -n $MTU ]]; then
		cmd ip link set mtu "$MTU" up dev "$INTERFACE"
		return
	fi
	while read -r _ endpoint; do
		[[ $endpoint =~ ^\[?([a-z0-9:.]+)\]?:[0-9]+$ ]] || continue
		output="$(ip route get "${BASH_REMATCH[1]}" || true)"
		[[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ( $mtufound -eq 0 || ${BASH_REMATCH[1]} -lt $mtu ) ]] && mtu="${BASH_REMATCH[1]}" && mtufound=1
	done < <(wg show "$INTERFACE" endpoints)
	if [[ $mtufound -eq 0 ]]; then
		read -r output < <(ip route show default || true) || true
		[[ $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ]] && mtu="${BASH_REMATCH[1]}" && mtufound=1
	fi
	[[ $mtufound -eq 1 ]] || mtu=1500
	cmd ip link set mtu $(( mtu - 80 )) up dev "$INTERFACE"
}