Browse code

Merge commit 'origin/ser_core_cvs'

* commit 'origin/ser_core_cvs':
core: log L_CRIT fix
sctp: internal macro/hooks for sctp events
sctp: internal macro-hooks for stats

Conflicts:
dprint.c
dprint.h

Andrei Pelinescu-Onciul authored on 07/05/2009 12:55:01
Showing 5 changed files
... ...
@@ -63,8 +63,9 @@ static int int_fac[]={LOG_AUTH ,  LOG_CRON , LOG_DAEMON ,
63 63
 
64 64
 struct log_level_info log_level_info[] = {
65 65
 	{"ALERT", LOG_ALERT},	  /* L_ALERT */
66
+	{"BUG", LOG_CRIT},        /* L_BUG */
66 67
 	{"CRITICAL", LOG_CRIT},   /* L_CRIT2 */
67
-	{"BUG", LOG_CRIT},        /* L_CRIT */
68
+	{"",    LOG_CRIT},         /* L_CRIT */
68 69
 	{"ERROR", LOG_ERR},       /* L_ERR */
69 70
 	{"WARNING", LOG_WARNING}, /* L_WARN */
70 71
 	{"NOTICE", LOG_NOTICE},   /* L_NOTICE */
... ...
@@ -72,9 +72,10 @@
72 72
 /*
73 73
  * Log levels
74 74
  */
75
-#define L_ALERT		-4
76
-#define L_CRIT2		-3  /* like L_CRIT, but not used for BUGs */
77
-#define L_CRIT  	-2  /* used only for BUG */
75
+#define L_ALERT		-5
76
+#define L_BUG		-4
77
+#define L_CRIT2		-3  /* like L_CRIT, but adds prefix */
78
+#define L_CRIT  	-2  /* no prefix added */
78 79
 #define L_ERR   	-1
79 80
 #define L_WARN   	0
80 81
 #define L_NOTICE 	1
... ...
@@ -257,7 +258,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
257 258
  */
258 259
 #ifdef __SUNPRO_C
259 260
 #	define ALERT(...)  LOG(L_ALERT,  __VA_ARGS__)
260
-#	define BUG(...)    LOG(L_CRIT,   __VA_ARGS__)
261
+#	define BUG(...)    LOG(L_BUG,   __VA_ARGS__)
261 262
 #	define ERR(...)    LOG(L_ERR,    __VA_ARGS__)
262 263
 #	define WARN(...)   LOG(L_WARN,   __VA_ARGS__)
263 264
 #	define NOTICE(...) LOG(L_NOTICE, __VA_ARGS__)
... ...
@@ -275,7 +276,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
275 276
 
276 277
 #else /* ! __SUNPRO_C */
277 278
 #	define ALERT(fmt, args...)  LOG(L_ALERT,  fmt, ## args)
278
-#	define BUG(fmt, args...)    LOG(L_CRIT,   fmt, ## args)
279
+#	define BUG(fmt, args...)    LOG(L_BUG,   fmt, ## args)
279 280
 #	define ERR(fmt, args...)    LOG(L_ERR,    fmt, ## args)
280 281
 #	define WARN(fmt, args...)   LOG(L_WARN,   fmt, ## args)
281 282
 #	define NOTICE(fmt, args...) LOG(L_NOTICE, fmt, ## args)
282 283
new file mode 100644
... ...
@@ -0,0 +1,97 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2009 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/*
19
+ * sctp_ev.h - sctp events
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2009-04-28  initial version (andrei)
25
+*/
26
+
27
+#ifndef __sctp_ev_h
28
+#define __sctp_ev_h
29
+
30
+#include <errno.h>
31
+#include <string.h>
32
+
33
+#ifndef USE_SCTP_EV
34
+
35
+#define SCTP_EV_ASSOC_CHANGE(lip, lport, src, reason, state)
36
+#define SCTP_EV_PEER_ADDR_CHANGE(lip, lport, src, reason, state, addr_su)
37
+#define SCTP_EV_REMOTE_ERROR(lip, lport, src, err)
38
+#define SCTP_EV_SEND_FAILED(lip, lport, src, err)
39
+#define SCTP_EV_SHUTDOWN_EVENT(lip, lport, src)
40
+#define SCTP_EV_SENDER_DRY_EVENT(lip, lport, src)
41
+
42
+#else /* USE_SCTP_EV */
43
+
44
+#include "ip_addr.h"
45
+
46
+
47
+/** an association has either been opened or closed.
48
+ * called for each SCTP_ASSOC_CHANGE event.
49
+ *
50
+ * @param err - if 0 it should be ignored (no corresp. libc error), if non-0
51
+ *                it will contain the errno.
52
+ * @param lip   - pointer to an ip_addr containing the local ip
53
+ *                   or 0 if dynamic (WARNING can be 0).
54
+ * @param lport - pointer to an ip_addr containing the local port or 0
55
+ *                   if unknown/dynamic.
56
+ * @param src   - pointer to a sockaddr_union containing the src.
57
+ * @param proto - protocol used
58
+ */
59
+#define SCTP_EV_ASSOC_CHANGE(lip, lport, src, reason, state) \
60
+	DBG("SCTP_ASSOC_CHANGE from %s on %s:%d: %s\n", \
61
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, reason)
62
+
63
+/** an address part of an assoc. changed state.
64
+ * called for the SCTP_PEER_ADDR_CHANGE event.*/
65
+#define SCTP_EV_PEER_ADDR_CHANGE(lip, lport, src, reason, state, addr_su) \
66
+	DBG("SCTP_PEER_ADDR_CHANGE from %s on %s:%d: %s\n", \
67
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, reason)
68
+
69
+/** remote operation error from the peer.
70
+ * called for the SCTP_REMOTE_ERROR event.*/
71
+#define SCTP_EV_REMOTE_ERROR(lip, lport, src, err) \
72
+	DBG("SCTP_REMOTE_ERROR from %s on %s:%d: %d\n", \
73
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, err)
74
+
75
+/** send failed.
76
+ * called for the SCTP_SEND_FAILED event.*/
77
+#define SCTP_EV_SEND_FAILED(lip, lport, src, err) \
78
+	DBG("SCTP_SEND_FAILED from %s on %s:%d: %d\n", \
79
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, err)
80
+
81
+/** the peer has sent a shutdown.
82
+ * called for the SCTP_SHUTDOWN_EVENT event.*/
83
+#define SCTP_EV_SHUTDOWN_EVENT(lip, lport, src) \
84
+	DBG("SCTP_SHUTDOWN_EVENT from %s on %s:%d\n", \
85
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport)
86
+
87
+/** kernel has finished sending all the queued data.
88
+ * called for the SCTP_SENDER_DRY_EVENT event.*/
89
+#define SCTP_EV_SENDER_DRY_EVENT(lip, lport, src) \
90
+	DBG("SCTP_SENDER_DRY_EVENT from %s on %s:%d\n", \
91
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport)
92
+
93
+#endif /* USE_SCTP_EV */
94
+
95
+#endif /*__sctp_ev_h*/
96
+
97
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -23,6 +23,7 @@
23 23
  * --------
24 24
  *  2008-08-07  initial version (andrei)
25 25
  *  2009-02-27  blacklist support (andrei)
26
+ *  2009-04-28  sctp stats & events macros (andrei)
26 27
  */
27 28
 
28 29
 #ifdef USE_SCTP
... ...
@@ -57,6 +58,8 @@
57 58
 #include "clist.h"
58 59
 #include "error.h"
59 60
 #include "timer.h"
61
+#include "sctp_stats.h"
62
+#include "sctp_ev.h"
60 63
 
61 64
 
62 65
 
... ...
@@ -1496,6 +1499,10 @@ int init_sctp()
1496 1499
 	int ret;
1497 1500
 	
1498 1501
 	ret=0;
1502
+	if (INIT_SCTP_STATS()!=0){
1503
+		ERR("sctp init: failed to intialize sctp stats\n");
1504
+		goto error;
1505
+	}
1499 1506
 	/* sctp options must be initialized before  calling this function */
1500 1507
 	sctp_conn_no=shm_malloc(sizeof(*sctp_conn_tracked));
1501 1508
 	if ( sctp_conn_no==0){
... ...
@@ -1522,6 +1529,7 @@ void destroy_sctp()
1522 1529
 #ifdef SCTP_CONN_REUSE
1523 1530
 	destroy_sctp_con_tracking();
1524 1531
 #endif
1532
+	DESTROY_SCTP_STATS();
1525 1533
 }
1526 1534
 
1527 1535
 
... ...
@@ -1613,6 +1621,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
1613 1621
 	int ret;
1614 1622
 	
1615 1623
 	ret=-1;
1624
+	SCTP_STATS_SEND_FAILED();
1616 1625
 	snp=(union sctp_notification*) buf;
1617 1626
 	retries=snp->sn_send_failed.ssf_info.sinfo_context;
1618 1627
 	
... ...
@@ -1623,6 +1632,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
1623 1632
 	 */
1624 1633
 	if (retries && (snp->sn_send_failed.ssf_error==0)) {
1625 1634
 		DBG("sctp: RETRY-ing (%d)\n", retries);
1635
+		SCTP_STATS_SEND_FORCE_RETRY();
1626 1636
 		retries--;
1627 1637
 		data=(char*)snp->sn_send_failed.ssf_data;
1628 1638
 		data_len=snp->sn_send_failed.ssf_length - 
... ...
@@ -1685,6 +1695,7 @@ static int sctp_handle_assoc_change(struct socket_info* si,
1685 1695
 	ret=-1;
1686 1696
 	switch(state){
1687 1697
 		case SCTP_COMM_UP:
1698
+			SCTP_STATS_ESTABLISHED();
1688 1699
 			atomic_inc(sctp_conn_no);
1689 1700
 #ifdef SCTP_CONN_REUSE
1690 1701
 			/* new connection, track it */
... ...
@@ -1707,6 +1718,7 @@ again:
1707 1718
 #endif /* SCTP_CONN_REUSE */
1708 1719
 			break;
1709 1720
 		case SCTP_COMM_LOST:
1721
+			SCTP_STATS_COMM_LOST();
1710 1722
 #ifdef USE_DST_BLACKLIST
1711 1723
 			/* blacklist only if send_retries is turned off (if on we don't
1712 1724
 			   know here if we did retry or we are at the first error) */
... ...
@@ -1732,6 +1744,7 @@ again:
1732 1744
 			/* do nothing on restart */
1733 1745
 			break;
1734 1746
 		case SCTP_CANT_STR_ASSOC:
1747
+			SCTP_STATS_CONNECT_FAILED();
1735 1748
 			/* do nothing when failing to start an assoc
1736 1749
 			  (in this case we never see SCTP_COMM_UP so we never 
1737 1750
 			  track the assoc) */
... ...
@@ -1781,6 +1794,8 @@ static int sctp_handle_notification(struct socket_info* si,
1781 1794
 		case SCTP_REMOTE_ERROR:
1782 1795
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_remote_error), si, su,
1783 1796
 								"SCTP_REMOTE_ERROR");
1797
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su, 
1798
+									ntohs(snp->sn_remote_error.sre_error) );
1784 1799
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_REMOTE_ERROR:"
1785 1800
 					" %d, len %d\n, assoc_id %d",
1786 1801
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1793,6 +1808,8 @@ static int sctp_handle_notification(struct socket_info* si,
1793 1808
 		case SCTP_SEND_FAILED:
1794 1809
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_send_failed), si, su,
1795 1810
 								"SCTP_SEND_FAILED");
1811
+			SCTP_EV_SEND_FAILED(&si->address, si->port_no, su, 
1812
+									snp->sn_send_failed.ssf_error);
1796 1813
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SEND_FAILED:"
1797 1814
 					" error %d, assoc_id %d, flags %x\n",
1798 1815
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1804,6 +1821,10 @@ static int sctp_handle_notification(struct socket_info* si,
1804 1821
 		case SCTP_PEER_ADDR_CHANGE:
1805 1822
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_paddr_change), si, su,
1806 1823
 								"SCTP_PEER_ADDR_CHANGE");
1824
+			SCTP_EV_PEER_ADDR_CHANGE(&si->address, si->port_no, su, 
1825
+					sctp_paddr_change_state2s(snp->sn_paddr_change.spc_state),
1826
+					snp->sn_paddr_change.spc_state,
1827
+					&snp->sn_paddr_change.spc_aaddr);
1807 1828
 			strcpy(su_buf, su2a((union sockaddr_union*)
1808 1829
 									&snp->sn_paddr_change.spc_aaddr, 
1809 1830
 									sizeof(snp->sn_paddr_change.spc_aaddr)));
... ...
@@ -1816,8 +1837,10 @@ static int sctp_handle_notification(struct socket_info* si,
1816 1837
 					);
1817 1838
 			break;
1818 1839
 		case SCTP_SHUTDOWN_EVENT:
1840
+			SCTP_STATS_REMOTE_SHUTDOWN();
1819 1841
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_shutdown_event), si, su,
1820 1842
 								"SCTP_SHUTDOWN_EVENT");
1843
+			SCTP_EV_SHUTDOWN_EVENT(&si->address, si->port_no, su);
1821 1844
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SHUTDOWN_EVENT:"
1822 1845
 					" assoc_id %d\n",
1823 1846
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1826,6 +1849,9 @@ static int sctp_handle_notification(struct socket_info* si,
1826 1849
 		case SCTP_ASSOC_CHANGE:
1827 1850
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_assoc_change), si, su,
1828 1851
 								"SCTP_ASSOC_CHANGE");
1852
+			SCTP_EV_ASSOC_CHANGE(&si->address, si->port_no, su, 
1853
+					sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state),
1854
+					snp->sn_assoc_change.sac_state);
1829 1855
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_ASSOC_CHANGE"
1830 1856
 					": %s: assoc_id %d, ostreams %d, istreams %d\n",
1831 1857
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1864,6 +1890,7 @@ static int sctp_handle_notification(struct socket_info* si,
1864 1890
 		case SCTP_SENDER_DRY_EVENT:
1865 1891
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_sender_dry_event),
1866 1892
 								si, su, "SCTP_SENDER_DRY_EVENT");
1893
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su);
1867 1894
 			SNOT("sctp notification from %s on %.*s:%d: "
1868 1895
 					"SCTP_SENDER_DRY_EVENT on %d\n",
1869 1896
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -2162,6 +2189,7 @@ again:
2162 2189
 			"one possible reason is the server is bound to localhost and\n"
2163 2190
 			"attempts to send to the net\n");
2164 2191
 		}else if (errno==EAGAIN || errno==EWOULDBLOCK){
2192
+			SCTP_STATS_SENDQ_FULL();
2165 2193
 			LOG(L_ERR, "ERROR: sctp_msg_send: failed to send, send buffers"
2166 2194
 						" full\n");
2167 2195
 		}
2168 2196
new file mode 100644
... ...
@@ -0,0 +1,99 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2009 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/*
19
+ * sctp_stats.h - sctp statistics macros
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2009-04-28  initial version (andrei)
25
+*/
26
+
27
+#ifndef __sctp_stats_h
28
+#define __sctp_stats_h
29
+
30
+
31
+#ifndef USE_SCTP_STATS
32
+
33
+#define INIT_SCTP_STATS() 0 /* success */
34
+#define DESTROY_SCTP_STATS()
35
+
36
+#define SCTP_STATS_ESTABLISHED()
37
+#define SCTP_STATS_CONNECT_FAILED()
38
+#define SCTP_STATS_LOCAL_REJECT()
39
+#define SCTP_STATS_REMOTE_SHUTDOWN()
40
+#define SCTP_STATS_COMM_LOST()
41
+#define SCTP_STATS_SENDQ_FULL()
42
+#define SCTP_STATS_SEND_FAILED()
43
+#define SCTP_STATS_SEND_FORCE_RETRY()
44
+
45
+#else /* USE_SCTP_STATS */
46
+
47
+#define INIT_SCTP_STATS() 0 /* success */
48
+
49
+#define DESTROY_SCTP_STATS()
50
+
51
+
52
+/** called each time a new sctp assoc. is established.
53
+ * sctp notification: SCTP_COMM_UP.
54
+ */
55
+#define SCTP_STATS_ESTABLISHED()
56
+
57
+/** called each time a new outgoing connection/assoc open fails.
58
+ *  sctp notification: SCTP_CANT_STR_ASSOC
59
+ */
60
+#define SCTP_STATS_CONNECT_FAILED()
61
+
62
+/** called each time a new incoming connection is rejected.  */
63
+#define SCTP_STATS_LOCAL_REJECT()
64
+
65
+
66
+/** called each time a connection is closed by the peer.
67
+  * sctp notification: SCTP_SHUTDOWN_EVENT
68
+  */
69
+#define SCTP_STATS_REMOTE_SHUTDOWN()
70
+
71
+
72
+/** called each time an established connection is closed due to some error.
73
+  * sctp notification: SCTP_COMM_LOST
74
+  */
75
+#define SCTP_STATS_COMM_LOST()
76
+
77
+
78
+/** called each time a send fails due to the buffering capacity being exceeded.
79
+  * (send fails due to full kernel buffers)
80
+  */
81
+#define SCTP_STATS_SENDQ_FULL()
82
+
83
+
84
+/** called each time a send fails.
85
+  * (send fails for any reason except buffers full)
86
+  * sctp notification: SCTP_SEND_FAILED
87
+  */
88
+#define SCTP_STATS_SEND_FAILED()
89
+
90
+/** called each time a failed send is force-retried.
91
+  * (possible only if sctp_send_retries is != 0)
92
+  */
93
+#define SCTP_STATS_SEND_FORCE_RETRY()
94
+
95
+#endif /* USE_SCTP_STATS */
96
+
97
+#endif /*__sctp_stats_h*/
98
+
99
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */