aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@primarydata.com>2018-03-20 17:03:05 -0400
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2018-04-10 16:06:22 -0400
commit0e779aa70308462e45f7cd1a54de418dfe101694 (patch)
tree5b350fb76a51514070ca8f92b29d114f6241ddf9 /net
parentd943f2dd8dba1ecde2de053500a6533e39577bfc (diff)
SUNRPC: Add helpers for decoding opaque and string types
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/xdr.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index e34f4ee7f2b6..30afbd236656 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -1519,6 +1519,88 @@ out:
1519EXPORT_SYMBOL_GPL(xdr_process_buf); 1519EXPORT_SYMBOL_GPL(xdr_process_buf);
1520 1520
1521/** 1521/**
1522 * xdr_stream_decode_opaque - Decode variable length opaque
1523 * @xdr: pointer to xdr_stream
1524 * @ptr: location to store opaque data
1525 * @size: size of storage buffer @ptr
1526 *
1527 * Return values:
1528 * On success, returns size of object stored in *@ptr
1529 * %-EBADMSG on XDR buffer overflow
1530 * %-EMSGSIZE on overflow of storage buffer @ptr
1531 */
1532ssize_t xdr_stream_decode_opaque(struct xdr_stream *xdr, void *ptr, size_t size)
1533{
1534 ssize_t ret;
1535 void *p;
1536
1537 ret = xdr_stream_decode_opaque_inline(xdr, &p, size);
1538 if (ret <= 0)
1539 return ret;
1540 memcpy(ptr, p, ret);
1541 return ret;
1542}
1543EXPORT_SYMBOL_GPL(xdr_stream_decode_opaque);
1544
1545/**
1546 * xdr_stream_decode_opaque_dup - Decode and duplicate variable length opaque
1547 * @xdr: pointer to xdr_stream
1548 * @ptr: location to store pointer to opaque data
1549 * @maxlen: maximum acceptable object size
1550 * @gfp_flags: GFP mask to use
1551 *
1552 * Return values:
1553 * On success, returns size of object stored in *@ptr
1554 * %-EBADMSG on XDR buffer overflow
1555 * %-EMSGSIZE if the size of the object would exceed @maxlen
1556 * %-ENOMEM on memory allocation failure
1557 */
1558ssize_t xdr_stream_decode_opaque_dup(struct xdr_stream *xdr, void **ptr,
1559 size_t maxlen, gfp_t gfp_flags)
1560{
1561 ssize_t ret;
1562 void *p;
1563
1564 ret = xdr_stream_decode_opaque_inline(xdr, &p, maxlen);
1565 if (ret > 0) {
1566 *ptr = kmemdup(p, ret, gfp_flags);
1567 if (*ptr != NULL)
1568 return ret;
1569 ret = -ENOMEM;
1570 }
1571 *ptr = NULL;
1572 return ret;
1573}
1574EXPORT_SYMBOL_GPL(xdr_stream_decode_opaque_dup);
1575
1576/**
1577 * xdr_stream_decode_string - Decode variable length string
1578 * @xdr: pointer to xdr_stream
1579 * @str: location to store string
1580 * @size: size of storage buffer @str
1581 *
1582 * Return values:
1583 * On success, returns length of NUL-terminated string stored in *@str
1584 * %-EBADMSG on XDR buffer overflow
1585 * %-EMSGSIZE on overflow of storage buffer @str
1586 */
1587ssize_t xdr_stream_decode_string(struct xdr_stream *xdr, char *str, size_t size)
1588{
1589 ssize_t ret;
1590 void *p;
1591
1592 ret = xdr_stream_decode_opaque_inline(xdr, &p, size);
1593 if (ret > 0) {
1594 memcpy(str, p, ret);
1595 str[ret] = '\0';
1596 return strlen(str);
1597 }
1598 *str = '\0';
1599 return ret;
1600}
1601EXPORT_SYMBOL_GPL(xdr_stream_decode_string);
1602
1603/**
1522 * xdr_stream_decode_string_dup - Decode and duplicate variable length string 1604 * xdr_stream_decode_string_dup - Decode and duplicate variable length string
1523 * @xdr: pointer to xdr_stream 1605 * @xdr: pointer to xdr_stream
1524 * @str: location to store pointer to string 1606 * @str: location to store pointer to string