Module: kamailio
Branch: master
Commit: 14d69ddb39cb3072fd51d6f8f053430b0750e2ba
URL:
https://github.com/kamailio/kamailio/commit/14d69ddb39cb3072fd51d6f8f053430…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-05-17T10:31:22+02:00
core: allow to set advertised address to -l command line parameter
* -l listen-address/advertised-address
* -l udp:10.0.0.10:5080/1.2.3.4:5060
---
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/14d69ddb39cb3072fd51d6f8f053430…
Patch:
https://github.com/kamailio/kamailio/commit/14d69ddb39cb3072fd51d6f8f053430…
---
diff --git a/src/main.c b/src/main.c
index 95a7c9e001..e680d92e69 100644
--- a/src/main.c
+++ b/src/main.c
@@ -177,11 +177,14 @@ Options:\n\
-I Print more internal compile flags and options\n\
-K Turn on \"via:\" host checking when forwarding replies\n\
-l address Listen on the specified address/interface (multiple -l\n\
- mean listening on more addresses). The address format is\n\
- [proto:]addr_lst[:port], where proto=udp|tcp|tls|sctp, \n\
- addr_lst= addr|(addr, addr_lst) and \n\
- addr= host|ip_address|interface_name. \n\
+ mean listening on more addresses). The address format is\n\
+ [proto:]addr_lst[:port][/advaddr], \n\
+ where proto=udp|tcp|tls|sctp, \n\
+ addr_lst= addr|(addr, addr_lst), \n\
+ addr=host|ip_address|interface_name and \n\
+ advaddr=addr[:port] (advertised address). \n\
E.g: -l localhost, -l udp:127.0.0.1:5080, -l eth0:5062,\n\
+ -l udp:127.0.0.1:5080/1.2.3.4:5060,\n\
-l \"sctp:(eth0)\", -l \"(eth0, eth1,
127.0.0.1):5065\".\n\
The default behaviour is to listen on all the interfaces.\n\
-L path Modules search path (default: " MODS_DIR ")\n\
@@ -1885,6 +1888,8 @@ int main(int argc, char** argv)
int tmp_len;
int port;
int proto;
+ char *ahost = NULL;
+ int aport = 0;
char *options;
int ret;
unsigned int seed;
@@ -1895,6 +1900,9 @@ int main(int argc, char** argv)
char *p;
struct stat st = {0};
+#define KSR_TBUF_SIZE 512
+ char tbuf[KSR_TBUF_SIZE];
+
int option_index = 0;
#define KARGOPTVAL 1024
@@ -2321,7 +2329,38 @@ int main(int argc, char** argv)
#endif
break;
case 'l':
- if ((n_lst=parse_phostport_mh(optarg, &tmp, &tmp_len,
+ p = strrchr(optarg, '/');
+ if(p==NULL) {
+ p = optarg;
+ } else {
+ if(strlen(optarg)>=KSR_TBUF_SIZE-1) {
+ fprintf(stderr, "listen value too long: %s\n",
+ optarg);
+ goto error;
+ }
+ strcpy(tbuf, optarg);
+ p = strrchr(tbuf, '/');
+ if(p==NULL) {
+ fprintf(stderr, "unexpected bug for listen: %s\n",
+ optarg);
+ goto error;
+ }
+ *p = '\0';
+ p++;
+ tmp_len = 0;
+ if(parse_phostport(p, &ahost, &tmp_len, &aport,
+ &proto)<0)
+ {
+ fprintf(stderr, "listen value with invalid advertise: %s\n",
+ optarg);
+ goto error;
+ }
+ if(ahost) {
+ ahost[tmp_len] = '\0';
+ }
+ p = tbuf;
+ }
+ if ((n_lst=parse_phostport_mh(p, &tmp, &tmp_len,
&port, &proto))==0){
fprintf(stderr, "bad -l address specifier: %s\n"
"Check disabled protocols\n",
@@ -2329,9 +2368,10 @@ int main(int argc, char** argv)
goto error;
}
/* add a new addr. to our address list */
- if (add_listen_iface(n_lst->name, n_lst->next, port,
- proto, n_lst->flags)!=0){
- fprintf(stderr, "failed to add new listen address\n");
+ if (add_listen_advertise_iface(n_lst->name, n_lst->next, port,
+ proto, ahost, aport, n_lst->flags)!=0){
+ fprintf(stderr, "failed to add new listen address: %s\n",
+ optarg);
free_name_lst(n_lst);
goto error;
}