cf-socket: log successful interface bind

When the setsockopt SO_BINDTODEVICE operation succeeds, output that in
the verbose output.

Ref: #11599
Closes #11608
This commit is contained in:
Daniel Stenberg 2023-08-07 09:58:47 +02:00
parent 90d0e0f83d
commit 80ea7f7fc2
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -444,29 +444,24 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
/* interface */ /* interface */
if(!is_host) { if(!is_host) {
#ifdef SO_BINDTODEVICE #ifdef SO_BINDTODEVICE
/* I am not sure any other OSs than Linux that provide this feature, /*
* and at the least I cannot test. --Ben * This binds the local socket to a particular interface. This will
* force even requests to other local interfaces to go out the external
* interface. Only bind to the interface when specified as interface,
* not just as a hostname or ip address.
* *
* This feature allows one to tightly bind the local socket to a * The interface might be a VRF, eg: vrf-blue, which means it cannot be
* particular interface. This will force even requests to other * converted to an IP address and would fail Curl_if2ip. Simply try to
* local interfaces to go out the external interface. * use it straight away.
*
*
* Only bind to the interface when specified as interface, not just
* as a hostname or ip address.
*
* interface might be a VRF, eg: vrf-blue, which means it cannot be
* converted to an IP address and would fail Curl_if2ip. Simply try
* to use it straight away.
*/ */
if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
dev, (curl_socklen_t)strlen(dev) + 1) == 0) { dev, (curl_socklen_t)strlen(dev) + 1) == 0) {
/* This is typically "errno 1, error: Operation not permitted" if /* This is often "errno 1, error: Operation not permitted" if you're
* you're not running as root or another suitable privileged * not running as root or another suitable privileged user. If it
* user. * succeeds it means the parameter was a valid interface and not an IP
* If it succeeds it means the parameter was a valid interface and * address. Return immediately.
* not an IP address. Return immediately.
*/ */
infof(data, "socket successfully bound to interface '%s'", dev);
return CURLE_OK; return CURLE_OK;
} }
#endif #endif