Skip to content

Commit c03799f

Browse files
committed
net: bind TCP listeners only in main
1 parent 72b59a9 commit c03799f

4 files changed

Lines changed: 29 additions & 16 deletions

File tree

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static const struct main_script main_script[] = {
234234
FN_HNDLR(fix_rls, !=, 0, "routing lists"),
235235
FN_HNDLR(init_log_level, !=, 0, "logging levels"),
236236
FN_HNDLR(init_log_event_cons, <, 0, "log event consumer"),
237-
FN_HNDLR(trans_init_all_listeners, <, 0, "all SIP listeners"),
237+
FN_HNDLR(trans_init_udp_listeners, <, 0, "all SIP listeners"),
238238
FN_HNDLR(init_script_reload, <, 0, "cfg reload ctx"),
239239
FN_HNDLR(init_suid, ==, -1, "do_suid"),
240240
FN_HNDLR(run_post_fork_handlers, <, 0, "post-fork handlers"),

net/net_tcp.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,8 +1689,19 @@ static void tcp_main_server(void)
16891689
if ( is_tcp_based_proto(n) )
16901690
for( sif=protos[n].listeners ; sif ; sif=sif->next ) {
16911691
struct socket_info* si = &sif->socket_info;
1692-
if ( (si->socket!=-1) &&
1693-
reactor_add_reader( si->socket, F_TCP_LISTENER,
1692+
if (protos[n].tran.init_listener(si)<0) {
1693+
LM_ERR("failed to init listener [%.*s], proto %s\n",
1694+
si->name.len, si->name.s,
1695+
protos[n].name );
1696+
goto error;
1697+
}
1698+
if (protos[n].tran.bind_listener && protos[n].tran.bind_listener(si)<0) {
1699+
LM_ERR("failed to bind listener [%.*s], proto %s\n",
1700+
si->name.len, si->name.s,
1701+
protos[n].name );
1702+
goto error;
1703+
}
1704+
if(reactor_add_reader( si->socket, F_TCP_LISTENER,
16941705
RCT_PRIO_NET, si)<0 ) {
16951706
LM_ERR("failed to add listen socket to reactor\n");
16961707
goto error;

net/trans.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int fix_all_socket_lists(void)
228228
}
229229

230230

231-
int trans_init_all_listeners(void)
231+
int trans_init_udp_listeners(void)
232232
{
233233
struct socket_info_full *sif;
234234
int i;
@@ -237,17 +237,19 @@ int trans_init_all_listeners(void)
237237
if (protos[i].id != PROTO_NONE)
238238
for( sif=protos[i].listeners ; sif ; sif=sif->next ) {
239239
struct socket_info *si = &sif->socket_info;
240-
if (protos[i].tran.init_listener(si)<0) {
241-
LM_ERR("failed to init listener [%.*s], proto %s\n",
242-
si->name.len, si->name.s,
243-
protos[i].name );
244-
return -1;
245-
}
246-
if (protos[i].tran.bind_listener && protos[i].tran.bind_listener(si)<0) {
247-
LM_ERR("failed to bind listener [%.*s], proto %s\n",
248-
si->name.len, si->name.s,
249-
protos[i].name );
250-
return -1;
240+
if (is_udp_based_proto(si->proto)) {
241+
if (protos[i].tran.init_listener(si)<0) {
242+
LM_ERR("failed to init listener [%.*s], proto %s\n",
243+
si->name.len, si->name.s,
244+
protos[i].name );
245+
return -1;
246+
}
247+
if (protos[i].tran.bind_listener && protos[i].tran.bind_listener(si)<0) {
248+
LM_ERR("failed to bind listener [%.*s], proto %s\n",
249+
si->name.len, si->name.s,
250+
protos[i].name );
251+
return -1;
252+
}
251253
}
252254
/* set first IPv4 and IPv6 listeners for this proto */
253255
if ((si->address.af==AF_INET) &&

net/trans.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int fix_all_socket_lists(void);
115115
/*
116116
* init all registered listening sockets
117117
*/
118-
int trans_init_all_listeners(void);
118+
int trans_init_udp_listeners(void);
119119

120120
void print_all_socket_lists(void);
121121

0 commit comments

Comments
 (0)