From nobody Fri Nov 12 15:51:31 2021 X-Original-To: dev-commits-src-all@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 10C07184BB71; Fri, 12 Nov 2021 15:51:32 +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 4HrNNz728pz4stq; Fri, 12 Nov 2021 15:51:31 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C770822239; Fri, 12 Nov 2021 15:51:31 +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 1ACFpVSM086505; Fri, 12 Nov 2021 15:51:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ACFpVxE086504; Fri, 12 Nov 2021 15:51:31 GMT (envelope-from git) Date: Fri, 12 Nov 2021 15:51:31 GMT Message-Id: <202111121551.1ACFpVxE086504@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 0359e7a5e49f - main - net: sprinkle __predict_false in ip_input on error conditions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0359e7a5e49f3fa8f9e87923a0830239d3372132 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=0359e7a5e49f3fa8f9e87923a0830239d3372132 commit 0359e7a5e49f3fa8f9e87923a0830239d3372132 Author: Mateusz Guzik AuthorDate: 2021-11-10 17:15:51 +0000 Commit: Mateusz Guzik CommitDate: 2021-11-12 15:40:28 +0000 net: sprinkle __predict_false in ip_input on error conditions While here rearrange the RVSP check to inspect proto first and avoid evaluating V_rsvp in the common case to begin with (most notably avoid the expensive read). Reviewed by: glebius Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D32929 --- sys/netinet/ip_input.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index dc122dd62e99..be04e27b8224 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -476,28 +476,31 @@ ip_input(struct mbuf *m) IPSTAT_INC(ips_total); - if (m->m_pkthdr.len < sizeof(struct ip)) + if (__predict_false(m->m_pkthdr.len < sizeof(struct ip))) goto tooshort; - if (m->m_len < sizeof (struct ip) && - (m = m_pullup(m, sizeof (struct ip))) == NULL) { - IPSTAT_INC(ips_toosmall); - return; + if (m->m_len < sizeof(struct ip)) { + m = m_pullup(m, sizeof(struct ip)); + if (__predict_false(m == NULL)) { + IPSTAT_INC(ips_toosmall); + return; + } } ip = mtod(m, struct ip *); - if (ip->ip_v != IPVERSION) { + if (__predict_false(ip->ip_v != IPVERSION)) { IPSTAT_INC(ips_badvers); goto bad; } hlen = ip->ip_hl << 2; - if (hlen < sizeof(struct ip)) { /* minimum header length */ + if (__predict_false(hlen < sizeof(struct ip))) { /* minimum header length */ IPSTAT_INC(ips_badhlen); goto bad; } if (hlen > m->m_len) { - if ((m = m_pullup(m, hlen)) == NULL) { + m = m_pullup(m, hlen); + if (__predict_false(m == NULL)) { IPSTAT_INC(ips_badhlen); return; } @@ -525,7 +528,7 @@ ip_input(struct mbuf *m) sum = in_cksum(m, hlen); } } - if (sum) { + if (__predict_false(sum)) { IPSTAT_INC(ips_badsum); goto bad; } @@ -537,7 +540,7 @@ ip_input(struct mbuf *m) #endif ip_len = ntohs(ip->ip_len); - if (ip_len < hlen) { + if (__predict_false(ip_len < hlen)) { IPSTAT_INC(ips_badlen); goto bad; } @@ -548,7 +551,7 @@ ip_input(struct mbuf *m) * Trim mbufs if longer than we expect. * Drop packet if shorter than we expect. */ - if (m->m_pkthdr.len < ip_len) { + if (__predict_false(m->m_pkthdr.len < ip_len)) { tooshort: IPSTAT_INC(ips_tooshort); goto bad; @@ -650,7 +653,7 @@ passin: * anywhere else. Also checks if the rsvp daemon is running before * grabbing the packet. */ - if (V_rsvp_on && ip->ip_p==IPPROTO_RSVP) + if (ip->ip_p == IPPROTO_RSVP && V_rsvp_on) goto ours; /*