This is a a request to validate and incorporate a custom source routing feature in the driver. If possible we ask to incorporate this in the standard driver distribution for supportability purposes.
Based on mongocxx-driver version 3.6.0, the corresponding custom function was added to the driver the source. The source IP binding was performed only in the mongoc_client_connect_tcp function and the mongoc_topology_scanner_tcp_initiate function. Please validate if there are any other cases to consider.
extern char global_local_uri[16];
|
char global_local_uri[16];
|
|
void
|
mongoc_uri_set_local_uri (const char *local_uri)
|
{
|
if (0 < strlen (local_uri)) {
|
strcpy(global_local_uri, local_uri);
|
} else {
|
strcpy(global_local_uri, "");
|
}
|
}
|
|
static bool
|
mongoc_uri_apply_options (mongoc_uri_t *uri,
|
const bson_t *options,
|
bool from_dns,
|
bson_error_t *error)
|
{
|
|
...
|
|
} else if (!strcmp (key, MONGOC_URI_LOCALURI)) {
|
mongoc_uri_set_local_uri (value);
|
|
}
|
|
...
|
|
}
|
mongoc_stream_t *
|
mongoc_client_connect_tcp (int32_t connecttimeoutms,
|
const mongoc_host_list_t *host,
|
bson_error_t *error)
|
{
|
|
...
|
|
if (strlen(global_local_uri) > 0)
|
{
|
struct sockaddr_in server_addr_in = {0};
|
memset (&server_addr_in, 0, sizeof (server_addr_in));
|
server_addr_in.sin_family = AF_INET;
|
server_addr_in.sin_addr.s_addr = inet_addr(global_local_uri);
|
mongoc_socket_bind (sock,
|
(struct sockaddr *) &server_addr_in,
|
sizeof (server_addr_in));
|
}
|
|
...
|
|
}
|
mongoc_stream_t *
|
|
_mongoc_topology_scanner_tcp_initiate (mongoc_async_cmd_t *acmd)
|
{
|
...
|
|
if (strlen(global_local_uri) > 0)
|
{
|
struct sockaddr_in server_addr_in = {0};
|
memset (&server_addr_in, 0, sizeof (server_addr_in));
|
server_addr_in.sin_family = AF_INET;
|
server_addr_in.sin_addr.s_addr = inet_addr(global_local_uri);
|
mongoc_socket_bind (sock,
|
(struct sockaddr *) &server_addr_in,
|
sizeof (server_addr_in));
|
}
|
|
...
|
|
}
|