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 @@
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: */
... ...
@@ -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 1794
 		case SCTP_REMOTE_ERROR:
1794 1795
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_remote_error), si, su,
1795 1796
 								"SCTP_REMOTE_ERROR");
1797
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su, 
1798
+									ntohs(snp->sn_remote_error.sre_error) );
1796 1799
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_REMOTE_ERROR:"
1797 1800
 					" %d, len %d\n, assoc_id %d",
1798 1801
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1805,6 +1808,8 @@ static int sctp_handle_notification(struct socket_info* si,
1805 1808
 		case SCTP_SEND_FAILED:
1806 1809
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_send_failed), si, su,
1807 1810
 								"SCTP_SEND_FAILED");
1811
+			SCTP_EV_SEND_FAILED(&si->address, si->port_no, su, 
1812
+									snp->sn_send_failed.ssf_error);
1808 1813
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SEND_FAILED:"
1809 1814
 					" error %d, assoc_id %d, flags %x\n",
1810 1815
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1816,6 +1821,10 @@ static int sctp_handle_notification(struct socket_info* si,
1816 1821
 		case SCTP_PEER_ADDR_CHANGE:
1817 1822
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_paddr_change), si, su,
1818 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);
1819 1828
 			strcpy(su_buf, su2a((union sockaddr_union*)
1820 1829
 									&snp->sn_paddr_change.spc_aaddr, 
1821 1830
 									sizeof(snp->sn_paddr_change.spc_aaddr)));
... ...
@@ -1831,6 +1840,7 @@ static int sctp_handle_notification(struct socket_info* si,
1831 1840
 			SCTP_STATS_REMOTE_SHUTDOWN();
1832 1841
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_shutdown_event), si, su,
1833 1842
 								"SCTP_SHUTDOWN_EVENT");
1843
+			SCTP_EV_SHUTDOWN_EVENT(&si->address, si->port_no, su);
1834 1844
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SHUTDOWN_EVENT:"
1835 1845
 					" assoc_id %d\n",
1836 1846
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1839,6 +1849,9 @@ static int sctp_handle_notification(struct socket_info* si,
1839 1849
 		case SCTP_ASSOC_CHANGE:
1840 1850
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_assoc_change), si, su,
1841 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);
1842 1855
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_ASSOC_CHANGE"
1843 1856
 					": %s: assoc_id %d, ostreams %d, istreams %d\n",
1844 1857
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,
... ...
@@ -1877,6 +1890,7 @@ static int sctp_handle_notification(struct socket_info* si,
1877 1890
 		case SCTP_SENDER_DRY_EVENT:
1878 1891
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_sender_dry_event),
1879 1892
 								si, su, "SCTP_SENDER_DRY_EVENT");
1893
+			SCTP_EV_REMOTE_ERROR(&si->address, si->port_no, su);
1880 1894
 			SNOT("sctp notification from %s on %.*s:%d: "
1881 1895
 					"SCTP_SENDER_DRY_EVENT on %d\n",
1882 1896
 					su2a(su, sizeof(*su)), si->name.len, si->name.s,