Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Sep 2022 02:23:00 GMT
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: da6715bbb125 - main - ip_output: always increase "cantfrag" stat if ip_fragment() fails
Message-ID:  <202209150223.28F2N0W2091369@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=da6715bbb125ebe5d3ca7fd7656e8409b2d31921

commit da6715bbb125ebe5d3ca7fd7656e8409b2d31921
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-09-15 02:22:40 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-09-15 02:22:40 +0000

    ip_output: always increase "cantfrag" stat if ip_fragment() fails
    
    While here, join two unlikely cases into one if clause.
    
    Submitted by:           Ivan Rozhuk <rozhuk.im gmail.com>
    PR:                     265718
    Reviewed by:            mjg, melifaro
    Differential revision:  https://reviews.freebsd.org/D36584
---
 sys/netinet/ip_output.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index db39663e508e..375db580296e 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -868,16 +868,14 @@ ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
 	ip_len = ntohs(ip->ip_len);
 	ip_off = ntohs(ip->ip_off);
 
-	if (ip_off & IP_DF) {	/* Fragmentation not allowed */
-		IPSTAT_INC(ips_cantfrag);
-		return EMSGSIZE;
-	}
-
 	/*
-	 * Must be able to put at least 8 bytes per fragment.
+	 * Packet shall not have "Don't Fragment" flag and have at least 8
+	 * bytes of payload.
 	 */
-	if (len < 8)
-		return EMSGSIZE;
+	if (__predict_false((ip_off & IP_DF) || len < 8)) {
+		IPSTAT_INC(ips_cantfrag);
+		return (EMSGSIZE);
+	}
 
 	/*
 	 * If the interface will not calculate checksums on



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202209150223.28F2N0W2091369>