Browse code

tcp: use the forced socket ip as source

- 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).

Andrei Pelinescu-Onciul authored on 05/11/2009 15:21:35
Showing 1 changed files
... ...
@@ -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 152
 					" support is disabled\n");
153 153
 			goto error;
154 154
 		}else{
155
-			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
155
+			from=0;
156
+			if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) &&
157
+						dst->send_sock)) {
158
+				local_addr=dst->send_sock->su;
159
+				su_setport(&local_addr, 0); /* any local port will do */
160
+				from=&local_addr;
161
+			}
162
+			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
156 163
 				STATS_TX_DROPS;
157 164
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
158 165
 				goto error;
... ...
@@ -167,7 +179,14 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
167 167
 					" support is disabled\n");
168 168
 			goto error;
169 169
 		}else{
170
-			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
170
+			from=0;
171
+			if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) &&
172
+						dst->send_sock)) {
173
+				local_addr=dst->send_sock->su;
174
+				su_setport(&local_addr, 0); /* any local port will do */
175
+				from=&local_addr;
176
+			}
177
+			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
171 178
 				STATS_TX_DROPS;
172 179
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
173 180
 				goto error;