diff --git a/doc/man/s3fs.1.in b/doc/man/s3fs.1.in index d929edf3d7..30631a0b04 100644 --- a/doc/man/s3fs.1.in +++ b/doc/man/s3fs.1.in @@ -418,6 +418,12 @@ Username and passphrase are valid only for HTTP schema. If the HTTP proxy does not require authentication, this option is not required. Separate the username and passphrase with a ':' character and specify each as a URL-encoded string. .TP +\fB\-o\fR ipresolve (default="whatever") +Select what type of IP addresses to use when establishing a connection. +Default('whatever') can use addresses of all IP versions(IPv4 and IPv6) that your system allows. +If you specify 'IPv4', only IPv4 addresses are used. +And when 'IPv6' is specified, only IPv6 addresses will be used. +.TP \fB\-o\fR logfile - specify the log output file. s3fs outputs the log file to syslog. Alternatively, if s3fs is started with the "-f" option specified, the log will be output to the stdout/stderr. You can use this option to specify the log file that s3fs outputs. diff --git a/src/curl.cpp b/src/curl.cpp index a54ed32ce5..55d16e7847 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -130,6 +130,7 @@ bool S3fsCurl::requester_pays = false; // default std::string S3fsCurl::proxy_url; bool S3fsCurl::proxy_http = false; std::string S3fsCurl::proxy_userpwd; +long S3fsCurl::ipresolve_type = CURL_IPRESOLVE_WHATEVER; //------------------------------------------------------------------- // Class methods for S3fsCurl @@ -1174,6 +1175,23 @@ bool S3fsCurl::SetProxyUserPwd(const char* file) return true; } +bool S3fsCurl::SetIPResolveType(const char* value) +{ + if(!value){ + return false; + } + if(0 == strcasecmp(value, "ipv4")){ + S3fsCurl::ipresolve_type = CURL_IPRESOLVE_V4; + }else if(0 == strcasecmp(value, "ipv6")){ + S3fsCurl::ipresolve_type = CURL_IPRESOLVE_V6; + }else if(0 == strcasecmp(value, "whatever")){ // = default type + S3fsCurl::ipresolve_type = CURL_IPRESOLVE_WHATEVER; + }else{ + return false; + } + return true; +} + // cppcheck-suppress unmatchedSuppression // cppcheck-suppress constParameter // cppcheck-suppress constParameterCallback @@ -1949,7 +1967,11 @@ bool S3fsCurl::ResetHandle(AutoLock::Type locktype) if(CURLE_OK != curl_easy_setopt(hCurl, S3FS_CURLOPT_KEEP_SENDING_ON_ERROR, 1) && !run_once){ S3FS_PRN_WARN("The S3FS_CURLOPT_KEEP_SENDING_ON_ERROR option could not be set. For maximize performance you need to enable this option and you should use libcurl 7.51.0 or later."); } - + if(CURL_IPRESOLVE_WHATEVER != S3fsCurl::ipresolve_type){ // CURL_IPRESOLVE_WHATEVER is default, so not need to set. + if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_IPRESOLVE, S3fsCurl::ipresolve_type)){ + return false; + } + } if(type != REQTYPE::IAMCRED && type != REQTYPE::IAMROLE){ // REQTYPE::IAMCRED and REQTYPE::IAMROLE are always HTTP if(0 == S3fsCurl::ssl_verify_hostname){ diff --git a/src/curl.h b/src/curl.h index e382ed11b9..e288c8545e 100644 --- a/src/curl.h +++ b/src/curl.h @@ -156,6 +156,7 @@ class S3fsCurl static std::string proxy_url; static bool proxy_http; static std::string proxy_userpwd; // load from file(:) + static long ipresolve_type; // this value is a libcurl symbol. // variables CURL* hCurl; @@ -340,6 +341,7 @@ class S3fsCurl static bool IsRequesterPays() { return S3fsCurl::requester_pays; } static bool SetProxy(const char* url); static bool SetProxyUserPwd(const char* userpwd); + static bool SetIPResolveType(const char* value); // methods bool CreateCurlHandle(bool only_pool = false, bool remake = false); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index ca17fe727b..1e633a2f44 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -5434,6 +5434,14 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar } return 0; } + else if(is_prefix(arg, "ipresolve=")){ + const char* pipresolve = &arg[strlen("ipresolve=")]; + if(!S3fsCurl::SetIPResolveType(pipresolve)){ + S3FS_PRN_EXIT("failed to ip resolve option value(%s).", pipresolve); + return -1; + } + return 0; + } // // log file option // diff --git a/src/s3fs_help.cpp b/src/s3fs_help.cpp index fad50a6d4f..735c48590a 100644 --- a/src/s3fs_help.cpp +++ b/src/s3fs_help.cpp @@ -527,6 +527,14 @@ static constexpr char help_string[] = " Separate the username and passphrase with a ':' character and\n" " specify each as a URL-encoded string.\n" "\n" + " ipresolve (default=\"whatever\")\n" + " Select what type of IP addresses to use when establishing a\n" + " connection.\n" + " Default('whatever') can use addresses of all IP versions(IPv4 and\n" + " IPv6) that your system allows. If you specify 'IPv4', only IPv4\n" + " addresses are used. And when 'IPv6'is specified, only IPv6 addresses\n" + " will be used.\n" + "\n" " logfile - specify the log output file.\n" " s3fs outputs the log file to syslog. Alternatively, if s3fs is\n" " started with the \"-f\" option specified, the log will be output\n"