From owner-svn-src-stable-12@freebsd.org Mon Aug 24 08:16:08 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 61F143B4BAD; Mon, 24 Aug 2020 08:16:08 +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 4BZlLw1wL6z4Kn6; Mon, 24 Aug 2020 08:16:08 +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 2522115952; Mon, 24 Aug 2020 08:16:08 +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 07O8G8VS064749; Mon, 24 Aug 2020 08:16:08 GMT (envelope-from tuexen@FreeBSD.org) Received: (from tuexen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07O8G7Zu064747; Mon, 24 Aug 2020 08:16:07 GMT (envelope-from tuexen@FreeBSD.org) Message-Id: <202008240816.07O8G7Zu064747@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:16:07 +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: r364616 - stable/12/sys/netinet X-SVN-Group: stable-12 X-SVN-Commit-Author: tuexen X-SVN-Commit-Paths: stable/12/sys/netinet X-SVN-Commit-Revision: 364616 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:16:08 -0000 Author: tuexen Date: Mon Aug 24 08:16:07 2020 New Revision: 364616 URL: https://svnweb.freebsd.org/changeset/base/364616 Log: MFC r362448: Cleanup the adding and deleting of addresses via sctp_bindx(). There is no need to use the association identifier, so remove it. While there, cleanup the code a bit. Modified: stable/12/sys/netinet/sctp_usrreq.c stable/12/sys/netinet/sctputil.c stable/12/sys/netinet/sctputil.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netinet/sctp_usrreq.c ============================================================================== --- stable/12/sys/netinet/sctp_usrreq.c Mon Aug 24 08:14:41 2020 (r364615) +++ stable/12/sys/netinet/sctp_usrreq.c Mon Aug 24 08:16:07 2020 (r364616) @@ -6013,9 +6013,7 @@ sctp_setopt(struct socket *so, int optname, void *optv error = EAFNOSUPPORT; break; } - sctp_bindx_add_address(so, inp, addrs->addr, - addrs->sget_assoc_id, vrf_id, - &error, p); + sctp_bindx_add_address(so, inp, addrs->addr, vrf_id, &error, p); break; } case SCTP_BINDX_REM_ADDR: @@ -6059,9 +6057,7 @@ sctp_setopt(struct socket *so, int optname, void *optv error = EAFNOSUPPORT; break; } - sctp_bindx_delete_address(inp, addrs->addr, - addrs->sget_assoc_id, vrf_id, - &error); + sctp_bindx_delete_address(inp, addrs->addr, vrf_id, &error); break; } case SCTP_EVENT: Modified: stable/12/sys/netinet/sctputil.c ============================================================================== --- stable/12/sys/netinet/sctputil.c Mon Aug 24 08:14:41 2020 (r364615) +++ stable/12/sys/netinet/sctputil.c Mon Aug 24 08:16:07 2020 (r364616) @@ -6682,13 +6682,21 @@ sctp_connectx_helper_find(struct sctp_inpcb *inp, stru */ void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, - struct sockaddr *sa, sctp_assoc_t assoc_id, - uint32_t vrf_id, int *error, void *p) + struct sockaddr *sa, uint32_t vrf_id, int *error, + void *p) { - struct sockaddr *addr_touse; #if defined(INET) && defined(INET6) struct sockaddr_in sin; #endif +#ifdef INET6 + struct sockaddr_in6 *sin6; +#endif +#ifdef INET + struct sockaddr_in *sinp; +#endif + struct sockaddr *addr_to_use; + struct sctp_inpcb *lep; + uint16_t port; /* see if we're bound all already! */ if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { @@ -6696,13 +6704,9 @@ sctp_bindx_add_address(struct socket *so, struct sctp_ *error = EINVAL; return; } - addr_touse = sa; + switch (sa->sa_family) { #ifdef INET6 - if (sa->sa_family == AF_INET6) { -#ifdef INET - struct sockaddr_in6 *sin6; - -#endif + case AF_INET6: if (sa->sa_len != sizeof(struct sockaddr_in6)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); *error = EINVAL; @@ -6714,8 +6718,9 @@ sctp_bindx_add_address(struct socket *so, struct sctp_ *error = EINVAL; return; } + sin6 = (struct sockaddr_in6 *)sa; + port = sin6->sin6_port; #ifdef INET - sin6 = (struct sockaddr_in6 *)addr_touse; if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && SCTP_IPV6_V6ONLY(inp)) { @@ -6725,13 +6730,15 @@ sctp_bindx_add_address(struct socket *so, struct sctp_ return; } in6_sin6_2_sin(&sin, sin6); - addr_touse = (struct sockaddr *)&sin; + addr_to_use = (struct sockaddr *)&sin; + } else { + addr_to_use = sa; } #endif - } + break; #endif #ifdef INET - if (sa->sa_family == AF_INET) { + case AF_INET: if (sa->sa_len != sizeof(struct sockaddr_in)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); *error = EINVAL; @@ -6744,8 +6751,16 @@ sctp_bindx_add_address(struct socket *so, struct sctp_ *error = EINVAL; return; } - } + sinp = (struct sockaddr_in *)sa; + port = sinp->sin_port; + addr_to_use = sa; + break; #endif + default: + SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); + *error = EINVAL; + return; + } if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) { if (p == NULL) { /* Can't get proc for Net/Open BSD */ @@ -6753,55 +6768,25 @@ sctp_bindx_add_address(struct socket *so, struct sctp_ *error = EINVAL; return; } - *error = sctp_inpcb_bind(so, addr_touse, NULL, p); + *error = sctp_inpcb_bind(so, addr_to_use, NULL, p); return; } - /* - * No locks required here since bind and mgmt_ep_sa all do their own - * locking. If we do something for the FIX: below we may need to - * lock in that case. - */ - if (assoc_id == 0) { + /* Validate the incoming port. */ + if ((port != 0) && (port != inp->sctp_lport)) { + SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); + *error = EINVAL; + return; + } + lep = sctp_pcb_findep(addr_to_use, 1, 0, vrf_id); + if (lep == NULL) { /* add the address */ - struct sctp_inpcb *lep; - struct sockaddr_in *lsin = (struct sockaddr_in *)addr_touse; - - /* validate the incoming port */ - if ((lsin->sin_port != 0) && - (lsin->sin_port != inp->sctp_lport)) { - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); - *error = EINVAL; - return; - } else { - /* user specified 0 port, set it to existing port */ - lsin->sin_port = inp->sctp_lport; - } - - lep = sctp_pcb_findep(addr_touse, 1, 0, vrf_id); - if (lep != NULL) { - /* - * We must decrement the refcount since we have the - * ep already and are binding. No remove going on - * here. - */ - SCTP_INP_DECR_REF(lep); - } - if (lep == inp) { - /* already bound to it.. ok */ - return; - } else if (lep == NULL) { - ((struct sockaddr_in *)addr_touse)->sin_port = 0; - *error = sctp_addr_mgmt_ep_sa(inp, addr_touse, - SCTP_ADD_IP_ADDRESS, vrf_id); - } else { + *error = sctp_addr_mgmt_ep_sa(inp, addr_to_use, + SCTP_ADD_IP_ADDRESS, vrf_id); + } else { + if (lep != inp) { *error = EADDRINUSE; } - if (*error) - return; - } else { - /* - * FIX: decide whether we allow assoc based bindx - */ + SCTP_INP_DECR_REF(lep); } } @@ -6811,11 +6796,11 @@ sctp_bindx_add_address(struct socket *so, struct sctp_ */ void sctp_bindx_delete_address(struct sctp_inpcb *inp, - struct sockaddr *sa, sctp_assoc_t assoc_id, - uint32_t vrf_id, int *error) + struct sockaddr *sa, uint32_t vrf_id, int *error) { - struct sockaddr *addr_touse; + struct sockaddr *addr_to_use; #if defined(INET) && defined(INET6) + struct sockaddr_in6 *sin6; struct sockaddr_in sin; #endif @@ -6825,13 +6810,9 @@ sctp_bindx_delete_address(struct sctp_inpcb *inp, *error = EINVAL; return; } - addr_touse = sa; + switch (sa->sa_family) { #ifdef INET6 - if (sa->sa_family == AF_INET6) { -#ifdef INET - struct sockaddr_in6 *sin6; -#endif - + case AF_INET6: if (sa->sa_len != sizeof(struct sockaddr_in6)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); *error = EINVAL; @@ -6844,7 +6825,7 @@ sctp_bindx_delete_address(struct sctp_inpcb *inp, return; } #ifdef INET - sin6 = (struct sockaddr_in6 *)addr_touse; + sin6 = (struct sockaddr_in6 *)sa; if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && SCTP_IPV6_V6ONLY(inp)) { @@ -6854,13 +6835,15 @@ sctp_bindx_delete_address(struct sctp_inpcb *inp, return; } in6_sin6_2_sin(&sin, sin6); - addr_touse = (struct sockaddr *)&sin; + addr_to_use = (struct sockaddr *)&sin; + } else { + addr_to_use = sa; } #endif - } + break; #endif #ifdef INET - if (sa->sa_family == AF_INET) { + case AF_INET: if (sa->sa_len != sizeof(struct sockaddr_in)) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); *error = EINVAL; @@ -6873,22 +6856,17 @@ sctp_bindx_delete_address(struct sctp_inpcb *inp, *error = EINVAL; return; } - } + addr_to_use = sa; + break; #endif - /* - * No lock required mgmt_ep_sa does its own locking. If the FIX: - * below is ever changed we may need to lock before calling - * association level binding. - */ - if (assoc_id == 0) { - /* delete the address */ - *error = sctp_addr_mgmt_ep_sa(inp, addr_touse, - SCTP_DEL_IP_ADDRESS, vrf_id); - } else { - /* - * FIX: decide whether we allow assoc based bindx - */ + default: + SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); + *error = EINVAL; + return; } + /* No lock required mgmt_ep_sa does its own locking. */ + *error = sctp_addr_mgmt_ep_sa(inp, addr_to_use, SCTP_DEL_IP_ADDRESS, + vrf_id); } /* Modified: stable/12/sys/netinet/sctputil.h ============================================================================== --- stable/12/sys/netinet/sctputil.h Mon Aug 24 08:14:41 2020 (r364615) +++ stable/12/sys/netinet/sctputil.h Mon Aug 24 08:16:07 2020 (r364616) @@ -229,11 +229,10 @@ struct mbuf *sctp_generate_no_user_data_cause(uint32_t void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, - struct sockaddr *sa, sctp_assoc_t assoc_id, - uint32_t vrf_id, int *error, void *p); + struct sockaddr *sa, uint32_t vrf_id, int *error, + void *p); void -sctp_bindx_delete_address(struct sctp_inpcb *inp, - struct sockaddr *sa, sctp_assoc_t assoc_id, +sctp_bindx_delete_address(struct sctp_inpcb *inp, struct sockaddr *sa, uint32_t vrf_id, int *error); int sctp_local_addr_count(struct sctp_tcb *stcb);