Browse code

http_client: new param netinterface to set curl network interface

Daniel-Constantin Mierla authored on 17/01/2020 11:39:11
Showing 3 changed files
... ...
@@ -57,6 +57,7 @@ typedef struct
57 57
 	char *failovercon;
58 58
 	char *useragent;
59 59
 	char *hdrs;
60
+	char *netinterface;
60 61
 	unsigned int authmethod;
61 62
 	unsigned int http_proxy_port;
62 63
 	unsigned int tlsversion;
... ...
@@ -249,7 +250,9 @@ static int curL_query_url(struct sip_msg *_m, const char *_url, str *_dst,
249 250
 	if(params->http_follow_redirect) {
250 251
 		LM_DBG("Following redirects for this request! \n");
251 252
 	}
252
-
253
+	if(params->netinterface != NULL) {
254
+		res |= curl_easy_setopt(curl, CURLOPT_INTERFACE, params->netinterface);
255
+	}
253 256
 
254 257
 	res |= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
255 258
 	res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)(&stream));
... ...
@@ -576,6 +579,7 @@ int curl_con_query_url_f(struct sip_msg *_m, const str *connection,
576 579
 	query_params.keep_connections = conn->keep_connections;
577 580
 	query_params.oneline = 0;
578 581
 	query_params.maxdatasize = maxdatasize;
582
+	query_params.netinterface = default_netinterface;
579 583
 	query_params.http_proxy_port = conn->http_proxy_port;
580 584
 	if(conn->failover.s) {
581 585
 		failovercon = as_asciiz(&conn->failover);
... ...
@@ -654,6 +658,7 @@ int http_client_query(
654 658
 	query_params.http_follow_redirect = default_http_follow_redirect;
655 659
 	query_params.oneline = default_query_result;
656 660
 	query_params.maxdatasize = default_query_maxdatasize;
661
+	query_params.netinterface = default_netinterface;
657 662
 	if(default_useragent.s != NULL && default_useragent.len > 0) {
658 663
 		query_params.useragent = default_useragent.s;
659 664
 	}
... ...
@@ -100,6 +100,8 @@ unsigned int default_authmethod =
100 100
 		CURLAUTH_BASIC
101 101
 		| CURLAUTH_DIGEST; /*!< authentication method - Basic, Digest or both */
102 102
 
103
+char *default_netintrface = 0; /*!< local network interface */
104
+
103 105
 /*!< Default http query result mode
104 106
  * - 0: return full result
105 107
  * - 1: return first line only */
... ...
@@ -204,6 +206,7 @@ static param_export_t params[] = {
204 206
 	{"keep_connections", PARAM_INT, &default_keep_connections },
205 207
 	{"query_result", PARAM_INT, &default_query_result },
206 208
 	{"query_maxdatasize", PARAM_INT, &default_query_maxdatasize },
209
+	{"netinterface", PARAM_STRING,  &default_netinterface },
207 210
 	{0, 0, 0}
208 211
 };
209 212
 
... ...
@@ -69,6 +69,8 @@ extern counter_handle_t connections; /* Number of connection definitions */
69 69
 extern counter_handle_t connok;		 /* Successful Connection attempts */
70 70
 extern counter_handle_t connfail;	/* Failed Connection attempts */
71 71
 
72
+extern char *default_netinterface;
73
+
72 74
 /* Curl  stream object  */
73 75
 typedef struct
74 76
 {