-.\" $OpenBSD: mbuf.9,v 1.113 2018/09/10 13:52:37 jmc Exp $
+.\" $OpenBSD: mbuf.9,v 1.114 2018/09/10 16:14:07 bluhm Exp $
.\"
.\" Copyright (c) 2001 Jean-Jacques Bernard-Gundol <jjbg@openbsd.org>
.\" All rights reserved.
.Nm m_gethdr ,
.Nm m_removehdr ,
.Nm m_resethdr ,
+.Nm m_calchdrlen ,
.Nm MGETHDR ,
.Nm m_prepend ,
.Nm M_PREPEND ,
.Fn m_removehdr "struct mbuf *m"
.Ft void
.Fn m_resethdr "struct mbuf *m"
+.Ft void
+.Fn m_calchdrlen "struct mbuf *m"
.Ft struct mbuf *
.Fn m_gethdr "int how" "int type"
.Fn MGETHDR "struct mbuf *m" "int how" "int type"
data and all tags attached to an
.Fa mbuf .
Keep the data and mbuf chain, initialize the packet header.
+.It Fn m_calchdrlen "struct mbuf *m"
+Set the packet header length to the sum of all length values in the
+mbuf chain.
.It Fn m_gethdr "int how" "int type"
Return a pointer to an mbuf of the type specified after initializing
it to contain a packet header.
-/* $OpenBSD: uipc_mbuf.c,v 1.257 2018/09/10 12:47:02 bluhm Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.258 2018/09/10 16:14:07 bluhm Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
m->m_pkthdr.ph_loopcnt = loopcnt;
}
+void
+m_calchdrlen(struct mbuf *m)
+{
+ struct mbuf *n;
+ int plen = 0;
+
+ KASSERT(m->m_flags & M_PKTHDR);
+ for (n = m; n; n = n->m_next)
+ plen += n->m_len;
+ m->m_pkthdr.len = plen;
+}
+
struct mbuf *
m_getclr(int nowait, int type)
{
-/* $OpenBSD: pf_norm.c,v 1.215 2018/09/10 12:47:02 bluhm Exp $ */
+/* $OpenBSD: pf_norm.c,v 1.216 2018/09/10 16:14:07 bluhm Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
hdrlen = frent->fe_hdrlen;
m = *m0 = pf_join_fragment(frag);
frag = NULL;
-
- {
- int plen = 0;
-
- KASSERT(m->m_flags & M_PKTHDR);
- for (m = *m0; m; m = m->m_next)
- plen += m->m_len;
- m = *m0;
- m->m_pkthdr.len = plen;
- }
+ m_calchdrlen(m);
ip = mtod(m, struct ip *);
ip->ip_len = htons(hdrlen + total);
if (frag6_deletefraghdr(m, hdrlen) != 0)
goto fail;
- {
- int plen = 0;
-
- KASSERT(m->m_flags & M_PKTHDR);
- for (m = *m0; m; m = m->m_next)
- plen += m->m_len;
- m = *m0;
- m->m_pkthdr.len = plen;
- }
+ m_calchdrlen(m);
if ((mtag = m_tag_get(PACKET_TAG_PF_REASSEMBLED, sizeof(struct
pf_fragment_tag), M_NOWAIT)) == NULL)
-/* $OpenBSD: ip_input.c,v 1.339 2018/09/10 12:47:02 bluhm Exp $ */
+/* $OpenBSD: ip_input.c,v 1.340 2018/09/10 16:14:07 bluhm Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
pool_put(&ipq_pool, fp);
m->m_len += (ip->ip_hl << 2);
m->m_data -= (ip->ip_hl << 2);
- {
- int plen = 0;
-
- KASSERT(m->m_flags & M_PKTHDR);
- for (t = m; t; t = t->m_next)
- plen += t->m_len;
- m->m_pkthdr.len = plen;
- }
+ m_calchdrlen(m);
return (m);
dropfrag:
-/* $OpenBSD: frag6.c,v 1.84 2018/09/10 12:47:02 bluhm Exp $ */
+/* $OpenBSD: frag6.c,v 1.85 2018/09/10 16:14:08 bluhm Exp $ */
/* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */
/*
pool_put(&ip6q_pool, q6);
- {
- int plen = 0;
-
- KASSERT(m->m_flags & M_PKTHDR);
- for (t = m; t; t = t->m_next)
- plen += t->m_len;
- m->m_pkthdr.len = plen;
- }
+ m_calchdrlen(m);
/*
* Restore NXT to the original.
-/* $OpenBSD: krpc_subr.c,v 1.34 2018/07/30 12:22:14 mpi Exp $ */
+/* $OpenBSD: krpc_subr.c,v 1.35 2018/09/10 16:14:08 bluhm Exp $ */
/* $NetBSD: krpc_subr.c,v 1.12.4.1 1996/06/07 00:52:26 cgd Exp $ */
/*
/*
* Setup packet header
*/
- len = 0;
- m = mhead;
- while (m) {
- len += m->m_len;
- m = m->m_next;
- }
- mhead->m_pkthdr.len = len;
+ m_calchdrlen(mhead);
mhead->m_pkthdr.ph_ifidx = 0;
/*
-/* $OpenBSD: nfs_socket.c,v 1.130 2018/07/30 12:22:14 mpi Exp $ */
+/* $OpenBSD: nfs_socket.c,v 1.131 2018/09/10 16:14:08 bluhm Exp $ */
/* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */
/*
int t1, i, error = 0;
int trylater_delay;
struct nfsreq *rep;
- int mrest_len;
struct nfsm_info info;
rep = pool_get(&nfsreqpl, PR_WAITOK);
rep->r_procp = infop->nmi_procp;
rep->r_procnum = procnum;
- mrest_len = 0;
- m = infop->nmi_mreq;
- while (m) {
- mrest_len += m->m_len;
- m = m->m_next;
- }
-
/* empty mbuf for AUTH_UNIX header */
rep->r_mreq = m_gethdr(M_WAIT, MT_DATA);
rep->r_mreq->m_next = infop->nmi_mreq;
- rep->r_mreq->m_pkthdr.len = mrest_len;
+ rep->r_mreq->m_len = 0;
+ m_calchdrlen(rep->r_mreq);
trylater_delay = NFS_MINTIMEO;
-/* $OpenBSD: mbuf.h,v 1.237 2018/09/10 12:47:02 bluhm Exp $ */
+/* $OpenBSD: mbuf.h,v 1.238 2018/09/10 16:14:08 bluhm Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
struct mbuf *m_inithdr(struct mbuf *);
void m_removehdr(struct mbuf *);
void m_resethdr(struct mbuf *);
+void m_calchdrlen(struct mbuf *);
int m_defrag(struct mbuf *, int);
struct mbuf *m_prepend(struct mbuf *, int, int);
struct mbuf *m_pulldown(struct mbuf *, int, int, int *);