Branch data Line data Source code
1 : : // $Id: RPC.h 6219 2008-10-01 05:39:07Z vern $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #ifndef rpc_h
6 : : #define rpc_h
7 : :
8 : : #include "TCP.h"
9 : : #include "UDP.h"
10 : :
11 : : enum {
12 : : RPC_CALL = 0,
13 : : RPC_REPLY = 1,
14 : : };
15 : :
16 : : enum {
17 : : RPC_MSG_ACCEPTED = 0,
18 : : RPC_MSG_DENIED = 1,
19 : : };
20 : :
21 : : enum {
22 : : RPC_SUCCESS = 0,
23 : : RPC_PROG_UNAVAIL = 1,
24 : : RPC_PROG_MISMATCH = 2,
25 : : RPC_PROC_UNAVAIL = 3,
26 : : RPC_GARBAGE_ARGS = 4,
27 : : RPC_SYSTEM_ERR = 5,
28 : : };
29 : :
30 : : enum {
31 : : RPC_MISMATCH = 0,
32 : : RPC_AUTH_ERROR = 1,
33 : : };
34 : :
35 : : enum {
36 : : RPC_AUTH_BADCRED = 1,
37 : : RPC_AUTH_REJECTEDCRED = 2,
38 : : RPC_AUTH_BADVERF = 3,
39 : : RPC_AUTH_REJECTEDVERF = 4,
40 : : RPC_AUTH_TOOWEAK = 5,
41 : : };
42 : :
43 : : enum {
44 : : RPC_AUTH_NULL = 0,
45 : : RPC_AUTH_UNIX = 1,
46 : : RPC_AUTH_SHORT = 2,
47 : : RPC_AUTH_DES = 3,
48 : : };
49 : :
50 : : class RPC_CallInfo {
51 : : public:
52 : : RPC_CallInfo(uint32 xid, const u_char*& buf, int& n);
53 : : ~RPC_CallInfo();
54 : :
55 : 0 : void AddVal(Val* arg_v) { Unref(v); v = arg_v; }
56 : 0 : Val* RequestVal() const { return v; }
57 : 0 : Val* TakeRequestVal() { Val* rv = v; v = 0; return rv; }
58 : :
59 : : int CompareRexmit(const u_char* buf, int n) const;
60 : :
61 : 0 : uint32 Program() const { return prog; }
62 : 0 : uint32 Version() const { return vers; }
63 : 0 : uint32 Proc() const { return proc; }
64 : :
65 : 0 : double StartTime() const { return start_time; }
66 : 0 : int CallLen() const { return call_n; }
67 : 0 : int HeaderLen() const { return header_len; }
68 : :
69 : : uint32 XID() const { return xid; }
70 : :
71 : 0 : void SetValidCall() { valid_call = true; }
72 : 0 : bool IsValidCall() const { return valid_call; }
73 : :
74 : : protected:
75 : : uint32 xid, rpc_version, prog, vers, proc;
76 : : uint32 cred_flavor, verf_flavor;
77 : : u_char* call_buf; // copy of original call buffer
78 : : double start_time;
79 : : int call_n; // size of call buf
80 : : int header_len; // size of data before the arguments
81 : : bool valid_call; // whether call was well-formed
82 : :
83 : : Val* v; // single (perhaps compound) value corresponding to call
84 : : };
85 : :
86 [ # # ][ # # ]: 0 : declare(PDict,RPC_CallInfo);
87 : :
88 : : class RPC_Interpreter {
89 : : public:
90 : : RPC_Interpreter(Analyzer* analyzer);
91 : : virtual ~RPC_Interpreter();
92 : :
93 : : // Delivers the given RPC. Returns true if "len" bytes were
94 : : // enough, false otherwise. "is_orig" is true if the data is
95 : : // from the originator of the connection.
96 : : int DeliverRPC(const u_char* data, int len, int is_orig);
97 : :
98 : : void Timeout();
99 : :
100 : : protected:
101 : : virtual int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) = 0;
102 : : virtual int RPC_BuildReply(const RPC_CallInfo* c, int success,
103 : : const u_char*& buf, int& n,
104 : : EventHandlerPtr& event, Val*& reply) = 0;
105 : :
106 : : virtual void Event(EventHandlerPtr f, Val* request, int status, Val* reply) = 0;
107 : :
108 : : void RPC_Event(RPC_CallInfo* c, int status, int reply_len);
109 : :
110 : : void Weird(const char* name);
111 : :
112 : : PDict(RPC_CallInfo) calls;
113 : : Analyzer* analyzer;
114 : : };
115 : :
116 : : typedef enum {
117 : : RPC_RECORD_MARKER, // building up the stream record marker
118 : : RPC_MESSAGE_BUFFER, // building up the message in the buffer
119 : : RPC_COMPLETE // message fully built
120 : : } TCP_RPC_state;
121 : :
122 : : class Contents_RPC : public TCP_SupportAnalyzer {
123 : : public:
124 : : Contents_RPC(Connection* conn, bool orig, RPC_Interpreter* interp);
125 : : virtual ~Contents_RPC();
126 : :
127 : 0 : TCP_RPC_state State() const { return state; }
128 : :
129 : : protected:
130 : : virtual void Init();
131 : : virtual void DeliverStream(int len, const u_char* data, bool orig);
132 : : virtual void Undelivered(int seq, int len, bool orig);
133 : :
134 : : virtual void InitBuffer();
135 : :
136 : : RPC_Interpreter* interp;
137 : :
138 : : u_char* msg_buf;
139 : : int buf_n; // number of bytes in msg_buf
140 : : int buf_len; // size off msg_buf
141 : : int last_frag; // if this buffer corresponds to the last "fragment"
142 : : bool resync;
143 : :
144 : : TCP_RPC_state state;
145 : : };
146 : :
147 : : class RPC_Analyzer : public TCP_ApplicationAnalyzer {
148 : : public:
149 : : RPC_Analyzer(AnalyzerTag::Tag tag, Connection* conn,
150 : : RPC_Interpreter* arg_interp);
151 : : virtual ~RPC_Analyzer();
152 : :
153 : : virtual void Done();
154 : :
155 : : protected:
156 : : virtual void DeliverPacket(int len, const u_char* data, bool orig,
157 : : int seq, const IP_Hdr* ip, int caplen);
158 : :
159 : : void ExpireTimer(double t);
160 : :
161 : : RPC_Interpreter* interp;
162 : :
163 : : Contents_RPC* orig_rpc;
164 : : Contents_RPC* resp_rpc;
165 : : };
166 : :
167 : : #include "rpc_pac.h"
168 : :
169 : : class RPC_UDP_Analyzer_binpac : public Analyzer {
170 : : public:
171 : : RPC_UDP_Analyzer_binpac(Connection* conn);
172 : : virtual ~RPC_UDP_Analyzer_binpac();
173 : :
174 : : virtual void Done();
175 : : virtual void DeliverPacket(int len, const u_char* data, bool orig,
176 : : int seq, const IP_Hdr* ip, int caplen);
177 : :
178 : 0 : static Analyzer* InstantiateAnalyzer(Connection* conn)
179 : 0 : { return new RPC_UDP_Analyzer_binpac(conn); }
180 : :
181 : 1 : static bool Available()
182 [ + - ][ - + ]: 1 : { return pm_request || rpc_call; }
183 : :
184 : : protected:
185 : : friend class AnalyzerTimer;
186 : : void ExpireTimer(double t);
187 : :
188 : : binpac::SunRPC::RPC_Conn* interp;
189 : : };
190 : :
191 : : #endif
|