Browse Source

core: send_flags preliminary blacklist support

- send_flags_t contains now also a blacklist ignore mask (changed
  to a structure).
Andrei Pelinescu-Onciul 15 years ago
parent
commit
8cf5dde505
8 changed files with 47 additions and 18 deletions
  1. 4 4
      action.c
  2. 1 1
      forward.c
  3. 2 2
      forward.h
  4. 27 2
      ip_addr.h
  5. 2 2
      parser/msg_parser.h
  6. 7 3
      tcp_conn.h
  7. 3 3
      tcp_main.c
  8. 1 1
      tcp_read.c

+ 4 - 4
action.c

@@ -1217,19 +1217,19 @@ match_cleanup:
 				ret=v;
 			break;
 		case SET_FWD_NO_CONNECT_T:
-			msg->fwd_send_flags|= SND_F_FORCE_CON_REUSE;
+			msg->fwd_send_flags.f|= SND_F_FORCE_CON_REUSE;
 			ret=1; /* continue processing */
 			break;
 		case SET_RPL_NO_CONNECT_T:
-			msg->rpl_send_flags|= SND_F_FORCE_CON_REUSE;
+			msg->rpl_send_flags.f|= SND_F_FORCE_CON_REUSE;
 			ret=1; /* continue processing */
 			break;
 		case SET_FWD_CLOSE_T:
-			msg->fwd_send_flags|= SND_F_CON_CLOSE;
+			msg->fwd_send_flags.f|= SND_F_CON_CLOSE;
 			ret=1; /* continue processing */
 			break;
 		case SET_RPL_CLOSE_T:
-			msg->rpl_send_flags|= SND_F_CON_CLOSE;
+			msg->rpl_send_flags.f|= SND_F_CON_CLOSE;
 			ret=1; /* continue processing */
 			break;
 /*

+ 1 - 1
forward.c

@@ -698,7 +698,7 @@ int forward_reply(struct sip_msg* msg)
 	}
 
 	dst.proto=msg->via2->proto;
-	dst.send_flags=msg->fwd_send_flags | msg->rpl_send_flags;
+	dst.send_flags.f=msg->fwd_send_flags.f | msg->rpl_send_flags.f;
 	if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
 #ifdef USE_COMP
 	dst.comp=msg->via2->comp_no;

+ 2 - 2
forward.h

@@ -158,7 +158,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
 			goto error;
 		}else{
 			from=0;
-			if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) &&
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
 						dst->send_sock)) {
 				local_addr=dst->send_sock->su;
 				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)
 			goto error;
 		}else{
 			from=0;
-			if (unlikely((dst->send_flags & SND_F_FORCE_SOCKET) &&
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
 						dst->send_sock)) {
 				local_addr=dst->send_sock->su;
 				su_setport(&local_addr, 0); /* any local port will do */

+ 27 - 2
ip_addr.h

@@ -142,7 +142,31 @@ struct receive_info{
 #define SND_F_CON_CLOSE			2 /* close the connection after sending */
 #define SND_F_FORCE_SOCKET		4 /* send socket in dst is forced */
 
-typedef unsigned char  snd_flags_t;
+struct snd_flags {
+	unsigned char f;          /* snd flags */
+	unsigned char blst_imask; /* blacklist ignore mask */
+};
+
+
+typedef struct snd_flags  snd_flags_t;
+
+#define SND_FLAGS_INIT(sflags) \
+	do{ \
+		(sflags)->f=0; \
+		(sflags)->blst_imask=0; \
+	}while(0)
+
+#define SND_FLAGS_OR(dst, src1, src2) \
+	do{ \
+		(dst)->f = (src1)->f | (src2)->f; \
+		(dst)->blst_imask = (src1)->blst_imask | (src2)->blst_imask; \
+	}while(0)
+
+#define SND_FLAGS_AND(dst, src1, src2) \
+	do{ \
+		(dst)->f = (src1)->f & (src2)->f; \
+		(dst)->blst_imask = (src1)->blst_imask & (src2)->blst_imask; \
+	}while(0)
 
 struct dest_info{
 	struct socket_info* send_sock;
@@ -757,7 +781,8 @@ inline static void init_dst_from_rcv(struct dest_info* dst,
 		dst->to=rcv->src_su;
 		dst->id=rcv->proto_reserved1;
 		dst->proto=rcv->proto;
-		dst->send_flags=0;
+		dst->send_flags.f=0;
+		dst->send_flags.blst_imask=0;
 #ifdef USE_COMP
 		dst->comp=rcv->comp;
 #endif

+ 2 - 2
parser/msg_parser.h

@@ -477,9 +477,9 @@ void reset_path_vector(struct sip_msg* msg);
 	do { \
 		(msg)->force_send_socket=(fsocket); \
 		if ((msg)->force_send_socket) \
-			(msg)->fwd_send_flags |= SND_F_FORCE_SOCKET; \
+			(msg)->fwd_send_flags.f |= SND_F_FORCE_SOCKET; \
 		else \
-			(msg)->fwd_send_flags &= ~SND_F_FORCE_SOCKET; \
+			(msg)->fwd_send_flags.f &= ~SND_F_FORCE_SOCKET; \
 	} while (0)
 
 /** reset a previously forced send socket. */

+ 7 - 3
tcp_conn.h

@@ -172,7 +172,7 @@ struct tcp_connection{
 	atomic_t refcnt;
 	enum sip_protos type; /* PROTO_TCP or a protocol over it, e.g. TLS */
 	unsigned short flags; /* connection related flags */
-	unsigned short send_flags; /* special send flags */
+	snd_flags_t send_flags; /* special send flags */
 	enum tcp_conn_states state; /* connection state */
 	void* extra_data; /* extra data associated to the connection, 0 for tcp*/
 	struct timer_ln timer;
@@ -192,9 +192,13 @@ struct tcp_connection{
 
 /* helper macros */
 
-#define tcpconn_set_send_flags(c, snd_flags) ((c)->send_flags|=(snd_flags))
+#define tcpconn_set_send_flags(c, snd_flags) \
+	do{ \
+		(c)->send_flags.f|=(snd_flags).f; \
+		(c)->send_flags.blst_imask|=(snd_flags).blst_imask; \
+	}while(0)
 
-#define tcpconn_close_after_send(c)	((c)->send_flags & SND_F_CON_CLOSE)
+#define tcpconn_close_after_send(c)	((c)->send_flags.f & SND_F_CON_CLOSE)
 
 #define TCP_RCV_INFO(c) (&(c)->rcv)
 

+ 3 - 3
tcp_main.c

@@ -1780,7 +1780,7 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
 				c=0;
 			}
 			/* check if connect() is disabled */
-			if (unlikely((dst->send_flags & SND_F_FORCE_CON_REUSE) ||
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_CON_REUSE) ||
 							cfg_get(tcp, tcp_cfg, no_connect)))
 				return -1;
 			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,
 				}
 				LOG(L_INFO, "tcp_send: quick connect for %p\n", c);
 				TCP_STATS_ESTABLISHED(S_CONN_CONNECT);
-				if (unlikely(dst->send_flags & SND_F_CON_CLOSE)){
+				if (unlikely(dst->send_flags.f & SND_F_CON_CLOSE)){
 					/* if close-after-send requested, don't bother
 					   sending the fd back to tcp_main, try closing it
 					   immediately (no other tcp_send should use it,
@@ -2224,7 +2224,7 @@ error:
 			TCP_STATS_ESTABLISHED(c->state);
 			c->state=S_CONN_OK;
 	}
-	if (unlikely(dst->send_flags & SND_F_CON_CLOSE)){
+	if (unlikely(dst->send_flags.f & SND_F_CON_CLOSE)){
 		/* close after write => send EOF request to tcp_main */
 		c->state=S_CONN_BAD;
 		c->timeout=get_ticks_raw();

+ 1 - 1
tcp_read.c

@@ -964,7 +964,7 @@ again:
 			con=(struct tcp_connection*)fm->data;
 			if (unlikely(con->state==S_CONN_BAD)){
 				resp=CONN_ERROR;
-				if (!(con->send_flags & SND_F_CON_CLOSE))
+				if (!(con->send_flags.f & SND_F_CON_CLOSE))
 					LOG(L_WARN, "WARNING: tcp_receive: handle_io: F_TCPCONN"
 							" connection marked as bad: %p id %d refcnt %d\n",
 							con, con->id, atomic_get(&con->refcnt));