Browse code

core: print src and dst addresses in tcp error log messages

Daniel-Constantin Mierla authored on 04/11/2015 09:08:02
Showing 1 changed files
... ...
@@ -268,14 +268,19 @@ again:
268 268
 						}
269 269
 				}
270 270
 				LOG(cfg_get(core, core_cfg, corelog),
271
-						"error reading: %s (%d)\n", strerror(errno), errno);
271
+						"error reading: %s (%d) ([%s]:%u -> [%s]:%u)\n",
272
+						strerror(errno), errno,
273
+						ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
274
+						ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
272 275
 				return -1;
273 276
 			}
274 277
 		}else if (unlikely((bytes_read==0) || 
275 278
 					(*flags & RD_CONN_FORCE_EOF))){
276 279
 			c->state=S_CONN_EOF;
277 280
 			*flags|=RD_CONN_EOF;
278
-			LM_DBG("EOF on %p, FD %d\n", c, fd);
281
+			LM_DBG("EOF on %p, FD %d ([%s]:%u -> [%s]:%u)\n", c, fd,
282
+					ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
283
+					ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
279 284
 		}else{
280 285
 			if (unlikely(c->state==S_CONN_CONNECT || c->state==S_CONN_ACCEPT)){
281 286
 				TCP_STATS_ESTABLISHED(c->state);
... ...
@@ -319,7 +324,9 @@ int tcp_read(struct tcp_connection *c, int* flags)
319 319
 	bytes_free=r->b_size- (int)(r->pos - r->buf);
320 320
 	
321 321
 	if (unlikely(bytes_free==0)){
322
-		LM_ERR("buffer overrun, dropping\n");
322
+		LM_ERR("buffer overrun, dropping ([%s]:%u -> [%s]:%u)\n",
323
+				ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
324
+				ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
323 325
 		r->error=TCP_REQ_OVERRUN;
324 326
 		return -1;
325 327
 	}
... ...
@@ -507,7 +514,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
507 507
 								p++;
508 508
 								goto skip;
509 509
 							} else {
510
-								LM_DBG("ERROR: no clen, p=%X\n", *p);
510
+								LM_DBG("no clen, p=%X\n", *p);
511 511
 								r->error=TCP_REQ_BAD_LEN;
512 512
 							}
513 513
 						}
... ...
@@ -579,7 +586,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
579 579
 							p++;
580 580
 							goto skip;
581 581
 						} else {
582
-							LM_DBG("ERROR: no clen, p=%X\n", *p);
582
+							LM_DBG("no clen, p=%X\n", *p);
583 583
 							r->error=TCP_REQ_BAD_LEN;
584 584
 						}
585 585
 					}
... ...
@@ -1367,7 +1374,9 @@ again:
1367 1367
 				init_dst_from_rcv(&dst, &con->rcv);
1368 1368
 
1369 1369
 				if (tcp_send(&dst, 0, CRLF, CRLF_LEN) < 0) {
1370
-					LM_ERR("CRLF ping: tcp_send() failed\n");
1370
+					LM_ERR("CRLF ping: tcp_send() failed ([%s]:%u -> [%s]:%u)\n",
1371
+							ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
1372
+							ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
1371 1373
 				}
1372 1374
 				ret = 0;
1373 1375
 			} else if (unlikely(req->state==H_STUN_END)) {
... ...
@@ -1428,7 +1437,9 @@ again:
1428 1428
 				/*if we still have some unparsed bytes, try to parse them too*/
1429 1429
 				goto again;
1430 1430
 			} else if (unlikely(con->state==S_CONN_EOF)){
1431
-				LM_DBG("EOF after reading complete request\n");
1431
+				LM_DBG("EOF after reading complete request ([%s]:%u -> [%s]:%u)\n",
1432
+						ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
1433
+						ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
1432 1434
 				resp=CONN_EOF;
1433 1435
 			}
1434 1436
 			req->parsed=req->buf; /* fix req->parsed */
... ...
@@ -1446,8 +1457,10 @@ void release_tcpconn(struct tcp_connection* c, long state, int unix_sock)
1446 1446
 {
1447 1447
 	long response[2];
1448 1448
 	
1449
-		LM_DBG("releasing con %p, state %ld, fd=%d, id=%d\n",
1450
-				c, state, c->fd, c->id);
1449
+		LM_DBG("releasing con %p, state %ld, fd=%d, id=%d ([%s]:%u -> [%s]:%u)\n",
1450
+				c, state, c->fd, c->id,
1451
+				ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
1452
+				ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
1451 1453
 		LM_DBG("extra_data %p\n", c->extra_data);
1452 1454
 		/* release req & signal the parent */
1453 1455
 		c->reader_pid=0; /* reset it */
... ...
@@ -1479,8 +1492,11 @@ static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data)
1479 1479
 	/* if conn->state is ERROR or BAD => force timeout too */
1480 1480
 	if (unlikely(io_watch_del(&io_w, c->fd, -1, IO_FD_CLOSING)<0)){
1481 1481
 		LM_ERR("io_watch_del failed for %p"
1482
-					" id %d fd %d, state %d, flags %x, main fd %d\n",
1483
-					c, c->id, c->fd, c->state, c->flags, c->s);
1482
+					" id %d fd %d, state %d, flags %x, main fd %d"
1483
+					" ([%s]:%u -> [%s]:%u)\n",
1484
+					c, c->id, c->fd, c->state, c->flags, c->s,
1485
+					ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
1486
+					ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
1484 1487
 	}
1485 1488
 	tcpconn_listrm(tcp_conn_lst, c, c_next, c_prev);
1486 1489
 	release_tcpconn(c, (c->state<0)?CONN_ERROR:CONN_RELEASE, tcpmain_sock);
... ...
@@ -1594,9 +1610,11 @@ repeat_1st_read:
1594 1594
 								S_TO_TICKS(TCP_CHILD_TIMEOUT), t);
1595 1595
 			if (unlikely(io_watch_add(&io_w, s, POLLIN, F_TCPCONN, con)<0)){
1596 1596
 				LM_CRIT("io_watch_add failed for %p id %d fd %d, state %d, flags %x,"
1597
-							" main fd %d, refcnt %d\n",
1597
+							" main fd %d, refcnt %d ([%s]:%u -> [%s]:%u)\n",
1598 1598
 							con, con->id, con->fd, con->state, con->flags,
1599
-							con->s, atomic_get(&con->refcnt));
1599
+							con->s, atomic_get(&con->refcnt),
1600
+							ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
1601
+							ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
1600 1602
 				tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
1601 1603
 				local_timer_del(&tcp_reader_ltimer, &con->timer);
1602 1604
 				goto con_error;
... ...
@@ -1628,9 +1646,12 @@ read_error:
1628 1628
 				if (unlikely(io_watch_del(&io_w, con->fd, idx,
1629 1629
 											IO_FD_CLOSING) < 0)){
1630 1630
 					LM_CRIT("io_watch_del failed for %p id %d fd %d,"
1631
-							" state %d, flags %x, main fd %d, refcnt %d\n",
1631
+							" state %d, flags %x, main fd %d, refcnt %d"
1632
+							" ([%s]:%u -> [%s]:%u)\n",
1632 1633
 							con, con->id, con->fd, con->state,
1633
-							con->flags, con->s, atomic_get(&con->refcnt));
1634
+							con->flags, con->s, atomic_get(&con->refcnt),
1635
+							ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
1636
+							ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
1634 1637
 				}
1635 1638
 				tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
1636 1639
 				local_timer_del(&tcp_reader_ltimer, &con->timer);
... ...
@@ -1696,7 +1717,7 @@ void tcp_receive_loop(int unix_sock)
1696 1696
 		goto error;
1697 1697
 	/* add the unix socket */
1698 1698
 	if (io_watch_add(&io_w, tcpmain_sock, POLLIN,  F_TCPMAIN, 0)<0){
1699
-		LM_CRIT("failed to add socket to the fd list\n");
1699
+		LM_CRIT("failed to add tcp main socket to the fd list\n");
1700 1700
 		goto error;
1701 1701
 	}
1702 1702