mirror of
https://github.com/opnsense/src.git
synced 2026-06-14 19:20:18 -04:00
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")
This commit is contained in:
parent
5d28f4cab8
commit
76e00c722b
2 changed files with 37 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue