- if a socket is forced always use the forced socket ip as source
(if a connection exists with different ip as source, open a new
one with the forced ip).
... | ... |
@@ -123,6 +123,11 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len) |
123 | 123 |
{ |
124 | 124 |
struct dest_info new_dst; |
125 | 125 |
str outb; |
126 |
+#ifdef USE_TCP |
|
127 |
+ union sockaddr_union* from; |
|
128 |
+ union sockaddr_union local_addr; |
|
129 |
+#endif |
|
130 |
+ |
|
126 | 131 |
outb.s = buf; |
127 | 132 |
outb.len = len; |
128 | 133 |
sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb); |
... | ... |
@@ -152,7 +157,14 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len) |
152 | 157 |
" support is disabled\n"); |
153 | 158 |
goto error; |
154 | 159 |
}else{ |
155 |
- if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){ |
|
160 |
+ from=0; |
|
161 |
+ if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) && |
|
162 |
+ dst->send_sock)) { |
|
163 |
+ local_addr=dst->send_sock->su; |
|
164 |
+ su_setport(&local_addr, 0); /* any local port will do */ |
|
165 |
+ from=&local_addr; |
|
166 |
+ } |
|
167 |
+ if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){ |
|
156 | 168 |
STATS_TX_DROPS; |
157 | 169 |
LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n"); |
158 | 170 |
goto error; |
... | ... |
@@ -167,7 +179,14 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len) |
167 | 179 |
" support is disabled\n"); |
168 | 180 |
goto error; |
169 | 181 |
}else{ |
170 |
- if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){ |
|
182 |
+ from=0; |
|
183 |
+ if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) && |
|
184 |
+ dst->send_sock)) { |
|
185 |
+ local_addr=dst->send_sock->su; |
|
186 |
+ su_setport(&local_addr, 0); /* any local port will do */ |
|
187 |
+ from=&local_addr; |
|
188 |
+ } |
|
189 |
+ if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){ |
|
171 | 190 |
STATS_TX_DROPS; |
172 | 191 |
LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n"); |
173 | 192 |
goto error; |