Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Added IP_FREEBIND flag durring socket initialization #1113

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cfg.lex
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ DST_BLST_TCP_IMASK dst_blacklist_tcp_imask
DST_BLST_TLS_IMASK dst_blacklist_tls_imask
DST_BLST_SCTP_IMASK dst_blacklist_sctp_imask

IP_FREE_BIND ip_free_bind|ip_freebind|ipfreebind

PORT port
STAT statistics
Expand Down Expand Up @@ -751,6 +752,7 @@ IMPORTFILE "import_file"
return DST_BLST_TLS_IMASK; }
<INITIAL>{DST_BLST_SCTP_IMASK} { count(); yylval.strval=yytext;
return DST_BLST_SCTP_IMASK; }
<INITIAL>{IP_FREE_BIND} { count(); yylval.strval=yytext; return IP_FREE_BIND; }
<INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
<INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
<INITIAL>{MAXBUFFER} { count(); yylval.strval=yytext; return MAXBUFFER; }
Expand Down
3 changes: 3 additions & 0 deletions cfg.y
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ extern char *default_routename;
%token DST_BLST_TCP_IMASK
%token DST_BLST_TLS_IMASK
%token DST_BLST_SCTP_IMASK
%token IP_FREE_BIND

%token PORT
%token STAT
Expand Down Expand Up @@ -869,6 +870,8 @@ assign_stm:
IF_DST_BLACKLIST(default_core_cfg.blst_sctp_imask=$3);
}
| DST_BLST_SCTP_IMASK error { yyerror("number(flags) expected"); }
| IP_FREE_BIND EQUAL intno { _sr_ip_free_bind=$3; }
| IP_FREE_BIND EQUAL error { yyerror("int value expected"); }
| PORT EQUAL NUMBER { port_no=$3; }
| STAT EQUAL STRING {
#ifdef STATS
Expand Down
1 change: 1 addition & 0 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ extern int rt_timer1_policy; /* "fast" timer, SCHED_OTHER */
extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */

extern int http_reply_parse;
extern int _sr_ip_free_bind;

#ifdef USE_DNS_CACHE
extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
Expand Down
15 changes: 13 additions & 2 deletions modules/sctp/sctp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,18 @@ static int sctp_init_sock_opt_common(int s, int af)
/* continue since this is not critical */
}
}


#if defined(IP_FREEBIND)
/* allow bind to non local address.
* useful when daemon started before network initialized */
optval = 1;
if (_sr_ip_free_bind && setsockopt(s, IPPROTO_IP, IP_FREEBIND,
(void*)&optval, sizeof(optval)) ==-1) {
LM_WARN("setsockopt freebind failed: %s\n", strerror(errno));
/* continue since this is not critical */
}
#endif

/* set receive buffer: SO_RCVBUF*/
if (cfg_get(sctp, sctp_cfg, so_rcvbuf)){
optval=cfg_get(sctp, sctp_cfg, so_rcvbuf);
Expand All @@ -479,7 +490,7 @@ static int sctp_init_sock_opt_common(int s, int af)
/* continue, non-critical */
}
}

/* set send buffer: SO_SNDBUF */
if (cfg_get(sctp, sctp_cfg, so_sndbuf)){
optval=cfg_get(sctp, sctp_cfg, so_sndbuf);
Expand Down
2 changes: 2 additions & 0 deletions receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#include <mem/dmalloc.h>
#endif

int _sr_ip_free_bind = 0;

unsigned int msg_no=0;
/* address preset vars */
str default_global_address={0,0};
Expand Down
11 changes: 11 additions & 0 deletions tcp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,17 @@ int tcp_init(struct socket_info* sock_info)
/* continue since this is not critical */
}
}

#if defined(IP_FREEBIND)
/* allow bind to non local address.
* useful when daemon started before network initialized */
if (_sr_ip_free_bind && setsockopt(sock_info->socket, IPPROTO_IP,
IP_FREEBIND, (void*)&optval, sizeof(optval)) ==-1) {
LM_WARN("setsockopt freebind failed: %s\n", strerror(errno));
/* continue since this is not critical */
}
#endif

#ifdef HAVE_TCP_DEFER_ACCEPT
/* linux only */
if ((optval=cfg_get(tcp, tcp_cfg, defer_accept))){
Expand Down
10 changes: 10 additions & 0 deletions udp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ int udp_init(struct socket_info* sock_info)
}
#endif

#if defined(IP_FREEBIND)
/* allow bind to non local address.
* useful when daemon started before network initialized */
optval = 1;
if (_sr_ip_free_bind && setsockopt(sock_info->socket, IPPROTO_IP,
IP_FREEBIND, (void*)&optval, sizeof(optval)) ==-1) {
LM_WARN("setsockopt freebind failed: %s\n", strerror(errno));
/* continue since this is not critical */
}
#endif
#ifdef USE_MCAST
if ((sock_info->flags & SI_IS_MCAST)
&& (setup_mcast_rcvr(sock_info->socket, addr)<0)){
Expand Down