Skip to content

Commit

Permalink
add option to support curl binding local interface/ip for sbi calls
Browse files Browse the repository at this point in the history
  • Loading branch information
spencersevilla committed Feb 10, 2025
1 parent 056b50c commit 24ff3e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/sbi/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ void ogs_sbi_client_remove(ogs_sbi_client_t *client)
ogs_free(client->cert);
if (client->sslkeylog)
ogs_free(client->sslkeylog);
if (client->local_if)
ogs_free(client->local_if);

if (client->fqdn)
ogs_free(client->fqdn);
Expand Down Expand Up @@ -558,6 +560,10 @@ static connection_t *connection_add(
curl_easy_setopt(conn->easy, CURLOPT_RESOLVE, conn->resolve_list);
}

if (client->local_if) {
curl_easy_setopt(conn->easy, CURLOPT_INTERFACE, client->local_if);
}

curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn);
curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb);
curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, conn);
Expand Down
1 change: 1 addition & 0 deletions lib/sbi/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef struct ogs_sbi_client_s {
OpenAPI_uri_scheme_e scheme;
bool insecure_skip_verify;
char *cacert, *private_key, *cert, *sslkeylog;
char *local_if;

char *fqdn;
uint16_t fqdn_port;
Expand Down
10 changes: 10 additions & 0 deletions lib/sbi/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ ogs_sbi_client_t *ogs_sbi_context_parse_client_config(ogs_yaml_iter_t *iter)
const char *client_private_key = NULL;
const char *client_cert = NULL;
const char *client_sslkeylog = NULL;
const char *local_if = NULL;

bool rc;

Expand Down Expand Up @@ -1116,6 +1117,8 @@ ogs_sbi_client_t *ogs_sbi_context_parse_client_config(ogs_yaml_iter_t *iter)
client_cert = ogs_yaml_iter_value(iter);
} else if (!strcmp(key, "client_sslkeylogfile")) {
client_sslkeylog = ogs_yaml_iter_value(iter);
} else if (!strcmp(key, "interface")) {
local_if = ogs_yaml_iter_value(iter);
}
}

Expand Down Expand Up @@ -1192,6 +1195,13 @@ ogs_sbi_client_t *ogs_sbi_context_parse_client_config(ogs_yaml_iter_t *iter)
ogs_assert(client->sslkeylog);
}

if (local_if) {
if (client->local_if)
ogs_free(client->local_if);
client->local_if = ogs_strdup(local_if);
ogs_assert(client->local_if);
}

if ((!client_private_key && client_cert) ||
(client_private_key && !client_cert)) {
ogs_error("Either the private key or certificate is missing.");
Expand Down

0 comments on commit 24ff3e0

Please sign in to comment.