From 8582775421b71150298c4828412cbc27be75505d Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 3 Jan 2019 14:43:03 -0500 Subject: [PATCH] freebsd_network: Implement m_cljget without mbuf. This returns an ext_buf that can be attached to an mbuf later, which is something iflib does. --- src/libs/compat/freebsd_network/mbuf.c | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libs/compat/freebsd_network/mbuf.c b/src/libs/compat/freebsd_network/mbuf.c index 4211219a6a..d1f9a837b2 100644 --- a/src/libs/compat/freebsd_network/mbuf.c +++ b/src/libs/compat/freebsd_network/mbuf.c @@ -65,8 +65,8 @@ m_init(struct mbuf *m, int how, short type, int flags) } -static int -construct_ext_sized_mbuf(struct mbuf *memoryBuffer, int how, int size) +static void* +allocate_ext_buf(int how, int size, int* ext_type) { object_cache *cache; int extType; @@ -84,7 +84,18 @@ construct_ext_sized_mbuf(struct mbuf *memoryBuffer, int how, int size) extType = EXT_JUMBOP; } - memoryBuffer->m_ext.ext_buf = object_cache_alloc(cache, m_to_oc_flags(how)); + if (ext_type != NULL) + *ext_type = extType; + return object_cache_alloc(cache, m_to_oc_flags(how)); +} + + +static int +construct_ext_sized_mbuf(struct mbuf *memoryBuffer, int how, int size) +{ + int extType; + + memoryBuffer->m_ext.ext_buf = allocate_ext_buf(how, size, &extType); if (memoryBuffer->m_ext.ext_buf == NULL) return B_NO_MEMORY; @@ -209,17 +220,18 @@ m_clget(struct mbuf *memoryBuffer, int how) } -void * -m_cljget(struct mbuf *memoryBuffer, int how, int size) +void* +m_cljget(struct mbuf* memoryBuffer, int how, int size) { if (memoryBuffer == NULL) - panic("m_cljget doesn't support allocate mbuf"); + return allocate_ext_buf(how, size, NULL); + memoryBuffer->m_ext.ext_buf = NULL; construct_ext_sized_mbuf(memoryBuffer, how, size); - /* shouldn't be used */ - return NULL; + return memoryBuffer->m_ext.ext_buf; } + static void mb_free_ext(struct mbuf *memoryBuffer) {