Mercurial > hg > waaad
changeset 334:9a0a3220ad9f
Automated merge with ssh://thedoc@morbier.koganei.wide.ad.jp//var/hg/repos/waaad/
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 31 Mar 2009 15:59:14 +0900 |
parents | 3841075afdde (current diff) 70384e14ba9e (diff) |
children | 7bdc3fc65ae2 |
files | |
diffstat | 2 files changed, 73 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/waaad/peer-sctp.c Thu Mar 26 07:31:24 2009 +0900 +++ b/waaad/peer-sctp.c Tue Mar 31 15:59:14 2009 +0900 @@ -53,7 +53,7 @@ /*******************************************************************************************************/ /* local functions */ -static int _sctp_setsockopt(int sk, uint16_t nstreams) +static int _sctp_setsockopt_pre(int sk, uint16_t nstreams) { #ifdef DEBUG_SCTP socklen_t sz; @@ -359,38 +359,6 @@ TRACE_DEBUG(FULL, "Skipping SCTP_FRAGMENT_INTERLEAVE"); #endif /* SCTP_FRAGMENT_INTERLEAVE */ - /* Set the ASCONF option */ - #ifdef SCTP_AUTO_ASCONF - { - int asconf; - - #ifdef DEBUG_SCTP - sz = sizeof(asconf); - /* Read socket defaults */ - CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz) ); - if (sz != sizeof(asconf)) - { - TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(asconf)); - return ENOTSUP; - } - TRACE_DEBUG(FULL, "Def SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false"); - #endif /* DEBUG_SCTP */ - - asconf = 1; /* allow automatic use of added or removed addresses in the association (for bound-all sockets) */ - - /* Set the option to the socket */ - CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, sizeof(asconf)) ); - - #ifdef DEBUG_SCTP - /* Check new values */ - CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz) ); - TRACE_DEBUG(FULL, "New SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false"); - #endif /* DEBUG_SCTP */ - } - #else /* SCTP_AUTO_ASCONF */ - TRACE_DEBUG(FULL, "Skipping SCTP_AUTO_ASCONF"); - #endif /* SCTP_AUTO_ASCONF */ - /* Set the v4 mapped addresses option */ #ifdef SCTP_I_WANT_MAPPED_V4_ADDR { @@ -461,6 +429,52 @@ return 0; } +static int _sctp_setsockopt_post(int sk, int bound_all) +{ + #ifdef DEBUG_SCTP + socklen_t sz; + #endif /* DEBUG_SCTP */ + + TRACE_ENTRY( "%d", sk); + + CHECK_PARAMS( (sk > 0) ); + + /* Set the ASCONF option */ + #ifdef SCTP_AUTO_ASCONF + if (bound_all) { + int asconf; + + #ifdef DEBUG_SCTP + sz = sizeof(asconf); + /* Read socket defaults */ + CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz) ); + if (sz != sizeof(asconf)) + { + TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(asconf)); + return ENOTSUP; + } + TRACE_DEBUG(FULL, "Def SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false"); + #endif /* DEBUG_SCTP */ + + asconf = 1; /* allow automatic use of added or removed addresses in the association (for bound-all sockets) */ + + /* Set the option to the socket */ + CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, sizeof(asconf)) ); + + #ifdef DEBUG_SCTP + /* Check new values */ + CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz) ); + TRACE_DEBUG(FULL, "New SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false"); + #endif /* DEBUG_SCTP */ + } + #else /* SCTP_AUTO_ASCONF */ + TRACE_DEBUG(FULL, "Skipping SCTP_AUTO_ASCONF"); + #endif /* SCTP_AUTO_ASCONF */ + + return 0; +} + + /* Read the list of bound addresses from a socket and save it to g_pconf->local_addr_sec_sa. Note that the local addresses (127.0.0.1, ::1) are not saved. */ static int _sctp_getboundaddrs(int sk) @@ -561,6 +575,7 @@ { int af; int sk; + int bound_all = 0; sSS * ss; TRACE_ENTRY("%p", sock); @@ -576,7 +591,7 @@ CHECK_SYS( sk = socket(af, SOCK_STREAM, IPPROTO_SCTP) ); /* Set the number of streams and other common options to the socket */ - CHECK_FCT( _sctp_setsockopt(sk, g_pconf->sctp_streams) ); + CHECK_FCT( _sctp_setsockopt_pre(sk, g_pconf->sctp_streams) ); /* Now bind to all the requested addresses if specified, or default set otherwise */ if ((g_pconf->local_addr_pri_sa == NULL) && (g_pconf->local_addr_sec_sa == NULL)) { @@ -594,6 +609,7 @@ CHECK_SYS( bind(sk, (sSA *)&sin, sizeof(sin)) ); /* And now save the list of addresses to which we are bound */ + bound_all = 1; CHECK_FCT( _sctp_getboundaddrs(sk) ); } else { /* we have the list of addresses to bind to, use sctp_bindx */ @@ -736,6 +752,8 @@ TRACE_DEBUG(FULL, "SCTP socket created: %d", sk); } #endif /* DEBUG_SCTP */ + + CHECK_FCT( _sctp_setsockopt_post(sk, bound_all) ); *sock = sk; return 0; @@ -842,13 +860,14 @@ CHECK_SYS( sk = socket(af, SOCK_STREAM, IPPROTO_SCTP) ); /* Set the number of streams and other common options to the socket */ - CHECK_FCT( _sctp_setsockopt(sk, *ostreams) ); + CHECK_FCT( _sctp_setsockopt_pre(sk, *ostreams) ); sSA_DUMP( FULL, "Connecting to SCTP server: ", addr ); CHECK_SYS( connect(sk, addr, addrlen) ); /* Now that we are connected, retrieve the number of streams */ + CHECK_FCT( _sctp_setsockopt_post(sk, 1) ); /* Read the association parameters */ memset(&status, 0, sizeof(status));
--- a/waaad/peer-tcp.c Thu Mar 26 07:31:24 2009 +0900 +++ b/waaad/peer-tcp.c Tue Mar 31 15:59:14 2009 +0900 @@ -43,9 +43,10 @@ #include "peer-internal.h" #include <netinet/tcp.h> +#include <netinet/ip6.h> -/* Set the socket options for TCP sockets */ -static int _tcp_setsockopt(int sk) +/* Set the socket options for TCP sockets, before bind is called */ +static int _tcp_setsockopt(int family, int sk) { int ret = 0; int opt; @@ -76,12 +77,25 @@ - yeah */ + /* In case of v6 address, force the v6only option, we use a different socket for v4 */ + #ifdef IPV6_V6ONLY + if (family == AF_INET6) { + opt = 1; + ret = setsockopt(sk, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)); + if (ret != 0) { + ret = errno; + TRACE_DEBUG(INFO, "Unable to set the socket IPV6_V6ONLY option: %s", strerror(ret)); + return ret; + } + } + #endif /* IPV6_V6ONLY */ + + /* There are also others sockopt that can be set, but nothing useful for us AFAICT */ return 0; } - /* * FUNCTION: _peer_tcp_create_server * @@ -107,7 +121,7 @@ CHECK_SYS( *sock = socket(addr->sa_family, SOCK_STREAM, IPPROTO_TCP) ); /* Set the socket options */ - CHECK_FCT( _tcp_setsockopt(*sock) ); + CHECK_FCT( _tcp_setsockopt(addr->sa_family, *sock) ); /* Bind the socket */ CHECK_SYS( bind( *sock, addr, salen ) ); @@ -144,7 +158,7 @@ CHECK_SYS( *sock = socket(addr->sa_family, SOCK_STREAM, IPPROTO_TCP) ); /* Set the socket options */ - CHECK_FCT( _tcp_setsockopt(*sock) ); + CHECK_FCT( _tcp_setsockopt(addr->sa_family, *sock) ); sSA_DUMP( FULL, "Attempting TCP connection with peer: ", addr );