From nobody Wed Dec 07 19:51:59 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NS7GR6MQzz4jgf5; Wed, 7 Dec 2022 19:51:59 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NS7GR5jCwz3MbR; Wed, 7 Dec 2022 19:51:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670442719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PQiMZmGIImt3/v+clsW90vg0RcmjFwAXYTpZJpbQAUU=; b=q0PNViQ9J58vVjaguJFsqdPmbVwUSuhpgxRbE1Nm2Pc0Hz07D7th1OzZ13BjTHvz5bRyNz wQnzCsMvYd3XWwuYPrr51zI5Ie5SewmDwVPOsSejOcxSH7QmcnECFrhs3OgKv2P7fm3dhx M7jRe/IitOVMLD30hDjhBufYglC5qZHDiOyHLEKGMbvBsLfuzHuqe02X7UTejK7q0oUAYs 7DYuYjGe01qDweWczIuMKqkImCSAufLCK3RixPOFJdnPE0DdFjz5tq1vlOLSu9dWj8qJi7 EvWn4KCZdVaKvDKxY1QL4y8l4u3tU6fsXlIlMAA/gRU85gP2/r/N+EVJ+fqLdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670442719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PQiMZmGIImt3/v+clsW90vg0RcmjFwAXYTpZJpbQAUU=; b=XD9iVheqPow7w430tc8FaHbuIItXV4xyaYQjdpfUb20Vect5o9IkPD5wzjZuI/y4lOL3Lf 9NZb4u/VEvipOA0KFdY8G5dFMqRpEwVNAIjSkrtU/n+qZrpAXkxEPKGFUbwy+TCzBouobZ ueRLj4DXbCtVnH/T4vhyRMbZQ6IdgvRPh+IQC3MFiAB24Mb1dSG4A40SV5WK3KN0igx7uq eHRP4LX5z5n5mFnV0VgVArF+WpT/6zSnD3EDGJeoMHUBy53ApOT+SJsBnKWsmvmGYgZ9VI kX5Isu8I9ibPCozlzhwMb4jlDMUbxcFG8rNK5RYQ5h7dSz3FqOcxwNhY+9AQEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670442719; a=rsa-sha256; cv=none; b=tGo+LiijGG+j94ygINtaMIZSTsDkSSOUg/u/fX7C8jY1F2KP9A4P+3hcLPuzjbfUVAqUuS 0CaLYHUC/+nfMnpZTvxG7sF9+6blmDro2lHkLVyGValcm2MTFRerl4+ctRWfzVrCe2TgkG C8tBRVq3fGdJ+hPn0+siWT46g5Xt1ru+17ji7v7ho3C0XEa3AlW4l1aJTekkDyC/S8+8Ld rvsDIp7sRZFpElOR7vDysEV0NltnpeTKvSaIXaaYAtFPQ5713JZc/w7oUjTOuzZZgu/eh2 V+ebcMHwyva1LeDxbrh+mUm46GE5MkFT8i7J7SEGiUG6AwnZrt1LYu+MWbFPPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NS7GR4l1rzTR0; Wed, 7 Dec 2022 19:51:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2B7Jpx0r028199; Wed, 7 Dec 2022 19:51:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B7Jpx48028198; Wed, 7 Dec 2022 19:51:59 GMT (envelope-from git) Date: Wed, 7 Dec 2022 19:51:59 GMT Message-Id: <202212071951.2B7Jpx48028198@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 483fe96511ec - main - udp: embed inpcb into udpcb List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 483fe96511ec02a3f077f9a59f1a96acb3640dea Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=483fe96511ec02a3f077f9a59f1a96acb3640dea commit 483fe96511ec02a3f077f9a59f1a96acb3640dea Author: Gleb Smirnoff AuthorDate: 2022-12-07 19:51:42 +0000 Commit: Gleb Smirnoff CommitDate: 2022-12-07 19:51:42 +0000 udp: embed inpcb into udpcb See similar change to TCP e68b3792440 for more context. For UDP the change is much simplier, though. --- sys/netinet/udp_usrreq.c | 48 ++++++---------------------------------------- sys/netinet/udp_var.h | 9 +++++---- sys/netinet6/udp6_usrreq.c | 8 -------- 3 files changed, 11 insertions(+), 54 deletions(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index e8aaf1f11134..44f7b949c140 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -149,8 +149,6 @@ SYSCTL_ULONG(_net_inet_udp, UDPCTL_RECVSPACE, recvspace, CTLFLAG_RW, VNET_DEFINE(struct inpcbinfo, udbinfo); VNET_DEFINE(struct inpcbinfo, ulitecbinfo); -VNET_DEFINE_STATIC(uma_zone_t, udpcb_zone); -#define V_udpcb_zone VNET(udpcb_zone) #ifndef UDBHASHSIZE #define UDBHASHSIZE 128 @@ -170,8 +168,8 @@ static int udp_output(struct inpcb *, struct mbuf *, struct sockaddr *, struct mbuf *, struct thread *, int); #endif -INPCBSTORAGE_DEFINE(udpcbstor, inpcb, "udpinp", "udp_inpcb", "udp", "udphash"); -INPCBSTORAGE_DEFINE(udplitecbstor, inpcb, "udpliteinp", "udplite_inpcb", +INPCBSTORAGE_DEFINE(udpcbstor, udpcb, "udpinp", "udp_inpcb", "udp", "udphash"); +INPCBSTORAGE_DEFINE(udplitecbstor, udpcb, "udpliteinp", "udplite_inpcb", "udplite", "udplitehash"); static void @@ -186,11 +184,6 @@ udp_vnet_init(void *arg __unused) * a 4-tuple, flip this to 4-tuple. */ in_pcbinfo_init(&V_udbinfo, &udpcbstor, UDBHASHSIZE, UDBHASHSIZE); - V_udpcb_zone = uma_zcreate("udpcb", sizeof(struct udpcb), - NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); - uma_zone_set_max(V_udpcb_zone, maxsockets); - uma_zone_set_warning(V_udpcb_zone, "kern.ipc.maxsockets limit reached"); - /* Additional pcbinfo for UDP-Lite */ in_pcbinfo_init(&V_ulitecbinfo, &udplitecbstor, UDBHASHSIZE, UDBHASHSIZE); @@ -212,25 +205,6 @@ kmod_udpstat_inc(int statnum) counter_u64_add(VNET(udpstat)[statnum], 1); } -int -udp_newudpcb(struct inpcb *inp) -{ - struct udpcb *up; - - up = uma_zalloc(V_udpcb_zone, M_NOWAIT | M_ZERO); - if (up == NULL) - return (ENOBUFS); - inp->inp_ppcb = up; - return (0); -} - -void -udp_discardcb(struct udpcb *up) -{ - - uma_zfree(V_udpcb_zone, up); -} - #ifdef VIMAGE static void udp_destroy(void *unused __unused) @@ -238,7 +212,6 @@ udp_destroy(void *unused __unused) in_pcbinfo_destroy(&V_udbinfo); in_pcbinfo_destroy(&V_ulitecbinfo); - uma_zdestroy(V_udpcb_zone); } VNET_SYSUNINIT(udp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, udp_destroy, NULL); #endif @@ -1482,8 +1455,9 @@ static int udp_attach(struct socket *so, int proto, struct thread *td) { static uint32_t udp_flowid; - struct inpcb *inp; struct inpcbinfo *pcbinfo; + struct inpcb *inp; + struct udpcb *up; int error; pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol); @@ -1500,13 +1474,8 @@ udp_attach(struct socket *so, int proto, struct thread *td) inp->inp_ip_ttl = V_ip_defttl; inp->inp_flowid = atomic_fetchadd_int(&udp_flowid, 1); inp->inp_flowtype = M_HASHTYPE_OPAQUE; - - error = udp_newudpcb(inp); - if (error) { - in_pcbdetach(inp); - in_pcbfree(inp); - return (error); - } + up = intoudpcb(inp); + bzero(&up->u_start_zero, u_zero_size); INP_WUNLOCK(inp); return (0); @@ -1636,19 +1605,14 @@ static void udp_detach(struct socket *so) { struct inpcb *inp; - struct udpcb *up; inp = sotoinpcb(so); KASSERT(inp != NULL, ("udp_detach: inp == NULL")); KASSERT(inp->inp_faddr.s_addr == INADDR_ANY, ("udp_detach: not disconnected")); INP_WLOCK(inp); - up = intoudpcb(inp); - KASSERT(up != NULL, ("%s: up == NULL", __func__)); - inp->inp_ppcb = NULL; in_pcbdetach(inp); in_pcbfree(inp); - udp_discardcb(up); } pr_disconnect_t udp_disconnect; /* shared with udp6_usrreq.c */ diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 965630965352..26e56be53f16 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -110,6 +110,10 @@ typedef void udp_tun_icmp_t(udp_tun_icmp_param_t); * UDP control block; one per udp. */ struct udpcb { + struct inpcb u_inpcb; +#define u_start_zero u_tun_func +#define u_zero_size (sizeof(struct udpcb) - \ + offsetof(struct udpcb, u_start_zero)) udp_tun_func_t *u_tun_func; /* UDP kernel tunneling callback. */ udp_tun_icmp_t *u_icmp_func; /* UDP kernel tunneling icmp callback */ u_int u_flags; /* Generic UDP flags. */ @@ -118,7 +122,7 @@ struct udpcb { void *u_tun_ctx; /* Tunneling callback context. */ }; -#define intoudpcb(ip) ((struct udpcb *)(ip)->inp_ppcb) +#define intoudpcb(ip) __containerof((inp), struct udpcb, u_inpcb) #define sotoudpcb(so) (intoudpcb(sotoinpcb(so))) VNET_PCPUSTAT_DECLARE(struct udpstat, udpstat); @@ -164,9 +168,6 @@ udp_get_inpcbinfo(int protocol) return (protocol == IPPROTO_UDP) ? &V_udbinfo : &V_ulitecbinfo; } -int udp_newudpcb(struct inpcb *); -void udp_discardcb(struct udpcb *); - int udp_ctloutput(struct socket *, struct sockopt *); void udplite_input(struct mbuf *, int); struct inpcb *udp_notify(struct inpcb *inp, int errno); diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index b491a41a7a4b..2d309d938056 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -1005,13 +1005,6 @@ udp6_attach(struct socket *so, int proto, struct thread *td) * which may match an IPv4-mapped IPv6 address. */ inp->inp_ip_ttl = V_ip_defttl; - - error = udp_newudpcb(inp); - if (error) { - in_pcbdetach(inp); - in_pcbfree(inp); - return (error); - } INP_WUNLOCK(inp); return (0); } @@ -1213,7 +1206,6 @@ udp6_detach(struct socket *so) KASSERT(up != NULL, ("%s: up == NULL", __func__)); in_pcbdetach(inp); in_pcbfree(inp); - udp_discardcb(up); } static int