socket: osmo_sock_init2_multiaddr2(): Apply params too if no OSMO_SOCK_F_BIND flag set

Those parameters are not related to binding and hence should be
applicable before binding. This allows a caller setting them while not
caring about explicit binding (OSMO_SOCK_F_BIND).
Until recently calling this function without OSMO_SOCK_F_BIND was not
really supported, so the previous placement setting these params in the
function didn't matter much. It does now.

Change-Id: Ia32510e8db1de0cc0dc36cebf8a94f09e44fda70
diff --git a/src/core/socket.c b/src/core/socket.c
index 0bc275b..7fc1b72 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -959,23 +959,8 @@
 		goto ret_freeaddrinfo;
 	}
 
-	if (flags & OSMO_SOCK_F_BIND) {
-		/* Since so far we only allow IPPROTO_SCTP in this function,
-		   no need to check below for "proto != IPPROTO_UDP || flags & OSMO_SOCK_F_UDP_REUSEADDR" */
-		rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
-				&on, sizeof(on));
-		if (rc < 0) {
-			int err = errno;
-			multiaddr_snprintf(strbuf, sizeof(strbuf), local_hosts, local_hosts_cnt);
-			LOGP(DLGLOBAL, LOGL_ERROR,
-			     "cannot setsockopt socket:"
-			     " %s:%u: %s\n",
-			     strbuf, local_port,
-			     strerror(err));
-			goto ret_close;
-		}
-
-		if (pars && pars->sctp.sockopt_auth_supported.set) {
+	if (pars) {
+		if (pars->sctp.sockopt_auth_supported.set) {
 			/* RFC 5061 4.2.7: ASCONF also requires AUTH feature. */
 			rc = setsockopt_sctp_auth_supported(sfd, pars->sctp.sockopt_auth_supported.value);
 			if (rc < 0) {
@@ -991,7 +976,7 @@
 			}
 		}
 
-		if (pars && pars->sctp.sockopt_asconf_supported.set) {
+		if (pars->sctp.sockopt_asconf_supported.set) {
 			rc = setsockopt_sctp_asconf_supported(sfd, pars->sctp.sockopt_asconf_supported.value);
 			if (rc < 0) {
 				int err = errno;
@@ -1006,7 +991,7 @@
 			}
 		}
 
-		if (pars && pars->sctp.sockopt_initmsg.set) {
+		if (pars->sctp.sockopt_initmsg.set) {
 			rc = setsockopt_sctp_initmsg(sfd, pars);
 			if (rc < 0) {
 				int err = errno;
@@ -1019,6 +1004,23 @@
 				/* do not fail, some parameters will be left as the global default */
 			}
 		}
+	}
+
+	if (flags & OSMO_SOCK_F_BIND) {
+		/* Since so far we only allow IPPROTO_SCTP in this function,
+		   no need to check below for "proto != IPPROTO_UDP || flags & OSMO_SOCK_F_UDP_REUSEADDR" */
+		rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
+				&on, sizeof(on));
+		if (rc < 0) {
+			int err = errno;
+			multiaddr_snprintf(strbuf, sizeof(strbuf), local_hosts, local_hosts_cnt);
+			LOGP(DLGLOBAL, LOGL_ERROR,
+			     "cannot setsockopt socket:"
+			     " %s:%u: %s\n",
+			     strbuf, local_port,
+			     strerror(err));
+			goto ret_close;
+		}
 
 		/* Build array of addresses taking first entry for each host.
 		   TODO: Ideally we should use backtracking storing last used