~ubuntu-branches/ubuntu/raring/openafs/raring

« back to all changes in this revision

Viewing changes to .pc/debian-changes/src/rx/rx_packet.h

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-03-05 01:01:49 UTC
  • mfrom: (44.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130305010149-3ui1dhq9a2fw9abp
Tags: 1.6.2-1+ubuntu2
Explicitly include -pthread in UAFS_XLIBS to fix build failure

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2000, International Business Machines Corporation and others.
3
 
 * All Rights Reserved.
4
 
 *
5
 
 * This software has been released under the terms of the IBM Public
6
 
 * License.  For details, see the LICENSE file in the top-level source
7
 
 * directory or online at http://www.openafs.org/dl/license10.html
8
 
 */
9
 
 
10
 
#ifndef _RX_PACKET_
11
 
#define _RX_PACKET_
12
 
#if defined(AFS_NT40_ENV)
13
 
#include "rx_xmit_nt.h"
14
 
#endif
15
 
#ifndef AFS_NT40_ENV
16
 
#include <sys/uio.h>
17
 
#endif /* !AFS_NT40_ENV */
18
 
/* this file includes the macros and decls which depend on packet
19
 
 * format, and related packet manipulation macros.  Note that code
20
 
 * which runs at NETPRI should not sleep, or AIX will panic */
21
 
/* There are some assumptions that various code makes -- I'll try to
22
 
 * express them all here:
23
 
 * 1.  rx_ReceiveAckPacket assumes that it can get an entire ack
24
 
 * contiguous in the first iovec.  As a result, the iovec buffers must
25
 
 * be >= sizeof (struct rx_ackpacket)
26
 
 * 2. All callers of rx_Pullup besides rx_ReceiveAckPacket try to pull
27
 
 * up less data than rx_ReceiveAckPacket does.
28
 
 * 3. rx_GetInt32 and rx_PutInt32 (and the slow versions of same) assume
29
 
 * that the iovec buffers are all integral multiples of the word size,
30
 
 * and that the offsets are as well.
31
 
 */
32
 
 
33
 
 
34
 
#if defined(AFS_NT40_ENV)
35
 
#ifndef MIN
36
 
#define MIN(a,b)  ((a)<(b)?(a):(b))
37
 
#endif
38
 
#ifndef MAX
39
 
#define MAX(a,b)  ((a)>(b)?(a):(b))
40
 
#endif
41
 
#else /* AFS_NT40_ENV */
42
 
#if !defined(AFS_DARWIN_ENV) && !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) && !defined(AFS_LINUX20_ENV)
43
 
#include <sys/sysmacros.h>      /* MIN, MAX on Solaris */
44
 
#endif
45
 
#if !defined(AFS_LINUX26_ENV)
46
 
#include <sys/param.h>          /* MIN, MAX elsewhere */
47
 
#endif
48
 
#endif /* AFS_NT40_ENV */
49
 
 
50
 
#define IPv6_HDR_SIZE           40      /* IPv6 Header */
51
 
#define IPv6_FRAG_HDR_SIZE       8      /* IPv6 Fragment Header */
52
 
#define UDP_HDR_SIZE             8      /* UDP Header */
53
 
#define RX_IP_SIZE              (IPv6_HDR_SIZE + IPv6_FRAG_HDR_SIZE)
54
 
#define _RX_IPUDP_SIZE          (RX_IP_SIZE + UDP_HDR_SIZE)
55
 
 
56
 
/* REMOTE_PACKET_SIZE is currently the same as local.  This is because REMOTE
57
 
 * is defined much too generally for my tastes, and includes the case of
58
 
 * multiple class C nets connected with a router within one campus or MAN.
59
 
 * I don't want to make local performance suffer just because of some
60
 
 * out-dated protocol that used to be in use on the NSFANET that's
61
 
 * practically unused anymore.  Any modern IP implementation will be
62
 
 * using MTU discovery, and even old routers shouldn't frag packets
63
 
 * when sending from one connected network directly to another.  Maybe
64
 
 * the next release of RX will do MTU discovery. */
65
 
 
66
 
/* MTUXXX the various "MAX" params here must be rationalized.  From now on,
67
 
 * the MAX packet size will be the maximum receive size, but the maximum send
68
 
 * size will be larger than that. */
69
 
 
70
 
#ifdef notdef
71
 
/*  some sample MTUs
72
 
           4352   what FDDI(RFC1188) uses... Larger?
73
 
           4096   VJ's recommendation for FDDI
74
 
          17914   what IBM 16MB TR  uses
75
 
           8166   IEEE 802.4
76
 
           4464   IEEE 802.5 MAX
77
 
           2002   IEEE 802.5 Recommended
78
 
           1500   what Ethernet uses
79
 
           1492   what 802.3 uses ( 8 bytes for 802.2 SAP )
80
 
           9180   Classical IP over ATM (RFC2225)
81
 
*/
82
 
 
83
 
/* * * * these are the old defines
84
 
*/
85
 
#define RX_MAX_PACKET_SIZE      (RX_MAX_DL_MTU -RX_IPUDP_SIZE)
86
 
 
87
 
#define RX_MAX_PACKET_DATA_SIZE (RX_MAX_PACKET_SIZE-RX_HEADER_SIZE)
88
 
#ifdef AFS_HPUX_ENV
89
 
/* HPUX by default uses an 802.3 size, and it's not evident from SIOCGIFCONF */
90
 
#define RX_LOCAL_PACKET_SIZE    (1492 - RX_IPUDP_SIZE)
91
 
#define RX_REMOTE_PACKET_SIZE   (1492 - RX_IPUDP_SIZE)
92
 
#else
93
 
#define RX_LOCAL_PACKET_SIZE    RX_MAX_PACKET_SIZE      /* For hosts on same net */
94
 
#define RX_REMOTE_PACKET_SIZE   RX_MAX_PACKET_SIZE      /* see note above */
95
 
#endif
96
 
#endif /* notdef */
97
 
 
98
 
/* These are the new, streamlined ones.
99
 
 */
100
 
#define RX_HEADER_SIZE          sizeof (struct rx_header)
101
 
 
102
 
/* The minimum MTU for an IP network is 576 bytes including headers */
103
 
#define RX_MIN_PACKET_SIZE      (576 - RX_IPUDP_SIZE)
104
 
#define RX_PP_PACKET_SIZE       RX_MIN_PACKET_SIZE
105
 
#define _RX_MIN_PACKET_SIZE      (576 - _RX_IPUDP_SIZE)
106
 
#define _RX_PP_PACKET_SIZE      _RX_MIN_PACKET_SIZE
107
 
 
108
 
#define OLD_MAX_PACKET_SIZE     (1500 - RX_IPUDP_SIZE)
109
 
#define _OLD_MAX_PACKET_SIZE    (1500 - _RX_IPUDP_SIZE)
110
 
 
111
 
/* if the other guy is not on the local net, use this size */
112
 
#define RX_REMOTE_PACKET_SIZE   (1500 - RX_IPUDP_SIZE)
113
 
#define _RX_REMOTE_PACKET_SIZE  (1500 - _RX_IPUDP_SIZE)
114
 
 
115
 
/* for now, never send more data than this */
116
 
#define RX_MAX_PACKET_SIZE      16384
117
 
#define RX_MAX_PACKET_DATA_SIZE (16384 - RX_HEADER_SIZE)
118
 
 
119
 
/* Packet types, for rx_packet.type */
120
 
#define RX_PACKET_TYPE_DATA         1   /* A vanilla data packet */
121
 
#define RX_PACKET_TYPE_ACK          2   /* Acknowledge packet */
122
 
#define RX_PACKET_TYPE_BUSY         3   /* Busy: can't accept call immediately; try later */
123
 
#define RX_PACKET_TYPE_ABORT        4   /* Abort packet.  No response needed. */
124
 
#define RX_PACKET_TYPE_ACKALL       5   /* Acknowledges receipt of all packets */
125
 
#define RX_PACKET_TYPE_CHALLENGE    6   /* Challenge client's identity: request credentials */
126
 
#define RX_PACKET_TYPE_RESPONSE     7   /* Respond to challenge packet */
127
 
#define RX_PACKET_TYPE_DEBUG        8   /* Get debug information */
128
 
 
129
 
#define RX_PACKET_TYPE_PARAMS       9   /* exchange size params (showUmine) */
130
 
#define RX_PACKET_TYPE_VERSION     13   /* get AFS version */
131
 
 
132
 
 
133
 
#define RX_PACKET_TYPES     {"data", "ack", "busy", "abort", "ackall", "challenge", "response", "debug", "params", "unused", "unused", "unused", "version"}
134
 
#define RX_N_PACKET_TYPES           13  /* Must agree with above list;
135
 
                                         * counts 0
136
 
                                         * WARNING: if this number ever
137
 
                                         * grows past 13, rxdebug packets
138
 
                                         * will need to be modified */
139
 
 
140
 
/* Packet classes, for rx_AllocPacket and rx_packetQuota */
141
 
#define RX_PACKET_CLASS_RECEIVE     0
142
 
#define RX_PACKET_CLASS_SEND        1
143
 
#define RX_PACKET_CLASS_SPECIAL     2
144
 
#define RX_PACKET_CLASS_RECV_CBUF   3
145
 
#define RX_PACKET_CLASS_SEND_CBUF   4
146
 
 
147
 
#define RX_N_PACKET_CLASSES         5   /* Must agree with above list */
148
 
 
149
 
/* Flags for rx_header flags field */
150
 
#define RX_CLIENT_INITIATED     1       /* Packet is sent/received from client side of call */
151
 
#define RX_REQUEST_ACK          2       /* Peer requests acknowledgement */
152
 
#define RX_LAST_PACKET          4       /* This is the last packet from this side of the call */
153
 
#define RX_MORE_PACKETS         8       /* There are more packets following this,
154
 
                                         * i.e. the next sequence number seen by
155
 
                                         * the receiver should be greater than
156
 
                                         * this one, rather than a resend of an
157
 
                                         * earlier sequence number */
158
 
#define RX_SLOW_START_OK        32      /* Set this flag in an ack packet to
159
 
                                         * inform the sender that slow start is
160
 
                                         * supported by the receiver. */
161
 
#define RX_JUMBO_PACKET         32      /* Set this flag in a data packet to
162
 
                                         * indicate that more packets follow
163
 
                                         * this packet in the datagram */
164
 
 
165
 
/* The following flags are preset per packet, i.e. they don't change
166
 
 * on retransmission of the packet */
167
 
#define RX_PRESET_FLAGS         (RX_CLIENT_INITIATED | RX_LAST_PACKET)
168
 
 
169
 
 
170
 
/*
171
 
 * Flags for the packet structure itself, housekeeping for the
172
 
 * most part.  These live in rx_packet->flags.
173
 
 */
174
 
#define RX_PKTFLAG_ACKED        0x01
175
 
#ifdef RX_TRACK_PACKETS
176
 
#define RX_PKTFLAG_FREE         0x02
177
 
#define RX_PKTFLAG_TQ           0x04
178
 
#define RX_PKTFLAG_RQ           0x08
179
 
#define RX_PKTFLAG_IOVQ         0x10
180
 
#define RX_PKTFLAG_CP           0x20
181
 
#endif
182
 
#define RX_PKTFLAG_SENT         0x40
183
 
 
184
 
/* The rx part of the header of a packet, in host form */
185
 
struct rx_header {
186
 
    afs_uint32 epoch;           /* Start time of client process */
187
 
    afs_uint32 cid;             /* Connection id (defined by client) */
188
 
    afs_uint32 callNumber;      /* Current call number */
189
 
    afs_uint32 seq;             /* Sequence number of this packet, within this call */
190
 
    afs_uint32 serial;          /* Serial number of this packet: a new serial
191
 
                                 * number is stamped on each packet sent out */
192
 
    u_char type;                /* RX packet type */
193
 
    u_char flags;               /* Flags, defined below */
194
 
    u_char userStatus;          /* User defined status information,
195
 
                                 * returned/set by macros
196
 
                                 * rx_Get/SetLocal/RemoteStatus */
197
 
    u_char securityIndex;       /* Which service-defined security method to use */
198
 
    u_short serviceId;          /* service this packet is directed _to_ */
199
 
    /* This spare is now used for packet header checkksum.  see
200
 
     * rxi_ReceiveDataPacket and packet cksum macros above for details. */
201
 
    u_short spare;
202
 
};
203
 
 
204
 
/* The abbreviated header for jumbo packets. Most fields in the
205
 
 * jumbo packet headers are either the same as or can be quickly
206
 
 * derived from their counterparts in the main packet header.
207
 
 */
208
 
struct rx_jumboHeader {
209
 
    u_char flags;               /* Flags, defined below */
210
 
    u_char spare1;
211
 
    u_short cksum;              /* packet header checksum */
212
 
};
213
 
 
214
 
/* For most Unixes, maximum elements in an iovec is 16 */
215
 
#define RX_MAXIOVECS 16         /* limit for ReadvProc/WritevProc */
216
 
#define RX_MAXWVECS RX_MAXIOVECS-1      /* need one iovec for packet header */
217
 
 
218
 
/*
219
 
 * The values for the RX buffer sizes are calculated to ensure efficient
220
 
 * use of network resources when sending AFS 3.5 jumbograms over Ethernet,
221
 
 * 802.3, FDDI, and ATM networks running IPv4 or IPv6. Changing these
222
 
 * values may affect interoperability with AFS 3.5 clients.
223
 
 */
224
 
 
225
 
/*
226
 
 * We always transmit jumbo grams so that each packet starts at the
227
 
 * beginning of a packet buffer. Because of the requirement that all
228
 
 * segments of a 3.4a jumbogram contain multiples of eight bytes, the
229
 
 * receivers iovec has RX_HEADERSIZE bytes in the first element,
230
 
 * RX_FIRSTBUFFERSIZE bytes in the second element, and RX_CBUFFERSIZE
231
 
 * bytes in each successive entry.  All packets in a jumbogram
232
 
 * except for the last must contain RX_JUMBOBUFFERSIZE bytes of data
233
 
 * so the receiver can split the AFS 3.5 jumbograms back into packets
234
 
 * without having to copy any of the data.
235
 
 */
236
 
#define RX_JUMBOBUFFERSIZE 1412
237
 
#define RX_JUMBOHEADERSIZE 4
238
 
/*
239
 
 * RX_FIRSTBUFFERSIZE must be larger than the largest ack packet,
240
 
 * the largest possible challenge or response packet.
241
 
 * Both Firstbuffersize and cbuffersize must be integral multiples of 8,
242
 
 * so the security header and trailer stuff works for rxkad_crypt.  yuck.
243
 
 */
244
 
#define RX_FIRSTBUFFERSIZE (RX_JUMBOBUFFERSIZE+RX_JUMBOHEADERSIZE)
245
 
/*
246
 
 * The size of a continuation buffer is buffer is the same as the
247
 
 * size of the first buffer, which must also the size of a jumbo packet
248
 
 * buffer plus the size of a jumbo packet header. */
249
 
#define RX_CBUFFERSIZE (RX_JUMBOBUFFERSIZE+RX_JUMBOHEADERSIZE)
250
 
/*
251
 
 * Add an extra four bytes of slop at the end of each buffer.
252
 
 */
253
 
#define RX_EXTRABUFFERSIZE 4
254
 
 
255
 
struct rx_packet {
256
 
    struct rx_queue queueItemHeader;    /* Packets are chained using the queue.h package */
257
 
    struct clock timeSent;      /* When this packet was transmitted last */
258
 
    afs_uint32 firstSerial;     /* Original serial number of this packet */
259
 
    struct clock firstSent;     /* When this packet was transmitted first */
260
 
    struct rx_header header;    /* The internal packet header */
261
 
    unsigned int niovecs;       /* # of iovecs that potentially have data */
262
 
    unsigned int aiovecs;       /* # of allocated iovecs */
263
 
    struct iovec wirevec[RX_MAXWVECS + 1];      /* the new form of the packet */
264
 
 
265
 
    u_char flags;               /* Flags for local state of this packet */
266
 
    u_char unused;              /* was backoff, now just here for alignment */
267
 
    u_short length;             /* Data length */
268
 
    /* NT port relies on the fact that the next two are physically adjacent.
269
 
     * If that assumption changes change sendmsg and recvmsg in rx_xmit_nt.c .
270
 
     * The jumbo datagram code also relies on the next two being
271
 
     * physically adjacent.
272
 
     * The Linux port uses this knowledge as well in osi_NetSend.
273
 
     *
274
 
     * The extradata field is padding in case the recvmsg implementation
275
 
     * writes beyond the end of the final iovec buffer.  We do not know
276
 
     * what platforms had this problem so we are reluctant to remove it.
277
 
     * the extradata must be adjacent to localdata.
278
 
     * See rxk_ReadPacket and rxi_ReadPacket.
279
 
     */
280
 
    afs_uint32 wirehead[RX_HEADER_SIZE / sizeof(afs_int32)];
281
 
    afs_uint32 localdata[RX_CBUFFERSIZE / sizeof(afs_int32)];
282
 
    afs_uint32 extradata[RX_EXTRABUFFERSIZE / sizeof(afs_int32)];
283
 
 
284
 
#ifdef RXDEBUG_PACKET
285
 
    /* For debugging */
286
 
    struct rx_packet *allNextp; /* A list of all packets */
287
 
    afs_uint32  packetId;       /* An unique id number for debugging */
288
 
#endif
289
 
};
290
 
 
291
 
/* Macro to convert continuation buffer pointers to packet pointers */
292
 
#define RX_CBUF_TO_PACKET(CP, PP) \
293
 
    ((struct rx_packet *) \
294
 
     ((char *)(CP) - ((char *)(&(PP)->localdata[0])-(char *)(PP))))
295
 
 
296
 
/* Macros callable by security modules, to set header/trailer lengths,
297
 
 * set actual packet size, and find the beginning of the security
298
 
 * header (or data) */
299
 
#define rx_SetSecurityHeaderSize(conn, length) ((conn)->securityHeaderSize = (length))
300
 
#define rx_SetSecurityMaxTrailerSize(conn, length) ((conn)->securityMaxTrailerSize = (length))
301
 
#define rx_GetSecurityHeaderSize(conn) ((conn)->securityHeaderSize)
302
 
#define rx_GetSecurityMaxTrailerSize(conn) ((conn)->securityMaxTrailerSize)
303
 
 
304
 
/* This is the address of the data portion of the packet.  Any encryption
305
 
 * headers will be at this address, the actual data, for a data packet, will
306
 
 * start at this address + the connection's security header size. */
307
 
#define rx_DataOf(packet)               ((char *) (packet)->wirevec[1].iov_base)
308
 
#define rx_GetDataSize(packet)          ((packet)->length)
309
 
#define rx_SetDataSize(packet, size)    ((packet)->length = (size))
310
 
 
311
 
/* These macros used in conjunction with reuse of packet header spare as a
312
 
 * packet cksum for rxkad security module. */
313
 
#define rx_GetPacketCksum(packet)        ((packet)->header.spare)
314
 
#define rx_SetPacketCksum(packet, cksum) ((packet)->header.spare = (cksum))
315
 
 
316
 
#ifdef KERNEL
317
 
#define rxi_OverQuota(packetclass) (rx_nFreePackets - 1 < rx_packetQuota[packetclass])
318
 
#define rxi_OverQuota2(packetclass,num_alloc) (rx_nFreePackets - (num_alloc) < rx_packetQuota[packetclass])
319
 
#endif /* KERNEL */
320
 
 
321
 
/* this returns an afs_int32 from byte offset o in packet p.  offset must
322
 
 * always be aligned properly for an afs_int32, I'm leaving this up to the
323
 
 * caller. */
324
 
#define rx_GetInt32(p,off) (( (off) >= (p)->wirevec[1].iov_len) ? \
325
 
   rx_SlowGetInt32((p), (off)) :  \
326
 
  *((afs_int32 *)((char *)((p)->wirevec[1].iov_base) + (off))))
327
 
 
328
 
#define rx_PutInt32(p,off,b) { \
329
 
       if ((off) >= (p)->wirevec[1].iov_len) \
330
 
          rx_SlowPutInt32((p), (off), (b));   \
331
 
       else *((afs_int32 *)((char *)((p)->wirevec[1].iov_base) + (off))) = b; }
332
 
 
333
 
#define rx_data(p, o, l) ((l=((struct rx_packet*)(p))->wirevec[(o+1)].iov_len),\
334
 
  (((struct rx_packet*)(p))->wirevec[(o+1)].iov_base))
335
 
 
336
 
 
337
 
/* copy data into an RX packet */
338
 
#define rx_packetwrite(p, off, len, in)               \
339
 
  ( (off) + (len) > (p)->wirevec[1].iov_len ?         \
340
 
    rx_SlowWritePacket(p, off, len, (char*)(in)) :             \
341
 
    ((memcpy((char*)((p)->wirevec[1].iov_base)+(off), (char *)(in), (len))),0))
342
 
 
343
 
/* copy data from an RX packet */
344
 
#define rx_packetread(p, off, len, out)               \
345
 
  ( (off) + (len) > (p)->wirevec[1].iov_len ?         \
346
 
    rx_SlowReadPacket(p, off, len, (char*)(out)) :             \
347
 
    ((memcpy((char *)(out), (char*)((p)->wirevec[1].iov_base)+(off), (len))),0))
348
 
 
349
 
#define rx_computelen(p,l) { unsigned int i; \
350
 
   for (l=0, i=1; i < p->niovecs; i++ ) l += p->wirevec[i].iov_len; }
351
 
 
352
 
/* return what the actual contiguous space is: should be min(length,size) */
353
 
/* The things that call this really want something like ...pullup MTUXXX  */
354
 
#define rx_Contiguous(p) \
355
 
    MIN((unsigned) (p)->length, (unsigned) ((p)->wirevec[1].iov_len))
356
 
 
357
 
#ifndef TRUE
358
 
#define TRUE 1
359
 
#define FALSE 0
360
 
#endif
361
 
 
362
 
/* === packet-ized down to here, the following macros work temporarily */
363
 
/* Unfortunately, they know that the cbuf stuff isn't there. */
364
 
 
365
 
/* try to ensure that rx_DataOf will return a contiguous space at
366
 
 * least size bytes long */
367
 
/* return what the actual contiguous space is: should be min(length,size) */
368
 
#define rx_Pullup(p,size)       /* this idea here is that this will make a guarantee */
369
 
 
370
 
 
371
 
/* The offset of the actual user's data in the packet, skipping any
372
 
 * security header */
373
 
/* DEPRECATED */
374
 
#define rx_UserDataOf(conn, packet)     (((char *) (packet)->wirevec[1].iov_base) + (conn)->securityHeaderSize)
375
 
 
376
 
#ifdef AFS_NT40_ENV
377
 
/* Debugging for Windows Cache Manager - fs memdump */
378
 
int rx_DumpPackets(FILE *outputFile, char *cookie);
379
 
#endif /* AFS_NT40_ENV */
380
 
 
381
 
#endif /* _RX_PACKET_ */