@@ -141,7 +141,7 @@ int tcp_connect_blocking(int fd, const struct sockaddr *servaddr,
141
141
}
142
142
143
143
int tcp_sync_connect_fd (union sockaddr_union * src , union sockaddr_union * dst ,
144
- enum sip_protos proto , struct tcp_conn_profile * prof )
144
+ enum sip_protos proto , struct tcp_conn_profile * prof , enum si_flags flags )
145
145
{
146
146
int s ;
147
147
union sockaddr_union my_name ;
@@ -153,15 +153,16 @@ int tcp_sync_connect_fd(union sockaddr_union* src, union sockaddr_union* dst,
153
153
goto error ;
154
154
}
155
155
156
- if (tcp_init_sock_opt (s , prof )< 0 ){
156
+ if (tcp_init_sock_opt (s , prof , flags )< 0 ){
157
157
LM_ERR ("tcp_init_sock_opt failed\n" );
158
158
goto error ;
159
159
}
160
160
161
161
if (src ) {
162
162
my_name_len = sockaddru_len (* src );
163
163
memcpy ( & my_name , src , my_name_len );
164
- su_setport ( & my_name , 0 );
164
+ if (!(flags & SI_REUSEPORT ))
165
+ su_setport ( & my_name , 0 );
165
166
if (bind (s , & my_name .s , my_name_len )!= 0 ) {
166
167
LM_ERR ("bind failed (%d) %s\n" , errno ,strerror (errno ));
167
168
goto error ;
@@ -187,7 +188,7 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock,
187
188
struct tcp_connection * con ;
188
189
int s ;
189
190
190
- s = tcp_sync_connect_fd (& send_sock -> su , server , send_sock -> proto , prof );
191
+ s = tcp_sync_connect_fd (& send_sock -> su , server , send_sock -> proto , prof , send_sock -> flags );
191
192
if (s < 0 )
192
193
return NULL ;
193
194
@@ -231,14 +232,15 @@ int tcp_async_connect(struct socket_info* send_sock,
231
232
return -1 ;
232
233
}
233
234
234
- if (tcp_init_sock_opt (fd , prof )< 0 ){
235
+ if (tcp_init_sock_opt (fd , prof , send_sock -> flags )< 0 ){
235
236
LM_ERR ("tcp_init_sock_opt failed\n" );
236
237
goto error ;
237
238
}
238
239
239
240
my_name_len = sockaddru_len (send_sock -> su );
240
241
memcpy ( & my_name , & send_sock -> su , my_name_len );
241
- su_setport ( & my_name , 0 );
242
+ if (!(send_sock -> flags & SI_REUSEPORT ))
243
+ su_setport ( & my_name , 0 );
242
244
if (bind (fd , & my_name .s , my_name_len )!= 0 ) {
243
245
LM_ERR ("bind failed (%d) %s\n" , errno ,strerror (errno ));
244
246
goto error ;
0 commit comments