Bladeren bron

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 16 jaren geleden
bovenliggende
commit
271bfb0e8f
5 gewijzigde bestanden met toevoegingen van 232 en 6 verwijderingen
  1. 2 1
      dprint.c
  2. 6 5
      dprint.h
  3. 97 0
      sctp_ev.h
  4. 28 0
      sctp_server.c
  5. 99 0
      sctp_stats.h

+ 2 - 1
dprint.c

@@ -63,8 +63,9 @@ static int int_fac[]={LOG_AUTH ,  LOG_CRON , LOG_DAEMON ,
 
 struct log_level_info log_level_info[] = {
 	{"ALERT", LOG_ALERT},	  /* L_ALERT */
+	{"BUG", LOG_CRIT},        /* L_BUG */
 	{"CRITICAL", LOG_CRIT},   /* L_CRIT2 */
-	{"BUG", LOG_CRIT},        /* L_CRIT */
+	{"",    LOG_CRIT},         /* L_CRIT */
 	{"ERROR", LOG_ERR},       /* L_ERR */
 	{"WARNING", LOG_WARNING}, /* L_WARN */
 	{"NOTICE", LOG_NOTICE},   /* L_NOTICE */

+ 6 - 5
dprint.h

@@ -72,9 +72,10 @@
 /*
  * Log levels
  */
-#define L_ALERT		-4
-#define L_CRIT2		-3  /* like L_CRIT, but not used for BUGs */
-#define L_CRIT  	-2  /* used only for BUG */
+#define L_ALERT		-5
+#define L_BUG		-4
+#define L_CRIT2		-3  /* like L_CRIT, but adds prefix */
+#define L_CRIT  	-2  /* no prefix added */
 #define L_ERR   	-1
 #define L_WARN   	0
 #define L_NOTICE 	1
@@ -257,7 +258,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
  */
 #ifdef __SUNPRO_C
 #	define ALERT(...)  LOG(L_ALERT,  __VA_ARGS__)
-#	define BUG(...)    LOG(L_CRIT,   __VA_ARGS__)
+#	define BUG(...)    LOG(L_BUG,   __VA_ARGS__)
 #	define ERR(...)    LOG(L_ERR,    __VA_ARGS__)
 #	define WARN(...)   LOG(L_WARN,   __VA_ARGS__)
 #	define NOTICE(...) LOG(L_NOTICE, __VA_ARGS__)
@@ -275,7 +276,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 
 #else /* ! __SUNPRO_C */
 #	define ALERT(fmt, args...)  LOG(L_ALERT,  fmt, ## args)
-#	define BUG(fmt, args...)    LOG(L_CRIT,   fmt, ## args)
+#	define BUG(fmt, args...)    LOG(L_BUG,   fmt, ## args)
 #	define ERR(fmt, args...)    LOG(L_ERR,    fmt, ## args)
 #	define WARN(fmt, args...)   LOG(L_WARN,   fmt, ## args)
 #	define NOTICE(fmt, args...) LOG(L_NOTICE, fmt, ## args)

+ 97 - 0
sctp_ev.h

@@ -0,0 +1,97 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * sctp_ev.h - sctp events
+ */
+/*
+ * History:
+ * --------
+ *  2009-04-28  initial version (andrei)
+*/
+
+#ifndef __sctp_ev_h
+#define __sctp_ev_h
+
+#include <errno.h>
+#include <string.h>
+
+#ifndef USE_SCTP_EV
+
+#define SCTP_EV_ASSOC_CHANGE(lip, lport, src, reason, state)
+#define SCTP_EV_PEER_ADDR_CHANGE(lip, lport, src, reason, state, addr_su)
+#define SCTP_EV_REMOTE_ERROR(lip, lport, src, err)
+#define SCTP_EV_SEND_FAILED(lip, lport, src, err)
+#define SCTP_EV_SHUTDOWN_EVENT(lip, lport, src)
+#define SCTP_EV_SENDER_DRY_EVENT(lip, lport, src)
+
+#else /* USE_SCTP_EV */
+
+#include "ip_addr.h"
+
+
+/** an association has either been opened or closed.
+ * called for each SCTP_ASSOC_CHANGE event.
+ *
+ * @param err - if 0 it should be ignored (no corresp. libc error), if non-0
+ *                it will contain the errno.
+ * @param lip   - pointer to an ip_addr containing the local ip
+ *                   or 0 if dynamic (WARNING can be 0).
+ * @param lport - pointer to an ip_addr containing the local port or 0
+ *                   if unknown/dynamic.
+ * @param src   - pointer to a sockaddr_union containing the src.
+ * @param proto - protocol used
+ */
+#define SCTP_EV_ASSOC_CHANGE(lip, lport, src, reason, state) \
+	DBG("SCTP_ASSOC_CHANGE from %s on %s:%d: %s\n", \
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, reason)
+
+/** an address part of an assoc. changed state.
+ * called for the SCTP_PEER_ADDR_CHANGE event.*/
+#define SCTP_EV_PEER_ADDR_CHANGE(lip, lport, src, reason, state, addr_su) \
+	DBG("SCTP_PEER_ADDR_CHANGE from %s on %s:%d: %s\n", \
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, reason)
+
+/** remote operation error from the peer.
+ * called for the SCTP_REMOTE_ERROR event.*/
+#define SCTP_EV_REMOTE_ERROR(lip, lport, src, err) \
+	DBG("SCTP_REMOTE_ERROR from %s on %s:%d: %d\n", \
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, err)
+
+/** send failed.
+ * called for the SCTP_SEND_FAILED event.*/
+#define SCTP_EV_SEND_FAILED(lip, lport, src, err) \
+	DBG("SCTP_SEND_FAILED from %s on %s:%d: %d\n", \
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, err)
+
+/** the peer has sent a shutdown.
+ * called for the SCTP_SHUTDOWN_EVENT event.*/
+#define SCTP_EV_SHUTDOWN_EVENT(lip, lport, src) \
+	DBG("SCTP_SHUTDOWN_EVENT from %s on %s:%d\n", \
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport)
+
+/** kernel has finished sending all the queued data.
+ * called for the SCTP_SENDER_DRY_EVENT event.*/
+#define SCTP_EV_SENDER_DRY_EVENT(lip, lport, src) \
+	DBG("SCTP_SENDER_DRY_EVENT from %s on %s:%d\n", \
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport)
+
+#endif /* USE_SCTP_EV */
+
+#endif /*__sctp_ev_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */

+ 28 - 0
sctp_server.c

@@ -23,6 +23,7 @@
  * --------
  *  2008-08-07  initial version (andrei)
  *  2009-02-27  blacklist support (andrei)
+ *  2009-04-28  sctp stats & events macros (andrei)
  */
 
 #ifdef USE_SCTP
@@ -57,6 +58,8 @@
 #include "clist.h"
 #include "error.h"
 #include "timer.h"
+#include "sctp_stats.h"
+#include "sctp_ev.h"
 
 
 
@@ -1496,6 +1499,10 @@ int init_sctp()
 	int ret;
 	
 	ret=0;
+	if (INIT_SCTP_STATS()!=0){
+		ERR("sctp init: failed to intialize sctp stats\n");
+		goto error;
+	}
 	/* sctp options must be initialized before  calling this function */
 	sctp_conn_no=shm_malloc(sizeof(*sctp_conn_tracked));
 	if ( sctp_conn_no==0){
@@ -1522,6 +1529,7 @@ void destroy_sctp()
 #ifdef SCTP_CONN_REUSE
 	destroy_sctp_con_tracking();
 #endif
+	DESTROY_SCTP_STATS();
 }
 
 
@@ -1613,6 +1621,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
 	int ret;
 	
 	ret=-1;
+	SCTP_STATS_SEND_FAILED();
 	snp=(union sctp_notification*) buf;
 	retries=snp->sn_send_failed.ssf_info.sinfo_context;
 	
@@ -1623,6 +1632,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
 	 */
 	if (retries && (snp->sn_send_failed.ssf_error==0)) {
 		DBG("sctp: RETRY-ing (%d)\n", retries);
+		SCTP_STATS_SEND_FORCE_RETRY();
 		retries--;
 		data=(char*)snp->sn_send_failed.ssf_data;
 		data_len=snp->sn_send_failed.ssf_length - 
@@ -1685,6 +1695,7 @@ static int sctp_handle_assoc_change(struct socket_info* si,
 	ret=-1;
 	switch(state){
 		case SCTP_COMM_UP:
+			SCTP_STATS_ESTABLISHED();
 			atomic_inc(sctp_conn_no);
 #ifdef SCTP_CONN_REUSE
 			/* new connection, track it */
@@ -1707,6 +1718,7 @@ again:
 #endif /* SCTP_CONN_REUSE */
 			break;
 		case SCTP_COMM_LOST:
+			SCTP_STATS_COMM_LOST();
 #ifdef USE_DST_BLACKLIST
 			/* blacklist only if send_retries is turned off (if on we don't
 			   know here if we did retry or we are at the first error) */
@@ -1732,6 +1744,7 @@ again:
 			/* do nothing on restart */
 			break;
 		case SCTP_CANT_STR_ASSOC:
+			SCTP_STATS_CONNECT_FAILED();
 			/* do nothing when failing to start an assoc
 			  (in this case we never see SCTP_COMM_UP so we never 
 			  track the assoc) */
@@ -1781,6 +1794,8 @@ static int sctp_handle_notification(struct socket_info* si,
 		case SCTP_REMOTE_ERROR:
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_remote_error), si, su,
 								"SCTP_REMOTE_ERROR");
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su, 
+									ntohs(snp->sn_remote_error.sre_error) );
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_REMOTE_ERROR:"
 					" %d, len %d\n, assoc_id %d",
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
@@ -1793,6 +1808,8 @@ static int sctp_handle_notification(struct socket_info* si,
 		case SCTP_SEND_FAILED:
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_send_failed), si, su,
 								"SCTP_SEND_FAILED");
+			SCTP_EV_SEND_FAILED(&si->address, si->port_no, su, 
+									snp->sn_send_failed.ssf_error);
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SEND_FAILED:"
 					" error %d, assoc_id %d, flags %x\n",
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
@@ -1804,6 +1821,10 @@ static int sctp_handle_notification(struct socket_info* si,
 		case SCTP_PEER_ADDR_CHANGE:
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_paddr_change), si, su,
 								"SCTP_PEER_ADDR_CHANGE");
+			SCTP_EV_PEER_ADDR_CHANGE(&si->address, si->port_no, su, 
+					sctp_paddr_change_state2s(snp->sn_paddr_change.spc_state),
+					snp->sn_paddr_change.spc_state,
+					&snp->sn_paddr_change.spc_aaddr);
 			strcpy(su_buf, su2a((union sockaddr_union*)
 									&snp->sn_paddr_change.spc_aaddr, 
 									sizeof(snp->sn_paddr_change.spc_aaddr)));
@@ -1816,8 +1837,10 @@ static int sctp_handle_notification(struct socket_info* si,
 					);
 			break;
 		case SCTP_SHUTDOWN_EVENT:
+			SCTP_STATS_REMOTE_SHUTDOWN();
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_shutdown_event), si, su,
 								"SCTP_SHUTDOWN_EVENT");
+			SCTP_EV_SHUTDOWN_EVENT(&si->address, si->port_no, su);
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SHUTDOWN_EVENT:"
 					" assoc_id %d\n",
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
@@ -1826,6 +1849,9 @@ static int sctp_handle_notification(struct socket_info* si,
 		case SCTP_ASSOC_CHANGE:
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_assoc_change), si, su,
 								"SCTP_ASSOC_CHANGE");
+			SCTP_EV_ASSOC_CHANGE(&si->address, si->port_no, su, 
+					sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state),
+					snp->sn_assoc_change.sac_state);
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_ASSOC_CHANGE"
 					": %s: assoc_id %d, ostreams %d, istreams %d\n",
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
@@ -1864,6 +1890,7 @@ static int sctp_handle_notification(struct socket_info* si,
 		case SCTP_SENDER_DRY_EVENT:
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_sender_dry_event),
 								si, su, "SCTP_SENDER_DRY_EVENT");
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su);
 			SNOT("sctp notification from %s on %.*s:%d: "
 					"SCTP_SENDER_DRY_EVENT on %d\n",
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
@@ -2162,6 +2189,7 @@ again:
 			"one possible reason is the server is bound to localhost and\n"
 			"attempts to send to the net\n");
 		}else if (errno==EAGAIN || errno==EWOULDBLOCK){
+			SCTP_STATS_SENDQ_FULL();
 			LOG(L_ERR, "ERROR: sctp_msg_send: failed to send, send buffers"
 						" full\n");
 		}

+ 99 - 0
sctp_stats.h

@@ -0,0 +1,99 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * sctp_stats.h - sctp statistics macros
+ */
+/*
+ * History:
+ * --------
+ *  2009-04-28  initial version (andrei)
+*/
+
+#ifndef __sctp_stats_h
+#define __sctp_stats_h
+
+
+#ifndef USE_SCTP_STATS
+
+#define INIT_SCTP_STATS() 0 /* success */
+#define DESTROY_SCTP_STATS()
+
+#define SCTP_STATS_ESTABLISHED()
+#define SCTP_STATS_CONNECT_FAILED()
+#define SCTP_STATS_LOCAL_REJECT()
+#define SCTP_STATS_REMOTE_SHUTDOWN()
+#define SCTP_STATS_COMM_LOST()
+#define SCTP_STATS_SENDQ_FULL()
+#define SCTP_STATS_SEND_FAILED()
+#define SCTP_STATS_SEND_FORCE_RETRY()
+
+#else /* USE_SCTP_STATS */
+
+#define INIT_SCTP_STATS() 0 /* success */
+
+#define DESTROY_SCTP_STATS()
+
+
+/** called each time a new sctp assoc. is established.
+ * sctp notification: SCTP_COMM_UP.
+ */
+#define SCTP_STATS_ESTABLISHED()
+
+/** called each time a new outgoing connection/assoc open fails.
+ *  sctp notification: SCTP_CANT_STR_ASSOC
+ */
+#define SCTP_STATS_CONNECT_FAILED()
+
+/** called each time a new incoming connection is rejected.  */
+#define SCTP_STATS_LOCAL_REJECT()
+
+
+/** called each time a connection is closed by the peer.
+  * sctp notification: SCTP_SHUTDOWN_EVENT
+  */
+#define SCTP_STATS_REMOTE_SHUTDOWN()
+
+
+/** called each time an established connection is closed due to some error.
+  * sctp notification: SCTP_COMM_LOST
+  */
+#define SCTP_STATS_COMM_LOST()
+
+
+/** called each time a send fails due to the buffering capacity being exceeded.
+  * (send fails due to full kernel buffers)
+  */
+#define SCTP_STATS_SENDQ_FULL()
+
+
+/** called each time a send fails.
+  * (send fails for any reason except buffers full)
+  * sctp notification: SCTP_SEND_FAILED
+  */
+#define SCTP_STATS_SEND_FAILED()
+
+/** called each time a failed send is force-retried.
+  * (possible only if sctp_send_retries is != 0)
+  */
+#define SCTP_STATS_SEND_FORCE_RETRY()
+
+#endif /* USE_SCTP_STATS */
+
+#endif /*__sctp_stats_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */