Browse code

core: extra flag when forcing a socket

- when forcing a socket set an extra send flag
(SND_F_FORCE_SOCKET), so that later we can tell if the socket in
the dst structure was forced or not (useful for forcing a
specific source ip on tcp or for keeping the forced socket
during dns failover in tm).
- added set_force_socket(msg, sock) and reset_force_socket(msg)
macros that should be used instead of directly setting
msg->force_send_socket (they take care of any extra work, like
setting/resetting flags).

Andrei Pelinescu-Onciul authored on 05/11/2009 13:43:38
Showing 3 changed files
... ...
@@ -1201,7 +1201,7 @@ match_cleanup:
1201 1201
 				ret=E_BUG;
1202 1202
 				goto error;
1203 1203
 			}
1204
-			msg->force_send_socket=(struct socket_info*)a->val[0].u.data;
1204
+			set_force_socket(msg, (struct socket_info*)a->val[0].u.data);
1205 1205
 			ret=1; /* continue processing */
1206 1206
 			break;
1207 1207
 
... ...
@@ -140,6 +140,7 @@ struct receive_info{
140 140
 /* send flags */
141 141
 #define SND_F_FORCE_CON_REUSE	1 /* reuse an existing connection or fail */
142 142
 #define SND_F_CON_CLOSE			2 /* close the connection after sending */
143
+#define SND_F_FORCE_SOCKET		4 /* send socket in dst is forced */
143 144
 
144 145
 typedef unsigned char  snd_flags_t;
145 146
 
... ...
@@ -467,4 +467,23 @@ int set_path_vector(struct sip_msg* msg, str* path);
467 467
 
468 468
 void reset_path_vector(struct sip_msg* msg);
469 469
 
470
+
471
+/** force a specific send socket for forwarding a request.
472
+ * @param msg - sip msg.
473
+ * @param fsocket - forced socket, pointer to struct socket_info, can be 0 (in
474
+ *                  which case it's equivalent to reset_force_socket()).
475
+ */
476
+#define set_force_socket(msg, fsocket) \
477
+	do { \
478
+		(msg)->force_send_socket=(fsocket); \
479
+		if ((msg)->force_send_socket) \
480
+			(msg)->fwd_send_flags |= SND_F_FORCE_SOCKET; \
481
+		else \
482
+			(msg)->fwd_send_flags &= ~SND_F_FORCE_SOCKET; \
483
+	} while (0)
484
+
485
+/** reset a previously forced send socket. */
486
+#define reset_force_socket(msg) set_force_socket(msg, 0)
487
+
488
+
470 489
 #endif