Browse code

enable sctp multihoming support

- listen on multiple sctp addresses, the primary address being the first
one in the list.

Andrei Pelinescu-Onciul authored on 18/08/2008 14:56:32
Showing 1 changed files
... ...
@@ -57,13 +57,25 @@ int sctp_init_sock(struct socket_info* sock_info)
57 57
 	union sockaddr_union* addr;
58 58
 	int optval;
59 59
 	socklen_t optlen;
60
+	struct addr_info* ai;
60 61
 	
61 62
 	addr=&sock_info->su;
62 63
 	sock_info->proto=PROTO_SCTP;
63 64
 	if (init_su(addr, &sock_info->address, sock_info->port_no)<0){
64
-		LOG(L_ERR, "ERROR: sctp_init_sock: could not init sockaddr_union\n");
65
+		LOG(L_ERR, "ERROR: sctp_init_sock: could not init sockaddr_union for"
66
+					"primary sctp address %.*s:%d\n",
67
+					sock_info->address_str.len, sock_info->address_str.s,
68
+					sock_info->port_no );
65 69
 		goto error;
66 70
 	}
71
+	for (ai=sock_info->addr_info_lst; ai; ai=ai->next)
72
+		if (init_su(&ai->su, &ai->address, sock_info->port_no)<0){
73
+			LOG(L_ERR, "ERROR: sctp_init_sock: could not init"
74
+					"backup sctp sockaddr_union for %.*s:%d\n",
75
+					ai->address_str.len, ai->address_str.s,
76
+					sock_info->port_no );
77
+			goto error;
78
+		}
67 79
 	sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_SEQPACKET, 
68 80
 								IPPROTO_SCTP);
69 81
 	if (sock_info->socket==-1){
... ...
@@ -190,6 +202,24 @@ int sctp_init_sock(struct socket_info* sock_info)
190 190
 	#endif
191 191
 		goto error;
192 192
 	}
193
+	for (ai=sock_info->addr_info_lst; ai; ai=ai->next)
194
+		if (sctp_bindx(sock_info->socket, &ai->su.s, 1, SCTP_BINDX_ADD_ADDR)
195
+					==-1){
196
+			LOG(L_ERR, "ERROR: sctp_init_sock: sctp_bindx(%x, %.*s:%d, 1, ...)"
197
+						" on %s:%d : [%d] %s (trying to continue)\n",
198
+						sock_info->socket,
199
+						ai->address_str.len, ai->address_str.s, 
200
+						sock_info->port_no,
201
+						sock_info->address_str.s, sock_info->port_no,
202
+						errno, strerror(errno));
203
+		#ifdef USE_IPV6
204
+			if (ai->su.s.sa_family==AF_INET6)
205
+				LOG(L_ERR, "ERROR: sctp_init_sock: might be caused by using a "
206
+							"link local address, try site local or global\n");
207
+		#endif
208
+			/* try to continue, a secondary address bind failure is not 
209
+			 * critical */
210
+		}
193 211
 	if (listen(sock_info->socket, 1)<0){
194 212
 		LOG(L_ERR, "ERROR: sctp_init_sock: listen(%x, 1) on %s: %s\n",
195 213
 					sock_info->socket, sock_info->address_str.s,