linux rx pmtu fixes
[openafs.git] / src / rx / xdr_len.c
1 /*
2  * Copyright (c) 2010 Your Filesystem Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include <afsconfig.h>
26 #include <afs/param.h>
27
28 #ifdef KERNEL
29 # include "afs/sysincludes.h"
30 #else
31 # include <stdlib.h>
32 #endif
33
34 #include "xdr.h"
35
36 static void
37 xdrlen_destroy(XDR *xdrs)
38 {
39 }
40
41 static bool_t
42 xdrlen_getint32(XDR *xdrs, afs_int32 * lp)
43 {
44     return (FALSE);
45 }
46
47 static bool_t
48 xdrlen_putint32(XDR *xdrs, afs_int32 * lp)
49 {
50     xdrs->x_handy += sizeof(afs_int32);
51     return (TRUE);
52 }
53
54 static bool_t
55 xdrlen_getbytes(XDR *xdrs, caddr_t addr, u_int len)
56 {
57     return (FALSE);
58 }
59
60 static bool_t
61 xdrlen_putbytes(XDR *xdrs, caddr_t addr, u_int len)
62 {
63     xdrs->x_handy += len;
64     return (TRUE);
65 }
66
67 static u_int
68 xdrlen_getpos(XDR *xdrs)
69 {
70     return xdrs->x_handy;
71 }
72
73 static bool_t
74 xdrlen_setpos(XDR *xdrs, u_int pos)
75 {
76     xdrs->x_handy = pos;
77     return (TRUE);
78 }
79
80 static afs_int32 *
81 xdrlen_inline(XDR *xdrs, u_int len)
82 {
83     return NULL;
84 }
85
86 static struct xdr_ops xdrlen_ops = {
87 #if defined(AFS_NT40_ENV) || defined(__SUNPRO_C) || (defined(AFS_SGI_ENV)  && !defined(__c99))
88 #ifdef AFS_XDR_64BITOPS
89     NULL,
90     NULL,
91 #endif
92     /* Windows does not support labeled assigments */
93     xdrlen_getint32,    /* not supported */
94     xdrlen_putint32,    /* serialize an afs_int32 */
95     xdrlen_getbytes,    /* not supported */
96     xdrlen_putbytes,    /* serialize counted bytes */
97     xdrlen_getpos,      /* get offset in the stream */
98     xdrlen_setpos,      /* set offset in the stream */
99     xdrlen_inline,      /* not supported */
100     xdrlen_destroy      /* destroy stream */
101 #else
102 #ifdef AFS_XDR_64BITOPS
103     .x_getint64 = NULL,
104     .x_putint64 = NULL,
105 #endif
106     .x_getint32 = xdrlen_getint32,
107     .x_putint32 = xdrlen_putint32,
108     .x_getbytes = xdrlen_getbytes,
109     .x_putbytes = xdrlen_putbytes,
110     .x_getpostn = xdrlen_getpos,
111     .x_setpostn = xdrlen_setpos,
112     .x_inline = xdrlen_inline,
113     .x_destroy = xdrlen_destroy
114 #endif
115 };
116
117 /**
118  * Initialise an XDR stream to calculate the space required to encode
119  *
120  * This initialises an XDR stream object which can be used to calculate
121  * the space required to encode a particular structure into memory. No
122  * encoding is actually performed, a later call using xdrmem is necessary
123  * to do so.
124  *
125  * @param xdrs
126  *      A pointer to a preallocated XDR sized block of memory.
127  */
128 void
129 xdrlen_create(XDR * xdrs)
130 {
131     xdrs->x_op = XDR_ENCODE;
132     xdrs->x_ops = &xdrlen_ops;
133     xdrs->x_handy = 0;
134 }