diff --git a/sys/xdr/xdr_mem.c b/sys/xdr/xdr_mem.c --- a/sys/xdr/xdr_mem.c +++ b/sys/xdr/xdr_mem.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,7 @@ static bool_t xdrmem_putlong_unaligned(XDR *, const long *); static bool_t xdrmem_getbytes(XDR *, char *, u_int); static bool_t xdrmem_putbytes(XDR *, const char *, u_int); +static bool_t xdrmem_putmbuf(XDR *, struct mbuf *); /* XXX: w/64-bit pointers, u_int not enough! */ static u_int xdrmem_getpos(XDR *); static bool_t xdrmem_setpos(XDR *, u_int); @@ -67,6 +69,7 @@ .x_putlong = xdrmem_putlong_aligned, .x_getbytes = xdrmem_getbytes, .x_putbytes = xdrmem_putbytes, + .x_putmbuf = xdrmem_putmbuf, .x_getpostn = xdrmem_getpos, .x_setpostn = xdrmem_setpos, .x_inline = xdrmem_inline_aligned, @@ -79,6 +82,7 @@ .x_putlong = xdrmem_putlong_unaligned, .x_getbytes = xdrmem_getbytes, .x_putbytes = xdrmem_putbytes, + .x_putmbuf = xdrmem_putmbuf, .x_getpostn = xdrmem_getpos, .x_setpostn = xdrmem_setpos, .x_inline = xdrmem_inline_unaligned, @@ -184,6 +188,27 @@ return (TRUE); } +/* + * Append mbuf. May fail if not enough space. Caller owns the mbuf. + */ +static bool_t +xdrmem_putmbuf(XDR *xdrs, struct mbuf *m) +{ + u_int len; + + if (__predict_false(m == NULL)) + return (TRUE); + + len = m_length(m, NULL); + + if (__predict_false(xdrs->x_handy < len)) + return (FALSE); + xdrs->x_handy -= len; + m_copydata(m, 0, len, xdrs->x_private); + xdrs->x_private = (char *)xdrs->x_private + len; + return (TRUE); +} + static u_int xdrmem_getpos(XDR *xdrs) {