2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* include/linux/sunrpc/xdr.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SUNRPC_XDR_H_
|
|
|
|
#define _SUNRPC_XDR_H_
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <linux/uio.h>
|
|
|
|
#include <asm/byteorder.h>
|
2006-12-05 08:22:33 +07:00
|
|
|
#include <linux/scatterlist.h>
|
2007-07-12 05:39:02 +07:00
|
|
|
#include <linux/smp_lock.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer adjustment
|
|
|
|
*/
|
|
|
|
#define XDR_QUADLEN(l) (((l) + 3) >> 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic opaque `network object.' At the kernel level, this type
|
|
|
|
* is used only by lockd.
|
|
|
|
*/
|
|
|
|
#define XDR_MAX_NETOBJ 1024
|
|
|
|
struct xdr_netobj {
|
|
|
|
unsigned int len;
|
|
|
|
u8 * data;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the generic XDR function. rqstp is either a rpc_rqst (client
|
|
|
|
* side) or svc_rqst pointer (server side).
|
|
|
|
* Encode functions always assume there's enough room in the buffer.
|
|
|
|
*/
|
2006-09-27 12:29:38 +07:00
|
|
|
typedef int (*kxdrproc_t)(void *rqstp, __be32 *data, void *obj);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic structure for transmission/reception of a client XDR message.
|
|
|
|
* Features a header (for a linear buffer containing RPC headers
|
|
|
|
* and the data payload for short messages), and then an array of
|
|
|
|
* pages.
|
|
|
|
* The tail iovec allows you to append data after the page array. Its
|
|
|
|
* main interest is for appending padding to the pages in order to
|
|
|
|
* satisfy the int_32-alignment requirements in RFC1832.
|
|
|
|
*
|
|
|
|
* For the future, we might want to string several of these together
|
|
|
|
* in a list if anybody wants to make use of NFSv4 COMPOUND
|
|
|
|
* operations and/or has a need for scatter/gather involving pages.
|
|
|
|
*/
|
|
|
|
struct xdr_buf {
|
|
|
|
struct kvec head[1], /* RPC header + non-page data */
|
|
|
|
tail[1]; /* Appended after page data */
|
|
|
|
|
|
|
|
struct page ** pages; /* Array of contiguous pages */
|
|
|
|
unsigned int page_base, /* Start of page data */
|
2007-09-11 00:44:58 +07:00
|
|
|
page_len, /* Length of page data */
|
|
|
|
flags; /* Flags for data disposition */
|
|
|
|
#define XDRBUF_READ 0x01 /* target of file read */
|
|
|
|
#define XDRBUF_WRITE 0x02 /* source of file write */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
unsigned int buflen, /* Total length of storage buffer */
|
|
|
|
len; /* Length of XDR encoded message */
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pre-xdr'ed macros.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define xdr_zero __constant_htonl(0)
|
|
|
|
#define xdr_one __constant_htonl(1)
|
|
|
|
#define xdr_two __constant_htonl(2)
|
|
|
|
|
|
|
|
#define rpc_success __constant_htonl(RPC_SUCCESS)
|
|
|
|
#define rpc_prog_unavail __constant_htonl(RPC_PROG_UNAVAIL)
|
|
|
|
#define rpc_prog_mismatch __constant_htonl(RPC_PROG_MISMATCH)
|
|
|
|
#define rpc_proc_unavail __constant_htonl(RPC_PROC_UNAVAIL)
|
|
|
|
#define rpc_garbage_args __constant_htonl(RPC_GARBAGE_ARGS)
|
|
|
|
#define rpc_system_err __constant_htonl(RPC_SYSTEM_ERR)
|
2006-10-17 14:10:18 +07:00
|
|
|
#define rpc_drop_reply __constant_htonl(RPC_DROP_REPLY)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define rpc_auth_ok __constant_htonl(RPC_AUTH_OK)
|
|
|
|
#define rpc_autherr_badcred __constant_htonl(RPC_AUTH_BADCRED)
|
|
|
|
#define rpc_autherr_rejectedcred __constant_htonl(RPC_AUTH_REJECTEDCRED)
|
|
|
|
#define rpc_autherr_badverf __constant_htonl(RPC_AUTH_BADVERF)
|
|
|
|
#define rpc_autherr_rejectedverf __constant_htonl(RPC_AUTH_REJECTEDVERF)
|
|
|
|
#define rpc_autherr_tooweak __constant_htonl(RPC_AUTH_TOOWEAK)
|
|
|
|
#define rpcsec_gsserr_credproblem __constant_htonl(RPCSEC_GSS_CREDPROBLEM)
|
|
|
|
#define rpcsec_gsserr_ctxproblem __constant_htonl(RPCSEC_GSS_CTXPROBLEM)
|
|
|
|
#define rpc_autherr_oldseqnum __constant_htonl(101)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous XDR helper functions
|
|
|
|
*/
|
2006-09-27 12:29:38 +07:00
|
|
|
__be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int len);
|
|
|
|
__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int len);
|
|
|
|
__be32 *xdr_encode_string(__be32 *p, const char *s);
|
2007-11-02 03:56:47 +07:00
|
|
|
__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, unsigned int *lenp,
|
|
|
|
unsigned int maxlen);
|
2006-09-27 12:29:38 +07:00
|
|
|
__be32 *xdr_encode_netobj(__be32 *p, const struct xdr_netobj *);
|
|
|
|
__be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
void xdr_encode_pages(struct xdr_buf *, struct page **, unsigned int,
|
|
|
|
unsigned int);
|
|
|
|
void xdr_inline_pages(struct xdr_buf *, unsigned int,
|
|
|
|
struct page **, unsigned int, unsigned int);
|
|
|
|
|
2006-09-27 12:29:38 +07:00
|
|
|
static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int len)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return xdr_encode_opaque(p, s, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode 64bit quantities (NFSv3 support)
|
|
|
|
*/
|
2006-09-27 12:29:38 +07:00
|
|
|
static inline __be32 *
|
|
|
|
xdr_encode_hyper(__be32 *p, __u64 val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
*p++ = htonl(val >> 32);
|
|
|
|
*p++ = htonl(val & 0xFFFFFFFF);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2006-09-27 12:29:38 +07:00
|
|
|
static inline __be32 *
|
|
|
|
xdr_decode_hyper(__be32 *p, __u64 *valp)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
*valp = ((__u64) ntohl(*p++)) << 32;
|
|
|
|
*valp |= ntohl(*p++);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust kvec to reflect end of xdr'ed data (RPC client XDR)
|
|
|
|
*/
|
|
|
|
static inline int
|
2006-09-27 12:29:38 +07:00
|
|
|
xdr_adjust_iovec(struct kvec *iov, __be32 *p)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return iov->iov_len = ((u8 *) p - (u8 *) iov->iov_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XDR buffer helper functions
|
|
|
|
*/
|
|
|
|
extern void xdr_shift_buf(struct xdr_buf *, size_t);
|
|
|
|
extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
|
2006-09-01 02:09:19 +07:00
|
|
|
extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
|
|
|
|
extern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, unsigned int);
|
|
|
|
extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
|
|
|
|
extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper structure for copying from an sk_buff.
|
|
|
|
*/
|
2006-12-06 04:35:44 +07:00
|
|
|
struct xdr_skb_reader {
|
2005-04-17 05:20:36 +07:00
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned int offset;
|
|
|
|
size_t count;
|
2006-11-15 12:36:14 +07:00
|
|
|
__wsum csum;
|
2006-12-06 04:35:44 +07:00
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-12-06 04:35:44 +07:00
|
|
|
typedef size_t (*xdr_skb_read_actor)(struct xdr_skb_reader *desc, void *to, size_t len);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-12-06 04:35:44 +07:00
|
|
|
size_t xdr_skb_read_bits(struct xdr_skb_reader *desc, void *to, size_t len);
|
2005-08-12 03:25:20 +07:00
|
|
|
extern int csum_partial_copy_to_xdr(struct xdr_buf *, struct sk_buff *);
|
2005-06-23 00:16:24 +07:00
|
|
|
extern ssize_t xdr_partial_copy_from_skb(struct xdr_buf *, unsigned int,
|
2006-12-06 04:35:44 +07:00
|
|
|
struct xdr_skb_reader *, xdr_skb_read_actor);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-09-01 02:09:19 +07:00
|
|
|
extern int xdr_encode_word(struct xdr_buf *, unsigned int, u32);
|
|
|
|
extern int xdr_decode_word(struct xdr_buf *, unsigned int, u32 *);
|
2005-06-23 00:16:24 +07:00
|
|
|
|
|
|
|
struct xdr_array2_desc;
|
|
|
|
typedef int (*xdr_xcode_elem_t)(struct xdr_array2_desc *desc, void *elem);
|
|
|
|
struct xdr_array2_desc {
|
|
|
|
unsigned int elem_size;
|
|
|
|
unsigned int array_len;
|
2005-08-11 05:15:12 +07:00
|
|
|
unsigned int array_maxlen;
|
2005-06-23 00:16:24 +07:00
|
|
|
xdr_xcode_elem_t xcode;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
|
|
|
|
struct xdr_array2_desc *desc);
|
|
|
|
extern int xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
|
|
|
|
struct xdr_array2_desc *desc);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Provide some simple tools for XDR buffer overflow-checking etc.
|
|
|
|
*/
|
|
|
|
struct xdr_stream {
|
2006-09-27 12:29:38 +07:00
|
|
|
__be32 *p; /* start of available buffer */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct xdr_buf *buf; /* XDR buffer to read/write */
|
|
|
|
|
2006-09-27 12:29:38 +07:00
|
|
|
__be32 *end; /* end of available buffer space */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct kvec *iov; /* pointer to the current kvec */
|
|
|
|
};
|
|
|
|
|
2006-09-27 12:29:38 +07:00
|
|
|
extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
|
|
|
|
extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
|
2005-04-17 05:20:36 +07:00
|
|
|
extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
|
|
|
|
unsigned int base, unsigned int len);
|
2006-09-27 12:29:38 +07:00
|
|
|
extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
|
|
|
|
extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
|
2005-04-17 05:20:36 +07:00
|
|
|
extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
|
2006-06-09 20:34:21 +07:00
|
|
|
extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
|
2006-12-05 08:22:33 +07:00
|
|
|
extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* _SUNRPC_XDR_H_ */
|