[sr-dev] git:andrei/blst_send_flags: core: send_flags preliminary blacklist support

Andrei Pelinescu-Onciul andrei at iptel.org
Wed Dec 23 13:42:55 CET 2009


Module: sip-router
Branch: andrei/blst_send_flags
Commit: 8cf5dde505392a2cfc1a99d4665c18dceacfbc2d
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8cf5dde505392a2cfc1a99d4665c18dceacfbc2d

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Dec 17 08:39:53 2009 +0100

core: send_flags preliminary blacklist support

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

---

 action.c            |    8 ++++----
 forward.c           |    2 +-
 forward.h           |    4 ++--
 ip_addr.h           |   29 +++++++++++++++++++++++++++--
 parser/msg_parser.h |    4 ++--
 tcp_conn.h          |   10 +++++++---
 tcp_main.c          |    6 +++---
 tcp_read.c          |    2 +-
 8 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/action.c b/action.c
index ddbf445..7641077 100644
--- a/action.c
+++ b/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;
 /*
diff --git a/forward.c b/forward.c
index d7fb827..e47831d 100644
--- a/forward.c
+++ b/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;
diff --git a/forward.h b/forward.h
index b365753..e5f1a38 100644
--- a/forward.h
+++ b/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 */
diff --git a/ip_addr.h b/ip_addr.h
index 2983e46..7ec9a1f 100644
--- a/ip_addr.h
+++ b/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
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index adedddb..c421384 100644
--- a/parser/msg_parser.h
+++ b/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. */
diff --git a/tcp_conn.h b/tcp_conn.h
index f596b59..121c965 100644
--- a/tcp_conn.h
+++ b/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)
 
diff --git a/tcp_main.c b/tcp_main.c
index 4840ddc..460e1fa 100644
--- a/tcp_main.c
+++ b/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();
diff --git a/tcp_read.c b/tcp_read.c
index d201765..c6d729c 100644
--- a/tcp_read.c
+++ b/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));




More information about the sr-dev mailing list