Browse code

core: trigger event_route execution for unexpectedly-closed and client-closed tcp connections

Armen Babikyan authored on 04/01/2016 22:05:30
Showing 1 changed files
... ...
@@ -186,6 +186,25 @@ int tcp_http11_continue(struct tcp_connection *c)
186 186
 }
187 187
 #endif /* HTTP11 */
188 188
 
189
+static int tcp_make_closed_event(struct receive_info* rcv_info, struct tcp_connection* con)
190
+{
191
+	int ret;
192
+	tcp_event_info_t tev;
193
+
194
+	ret = 0;
195
+	LM_DBG("TCP closed event creation triggered\n");
196
+	if(likely(sr_event_enabled(SREV_TCP_CLOSED))) {
197
+		memset(&tev, 0, sizeof(tcp_event_info_t));
198
+		tev.type = SREV_TCP_CLOSED;
199
+		tev.rcv = rcv_info;
200
+		tev.con = con;
201
+		ret = sr_event_exec(SREV_TCP_CLOSED, (void*)(&tev));
202
+	} else {
203
+		LM_DBG("no callback registering for handling TCP closed event - dropping!\n");
204
+	}
205
+	return ret;
206
+}
207
+
189 208
 
190 209
 /** reads data from an existing tcp connection.
191 210
  * Side-effects: blacklisting, sets connection state to S_CONN_OK, tcp stats.
... ...
@@ -272,12 +291,20 @@ again:
272 272
 						strerror(errno), errno,
273 273
 						ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
274 274
 						ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
275
+
276
+				if((errno == ECONNRESET || errno == ETIMEDOUT) && likely(c->rcv.proto_reserved1 != 0)){
277
+					tcp_make_closed_event(&c->rcv, c);
278
+				}
279
+
275 280
 				return -1;
276 281
 			}
277 282
 		}else if (unlikely((bytes_read==0) || 
278 283
 					(*flags & RD_CONN_FORCE_EOF))){
279 284
 			c->state=S_CONN_EOF;
280 285
 			*flags|=RD_CONN_EOF;
286
+			if (likely(c->rcv.proto_reserved1 != 0)){
287
+				tcp_make_closed_event(&c->rcv, c);
288
+			}
281 289
 			LM_DBG("EOF on %p, FD %d ([%s]:%u -> [%s]:%u)\n", c, fd,
282 290
 					ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
283 291
 					ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);