compile on modern FreeBSD. After Robert Watson <rwatson@FreeBSD.org> and Alec Kloss
[arla.git] / rx / rx_pkt.h
blob2264668833b126e49ca65217e54de5aed90255ae
1 #ifndef _RX_PACKET_
2 #define _RX_PACKET_
3 #include "sys/uio.h"
4 /*
5 * this file includes the macros and decls which depend on packet
6 * format, and related packet manipulation macros. Note that code
7 * which runs at NETPRI should not sleep, or AIX will panic
8 */
9 /*
10 * There are some assumptions that various code makes -- I'll try to
11 * express them all here:
12 * 1. rx_ReceiveAckPacket assumes that it can get an entire ack
13 * contiguous in the first iovec. As a result, the iovec buffers must
14 * be >= sizeof (struct rx_ackpacket)
15 * 2. All callers of rx_Pullup besides rx_ReceiveAckPacket try to pull
16 * up less data than rx_ReceiveAckPacket does.
17 * 3. rx_GetLong and rx_PutLong (and the slow versions of same) assume
18 * that the iovec buffers are all integral multiples of the word size,
19 * and that the offsets are as well.
23 #ifndef MIN
24 #define MIN(a,b) ((a)<(b)?(a):(b))
25 #endif
27 #define RX_IPUDP_SIZE 28
30 * REMOTE_PACKET_SIZE is currently the same as local. This is because REMOTE
31 * is defined much too generally for my tastes, and includes the case of
32 * multiple class C nets connected with a router within one campus or MAN.
33 * I don't want to make local performance suffer just because of some
34 * out-dated protocol that used to be in use on the NSFANET that's
35 * practically unused anymore. Any modern IP implementation will be
36 * using MTU discovery, and even old routers shouldn't frag packets
37 * when sending from one connected network directly to another. Maybe
38 * the next release of RX will do MTU discovery.
42 * MTUXXX the various "MAX" params here must be rationalized. From now on,
43 * the MAX packet size will be the maximum receive size, but the maximum send
44 * size will be larger than that.
47 #ifdef notdef
48 /* some sample MTUs
49 4352 what FDDI(RFC1188) uses... Larger?
50 4096 VJ's recommendation for FDDI
51 17914 what IBM 16MB TR uses
52 8166 IEEE 802.4
53 4464 IEEE 802.5 MAX
54 2002 IEEE 802.5 Recommended
55 1500 what Ethernet uses
56 1492 what 802.3 uses ( 8 bytes for 802.2 SAP )
59 /* * * * these are the old defines
61 #define RX_MAX_PACKET_SIZE (RX_MAX_DL_MTU -RX_IPUDP_SIZE)
63 #define RX_MAX_PACKET_DATA_SIZE (RX_MAX_PACKET_SIZE-RX_HEADER_SIZE)
64 #ifdef AFS_HPUX_ENV
65 /* HPUX by default uses an 802.3 size, and it's not evident from SIOCGIFCONF */
66 #define RX_LOCAL_PACKET_SIZE (1492 - RX_IPUDP_SIZE)
67 #define RX_REMOTE_PACKET_SIZE (1492 - RX_IPUDP_SIZE)
68 #else
69 #define RX_LOCAL_PACKET_SIZE RX_MAX_PACKET_SIZE /* For hosts on same net */
70 #define RX_REMOTE_PACKET_SIZE RX_MAX_PACKET_SIZE /* see note above */
71 #endif
73 #endif /* notdef */
75 /* These are the new, streamlined ones.
77 #define RX_HEADER_SIZE 28
79 #define OLD_MAX_PACKET_SIZE (1500 -RX_IPUDP_SIZE)
80 #define RX_PP_PACKET_SIZE (576 +RX_HEADER_SIZE)
82 /* if the other guy is not on the local net, use this size */
83 #define RX_REMOTE_PACKET_SIZE (1500 - RX_IPUDP_SIZE)
85 /* for now, never send more data than this */
86 #define RX_MAX_PACKET_SIZE (16384 + RX_HEADER_SIZE)
87 #define RX_MAX_PACKET_DATA_SIZE 16384
90 /* Packet types, for rx_packet.type */
91 #define RX_PACKET_TYPE_DATA 1 /* A vanilla data packet */
92 #define RX_PACKET_TYPE_ACK 2 /* Acknowledge packet */
93 #define RX_PACKET_TYPE_BUSY 3 /* Busy: can't accept call
94 * immediately; try later */
95 #define RX_PACKET_TYPE_ABORT 4 /* Abort packet. No response needed. */
96 #define RX_PACKET_TYPE_ACKALL 5 /* Acknowledges receipt of all packets */
97 #define RX_PACKET_TYPE_CHALLENGE 6 /* Challenge client's identity:
98 * request credentials */
99 #define RX_PACKET_TYPE_RESPONSE 7 /* Respond to challenge packet */
100 #define RX_PACKET_TYPE_DEBUG 8 /* Get debug information */
102 #define RX_PACKET_TYPE_PARAMS 9 /* exchange size params (showUmine) */
103 #define RX_PACKET_TYPE_VERSION 13 /* get AFS version */
106 #define RX_PACKET_TYPES {"data", "ack", "busy", "abort", "ackall", "challenge", "response", "debug", "params", "unused", "unused", "unused", "version"}
107 #define RX_N_PACKET_TYPES 13 /* Must agree with above list; counts
108 * 0 */
110 /* Packet classes, for rx_AllocPacket */
111 #define RX_PACKET_CLASS_RECEIVE 0
112 #define RX_PACKET_CLASS_SEND 1
113 #define RX_PACKET_CLASS_SPECIAL 2
115 #define RX_N_PACKET_CLASSES 3 /* Must agree with above list */
117 /* Flags for rx_header flags field */
118 #define RX_CLIENT_INITIATED 1 /* Packet is sent/received from client
119 * side of call */
120 #define RX_REQUEST_ACK 2 /* Peer requests acknowledgement */
121 #define RX_LAST_PACKET 4 /* This is the last packet from this
122 * side of the call */
123 #define RX_MORE_PACKETS 8 /* There are more packets following
124 * this, i.e. the next sequence number
125 * seen by the receiver should be
126 * greater than this one, rather than
127 * a resend of an earlier sequence
128 * number */
129 #define RX_SLOW_START_OK 32 /* Set this flag in an ack
130 * packet to inform the sender
131 * that slow start is supported
132 * by the receiver. */
134 /* The following flags are preset per packet, i.e. they don't change
135 * on retransmission of the packet */
136 #define RX_PRESET_FLAGS (RX_CLIENT_INITIATED | RX_LAST_PACKET)
139 /* The rx part of the header of a packet, in host form */
140 struct rx_header {
141 uint32_t epoch; /* Start time of client process */
142 uint32_t cid; /* Connection id (defined by client) */
143 uint32_t callNumber; /* Current call number */
144 uint32_t seq; /* Sequence number of this packet,
145 * within this call */
146 uint32_t serial; /* Serial number of this packet: a new
147 * serial number is stamped on each
148 * packet sent out */
149 u_char type; /* RX packet type */
150 u_char flags; /* Flags, defined below */
151 u_char userStatus; /* User defined status information,
152 * returned/set by macros
153 * rx_Get/SetLocal/RemoteStatus */
154 u_char securityIndex; /* Which service-defined security
155 * method to use */
156 u_short serviceId; /* service this packet is directed
157 * _to_ */
160 * This spare is now used for packet header checkksum. see
161 * rxi_ReceiveDataPacket and packet cksum macros above for details.
163 u_short spare;
166 #define RX_MAXWVECS 10 /* most Unixes max is 16, so never let
167 * this > 15 */
169 * RX_FIRSTBUFFERSIZE must be larger than the largest ack packet,
170 * the largest possible challenge or response packet.
171 * Both Firstbuffersize and cbuffersize must be integral multiples of 8,
172 * so the security header and trailer stuff works for rxkad_crypt. yuck.
175 #define RX_FIRSTBUFFERSIZE (OLD_MAX_PACKET_SIZE - RX_HEADER_SIZE - 4)
176 #define RX_CBUFFERSIZE 1024
178 #if 0
179 #if defined(AFS_SUN5_ENV) || defined(AFS_AOS_ENV)
180 #define RX_FIRSTBUFFERSIZE (OLD_MAX_PACKET_SIZE - RX_HEADER_SIZE)
181 #define RX_CBUFFERSIZE 1012
182 #else
183 #define RX_FIRSTBUFFERSIZE 480 /* MTUXXX should be 1444 */
184 #define RX_CBUFFERSIZE 504 /* MTUXXX change this to 1024 or 1012 */
185 #endif /* AFS_SUN5_ENV */
186 #endif
188 struct rx_packet {
189 struct rx_queue queueItemHeader; /* Packets are chained using the
190 * queue.h package */
191 struct clock retryTime; /* When this packet should NEXT be
192 * re-transmitted */
193 struct clock timeSent; /* When this packet was transmitted
194 * last */
195 uint32_t firstSerial; /* Original serial number of this
196 * packet */
197 struct clock firstSent; /* When this packet was transmitted
198 * first */
199 struct rx_header header; /* The internal packet header */
200 int niovecs;
201 struct iovec wirevec[RX_MAXWVECS + 1]; /* the new form of the packet */
202 u_long wirehead[RX_HEADER_SIZE / sizeof(u_long)+1 ];
203 u_long localdata[RX_FIRSTBUFFERSIZE / sizeof(u_long)+1];
204 uint32_t dummy;
205 u_char acked; /* This packet has been *tentatively*
206 * acknowledged */
207 u_char backoff; /* for multiple re-sends */
208 u_short length; /* Data length */
211 struct rx_cbuf {
212 struct rx_queue queueItemHeader;
213 u_long data[(RX_CBUFFERSIZE / sizeof(u_long)) + 1];
216 /* Macros callable by security modules, to set header/trailer lengths,
217 * set actual packet size, and find the beginning of the security
218 * header (or data) */
219 #define rx_SetSecurityHeaderSize(conn, length) ((conn)->securityHeaderSize = (length))
220 #define rx_SetSecurityMaxTrailerSize(conn, length) ((conn)->securityMaxTrailerSize = (length))
221 #define rx_GetSecurityHeaderSize(conn) ((conn)->securityHeaderSize)
222 #define rx_GetSecurityMaxTrailerSize(conn) ((conn)->securityMaxTrailerSize)
224 /* This is the address of the data portion of the packet. Any encryption
225 * headers will be at this address, the actual data, for a data packet, will
226 * start at this address + the connection's security header size. */
227 #define rx_DataOf(packet) ((char *) (packet)->wirevec[1].iov_base)
228 #define rx_GetDataSize(packet) ((packet)->length)
229 #define rx_SetDataSize(packet, size) ((packet)->length = (size))
231 /* These macros used in conjunction with reuse of packet header spare as a
232 * packet cksum for rxkad security module. */
233 #define rx_GetPacketCksum(packet) ((packet)->header.spare)
234 #define rx_SetPacketCksum(packet, cksum) ((packet)->header.spare = (cksum))
236 #define rxi_OverQuota(packetclass) (rx_nFreePackets - 1 < rx_packetQuota[packetclass])
238 /* compat stuff */
239 #define rx_GetLong(p,off) rx_SlowGetLong((p), (off))
240 #define rx_PutLong(p,off,b) rx_SlowPutLong((p), (off), (b))
242 #define rx_data(p, o, l) ((l=((struct rx_packet*)(p))->wirevec[(o+1)].iov_len),\
243 (((struct rx_packet*)(p))->wirevec[(o+1)].iov_base))
246 struct rx_packet *rx_AllocPacket(void);
247 void rxi_MorePackets(int);
248 void rx_CheckCbufs(unsigned long);
249 void rxi_FreePacket(struct rx_packet *);
250 int rxi_AllocDataBuf(struct rx_packet *, int);
251 size_t rx_SlowReadPacket(struct rx_packet*, int, int, void*);
252 size_t rx_SlowWritePacket(struct rx_packet*, int, int, void*);
253 int rxi_RoundUpPacket(struct rx_packet *, unsigned int);
255 uint32_t rx_SlowGetLong(struct rx_packet *packet, int offset);
256 int rx_SlowPutLong(struct rx_packet *packet, int offset, uint32_t data);
257 int rxi_FreeDataBufs(struct rx_packet *p, int first);
259 int osi_NetSend(osi_socket s, char *addr, struct iovec *dvec,
260 int nvecs, int length);
262 /* copy data into an RX packet */
263 #define rx_packetwrite(p, off, len, in) \
264 ( (off) + (len) > (p)->wirevec[1].iov_len ? \
265 rx_SlowWritePacket(p, off, len, in) : \
266 ((memcpy((char *)((p)->wirevec[1].iov_base)+(off), (in), (len))),0))
268 /* copy data from an RX packet */
269 #define rx_packetread(p, off, len, out) \
270 ( (off) + (len) > (p)->wirevec[1].iov_len ? \
271 rx_SlowReadPacket(p, off, len, out) : \
272 ((memcpy((out), (char *)((p)->wirevec[1].iov_base)+(off), len)),0))
274 #define rx_computelen(p,l) { int i; \
275 for (l=0, i=1; i < p->niovecs; i++ ) l += p->wirevec[i].iov_len; }
277 /* return what the actual contiguous space is: should be min(length,size) */
278 /* The things that call this really want something like ...pullup MTUXXX */
279 #define rx_Contiguous(p) MIN((p)->length,((p)->wirevec[1].iov_len))
281 #ifndef TRUE
282 #define TRUE 1
283 #define FALSE 0
284 #endif
286 /* === packet-ized down to here, the following macros work temporarily */
287 /* Unfortunately, they know that the cbuf stuff isn't there. */
289 /* try to ensure that rx_DataOf will return a contiguous space at
290 * least size bytes uint32_t */
291 /* return what the actual contiguous space is: should be min(length,size) */
292 #define rx_Pullup(p,size) /* this idea here is that this will
293 * make a guarantee */
296 /* The offset of the actual user's data in the packet, skipping any
297 * security header */
298 /* DEPRECATED: DON'T USE THIS! [ 93.05.03 lws ] */
299 #define rx_UserDataOf(conn, packet) (((char *) (packet)->wirevec[1].iov_base) + (conn)->securityHeaderSize)
301 #endif /* _RX_PACKET_ */