From owner-svn-src-stable-12@freebsd.org Mon Aug 24 08:19:26 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 95F243B4BCA; Mon, 24 Aug 2020 08:19:26 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BZlQk39xTz4KtP; Mon, 24 Aug 2020 08:19:26 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5136015836; Mon, 24 Aug 2020 08:19:26 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07O8JQoI064942; Mon, 24 Aug 2020 08:19:26 GMT (envelope-from tuexen@FreeBSD.org) Received: (from tuexen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07O8JP07064940; Mon, 24 Aug 2020 08:19:25 GMT (envelope-from tuexen@FreeBSD.org) Message-Id: <202008240819.07O8JP07064940@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tuexen set sender to tuexen@FreeBSD.org using -f From: Michael Tuexen Date: Mon, 24 Aug 2020 08:19:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364617 - in stable/12: lib/libc/net sys/netinet X-SVN-Group: stable-12 X-SVN-Commit-Author: tuexen X-SVN-Commit-Paths: in stable/12: lib/libc/net sys/netinet X-SVN-Commit-Revision: 364617 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2020 08:19:26 -0000 Author: tuexen Date: Mon Aug 24 08:19:25 2020 New Revision: 364617 URL: https://svnweb.freebsd.org/changeset/base/364617 Log: MFC r362451: Use a struct sockaddr_in or struct sockaddr_in6 as the option value for the IPPROTO_SCTP level socket options SCTP_BINDX_ADD_ADDR and SCTP_BINDX_REM_ADDR. These socket option are intended for internal use only to implement sctp_bindx(). This is one user of struct sctp_getaddresses less. struct sctp_getaddresses is strange and will be changed shortly. Modified: stable/12/lib/libc/net/sctp_sys_calls.c stable/12/sys/netinet/sctp_usrreq.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libc/net/sctp_sys_calls.c ============================================================================== --- stable/12/lib/libc/net/sctp_sys_calls.c Mon Aug 24 08:16:07 2020 (r364616) +++ stable/12/lib/libc/net/sctp_sys_calls.c Mon Aug 24 08:19:25 2020 (r364617) @@ -35,6 +35,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -170,13 +171,12 @@ sctp_connectx(int sd, const struct sockaddr *addrs, in int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) { - struct sctp_getaddresses *gaddrs; struct sockaddr *sa; struct sockaddr_in *sin; struct sockaddr_in6 *sin6; int i; - size_t argsz; - uint16_t sport = 0; + uint16_t sport; + bool fix_port; /* validate the flags */ if ((flags != SCTP_BINDX_ADD_ADDR) && @@ -189,6 +189,8 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt errno = EINVAL; return (-1); } + sport = 0; + fix_port = false; /* First pre-screen the addresses */ sa = addrs; for (i = 0; i < addrcnt; i++) { @@ -210,6 +212,7 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt } else { /* save off the port */ sport = sin->sin_port; + fix_port = (i > 0); } } break; @@ -230,6 +233,7 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt } else { /* save off the port */ sport = sin6->sin6_port; + fix_port = (i > 0); } } break; @@ -240,42 +244,29 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt } sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); } - argsz = sizeof(struct sctp_getaddresses) + - sizeof(struct sockaddr_storage); - if ((gaddrs = (struct sctp_getaddresses *)malloc(argsz)) == NULL) { - errno = ENOMEM; - return (-1); - } sa = addrs; for (i = 0; i < addrcnt; i++) { - memset(gaddrs, 0, argsz); - gaddrs->sget_assoc_id = 0; - memcpy(gaddrs->addr, sa, sa->sa_len); /* * Now, if there was a port mentioned, assure that the first * address has that port to make sure it fails or succeeds * correctly. */ - if ((i == 0) && (sport != 0)) { - switch (gaddrs->addr->sa_family) { + if (fix_port) { + switch (sa->sa_family) { case AF_INET: - sin = (struct sockaddr_in *)gaddrs->addr; - sin->sin_port = sport; + ((struct sockaddr_in *)sa)->sin_port = sport; break; case AF_INET6: - sin6 = (struct sockaddr_in6 *)gaddrs->addr; - sin6->sin6_port = sport; + ((struct sockaddr_in6 *)sa)->sin6_port = sport; break; } + fix_port = false; } - if (setsockopt(sd, IPPROTO_SCTP, flags, gaddrs, - (socklen_t)argsz) != 0) { - free(gaddrs); + if (setsockopt(sd, IPPROTO_SCTP, flags, sa, sa->sa_len) != 0) { return (-1); } sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); } - free(gaddrs); return (0); } Modified: stable/12/sys/netinet/sctp_usrreq.c ============================================================================== --- stable/12/sys/netinet/sctp_usrreq.c Mon Aug 24 08:16:07 2020 (r364616) +++ stable/12/sys/netinet/sctp_usrreq.c Mon Aug 24 08:19:25 2020 (r364617) @@ -5976,33 +5976,35 @@ sctp_setopt(struct socket *so, int optname, void *optv } case SCTP_BINDX_ADD_ADDR: { - struct sctp_getaddresses *addrs; + struct sockaddr *sa; struct thread *td; td = (struct thread *)p; - SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, - optsize); + SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize); #ifdef INET - if (addrs->addr->sa_family == AF_INET) { - if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) { + if (sa->sa_family == AF_INET) { + if (optsize < sizeof(struct sockaddr_in)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; break; } - if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) { + if (td != NULL && + (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) { SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); break; } } else #endif #ifdef INET6 - if (addrs->addr->sa_family == AF_INET6) { - if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) { + if (sa->sa_family == AF_INET6) { + if (optsize < sizeof(struct sockaddr_in6)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; break; } - if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr), + if (td != NULL && + (error = prison_local_ip6(td->td_ucred, + &(((struct sockaddr_in6 *)sa)->sin6_addr), (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); break; @@ -6013,40 +6015,41 @@ sctp_setopt(struct socket *so, int optname, void *optv error = EAFNOSUPPORT; break; } - sctp_bindx_add_address(so, inp, addrs->addr, vrf_id, &error, p); + sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p); break; } case SCTP_BINDX_REM_ADDR: { - struct sctp_getaddresses *addrs; + struct sockaddr *sa; struct thread *td; td = (struct thread *)p; - SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize); + SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize); #ifdef INET - if (addrs->addr->sa_family == AF_INET) { - if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) { + if (sa->sa_family == AF_INET) { + if (optsize < sizeof(struct sockaddr_in)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; break; } - if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) { + if (td != NULL && + (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) { SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); break; } } else #endif #ifdef INET6 - if (addrs->addr->sa_family == AF_INET6) { - if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) { + if (sa->sa_family == AF_INET6) { + if (optsize < sizeof(struct sockaddr_in6)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; break; } if (td != NULL && (error = prison_local_ip6(td->td_ucred, - &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr), + &(((struct sockaddr_in6 *)sa)->sin6_addr), (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); break; @@ -6057,7 +6060,7 @@ sctp_setopt(struct socket *so, int optname, void *optv error = EAFNOSUPPORT; break; } - sctp_bindx_delete_address(inp, addrs->addr, vrf_id, &error); + sctp_bindx_delete_address(inp, sa, vrf_id, &error); break; } case SCTP_EVENT: