Skip to content

Commit

Permalink
Added ipresolve option
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec authored and gaul committed Mar 13, 2024
1 parent 31676f6 commit a5cdd05
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/man/s3fs.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 23 additions & 1 deletion src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down
2 changes: 2 additions & 0 deletions src/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class S3fsCurl
static std::string proxy_url;
static bool proxy_http;
static std::string proxy_userpwd; // load from file(<username>:<passphrase>)
static long ipresolve_type; // this value is a libcurl symbol.

// variables
CURL* hCurl;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
8 changes: 8 additions & 0 deletions src/s3fs_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a5cdd05

Please sign in to comment.