Module: sip-router
Branch: ser_core_cvs
Commit: e11d7294437cee6544fb04c2394a6f31be09c4b2
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e11d729…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Apr 30 16:39:10 2009 +0000
sctp: internal macro/hooks for sctp events
Added macros for sctp events (for now empty, or defined to simple
example DBG()):
SCTP_EV_ASSOC_CHANGE
SCTP_EV_PEER_ADDR_CHANGE
SCTP_EV_REMOTE_ERROR
SCTP_EV_SEND_FAILED
SCTP_EV_SHUTDOWN_EVENT
SCTP_EV_SENDER_DRY_EVENT
---
sctp_ev.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sctp_server.c | 14 ++++++++
2 files changed, 111 insertions(+), 0 deletions(-)
diff --git a/sctp_ev.h b/sctp_ev.h
new file mode 100644
index 0000000..f801023
--- /dev/null
+++ b/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: */
diff --git a/sctp_server.c b/sctp_server.c
index b4aed18..077947d 100644
--- a/sctp_server.c
+++ b/sctp_server.c
@@ -59,6 +59,7 @@
#include "error.h"
#include "timer.h"
#include "sctp_stats.h"
+#include "sctp_ev.h"
@@ -1793,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,
@@ -1805,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,
@@ -1816,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)));
@@ -1831,6 +1840,7 @@ static int sctp_handle_notification(struct socket_info* si,
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,
@@ -1839,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,
@@ -1877,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,