Browse code

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

Andrei Pelinescu-Onciul authored on 30/04/2009 16:39:10
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,97 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2009 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * sctp_ev.h - sctp events
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2009-04-28  initial version (andrei)
24
+*/
25
+
26
+#ifndef __sctp_ev_h
27
+#define __sctp_ev_h
28
+
29
+#include <errno.h>
30
+#include <string.h>
31
+
32
+#ifndef USE_SCTP_EV
33
+
34
+#define SCTP_EV_ASSOC_CHANGE(lip, lport, src, reason, state)
35
+#define SCTP_EV_PEER_ADDR_CHANGE(lip, lport, src, reason, state, addr_su)
36
+#define SCTP_EV_REMOTE_ERROR(lip, lport, src, err)
37
+#define SCTP_EV_SEND_FAILED(lip, lport, src, err)
38
+#define SCTP_EV_SHUTDOWN_EVENT(lip, lport, src)
39
+#define SCTP_EV_SENDER_DRY_EVENT(lip, lport, src)
40
+
41
+#else /* USE_SCTP_EV */
42
+
43
+#include "ip_addr.h"
44
+
45
+
46
+/** an association has either been opened or closed.
47
+ * called for each SCTP_ASSOC_CHANGE event.
48
+ *
49
+ * @param err - if 0 it should be ignored (no corresp. libc error), if non-0
50
+ *                it will contain the errno.
51
+ * @param lip   - pointer to an ip_addr containing the local ip
52
+ *                   or 0 if dynamic (WARNING can be 0).
53
+ * @param lport - pointer to an ip_addr containing the local port or 0
54
+ *                   if unknown/dynamic.
55
+ * @param src   - pointer to a sockaddr_union containing the src.
56
+ * @param proto - protocol used
57
+ */
58
+#define SCTP_EV_ASSOC_CHANGE(lip, lport, src, reason, state) \
59
+	DBG("SCTP_ASSOC_CHANGE from %s on %s:%d: %s\n", \
60
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, reason)
61
+
62
+/** an address part of an assoc. changed state.
63
+ * called for the SCTP_PEER_ADDR_CHANGE event.*/
64
+#define SCTP_EV_PEER_ADDR_CHANGE(lip, lport, src, reason, state, addr_su) \
65
+	DBG("SCTP_PEER_ADDR_CHANGE from %s on %s:%d: %s\n", \
66
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, reason)
67
+
68
+/** remote operation error from the peer.
69
+ * called for the SCTP_REMOTE_ERROR event.*/
70
+#define SCTP_EV_REMOTE_ERROR(lip, lport, src, err) \
71
+	DBG("SCTP_REMOTE_ERROR from %s on %s:%d: %d\n", \
72
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, err)
73
+
74
+/** send failed.
75
+ * called for the SCTP_SEND_FAILED event.*/
76
+#define SCTP_EV_SEND_FAILED(lip, lport, src, err) \
77
+	DBG("SCTP_SEND_FAILED from %s on %s:%d: %d\n", \
78
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport, err)
79
+
80
+/** the peer has sent a shutdown.
81
+ * called for the SCTP_SHUTDOWN_EVENT event.*/
82
+#define SCTP_EV_SHUTDOWN_EVENT(lip, lport, src) \
83
+	DBG("SCTP_SHUTDOWN_EVENT from %s on %s:%d\n", \
84
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport)
85
+
86
+/** kernel has finished sending all the queued data.
87
+ * called for the SCTP_SENDER_DRY_EVENT event.*/
88
+#define SCTP_EV_SENDER_DRY_EVENT(lip, lport, src) \
89
+	DBG("SCTP_SENDER_DRY_EVENT from %s on %s:%d\n", \
90
+			su2a(src, sizeof(*(src))), ip_addr2a(lip), lport)
91
+
92
+#endif /* USE_SCTP_EV */
93
+
94
+#endif /*__sctp_ev_h*/
95
+
96
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -59,6 +59,7 @@
59 59
 #include "error.h"
60 60
 #include "timer.h"
61 61
 #include "sctp_stats.h"
62
+#include "sctp_ev.h"
62 63
 
63 64
 
64 65
 
... ...
@@ -1793,6 +1794,8 @@ static int sctp_handle_notification(struct socket_info* si,
1793 1793
 		case SCTP_REMOTE_ERROR:
1794 1794
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_remote_error), si, su,
1795 1795
 								"SCTP_REMOTE_ERROR");
1796
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su, 
1797
+									ntohs(snp->sn_remote_error.sre_error) );
1796 1798
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_REMOTE_ERROR:"
1797 1799
 					" %d, len %d\n, assoc_id %d",
1798 1800
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1805,6 +1808,8 @@ static int sctp_handle_notification(struct socket_info* si,
1805 1805
 		case SCTP_SEND_FAILED:
1806 1806
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_send_failed), si, su,
1807 1807
 								"SCTP_SEND_FAILED");
1808
+			SCTP_EV_SEND_FAILED(&si->address, si->port_no, su, 
1809
+									snp->sn_send_failed.ssf_error);
1808 1810
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SEND_FAILED:"
1809 1811
 					" error %d, assoc_id %d, flags %x\n",
1810 1812
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1816,6 +1821,10 @@ static int sctp_handle_notification(struct socket_info* si,
1816 1816
 		case SCTP_PEER_ADDR_CHANGE:
1817 1817
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_paddr_change), si, su,
1818 1818
 								"SCTP_PEER_ADDR_CHANGE");
1819
+			SCTP_EV_PEER_ADDR_CHANGE(&si->address, si->port_no, su, 
1820
+					sctp_paddr_change_state2s(snp->sn_paddr_change.spc_state),
1821
+					snp->sn_paddr_change.spc_state,
1822
+					&snp->sn_paddr_change.spc_aaddr);
1819 1823
 			strcpy(su_buf, su2a((union sockaddr_union*)
1820 1824
 									&snp->sn_paddr_change.spc_aaddr, 
1821 1825
 									sizeof(snp->sn_paddr_change.spc_aaddr)));
... ...
@@ -1831,6 +1840,7 @@ static int sctp_handle_notification(struct socket_info* si,
1831 1831
 			SCTP_STATS_REMOTE_SHUTDOWN();
1832 1832
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_shutdown_event), si, su,
1833 1833
 								"SCTP_SHUTDOWN_EVENT");
1834
+			SCTP_EV_SHUTDOWN_EVENT(&si->address, si->port_no, su);
1834 1835
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SHUTDOWN_EVENT:"
1835 1836
 					" assoc_id %d\n",
1836 1837
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1839,6 +1849,9 @@ static int sctp_handle_notification(struct socket_info* si,
1839 1839
 		case SCTP_ASSOC_CHANGE:
1840 1840
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_assoc_change), si, su,
1841 1841
 								"SCTP_ASSOC_CHANGE");
1842
+			SCTP_EV_ASSOC_CHANGE(&si->address, si->port_no, su, 
1843
+					sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state),
1844
+					snp->sn_assoc_change.sac_state);
1842 1845
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_ASSOC_CHANGE"
1843 1846
 					": %s: assoc_id %d, ostreams %d, istreams %d\n",
1844 1847
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1877,6 +1890,7 @@ static int sctp_handle_notification(struct socket_info* si,
1877 1877
 		case SCTP_SENDER_DRY_EVENT:
1878 1878
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_sender_dry_event),
1879 1879
 								si, su, "SCTP_SENDER_DRY_EVENT");
1880
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su);
1880 1881
 			SNOT("sctp notification from %s on %.*s:%d: "
1881 1882
 					"SCTP_SENDER_DRY_EVENT on %d\n",
1882 1883
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,