The branch main has been updated by glebius:

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

commit da6715bbb125ebe5d3ca7fd7656e8409b2d31921
Author:     Gleb Smirnoff <[email protected]>
AuthorDate: 2022-09-15 02:22:40 +0000
Commit:     Gleb Smirnoff <[email protected]>
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

Reply via email to