The branch main has been updated by kp:

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

commit 76e00c722bee123f902febce7b637ea7afa5e364
Author:     Kristof Provost <k...@freebsd.org>
AuthorDate: 2025-01-06 10:39:32 +0000
Commit:     Kristof Provost <k...@freebsd.org>
CommitDate: 2025-01-17 16:00:08 +0000

    dummymbuf: add 'enlarge'
    
    Teach dummymbuf to replace mbufs with larger ones.
    This can be useful for testing for bugs that depend on mbuf layout.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 share/man/man4/dummymbuf.4 |  4 +++-
 sys/net/dummymbuf.c        | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/share/man/man4/dummymbuf.4 b/share/man/man4/dummymbuf.4
index 844a7c0565bd..08926d2824c6 100644
--- a/share/man/man4/dummymbuf.4
+++ b/share/man/man4/dummymbuf.4
@@ -26,7 +26,7 @@
 .\"
 .\" Note: The date here should be updated whenever a non-trivial
 .\" change is made to the manual page.
-.Dd August 2, 2024
+.Dd January 6, 2025
 .Dt DUMMYMBUF 4
 .Os
 .Sh NAME
@@ -121,6 +121,8 @@ tail mbuf(s) left empty.
 .Pp
 As a result, only the layout of a mbuf chain is altered, its content logically
 is left intact.
+.It enlarge <number-of-bytes>
+Unconditionally replace the mbuf with an mbuf of the specified size.
 .El
 .Sh SYSCTL VARIABLES
 The following variables are available:
diff --git a/sys/net/dummymbuf.c b/sys/net/dummymbuf.c
index ff566cfb87c3..e88087e1572f 100644
--- a/sys/net/dummymbuf.c
+++ b/sys/net/dummymbuf.c
@@ -209,6 +209,37 @@ bad:
        return (NULL);
 }
 
+static struct mbuf *
+dmb_m_enlarge(struct mbuf *m, struct rule *rule)
+{
+       struct mbuf *n;
+       int size;
+
+       size = (int)strtol(rule->opargs, NULL, 10);
+       if (size < 0 || size > MJUM16BYTES)
+               goto bad;
+
+       if (!(m->m_flags & M_PKTHDR))
+               goto bad;
+       if (m->m_pkthdr.len <= 0)
+               return (m);
+
+       if ((n = m_get3(size, M_NOWAIT, MT_DATA, M_PKTHDR)) == NULL)
+               goto bad;
+
+       m_move_pkthdr(n, m);
+       m_copydata(m, 0, m->m_pkthdr.len, n->m_ext.ext_buf);
+       n->m_len = m->m_pkthdr.len;
+
+       n->m_next = m;
+
+       return (n);
+
+bad:
+       m_freem(m);
+       return (NULL);
+}
+
 static bool
 read_rule(const char **cur, struct rule *rule, bool *eof)
 {
@@ -278,6 +309,9 @@ read_rule(const char **cur, struct rule *rule, bool *eof)
        if (strstr(*cur, "pull-head") == *cur) {
                rule->op = dmb_m_pull_head;
                *cur += strlen("pull-head");
+       } else if (strstr(*cur, "enlarge") == *cur) {
+               rule->op = dmb_m_enlarge;
+               *cur += strlen("enlarge");
        } else {
                return (false);
        }

Reply via email to