void
pbuf_init_mbuf(pbuf_t *pbuf, struct mbuf *m, struct ifnet *ifp)
{
-
VERIFY((m->m_flags & M_PKTHDR) != 0);
pbuf->pb_type = PBUF_TYPE_MBUF;
void
pbuf_init_memory(pbuf_t *pbuf, const struct pbuf_memory *mp, struct ifnet *ifp)
{
-
pbuf->pb_type = PBUF_TYPE_MEMORY;
pbuf->pb_memory = *mp;
pbuf->pb_ifp = ifp;
void
pbuf_destroy(pbuf_t *pbuf)
{
-
if (pbuf->pb_type == PBUF_TYPE_MBUF) {
if (pbuf->pb_mbuf) {
m_freem(pbuf->pb_mbuf);
pbuf->pb_mbuf = NULL;
}
- } else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
VERIFY(pbuf->pb_memory.pm_buffer != NULL);
(void) (pbuf->pb_memory.pm_action)(&pbuf->pb_memory,
PBUF_ACTION_DESTROY);
void
pbuf_sync(pbuf_t *pbuf)
{
-
if (pbuf->pb_type == PBUF_TYPE_MBUF) {
struct mbuf *m = pbuf->pb_mbuf;
pbuf->pb_flowid = &m->m_pkthdr.pkt_flowid;
pbuf->pb_flags = &m->m_pkthdr.pkt_flags;
pbuf->pb_pftag = m_pftag(m);
- } else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
struct pbuf_memory *nm = &pbuf->pb_memory;
VERIFY(nm->pm_buffer != NULL);
pbuf->pb_flowid = &nm->pm_flowid;
pbuf->pb_flags = &nm->pm_flags;
pbuf->pb_pftag = &nm->pm_pftag;
- } else
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
}
struct mbuf *
pbuf->pb_mbuf = NULL;
pbuf_destroy(pbuf);
}
- } else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
if (pbuf->pb_packet_len > (u_int)MHLEN) {
if (pbuf->pb_packet_len > (u_int)MCLBYTES) {
printf("%s: packet too big for cluster (%u)\n",
__func__, pbuf->pb_packet_len);
- return (NULL);
+ return NULL;
}
m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
} else {
m = m_gethdr(M_DONTWAIT, MT_DATA);
}
- if (m == NULL)
- return (NULL);
+ if (m == NULL) {
+ return NULL;
+ }
m_copyback(m, 0, pbuf->pb_packet_len, pbuf->pb_data);
m->m_pkthdr.csum_flags = *pbuf->pb_csum_flags;
if (pbuf->pb_pftag != NULL) {
struct pf_mtag *pftag = m_pftag(m);
- if (pftag != NULL)
+ if (pftag != NULL) {
*pftag = *pbuf->pb_pftag;
+ }
}
- if (release_ptr)
+ if (release_ptr) {
pbuf_destroy(pbuf);
+ }
}
- return (m);
+ return m;
}
struct mbuf *
pbuf_sync(pbuf);
- if (pbuf->pb_type == PBUF_TYPE_MBUF)
+ if (pbuf->pb_type == PBUF_TYPE_MBUF) {
m = m_copy(pbuf->pb_mbuf, 0, M_COPYALL);
- else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY)
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
m = pbuf_to_mbuf(pbuf, FALSE);
- else
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
- return (m);
+ return m;
}
void *
pbuf_ensure_writable(pbuf_t *pbuf, size_t len)
{
-
if (pbuf->pb_type == PBUF_TYPE_MBUF) {
struct mbuf *m = pbuf->pb_mbuf;
- if (m_makewritable(&pbuf->pb_mbuf, 0, len, M_DONTWAIT))
- return (NULL);
+ if (m_makewritable(&pbuf->pb_mbuf, 0, len, M_DONTWAIT)) {
+ return NULL;
+ }
if (pbuf->pb_mbuf == NULL) {
pbuf_destroy(pbuf);
- return (NULL);
+ return NULL;
}
- if (m != pbuf->pb_mbuf)
+ if (m != pbuf->pb_mbuf) {
pbuf_sync(pbuf);
-
- } else
- if (pbuf->pb_type != PBUF_TYPE_MEMORY)
+ }
+ } else if (pbuf->pb_type != PBUF_TYPE_MEMORY) {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
- return (pbuf->pb_data);
+ return pbuf->pb_data;
}
void *
if (off > 0) {
/* Split the mbuf chain at the specified boundary */
- if ((n = m_split(m, off, M_DONTWAIT)) == NULL)
- return (NULL);
+ if ((n = m_split(m, off, M_DONTWAIT)) == NULL) {
+ return NULL;
+ }
} else {
n = m;
}
m_adj(n, olen);
/* Prepend new length */
- if (M_PREPEND(n, nlen, M_DONTWAIT, 0) == NULL)
- return (NULL);
+ if (M_PREPEND(n, nlen, M_DONTWAIT, 0) == NULL) {
+ return NULL;
+ }
rv = mtod(n, void *);
} else {
panic("pbuf_csum_flags_get: bad pb_type: %d", pbuf->pb_type);
}
- return (rv);
+ return rv;
}
void *
/* mbuf is freed by m_pulldown() in this case */
pbuf->pb_mbuf = NULL;
pbuf_destroy(pbuf);
- return (NULL);
+ return NULL;
}
pbuf_sync(pbuf);
rv = (void *)(mtod(n, uint8_t *) + moff);
- } else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
/*
* This always succeeds since memory pbufs are fully contig.
*/
rv = (void *)(uintptr_t)(((uint8_t *)pbuf->pb_data)[off]);
- } else
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
- return (rv);
+ return rv;
}
void
pbuf_copy_back(pbuf_t *pbuf, int off, int len, void *src)
{
-
VERIFY(off >= 0);
VERIFY(len >= 0);
VERIFY((u_int)(off + len) <= pbuf->pb_packet_len);
- if (pbuf->pb_type == PBUF_TYPE_MBUF)
- m_copyback(pbuf->pb_mbuf, off, len, src);
- else
if (pbuf->pb_type == PBUF_TYPE_MBUF) {
- if (len)
+ m_copyback(pbuf->pb_mbuf, off, len, src);
+ } else if (pbuf->pb_type == PBUF_TYPE_MBUF) {
+ if (len) {
memcpy(&((uint8_t *)pbuf->pb_data)[off], src, len);
- } else
+ }
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
}
void
pbuf_copy_data(pbuf_t *pbuf, int off, int len, void *dst)
{
-
VERIFY(off >= 0);
VERIFY(len >= 0);
VERIFY((u_int)(off + len) <= pbuf->pb_packet_len);
- if (pbuf->pb_type == PBUF_TYPE_MBUF)
- m_copydata(pbuf->pb_mbuf, off, len, dst);
- else
if (pbuf->pb_type == PBUF_TYPE_MBUF) {
- if (len)
+ m_copydata(pbuf->pb_mbuf, off, len, dst);
+ } else if (pbuf->pb_type == PBUF_TYPE_MBUF) {
+ if (len) {
memcpy(dst, &((uint8_t *)pbuf->pb_data)[off], len);
- } else
+ }
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
}
uint16_t
{
uint16_t sum = 0;
- if (pbuf->pb_type == PBUF_TYPE_MBUF)
+ if (pbuf->pb_type == PBUF_TYPE_MBUF) {
sum = inet_cksum(pbuf->pb_mbuf, nxt, off, len);
- else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY)
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
sum = inet_cksum_buffer(pbuf->pb_data, nxt, off, len);
- else
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
- return (sum);
+ return sum;
}
uint16_t
{
uint16_t sum = 0;
- if (pbuf->pb_type == PBUF_TYPE_MBUF)
+ if (pbuf->pb_type == PBUF_TYPE_MBUF) {
sum = inet6_cksum(pbuf->pb_mbuf, nxt, off, len);
- else
- if (pbuf->pb_type == PBUF_TYPE_MEMORY)
+ } else if (pbuf->pb_type == PBUF_TYPE_MEMORY) {
sum = inet6_cksum_buffer(pbuf->pb_data, nxt, off, len);
- else
+ } else {
panic("%s: bad pb_type: %d", __func__, pbuf->pb_type);
+ }
- return (sum);
+ return sum;
}
mbuf_svc_class_t
pbuf_get_service_class(const pbuf_t *pbuf)
{
-
- if (pbuf->pb_type == PBUF_TYPE_MBUF)
+ if (pbuf->pb_type == PBUF_TYPE_MBUF) {
return m_get_service_class(pbuf->pb_mbuf);
+ }
VERIFY(pbuf->pb_type == PBUF_TYPE_MEMORY);
- return (MBUF_SC_BE);
+ return MBUF_SC_BE;
}