Browse code

core: send_flags preliminary blacklist support

- send_flags_t contains now also a blacklist ignore mask (changed
to a structure).

Andrei Pelinescu-Onciul authored on 17/12/2009 07:39:53
Showing 8 changed files
... ...
@@ -1217,19 +1217,19 @@ match_cleanup:
1217 1217
 				ret=v;
1218 1218
 			break;
1219 1219
 		case SET_FWD_NO_CONNECT_T:
1220
-			msg->fwd_send_flags|= SND_F_FORCE_CON_REUSE;
1220
+			msg->fwd_send_flags.f|= SND_F_FORCE_CON_REUSE;
1221 1221
 			ret=1; /* continue processing */
1222 1222
 			break;
1223 1223
 		case SET_RPL_NO_CONNECT_T:
1224
-			msg->rpl_send_flags|= SND_F_FORCE_CON_REUSE;
1224
+			msg->rpl_send_flags.f|= SND_F_FORCE_CON_REUSE;
1225 1225
 			ret=1; /* continue processing */
1226 1226
 			break;
1227 1227
 		case SET_FWD_CLOSE_T:
1228
-			msg->fwd_send_flags|= SND_F_CON_CLOSE;
1228
+			msg->fwd_send_flags.f|= SND_F_CON_CLOSE;
1229 1229
 			ret=1; /* continue processing */
1230 1230
 			break;
1231 1231
 		case SET_RPL_CLOSE_T:
1232
-			msg->rpl_send_flags|= SND_F_CON_CLOSE;
1232
+			msg->rpl_send_flags.f|= SND_F_CON_CLOSE;
1233 1233
 			ret=1; /* continue processing */
1234 1234
 			break;
1235 1235
 /*
... ...
@@ -698,7 +698,7 @@ int forward_reply(struct sip_msg* msg)
698 698
 	}
699 699
 
700 700
 	dst.proto=msg->via2->proto;
701
-	dst.send_flags=msg->fwd_send_flags | msg->rpl_send_flags;
701
+	dst.send_flags.f=msg->fwd_send_flags.f | msg->rpl_send_flags.f;
702 702
 	if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
703 703
 #ifdef USE_COMP
704 704
 	dst.comp=msg->via2->comp_no;
... ...
@@ -158,7 +158,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
158 158
 			goto error;
159 159
 		}else{
160 160
 			from=0;
161
-			if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) &&
161
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
162 162
 						dst->send_sock)) {
163 163
 				local_addr=dst->send_sock->su;
164 164
 				su_setport(&local_addr, 0); /* any local port will do */
... ...
@@ -180,7 +180,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
180 180
 			goto error;
181 181
 		}else{
182 182
 			from=0;
183
-			if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) &&
183
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
184 184
 						dst->send_sock)) {
185 185
 				local_addr=dst->send_sock->su;
186 186
 				su_setport(&local_addr, 0); /* any local port will do */
... ...
@@ -142,7 +142,31 @@ struct receive_info{
142 142
 #define SND_F_CON_CLOSE			2 /* close the connection after sending */
143 143
 #define SND_F_FORCE_SOCKET		4 /* send socket in dst is forced */
144 144
 
145
-typedef unsigned char  snd_flags_t;
145
+struct snd_flags {
146
+	unsigned char f;          /* snd flags */
147
+	unsigned char blst_imask; /* blacklist ignore mask */
148
+};
149
+
150
+
151
+typedef struct snd_flags  snd_flags_t;
152
+
153
+#define SND_FLAGS_INIT(sflags) \
154
+	do{ \
155
+		(sflags)->f=0; \
156
+		(sflags)->blst_imask=0; \
157
+	}while(0)
158
+
159
+#define SND_FLAGS_OR(dst, src1, src2) \
160
+	do{ \
161
+		(dst)->f = (src1)->f | (src2)->f; \
162
+		(dst)->blst_imask = (src1)->blst_imask | (src2)->blst_imask; \
163
+	}while(0)
164
+
165
+#define SND_FLAGS_AND(dst, src1, src2) \
166
+	do{ \
167
+		(dst)->f = (src1)->f & (src2)->f; \
168
+		(dst)->blst_imask = (src1)->blst_imask & (src2)->blst_imask; \
169
+	}while(0)
146 170
 
147 171
 struct dest_info{
148 172
 	struct socket_info* send_sock;
... ...
@@ -757,7 +781,8 @@ inline static void init_dst_from_rcv(struct dest_info* dst,
757 757
 		dst->to=rcv->src_su;
758 758
 		dst->id=rcv->proto_reserved1;
759 759
 		dst->proto=rcv->proto;
760
-		dst->send_flags=0;
760
+		dst->send_flags.f=0;
761
+		dst->send_flags.blst_imask=0;
761 762
 #ifdef USE_COMP
762 763
 		dst->comp=rcv->comp;
763 764
 #endif
... ...
@@ -477,9 +477,9 @@ void reset_path_vector(struct sip_msg* msg);
477 477
 	do { \
478 478
 		(msg)->force_send_socket=(fsocket); \
479 479
 		if ((msg)->force_send_socket) \
480
-			(msg)->fwd_send_flags |= SND_F_FORCE_SOCKET; \
480
+			(msg)->fwd_send_flags.f |= SND_F_FORCE_SOCKET; \
481 481
 		else \
482
-			(msg)->fwd_send_flags &= ~SND_F_FORCE_SOCKET; \
482
+			(msg)->fwd_send_flags.f &= ~SND_F_FORCE_SOCKET; \
483 483
 	} while (0)
484 484
 
485 485
 /** reset a previously forced send socket. */
... ...
@@ -172,7 +172,7 @@ struct tcp_connection{
172 172
 	atomic_t refcnt;
173 173
 	enum sip_protos type; /* PROTO_TCP or a protocol over it, e.g. TLS */
174 174
 	unsigned short flags; /* connection related flags */
175
-	unsigned short send_flags; /* special send flags */
175
+	snd_flags_t send_flags; /* special send flags */
176 176
 	enum tcp_conn_states state; /* connection state */
177 177
 	void* extra_data; /* extra data associated to the connection, 0 for tcp*/
178 178
 	struct timer_ln timer;
... ...
@@ -192,9 +192,13 @@ struct tcp_connection{
192 192
 
193 193
 /* helper macros */
194 194
 
195
-#define tcpconn_set_send_flags(c, snd_flags) ((c)->send_flags|=(snd_flags))
195
+#define tcpconn_set_send_flags(c, snd_flags) \
196
+	do{ \
197
+		(c)->send_flags.f|=(snd_flags).f; \
198
+		(c)->send_flags.blst_imask|=(snd_flags).blst_imask; \
199
+	}while(0)
196 200
 
197
-#define tcpconn_close_after_send(c)	((c)->send_flags & SND_F_CON_CLOSE)
201
+#define tcpconn_close_after_send(c)	((c)->send_flags.f & SND_F_CON_CLOSE)
198 202
 
199 203
 #define TCP_RCV_INFO(c) (&(c)->rcv)
200 204
 
... ...
@@ -1780,7 +1780,7 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
1780 1780
 				c=0;
1781 1781
 			}
1782 1782
 			/* check if connect() is disabled */
1783
-			if (unlikely((dst->send_flags & SND_F_FORCE_CON_REUSE) ||
1783
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_CON_REUSE) ||
1784 1784
 							cfg_get(tcp, tcp_cfg, no_connect)))
1785 1785
 				return -1;
1786 1786
 			DBG("tcp_send: no open tcp connection found, opening new one\n");
... ...
@@ -1927,7 +1927,7 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
1927 1927
 				}
1928 1928
 				LOG(L_INFO, "tcp_send: quick connect for %p\n", c);
1929 1929
 				TCP_STATS_ESTABLISHED(S_CONN_CONNECT);
1930
-				if (unlikely(dst->send_flags & SND_F_CON_CLOSE)){
1930
+				if (unlikely(dst->send_flags.f & SND_F_CON_CLOSE)){
1931 1931
 					/* if close-after-send requested, don't bother
1932 1932
 					   sending the fd back to tcp_main, try closing it
1933 1933
 					   immediately (no other tcp_send should use it,
... ...
@@ -2224,7 +2224,7 @@ error:
2224 2224
 			TCP_STATS_ESTABLISHED(c->state);
2225 2225
 			c->state=S_CONN_OK;
2226 2226
 	}
2227
-	if (unlikely(dst->send_flags & SND_F_CON_CLOSE)){
2227
+	if (unlikely(dst->send_flags.f & SND_F_CON_CLOSE)){
2228 2228
 		/* close after write => send EOF request to tcp_main */
2229 2229
 		c->state=S_CONN_BAD;
2230 2230
 		c->timeout=get_ticks_raw();
... ...
@@ -964,7 +964,7 @@ again:
964 964
 			con=(struct tcp_connection*)fm->data;
965 965
 			if (unlikely(con->state==S_CONN_BAD)){
966 966
 				resp=CONN_ERROR;
967
-				if (!(con->send_flags & SND_F_CON_CLOSE))
967
+				if (!(con->send_flags.f & SND_F_CON_CLOSE))
968 968
 					LOG(L_WARN, "WARNING: tcp_receive: handle_io: F_TCPCONN"
969 969
 							" connection marked as bad: %p id %d refcnt %d\n",
970 970
 							con, con->id, atomic_get(&con->refcnt));