Coda Distributed File System
rpc2.private.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 7
5
6 Copyright (c) 1987-2019 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15
16#*/
17
18/*
19 IBM COPYRIGHT NOTICE
20
21 Copyright (C) 1986
22 International Business Machines Corporation
23 All Rights Reserved
24
25This file contains some code identical to or derived from the 1986
26version of the Andrew File System ("AFS"), which is owned by the IBM
27Corporation. This code is provided "AS IS" and IBM does not warrant
28that it is free of infringement of any intellectual rights of any
29third party. IBM disclaims liability of any kind for any damages
30whatsoever resulting directly or indirectly from use of this software
31or of any derivative work. Carnegie Mellon University has obtained
32permission to modify, distribute and sublicense this code, which is
33based on Version 2 of AFS and does not contain the features and
34enhancements that are part of Version 3 of AFS. Version 3 of AFS is
35commercially available and supported by Transarc Corporation,
36Pittsburgh, PA.
37
38*/
39
40#ifndef _RPC2_PRIVATE_H_
41#define _RPC2_PRIVATE_H_
42
43#ifdef HAVE_CONFIG_H
44#include <config.h>
45#endif
46
47#include <assert.h>
48#include <netinet/in.h>
49#include <signal.h>
50#include <stddef.h>
51#include <string.h>
52
53#include <lwp/lwp.h>
54#include <lwp/timer.h>
55#include <rpc2/rpc2.h>
56#include <rpc2/rpc2_addrinfo.h>
57#include <rpc2/secure.h>
58
59#include "dllist.h"
60
61#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
62/* this should be large enough to fit 'any' socket address. */
64 struct sockaddr __ss_sa;
65 char _ss_padding[128 - sizeof(struct sockaddr)];
66};
67#endif
68
69#ifndef HAVE_STRUCT_SOCKADDR_IN6
70struct in6_addr {
71 u_int8_t u6_addr[16];
72};
74 u_int16_t sin6_family;
75 u_int16_t sin6_port;
76 u_int32_t sin6_flowinfo;
78};
79#endif
80
81#ifndef HAVE_SOCKLEN_T
82#define socklen_t unsigned int
83#endif
84
85/*
86Magic Number assignments for runtime system objects.
87Truly random values to allow easy detection of storage corruption.
88*/
89
90#define OBJ_CENTRY 868
91#define OBJ_FREE_CENTRY 686
92#define OBJ_HENTRY 48127
93#define OBJ_MENTRY 69743
94#define OBJ_PACKETBUFFER 3247517
95#define OBJ_SLENTRY 107
96#define OBJ_SSENTRY 34079
97
98/* Role and state determination:
99 Top 2 bytes (0x0088 or 0x0044) determine client or server
100 Bottom 2 bytes determine state within client or server.
101 This allows rapid testing using bit masks.
102*/
103
104/* Server or Client? */
105#define FREE 0x0
106#define CLIENT 0x00880000
107#define SERVER 0x00440000
108
109/* Client States */
110#define C_THINK 0x1
111#define C_AWAITREPLY 0x2
112#define C_HARDERROR 0x4
113#define C_AWAITINIT2 0x8
114#define C_AWAITINIT4 0x10
115
116/* Server States */
117#define S_AWAITREQUEST 0x1
118#define S_REQINQUEUE 0x2
119#define S_PROCESS 0x4
120#define S_INSE 0x8
121#define S_HARDERROR 0x10
122#define S_STARTBIND 0x20
123#define S_AWAITINIT3 0x40
124#define S_FINISHBIND 0x80
125#define S_AWAITENABLE 0x0100
126
127#define SetRole(e, role) (e->State = role)
128#define SetState(e, new) (e->State = (e->State & 0xffff0000) | (new))
129#define TestRole(e, role) ((e->State & 0xffff0000) == role)
130#define TestState(e, role, smask) \
131 (TestRole(e, role) && ((e->State & 0x0000ffff) & (smask)))
132
133#ifndef O_BINARY
134#define O_BINARY 0
135#endif
136
137/* MAXRTO is used to avoid unbounded timeouts */
138#define RPC2_MAXRTO 30000000 /* max rto (rtt + variance) is 30 seconds */
139#define RPC2_DELACK_DELAY 100000
140/* delay for server to send an ack that it received a request. This provides an
141 * upper bound on server response time. */
142
143/* Definitions for Flags field of connections */
144#define CE_OLDV 0x1 /* old version detected during bind */
145
146/*---------------- Data Structures ----------------*/
147struct CEntry /* describes a single RPC connection */
148{
149 /* Link Entry Fields */
152 struct CEntry *Qname;
153
155
156 /* State, identity and sequencing */
157 long State;
161 RPC2_Integer Flags; /* CE_OLDV ? */
162 time_t LastRef; /* when CEntry was last looked up */
163
164 /* Security */
168
169 /* PeerInfo */
170 RPC2_Handle PeerHandle; /* peer's connection ID */
171 RPC2_Integer PeerUnique; /* Unique integer used in Init1 bind request
172 from peer */
173 struct HEntry *HostInfo; /* Link to host table and liveness
174 information */
175
176 /* Auxiliary stuff */
177 struct SE_Definition *SEProcs; /* pointer to side effect routines */
178 long sebroken; /* flag set on hard se errors */
179 struct MEntry *Mgrp; /* Multicast group of this conn */
180 char *PrivatePtr; /* rock for pointer to user data */
181 char *SideEffectPtr; /* rock for per-connection side-effect data */
182 RPC2_Integer Color; /* Packets sent out get this color.
183 See documentation for libfail(3).
184 Only lowest byte is useful. */
185 /* Stuff for SocketListener */
186 struct SL_Entry *MySl; /* SL entry pertaining to this conn, or NULL */
187 RPC2_PacketBuffer *HeldPacket; /* NULL or pointer to packet held in readiness
188 for retransmission (reply or last packet
189 of Bind handshake */
190 unsigned long reqsize; /* size of request, for RTT calcs */
191
192 unsigned int TimeStampEcho;
193 unsigned int RequestTime;
194 struct timeval TimeBomb; /* Time limit for some rpc2 requests on
195 this connection. */
196 struct timeval
197 SaveResponse; /* 2*KeepAlive, lifetime of saved response packet. */
198 RPC2_RequestFilter Filter; /* Set on the server during binding,
199 filter incoming requests so that the
200 SubsysID/Connection matches that of
201 the handler we authenticated with */
203};
204
205struct MEntry /* describes an RPC multicast connection */
206{
208
209 /* Multicast Group Connection info */
210 RPC2_Integer State; /* eg {C,S}_AWAITREQUEST */
211 struct RPC2_addrinfo *ClientAddr; /* | */
213 RPC2_Integer NextSeqNumber; /* for mgrp connection */
214
215 /* Auxiliary stuff */
216 struct SE_Definition *SEProcs; /* pointer to side effect routines */
217 char *SideEffectPtr; /* rock for per-mgrp side-effect data */
218
219 /* Connection entries associated with this Mgrp. Clients have an
220 array of these, servers only one. */
221 union {
222 struct {
229#define listeners me_conns.me_client.mec_listeners
230#define howmanylisteners me_conns.me_client.mec_howmanylisteners
231#define maxlisteners me_conns.me_client.mec_maxlisteners
232#define conn me_conns.mes_conn
233};
234
235/* SL entries are the data structures used for comm between user LWPs and
236 the SocketListener. The user LWP creates an entry, sets it up, sets a
237 timeout on it and goes to sleep. SocketListener eventually sets a
238 return code on the entry and wakes up the LWP.
239
240 SL Entries are typed:
241 REPLY associated with a specific connection
242 created by user LWP in SendResponse
243 creating LWP does not wait for timeout to expire
244 destroyed by SocketListener
245
246 REQ not associated with a specific connection
247 created and destroyed by user LWP in GetRequest
248
249 DELACK delayed ack response to receiving a request
250 created by SocketListener in HandleRequest
251 destroyed by SocketListener on timeout
252 destroyed by user LWP when reply is sent.
253
254 DELAYED_SEND Artificially introduced a transmission delay
255 DELAYED_RECV Artificially introduced a reception delay
256
257 OTHER associated with a specific connection
258 created and destroyed by user LWP
259
260Entries of type REQ are on a separate list to minimize list searching in
261SocketListener. Other types of entries can be directly accessed via the
262connection they are associated with.
263
264*/
265
266/* NOTE: enum definitions have to be non-anonymous: else a dbx bug is
267 * triggered */
269{
270 REPLY = 1421,
271 REQ = 1422,
272 OTHER = 1423,
273 DELACK = 20010911,
274 DELAYED_SEND = 20061016,
275 DELAYED_RECV = 20061017
278{
279 WAITING = 38358230,
280 ARRIVED = 38358231,
281 TIMEOUT = 38358232,
282 KEPTALIVE = 38358233,
283 KILLED = 38358234,
284 NAKED = 38358235
286
287/* data structure for communication with SocketListener */
288struct SL_Entry {
290
292
293 /* Timeout-related fields */
294 struct TM_Elem TElem; /* element to be inserted into timer chain;
295 The BackPointer field of TElem will
296 point to this SL_Entry */
297 enum RetVal ReturnCode; /* SocketListener changes this from WAITING */
298
299 /* Other fields */
300 RPC2_Handle Conn; /* NULL or conn corr to this SL Entry */
301 void *data; /* NULL, packet buffer, or delayed xmit data */
302 RPC2_RequestFilter Filter; /* useful only in GetRequest */
303 int RetryIndex; /* useful only in MakeRPC */
304 struct timeval RInterval; /* current retry timeout */
305};
306
307struct SubsysEntry /* Defines a subsystem being actively serviced by a server */
308{ /* Created by RPC2_InitSubsys(); destroyed by RPC2_EndSubsys() */
310 long Id; /* using a struct is a little excessive, but it makes things
311 uniform */
312};
313
314/* extend with other side effect types */
315typedef enum
316{
319 SMARTFTP_HE = 2
321
322struct HEntry {
324
325 struct HEntry *HLink; /* for host hash */
326 int RefCount; /* # connections that have a reference */
327 struct RPC2_addrinfo *Addr; /* network address */
328 struct timeval LastWord; /* Most recent time we've heard from this host */
329 unsigned RPC2_NumEntries; /* number of observations recorded */
331 /* circular buffer for recent observations on round trip times
332 * and packet sizes */
333 unsigned SE_NumEntries; /* number of sideeffect observations recorded */
335
336/* the RTT is shifted analogous to Jacobson's article in SIGCOMM'88 */
337#define RPC2_RTT_SHIFT 3 /* Bits to right of binary point of RTT */
338#define RPC2_RTTVAR_SHIFT 2 /* Bits to right of binary point of RTTvar */
339 unsigned long RTT; /* RTT (us<<RPC2_RTT_SHIFT) */
340 unsigned long RTTvar; /* RTT variance (us<<RPC2_RTTVAR_SHIFT) */
341
342#define RPC2_INITIAL_BW 100000
343#define RPC2_BW_SHIFT 4
344 uint32_t BWlo_in, BWhi_in; /* Incoming Bandwidth (B/s) */
345 uint32_t BWlo_out, BWhi_out; /* Outgoing Bandwidth (B/s) */
346};
347
348/*-------------- Format of special packets ----------------*/
349
350/* WARNING: if you port RPC2, make sure the structure sizes work out to be the
351 * same on your target machine */
352
353struct Init1Body /* Client to Server: format of packets with opcode of
354 RPC2_INIT1xxx */
355{
356 /* body of fake packet from RPC2_GetRequest() */
363 /* end of body of fake packet from RPC2_GetRequest() */
364 /* When MakeFake is called we'll clobber the remaining data in this packet
365 * because we don't really send a pointer to the ClientIdent.SeqBody, but
366 * we move it there from the tail of the packet so that the stub generator
367 * can unpack it as a valid RPC2_NEWCONNECTION rpc call */
368
369 RPC2_Integer XRandom; /* encrypted random number */
370 char usedtobehostport[92]; /* XXX not used anymore but old rpc2
371 servers need the alignment */
372 RPC2_Integer Uniquefier; /* to allow detection of retransmissions */
373 RPC2_Unsigned RPC2SEC_version; /* supported handshake version */
374 RPC2_Unsigned Preferred_Keysize; /* preferred encryption key length */
376 RPC2_Byte Version[96]; /* set to RPC2_VERSION */
377 RPC2_Byte Text[4]; /* Storage for the ClientIdent. Moved
378 to FakeBody_ClientIdent_SeqBody in
379 rpc2a.c:MakeFake(). It can of course
380 be more than 4 bytes, this is just
381 for alignment purposes. */
382};
383
384struct Init2Body /* Server to Client */
385{
391};
392
393struct Init3Body /* Client to Server */
394{
399};
400
401struct Init4Body /* Server to Client */
402{
404 InitialSeqNumber; /* Seq number of first expected packet from client */
405 RPC2_EncryptionKey SessionKey; /* for use from now on */
406 RPC2_Integer XRandomPlusTwo; /* prevent replays of this packet -rnw 2/7/98 */
409};
410
411struct InitMulticastBody /* Client to Server */
412{
414 RPC2_Integer InitialSeqNumber; /* Seq number of next packet from client */
415 RPC2_EncryptionKey SessionKey; /* for use on the multicast channel */
419};
420
421/* Macros for manipulating color field of packets */
422#define htonPktColor(p) (p->Header.Flags = htonl(p->Header.Flags))
423#define ntohPktColor(p) (p->Header.Flags = ntohl(p->Header.Flags))
424#define SetPktColor(p, c) \
425 (p->Header.Flags = (p->Header.Flags & 0xff00ffff) | ((c & 0xff) << 16))
426#define GetPktColor(p) ((p->Header.Flags >> 16) & 0x000000ff)
427
428/*------------- List headers and counts -------------*/
429
430/* NOTE: all these lists are doubly-linked and circular */
431
432/* The multicast group abstraction */
434
435/* Items for SocketListener */
436
437extern struct rpc2_LinkEntry *rpc2_SLReqList; /* SL_Entry in use, of type REQ */
439
440/* Lists holding allocated and free packet buffers */
442
443/* Subsystem definitions */
444extern struct rpc2_LinkEntry *rpc2_SSList; /* subsystems in active use */
445
446/* Host info definitions */
448
449/*------------- Miscellaneous global data ------------*/
450extern int rpc2_ipv6ready; /* can userspace handle IPv6 addresses */
451extern int rpc2_v4RequestSocket; /* fd of RPC socket */
452extern int rpc2_v6RequestSocket; /* fd of RPC socket */
453/* we may need more when we deal with many domains */
454extern struct TM_Elem *rpc2_TimerQueue;
455extern struct CBUF_Header *rpc2_TraceBuffHeader;
456extern PROCESS rpc2_SocketListenerPID; /* used in IOMGR_Cancel() calls */
457extern unsigned long rpc2_LamportClock;
458extern long Retry_N;
459extern struct timeval KeepAlive;
460extern uint32_t *rpc2_RTTvals;
461
462/* List manipulation routines */
463void rpc2_Replenish(struct rpc2_LinkEntry **whichList, long *whichCount,
464 long elemSize, long *creationCount, long magicNumber);
465struct rpc2_LinkEntry *rpc2_MoveEntry(struct rpc2_LinkEntry **fromPtr,
466 struct rpc2_LinkEntry **toPtr,
467 struct rpc2_LinkEntry *p, long *fromCount,
468 long *toCount);
469
470struct SL_Entry *rpc2_AllocSle(enum SL_Type slType, struct CEntry *slConn);
471void rpc2_FreeSle(struct SL_Entry **sl);
472void rpc2_ActivateSle(struct SL_Entry *selem, struct timeval *exptime);
473void rpc2_DeactivateSle(struct SL_Entry *sl, enum RetVal rc);
474struct SubsysEntry *rpc2_AllocSubsys(void);
475void rpc2_FreeSubsys(struct SubsysEntry **whichSubsys);
476
477void FreeHeld(struct SL_Entry *sle);
478
479/* Helpers to convert LinkEntry pointers to rpc2 objects */
480#define LE2(func, type, magic, member) \
481 static inline type *func(struct rpc2_LinkEntry *le) \
482 { \
483 if (!le) \
484 return NULL; \
485 assert(le->MagicNumber == magic); \
486 return (void *)((char *)le - offsetof(type, member)); \
487 }
488LE2(rpc2_LE2HE, struct HEntry, OBJ_HENTRY, LE)
489LE2(rpc2_LE2ME, struct MEntry, OBJ_MENTRY, LE)
490LE2(rpc2_LE2PB, RPC2_PacketBuffer, OBJ_PACKETBUFFER, Prefix.LE)
491LE2(rpc2_LE2SL, struct SL_Entry, OBJ_SLENTRY, LE)
492LE2(rpc2_LE2SS, struct SubsysEntry, OBJ_SSENTRY, LE)
493#undef LE2
494
495/* Socket creation */
496
497long rpc2_CreateIPSocket(int af, int *svar, struct RPC2_addrinfo *addr,
498 short *Port);
499
500/* Packet routines */
502void rpc2_XmitPacket(RPC2_PacketBuffer *pb, struct RPC2_addrinfo *addr,
503 int confirm);
505int rpc2_MorePackets(void);
506long rpc2_RecvPacket(long whichSocket, RPC2_PacketBuffer *whichBuff);
509long rpc2_CancelRetry(struct CEntry *Conn, struct SL_Entry *Sle);
510void rpc2_UpdateRTT(RPC2_PacketBuffer *pb, struct CEntry *ceaddr);
511void rpc2_ExpireEvents();
512void SavePacketForRetry(RPC2_PacketBuffer *pb, struct CEntry *ce);
513
514/* Connection manipulation routines */
515int rpc2_InitConn(void);
518struct CEntry *rpc2_ConnFromBindInfo(struct RPC2_addrinfo *peeraddr,
520 RPC2_Integer whichUnique);
521struct CEntry *__rpc2_GetConn(RPC2_Handle handle); /* doesn't bump lastref */
522struct CEntry *rpc2_GetConn(RPC2_Handle handle);
523void rpc2_ReapDeadConns(void);
524void rpc2_IncrementSeqNumber(struct CEntry *);
525
526/* Host manipulation routines */
527void rpc2_InitHost(void);
528struct HEntry *rpc2_GetHost(struct RPC2_addrinfo *addr);
529void rpc2_FreeHost(struct HEntry **whichHost);
530void rpc2_GetHostLog(struct HEntry *whichHost, RPC2_NetLog *log,
532int rpc2_AppendHostLog(struct HEntry *whichHost, RPC2_NetLogEntry *entry,
534void rpc2_ClearHostLog(struct HEntry *whichHost, NetLogEntryType type);
535
536void RPC2_UpdateEstimates(struct HEntry *whichHost, RPC2_Unsigned ElapsedTime,
537 RPC2_Unsigned InBytes, RPC2_Unsigned OutBytes);
538int rpc2_RetryInterval(struct CEntry *ce, int retry, struct timeval *tv,
539 RPC2_Unsigned OutBytes, RPC2_Unsigned InBytes, int sftp);
540
541/* Multicast group manipulation routines */
543struct MEntry *rpc2_AllocMgrp(struct RPC2_addrinfo *addr, RPC2_Handle handle);
544struct MEntry *rpc2_GetMgrp(struct RPC2_addrinfo *addr, RPC2_Handle handle,
545 long role);
546
547/* Hold queue routines */
550
551/* RPC2_GetRequest() filter matching function */
553
554/* Autonomous LWPs */
555void rpc2_SocketListener(void *);
556void rpc2_ClockTick(void *);
557
558/* rpc2_SocketListener packet handlers */
559void SL_RegisterHandler(unsigned int proto, void (*func)(RPC2_PacketBuffer *));
561void RPC2_DispatchProcess(void);
562
563/* Packet timestamp creation */
564unsigned int rpc2_TVTOTS(const struct timeval *tv);
565void rpc2_TSTOTV(const unsigned int ts, struct timeval *tv);
566unsigned int rpc2_MakeTimeStamp();
567
568/* Debugging routines */
572extern FILE *ErrorLogFile;
573
574/* encryption */
576
577void rpc2_ApplyD(RPC2_PacketBuffer *pb, struct CEntry *ce);
578void rpc2_ApplyE(RPC2_PacketBuffer *pb, struct CEntry *ce);
579
580time_t rpc2_time();
581long rpc2_InitRetry(long HowManyRetries, struct timeval *Beta0);
582
584 RPC2_Integer whichUnique, RPC2_Handle whichConn);
585
586int mkcall(RPC2_HandleResult_func *ClientHandler, int ArgCount, int HowMany,
587 RPC2_Handle ConnList[], long offset, long rpcval, int *args);
588
589/*----------- Macros ---------- */
590
591/* Test if more than one bit is set; WARNING: make sure at least one bit is set
592 * first! */
593#define MORETHANONEBITSET(x) (x != (1 << (ffs((long)x) - 1)))
594
595/* Macros to work with preemption package */
596/* #define rpc2_Enter() (PRE_BeginCritical()) */
597#define rpc2_Enter() \
598 do { \
599 } while (0)
600/*#define rpc2_Quit(rc) return(PRE_EndCritical(), (long)rc) */
601#define rpc2_Quit(rc) return ((long)rc)
602
603/* Macros to check if host and portal ident structures are equal */
604/* The lengths of the names really should be #defined. */
605#define rpc2_HostIdentEqual(_hi1p_, _hi2p_) \
606 (((_hi1p_)->Tag == RPC2_HOSTBYINETADDR && \
607 (_hi2p_)->Tag == RPC2_HOSTBYINETADDR) ? \
608 ((_hi1p_)->Value.AddrInfo->ai_family == \
609 (_hi2p_)->Value.AddrInfo->ai_family && \
610 (_hi1p_)->Value.AddrInfo->ai_addrlen == \
611 (_hi2p_)->Value.AddrInfo->ai_addrlen && \
612 !memcmp((_hi1p_)->Value.AddrInfo->ai_addr, \
613 (_hi2p_)->Value.AddrInfo->ai_addr, \
614 (_hi2p_)->Value.AddrInfo->ai_addrlen)) : \
615 (((_hi1p_)->Tag == RPC2_HOSTBYNAME && \
616 (_hi2p_)->Tag == RPC2_HOSTBYNAME) ? \
617 (strncmp((_hi1p_)->Value.Name, (_hi2p_)->Value.Name, 64) == 0) : \
618 0))
619
620/*------ Other definitions ------*/
621
622/* Allocation constants */
623
624#define SMALLPACKET 350
625#define MEDIUMPACKET 1500
626#define LARGEPACKET RPC2_MAXPACKETSIZE
627
628/* Packets sent */
629extern unsigned long rpc2_NoNaks;
632
633/* RPC2_addrinfo helper routines */
635void rpc2_printaddrinfo(const struct RPC2_addrinfo *ai, FILE *f);
637 const struct RPC2_addrinfo *ai);
639void rpc2_formataddrinfo(const struct RPC2_addrinfo *ai, char *buf,
640 size_t buflen, int use_canonname);
641
642/*---------------
643 * Useful definitions that used to be in potpourri.h or util.h
644 * ---------------*/
645/* Now included here to avoid including either of those files */
646
647/* Parameter usage */
648#define IN /* Input parameter */
649#define OUT /* Output parameter */
650#define INOUT /* Obvious */
651
652/* Conditional debugging output macros: no side effect in these! */
654#ifdef RPC2DEBUG
655#define say(when, what, how...) \
656 do { \
657 if (when < what) { \
658 fprintf(rpc2_logfile, \
659 "[%s]%s: \"%s\", line %d: ", rpc2_timestring(), \
660 LWP_Name(), __FILE__, __LINE__); \
661 fprintf(rpc2_logfile, ##how); \
662 (void)fflush(rpc2_logfile); \
663 } \
664 } while (0);
665#else
666#define say(when, what, how...)
667#endif
668
669#ifndef TRUE
670#define TRUE 1
671#define FALSE 0
672#endif
673
674/*--------- End stuff from util.h ------------*/
675
676/* macro to subtract one timeval from another */
677#define SUBTIME(fromp, subp) \
678 do { \
679 if ((subp)->tv_usec > (fromp)->tv_usec) { \
680 (fromp)->tv_sec--; \
681 (fromp)->tv_usec += 1000000; \
682 } \
683 (fromp)->tv_sec -= (subp)->tv_sec; \
684 (fromp)->tv_usec -= (subp)->tv_usec; \
685 } while (0);
686
687/* add one timeval to another */
688#define ADDTIME(top, fromp) \
689 do { \
690 (top)->tv_sec += (fromp)->tv_sec; \
691 (top)->tv_usec += (fromp)->tv_usec; \
692 if ((top)->tv_usec >= 1000000) { \
693 (top)->tv_sec++; \
694 (top)->tv_usec -= 1000000; \
695 } \
696 } while (0);
697
698#define CMPTIME(a, b, CMP) \
699 (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP(b)->tv_usec) : \
700 ((a)->tv_sec CMP(b)->tv_sec))
701
702#define CLRTIME(tm) ((tm)->tv_sec = 0, (tm)->tv_usec = 0)
703#define TIMERISSET(tm) ((tm)->tv_sec || (tm)->tv_usec)
704
705/* macros to convert between timeval and timestamp */
706#define TVTOTS(_tvp_, _ts_) \
707 do { \
708 _ts_ = ((_tvp_)->tv_sec * 1000000 + (_tvp_)->tv_usec); \
709 } while (0);
710
711#define TSTOTV(_tvp_, _ts_) \
712 do { \
713 (_tvp_)->tv_sec = (_ts_) / 1000000; \
714 (_tvp_)->tv_usec = (_ts_) % 1000000; \
715 } while (0);
716
717#define TSDELTA(_ts1_, _ts2_) ((int)(_ts1_) - (int)(_ts2_))
718
719#ifdef USE_LUA
720/* lua.c - include Lua interpreter for roundtrip time estimators */
721void LUA_init(void);
722void LUA_clocktick(void);
723void LUA_drop_hosttable(struct HEntry *he);
724
725void LUA_rtt_update(struct HEntry *he, uint32_t rtt, uint32_t tx, uint32_t rx);
726int LUA_rtt_getrto(struct HEntry *he, uint32_t tx, uint32_t rx);
727int LUA_rtt_getbandwidth(struct HEntry *he, uint32_t *bw_tx, uint32_t *bw_rx);
728/* not sure if we want to allow the estimator to control number of retries
729 * and/or overall timeout, so I might not actually use this function... */
731 uint32_t rx);
732int LUA_fail_delay(struct RPC2_addrinfo *addr, RPC2_PacketBuffer *pb, int out,
733 struct timeval *tv);
734#else
735/* do not include Lua interpreter, define empty stubs */
736#define LUA_init()
737#define LUA_clocktick()
738#define LUA_drop_hosttable(a)
739#define LUA_rtt_update(a, b, c, d)
740#define LUA_rtt_getrto(a, b, c) 0
741#define LUA_rtt_getbandwidth(a, b, c) 0
742#define LUA_rtt_retryinterval(a, b, c, d) 0
743#define LUA_fail_delay(a, b, c, d) 0
744#endif
745
746int rpc2_DelayedSend(int s, struct RPC2_addrinfo *addr, RPC2_PacketBuffer *pb,
747 struct timeval *delay);
748int rpc2_DelayedRecv(RPC2_PacketBuffer *pb, struct timeval *delay);
749
750void rpc2_SendDelayedPacket(struct SL_Entry *sl);
752
753#endif /* _RPC2_PRIVATE_H_ */
unsigned int uint32_t
Definition: coda.h:105
long RPC2_HandleResult_func(int HowMany, RPC2_Handle ConnList[], long offset, long rpcval,...)
Definition: multi.h:48
args
Definition: volusage.py:9
void(* type)()
Definition: rp2main.c:424
#define RPC2_MAXLOGLENGTH
Definition: rpc2.h:611
RPC2_Byte RPC2_EncryptionKey[RPC2_KEYSIZE]
Definition: rpc2.h:336
int32_t RPC2_Integer
Definition: rpc2.h:297
uint32_t RPC2_Unsigned
Definition: rpc2.h:300
RPC2_Integer RPC2_Handle
Definition: rpc2.h:345
NetLogEntryType
Definition: rpc2.h:630
uint8_t RPC2_Byte
Definition: rpc2.h:302
void rpc2_DeactivateSle(struct SL_Entry *sl, enum RetVal rc)
Definition: lists.c:234
#define LE2(func, type, magic, member)
Definition: rpc2.private.h:480
int rpc2_ipv6ready
Definition: globals.c:56
long rpc2_BindLimit
Definition: globals.c:99
#define OBJ_PACKETBUFFER
Definition: rpc2.private.h:94
void rpc2_InitHost(void)
Definition: host.c:96
void rpc2_FreeSle(struct SL_Entry **sl)
int rpc2_MorePackets(void)
Definition: sl.c:149
void rpc2_HoldPacket(RPC2_PacketBuffer *whichPB)
Definition: lists.c:276
void rpc2_PrintTMElem()
void rpc2_htonp(RPC2_PacketBuffer *p)
Definition: packet.c:489
void rpc2_PrintSLEntry()
void rpc2_ApplyE(RPC2_PacketBuffer *pb, struct CEntry *ce)
Definition: secure.c:121
void FreeHeld(struct SL_Entry *sle)
Definition: sl.c:1170
void rpc2_PrintSEDesc()
void rpc2_ActivateSle(struct SL_Entry *selem, struct timeval *exptime)
Definition: lists.c:204
long rpc2_CreateIPSocket(int af, int *svar, struct RPC2_addrinfo *addr, short *Port)
Definition: rpc2b.c:896
struct timeval KeepAlive
Definition: globals.c:67
void rpc2_Replenish(struct rpc2_LinkEntry **whichList, long *whichCount, long elemSize, long *creationCount, long magicNumber)
Definition: lists.c:60
void rpc2_SocketListener(void *)
Definition: sl.c:258
#define LUA_init()
Definition: rpc2.private.h:736
unsigned long rpc2_NoNaks
void rpc2_ntohp(RPC2_PacketBuffer *p)
Definition: packet.c:508
struct CEntry * rpc2_ConnFromBindInfo(struct RPC2_addrinfo *peeraddr, RPC2_Handle RemoteHandle, RPC2_Integer whichUnique)
Definition: conn.c:412
struct security_association * rpc2_GetSA(uint32_t spi)
Definition: packet.c:224
void rpc2_PrintCEntry()
void rpc2_HandlePacket(RPC2_PacketBuffer *pb)
Definition: sl.c:304
#define OBJ_SLENTRY
Definition: rpc2.private.h:95
void rpc2_InitMgrp()
unsigned long rpc2_LamportClock
Definition: globals.c:96
void rpc2_XmitPacket(RPC2_PacketBuffer *pb, struct RPC2_addrinfo *addr, int confirm)
Definition: packet.c:117
void rpc2_PrintTraceElem()
void SavePacketForRetry(RPC2_PacketBuffer *pb, struct CEntry *ce)
Definition: rpc2a.c:1275
long rpc2_MgrpFreeCount
Definition: globals.c:74
void rpc2_printaddrinfo(const struct RPC2_addrinfo *ai, FILE *f)
Definition: rpc2_addrinfo.c:545
time_t rpc2_time()
Definition: rpc2a.c:1270
struct SL_Entry * rpc2_AllocSle(enum SL_Type slType, struct CEntry *slConn)
Definition: lists.c:140
void SL_RegisterHandler(unsigned int proto, void(*func)(RPC2_PacketBuffer *))
unsigned int rpc2_MakeTimeStamp()
Definition: rpc2b.c:1002
void rpc2_IncrementSeqNumber(struct CEntry *)
Definition: sl.c:1143
#define OBJ_MENTRY
Definition: rpc2.private.h:93
long rpc2_SendReliably()
struct HEntry * rpc2_GetHost(struct RPC2_addrinfo *addr)
Definition: host.c:105
uint32_t * rpc2_RTTvals
Definition: globals.c:68
void rpc2_DeleteMgrp()
void rpc2_TSTOTV(const unsigned int ts, struct timeval *tv)
#define LUA_fail_delay(a, b, c, d)
Definition: rpc2.private.h:743
struct rpc2_LinkEntry * rpc2_SLReqList
Definition: globals.c:76
void rpc2_ClearHostLog(struct HEntry *whichHost, NetLogEntryType type)
Definition: host.c:295
struct CEntry * rpc2_GetConn(RPC2_Handle handle)
Definition: conn.c:122
long rpc2_InitRetry(long HowManyRetries, struct timeval *Beta0)
RPC2_PacketBuffer * rpc2_RecvDelayedPacket(struct SL_Entry *sl)
Definition: delay.c:106
int rpc2_AppendHostLog(struct HEntry *whichHost, RPC2_NetLogEntry *entry, NetLogEntryType type)
Definition: host.c:264
long rpc2_RecvPacket(long whichSocket, RPC2_PacketBuffer *whichBuff)
long rpc2_SLCount
Definition: rpc2.private.h:438
#define LUA_clocktick()
Definition: rpc2.private.h:737
struct RPC2_addrinfo * rpc2_resolve(RPC2_HostIdent *Host, RPC2_PortIdent *Port)
Definition: rpc2_addrinfo.c:553
long rpc2_HostCount
Definition: rpc2.private.h:447
SL_Type
Definition: rpc2.private.h:269
@ DELAYED_RECV
Definition: rpc2.private.h:275
@ REPLY
Definition: rpc2.private.h:270
@ DELACK
Definition: rpc2.private.h:273
@ DELAYED_SEND
Definition: rpc2.private.h:274
@ REQ
Definition: rpc2.private.h:271
@ OTHER
Definition: rpc2.private.h:272
int rpc2_FilterMatch()
HEType
Definition: rpc2.private.h:316
@ SMARTFTP_HE
Definition: rpc2.private.h:319
@ RPC2_HE
Definition: rpc2.private.h:318
@ UNSET_HE
Definition: rpc2.private.h:317
long rpc2_MSendPacketsReliably()
int mkcall(RPC2_HandleResult_func *ClientHandler, int ArgCount, int HowMany, RPC2_Handle ConnList[], long offset, long rpcval, int *args)
Definition: mkcall.c:48
void rpc2_FreeMgrp()
struct MEntry * rpc2_AllocMgrp(struct RPC2_addrinfo *addr, RPC2_Handle handle)
Definition: multi3.c:126
struct CEntry * __rpc2_GetConn(RPC2_Handle handle)
Definition: conn.c:88
void rpc2_PrintPortIdent()
void rpc2_UnholdPacket(RPC2_PacketBuffer *whichPB)
Definition: lists.c:286
int rpc2_v4RequestSocket
Definition: globals.c:58
struct SubsysEntry * rpc2_AllocSubsys(void)
Definition: lists.c:250
FILE * ErrorLogFile
Definition: ctest.c:83
RetVal
Definition: rpc2.private.h:278
@ WAITING
Definition: rpc2.private.h:279
@ KILLED
Definition: rpc2.private.h:283
@ NAKED
Definition: rpc2.private.h:284
@ TIMEOUT
Definition: rpc2.private.h:281
@ ARRIVED
Definition: rpc2.private.h:280
@ KEPTALIVE
Definition: rpc2.private.h:282
int rpc2_DelayedRecv(RPC2_PacketBuffer *pb, struct timeval *delay)
Definition: delay.c:79
long rpc2_FreeMgrps
Definition: globals.c:105
void rpc2_RemoveFromMgrp()
#define LUA_rtt_getbandwidth(a, b, c)
Definition: rpc2.private.h:741
struct CBUF_Header * rpc2_TraceBuffHeader
Definition: globals.c:63
int rpc2_DelayedSend(int s, struct RPC2_addrinfo *addr, RPC2_PacketBuffer *pb, struct timeval *delay)
Definition: delay.c:31
#define OBJ_SSENTRY
Definition: rpc2.private.h:96
#define LUA_drop_hosttable(a)
Definition: rpc2.private.h:738
long rpc2_CancelRetry(struct CEntry *Conn, struct SL_Entry *Sle)
Definition: packet.c:358
struct rpc2_LinkEntry * rpc2_SSList
Definition: globals.c:85
int rpc2_InitConn(void)
Definition: conn.c:68
void rpc2_InitPacket()
long rpc2_SLReqCount
Definition: globals.c:77
long rpc2_HostCreationCount
Definition: rpc2.private.h:447
long rpc2_MgrpCreationCount
Definition: rpc2.private.h:433
void rpc2_PrintHostIdent()
PROCESS rpc2_SocketListenerPID
Definition: globals.c:64
void rpc2_simplifyHost(RPC2_HostIdent *Host, RPC2_PortIdent *Port)
Definition: rpc2_addrinfo.c:647
char * rpc2_timestring()
struct MEntry * rpc2_GetMgrp(struct RPC2_addrinfo *addr, RPC2_Handle handle, long role)
Definition: multi3.c:205
void rpc2_formataddrinfo(const struct RPC2_addrinfo *ai, char *buf, size_t buflen, int use_canonname)
Definition: rpc2_addrinfo.c:303
struct rpc2_LinkEntry * rpc2_MoveEntry(struct rpc2_LinkEntry **fromPtr, struct rpc2_LinkEntry **toPtr, struct rpc2_LinkEntry *p, long *fromCount, long *toCount)
Definition: lists.c:92
void RPC2_UpdateEstimates(struct HEntry *whichHost, RPC2_Unsigned ElapsedTime, RPC2_Unsigned InBytes, RPC2_Unsigned OutBytes)
Definition: host.c:371
int rpc2_RetryInterval(struct CEntry *ce, int retry, struct timeval *tv, RPC2_Unsigned OutBytes, RPC2_Unsigned InBytes, int sftp)
Definition: host.c:450
void rpc2_GetHostLog(struct HEntry *whichHost, RPC2_NetLog *log, NetLogEntryType type)
Definition: host.c:202
void RPC2_DispatchProcess(void)
Definition: sl.c:287
#define LUA_rtt_update(a, b, c, d)
Definition: rpc2.private.h:739
long rpc2_HostFreeCount
Definition: globals.c:88
void rpc2_PrintPacketHeader()
void rpc2_SendDelayedPacket(struct SL_Entry *sl)
Definition: delay.c:68
#define LUA_rtt_getrto(a, b, c)
Definition: rpc2.private.h:740
int rpc2_v6RequestSocket
Definition: globals.c:59
#define LUA_rtt_retryinterval(a, b, c, d)
Definition: rpc2.private.h:742
struct TM_Elem * rpc2_TimerQueue
Definition: globals.c:62
void rpc2_FreeConn()
void rpc2_ClockTick(void *)
Definition: ct.c:65
void rpc2_NoteBinding(struct RPC2_addrinfo *peeraddr, RPC2_Handle RemoteHandle, RPC2_Integer whichUnique, RPC2_Handle whichConn)
Definition: conn.c:378
void rpc2_ApplyD(RPC2_PacketBuffer *pb, struct CEntry *ce)
Definition: secure.c:149
long rpc2_BindsInQueue
Definition: rpc2.private.h:630
void rpc2_UpdateRTT(RPC2_PacketBuffer *pb, struct CEntry *ceaddr)
Definition: rpc2b.c:1018
void rpc2_splitaddrinfo(RPC2_HostIdent *Host, RPC2_PortIdent *Port, const struct RPC2_addrinfo *ai)
Definition: rpc2_addrinfo.c:614
void rpc2_PrintFilter()
void rpc2_ExpireEvents()
Definition: sl.c:356
long Retry_N
Definition: globals.c:66
void rpc2_SetConnError()
struct rpc2_LinkEntry * rpc2_PBHoldList
Definition: rpc2.private.h:441
unsigned int rpc2_TVTOTS(const struct timeval *tv)
struct CEntry * rpc2_AllocConn()
#define OBJ_HENTRY
Definition: rpc2.private.h:92
struct rpc2_LinkEntry * rpc2_PBList
Definition: globals.c:79
void rpc2_FreeHost(struct HEntry **whichHost)
Definition: host.c:156
void rpc2_FreeSubsys(struct SubsysEntry **whichSubsys)
Definition: lists.c:265
long rpc2_AllocMgrps
Definition: rpc2.private.h:631
void rpc2_ReapDeadConns(void)
Definition: conn.c:299
@ f
Definition: rvm_private.h:416
long rc
Definition: sftp6.c:107
PeerInfo RemoteHandle
Definition: sftp6.c:136
Definition: cbuf.h:40
Definition: rpc2.private.h:148
struct SL_Entry * MySl
Definition: rpc2.private.h:186
struct HEntry * HostInfo
Definition: rpc2.private.h:173
struct SE_Definition * SEProcs
Definition: rpc2.private.h:177
struct MEntry * Mgrp
Definition: rpc2.private.h:179
unsigned int RequestTime
Definition: rpc2.private.h:193
unsigned long reqsize
Definition: rpc2.private.h:190
char * PrivatePtr
Definition: rpc2.private.h:180
RPC2_Integer Color
Definition: rpc2.private.h:182
struct CEntry * Qname
Definition: rpc2.private.h:152
struct timeval TimeBomb
Definition: rpc2.private.h:194
long State
Definition: rpc2.private.h:157
RPC2_Handle UniqueCID
Definition: rpc2.private.h:158
RPC2_Integer PeerUnique
Definition: rpc2.private.h:171
RPC2_EncryptionKey SessionKey
Definition: rpc2.private.h:166
struct timeval SaveResponse
Definition: rpc2.private.h:196
RPC2_Integer SecurityLevel
Definition: rpc2.private.h:165
RPC2_Integer SubsysId
Definition: rpc2.private.h:160
RPC2_RequestFilter Filter
Definition: rpc2.private.h:198
long sebroken
Definition: rpc2.private.h:178
long MagicNumber
Definition: rpc2.private.h:151
RPC2_Unsigned NextSeqNumber
Definition: rpc2.private.h:159
struct dllist_head connlist
Definition: rpc2.private.h:150
char * SideEffectPtr
Definition: rpc2.private.h:181
RPC2_PacketBuffer * HeldPacket
Definition: rpc2.private.h:187
RPC2_Integer Flags
Definition: rpc2.private.h:161
struct security_association sa
Definition: rpc2.private.h:202
struct dllist_head Chain
Definition: rpc2.private.h:154
time_t LastRef
Definition: rpc2.private.h:162
RPC2_Integer EncryptionType
Definition: rpc2.private.h:167
RPC2_Handle PeerHandle
Definition: rpc2.private.h:170
unsigned int TimeStampEcho
Definition: rpc2.private.h:192
Definition: rpc2.private.h:322
uint32_t BWhi_out
Definition: rpc2.private.h:345
unsigned long RTTvar
Definition: rpc2.private.h:340
RPC2_NetLogEntry SE_Log[RPC2_MAXLOGLENGTH]
Definition: rpc2.private.h:334
int RefCount
Definition: rpc2.private.h:326
uint32_t BWlo_out
Definition: rpc2.private.h:345
struct RPC2_addrinfo * Addr
Definition: rpc2.private.h:327
struct timeval LastWord
Definition: rpc2.private.h:328
unsigned RPC2_NumEntries
Definition: rpc2.private.h:329
struct rpc2_LinkEntry LE
Definition: rpc2.private.h:323
uint32_t BWlo_in
Definition: rpc2.private.h:344
RPC2_NetLogEntry RPC2_Log[RPC2_MAXLOGLENGTH]
Definition: rpc2.private.h:330
struct HEntry * HLink
Definition: rpc2.private.h:325
uint32_t BWhi_in
Definition: rpc2.private.h:344
unsigned long RTT
Definition: rpc2.private.h:339
unsigned SE_NumEntries
Definition: rpc2.private.h:333
Definition: rpc2.private.h:355
RPC2_Unsigned FakeBody_ClientIdent_SeqBody
Definition: rpc2.private.h:362
RPC2_Integer Spare3
Definition: rpc2.private.h:375
char usedtobehostport[92]
Definition: rpc2.private.h:370
RPC2_Integer FakeBody_EncryptionType
Definition: rpc2.private.h:359
RPC2_Integer Uniquefier
Definition: rpc2.private.h:372
RPC2_Integer XRandom
Definition: rpc2.private.h:369
RPC2_Integer FakeBody_SecurityLevel
Definition: rpc2.private.h:358
RPC2_Integer FakeBody_AuthenticationType
Definition: rpc2.private.h:360
RPC2_Unsigned RPC2SEC_version
Definition: rpc2.private.h:373
RPC2_Byte Text[4]
Definition: rpc2.private.h:377
RPC2_Unsigned FakeBody_ClientIdent_SeqLen
Definition: rpc2.private.h:361
RPC2_Byte Version[96]
Definition: rpc2.private.h:376
RPC2_Integer FakeBody_SideEffectType
Definition: rpc2.private.h:357
RPC2_Unsigned Preferred_Keysize
Definition: rpc2.private.h:374
Definition: rpc2.private.h:385
RPC2_Integer Spare2
Definition: rpc2.private.h:389
RPC2_Integer YRandom
Definition: rpc2.private.h:387
RPC2_Integer Spare1
Definition: rpc2.private.h:388
RPC2_Integer Spare3
Definition: rpc2.private.h:390
RPC2_Integer XRandomPlusOne
Definition: rpc2.private.h:386
Definition: rpc2.private.h:394
RPC2_Integer Spare3
Definition: rpc2.private.h:398
RPC2_Integer Spare1
Definition: rpc2.private.h:396
RPC2_Integer Spare2
Definition: rpc2.private.h:397
RPC2_Integer YRandomPlusOne
Definition: rpc2.private.h:395
Definition: rpc2.private.h:402
RPC2_Integer InitialSeqNumber
Definition: rpc2.private.h:404
RPC2_EncryptionKey SessionKey
Definition: rpc2.private.h:405
RPC2_Integer Spare2
Definition: rpc2.private.h:408
RPC2_Integer XRandomPlusTwo
Definition: rpc2.private.h:406
RPC2_Integer Spare1
Definition: rpc2.private.h:407
Definition: rpc2.private.h:412
RPC2_Integer Spare2
Definition: rpc2.private.h:417
RPC2_Integer InitialSeqNumber
Definition: rpc2.private.h:414
RPC2_Handle MgroupHandle
Definition: rpc2.private.h:413
RPC2_Integer Spare1
Definition: rpc2.private.h:416
RPC2_Integer Spare3
Definition: rpc2.private.h:418
RPC2_EncryptionKey SessionKey
Definition: rpc2.private.h:415
Definition: rpc2.private.h:206
struct SE_Definition * SEProcs
Definition: rpc2.private.h:216
union MEntry::@51 me_conns
RPC2_Integer State
Definition: rpc2.private.h:210
long mec_maxlisteners
Definition: rpc2.private.h:225
char * SideEffectPtr
Definition: rpc2.private.h:217
struct RPC2_addrinfo * ClientAddr
Definition: rpc2.private.h:211
struct MEntry::@51::@52 me_client
long mec_howmanylisteners
Definition: rpc2.private.h:224
struct CEntry ** mec_listeners
Definition: rpc2.private.h:223
struct CEntry * mes_conn
Definition: rpc2.private.h:227
struct rpc2_LinkEntry LE
Definition: rpc2.private.h:207
RPC2_Integer NextSeqNumber
Definition: rpc2.private.h:213
RPC2_Handle MgroupID
Definition: rpc2.private.h:212
Definition: rpc2.h:348
Definition: rpc2.h:635
Definition: rpc2.h:654
Definition: rpc2.h:406
Definition: rpc2.h:358
Definition: rpc2.h:508
Definition: rpc2_addrinfo.h:28
Definition: se.h:45
Definition: rpc2.private.h:288
void * data
Definition: rpc2.private.h:301
RPC2_RequestFilter Filter
Definition: rpc2.private.h:302
enum SL_Type Type
Definition: rpc2.private.h:291
RPC2_Handle Conn
Definition: rpc2.private.h:300
struct timeval RInterval
Definition: rpc2.private.h:304
struct TM_Elem TElem
Definition: rpc2.private.h:294
enum RetVal ReturnCode
Definition: rpc2.private.h:297
int RetryIndex
Definition: rpc2.private.h:303
struct rpc2_LinkEntry LE
Definition: rpc2.private.h:289
Definition: rpc2.private.h:308
struct rpc2_LinkEntry LE
Definition: rpc2.private.h:309
long Id
Definition: rpc2.private.h:310
Definition: timer.h:47
Definition: dllist.h:30
Definition: codamergedump.cc:54
Definition: resutil.h:34
Definition: rpc2.private.h:70
u_int8_t u6_addr[16]
Definition: rpc2.private.h:71
Definition: lwp.private_pt.h:33
Definition: rpc2.h:397
Definition: secure.h:100
Definition: rpc2.private.h:73
u_int16_t sin6_family
Definition: rpc2.private.h:74
struct in6_addr sin6_addr
Definition: rpc2.private.h:77
u_int16_t sin6_port
Definition: rpc2.private.h:75
u_int32_t sin6_flowinfo
Definition: rpc2.private.h:76
Definition: rpc2.private.h:63
struct sockaddr __ss_sa
Definition: rpc2.private.h:64
char _ss_padding[128 - sizeof(struct sockaddr)]
Definition: rpc2.private.h:65