mon.c (36e8e668d3e6a61848a8921ddeb663b417299fa5) mon.c (03eb1dcbb799304b58730f4dba65812f49fb305e)
1/*
2 * linux/fs/lockd/mon.c
3 *
4 * The kernel statd client.
5 *
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
8

--- 179 unchanged lines hidden (view full) ---

188
189/*
190 * XDR functions for NSM.
191 *
192 * See http://www.opengroup.org/ for details on the Network
193 * Status Monitor wire protocol.
194 */
195
1/*
2 * linux/fs/lockd/mon.c
3 *
4 * The kernel statd client.
5 *
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
8

--- 179 unchanged lines hidden (view full) ---

188
189/*
190 * XDR functions for NSM.
191 *
192 * See http://www.opengroup.org/ for details on the Network
193 * Status Monitor wire protocol.
194 */
195
196static __be32 *xdr_encode_nsm_string(__be32 *p, char *string)
196static int encode_nsm_string(struct xdr_stream *xdr, const char *string)
197{
197{
198 size_t len = strlen(string);
198 const u32 len = strlen(string);
199 __be32 *p;
199
200
200 if (len > SM_MAXSTRLEN)
201 len = SM_MAXSTRLEN;
202 return xdr_encode_opaque(p, string, len);
201 if (unlikely(len > SM_MAXSTRLEN))
202 return -EIO;
203 p = xdr_reserve_space(xdr, sizeof(u32) + len);
204 if (unlikely(p == NULL))
205 return -EIO;
206 xdr_encode_opaque(p, string, len);
207 return 0;
203}
204
205/*
206 * "mon_name" specifies the host to be monitored.
207 */
208}
209
210/*
211 * "mon_name" specifies the host to be monitored.
212 */
208static __be32 *xdr_encode_mon_name(__be32 *p, struct nsm_args *argp)
213static int encode_mon_name(struct xdr_stream *xdr, const struct nsm_args *argp)
209{
214{
210 return xdr_encode_nsm_string(p, argp->mon_name);
215 return encode_nsm_string(xdr, argp->mon_name);
211}
212
213/*
214 * The "my_id" argument specifies the hostname and RPC procedure
215 * to be called when the status manager receives notification
216 * (via the NLMPROC_SM_NOTIFY call) that the state of host "mon_name"
217 * has changed.
218 */
216}
217
218/*
219 * The "my_id" argument specifies the hostname and RPC procedure
220 * to be called when the status manager receives notification
221 * (via the NLMPROC_SM_NOTIFY call) that the state of host "mon_name"
222 * has changed.
223 */
219static __be32 *xdr_encode_my_id(__be32 *p, struct nsm_args *argp)
224static int encode_my_id(struct xdr_stream *xdr, const struct nsm_args *argp)
220{
225{
221 p = xdr_encode_nsm_string(p, utsname()->nodename);
222 if (!p)
223 return ERR_PTR(-EIO);
226 int status;
227 __be32 *p;
224
228
229 status = encode_nsm_string(xdr, utsname()->nodename);
230 if (unlikely(status != 0))
231 return status;
232 p = xdr_reserve_space(xdr, 3 * sizeof(u32));
233 if (unlikely(p == NULL))
234 return -EIO;
225 *p++ = htonl(argp->prog);
226 *p++ = htonl(argp->vers);
227 *p++ = htonl(argp->proc);
235 *p++ = htonl(argp->prog);
236 *p++ = htonl(argp->vers);
237 *p++ = htonl(argp->proc);
228
229 return p;
238 return 0;
230}
231
232/*
233 * The "mon_id" argument specifies the non-private arguments
234 * of an NSMPROC_MON or NSMPROC_UNMON call.
235 */
239}
240
241/*
242 * The "mon_id" argument specifies the non-private arguments
243 * of an NSMPROC_MON or NSMPROC_UNMON call.
244 */
236static __be32 *xdr_encode_mon_id(__be32 *p, struct nsm_args *argp)
245static int encode_mon_id(struct xdr_stream *xdr, const struct nsm_args *argp)
237{
246{
238 p = xdr_encode_mon_name(p, argp);
239 if (!p)
240 return ERR_PTR(-EIO);
247 int status;
241
248
242 return xdr_encode_my_id(p, argp);
249 status = encode_mon_name(xdr, argp);
250 if (unlikely(status != 0))
251 return status;
252 return encode_my_id(xdr, argp);
243}
244
245/*
246 * The "priv" argument may contain private information required
247 * by the NSMPROC_MON call. This information will be supplied in the
248 * NLMPROC_SM_NOTIFY call.
249 *
250 * Linux provides the raw IP address of the monitored host,
251 * left in network byte order.
252 */
253}
254
255/*
256 * The "priv" argument may contain private information required
257 * by the NSMPROC_MON call. This information will be supplied in the
258 * NLMPROC_SM_NOTIFY call.
259 *
260 * Linux provides the raw IP address of the monitored host,
261 * left in network byte order.
262 */
253static __be32 *xdr_encode_priv(__be32 *p, struct nsm_args *argp)
263static int encode_priv(struct xdr_stream *xdr, const struct nsm_args *argp)
254{
264{
265 __be32 *p;
266
267 p = xdr_reserve_space(xdr, SM_PRIV_SIZE);
268 if (unlikely(p == NULL))
269 return -EIO;
255 *p++ = argp->addr;
256 *p++ = 0;
257 *p++ = 0;
258 *p++ = 0;
270 *p++ = argp->addr;
271 *p++ = 0;
272 *p++ = 0;
273 *p++ = 0;
259
260 return p;
274 return 0;
261}
262
275}
276
263static int
264xdr_encode_mon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
277static int xdr_enc_mon(struct rpc_rqst *req, __be32 *p,
278 const struct nsm_args *argp)
265{
279{
266 p = xdr_encode_mon_id(p, argp);
267 if (IS_ERR(p))
268 return PTR_ERR(p);
280 struct xdr_stream xdr;
281 int status;
269
282
270 p = xdr_encode_priv(p, argp);
271 if (IS_ERR(p))
272 return PTR_ERR(p);
273
274 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
275 return 0;
283 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
284 status = encode_mon_id(&xdr, argp);
285 if (unlikely(status))
286 return status;
287 return encode_priv(&xdr, argp);
276}
277
288}
289
278static int
279xdr_encode_unmon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
290static int xdr_enc_unmon(struct rpc_rqst *req, __be32 *p,
291 const struct nsm_args *argp)
280{
292{
281 p = xdr_encode_mon_id(p, argp);
282 if (IS_ERR(p))
283 return PTR_ERR(p);
284 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
285 return 0;
293 struct xdr_stream xdr;
294
295 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
296 return encode_mon_id(&xdr, argp);
286}
287
297}
298
288static int
289xdr_decode_stat_res(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res *resp)
299static int xdr_dec_stat_res(struct rpc_rqst *rqstp, __be32 *p,
300 struct nsm_res *resp)
290{
301{
302 struct xdr_stream xdr;
303
304 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
305 p = xdr_inline_decode(&xdr, 2 * sizeof(u32));
306 if (unlikely(p == NULL))
307 return -EIO;
291 resp->status = ntohl(*p++);
308 resp->status = ntohl(*p++);
292 resp->state = ntohl(*p++);
293 dprintk("nsm: xdr_decode_stat_res status %d state %d\n",
309 resp->state = ntohl(*p);
310
311 dprintk("lockd: xdr_dec_stat_res status %d state %d\n",
294 resp->status, resp->state);
295 return 0;
296}
297
312 resp->status, resp->state);
313 return 0;
314}
315
298static int
299xdr_decode_stat(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res *resp)
316static int xdr_dec_stat(struct rpc_rqst *rqstp, __be32 *p,
317 struct nsm_res *resp)
300{
318{
301 resp->state = ntohl(*p++);
319 struct xdr_stream xdr;
320
321 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
322 p = xdr_inline_decode(&xdr, sizeof(u32));
323 if (unlikely(p == NULL))
324 return -EIO;
325 resp->state = ntohl(*p);
326
327 dprintk("lockd: xdr_dec_stat state %d\n", resp->state);
302 return 0;
303}
304
305#define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
306#define SM_my_id_sz (SM_my_name_sz+3)
307#define SM_mon_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
308#define SM_mon_id_sz (SM_mon_name_sz+SM_my_id_sz)
309#define SM_priv_sz (XDR_QUADLEN(SM_PRIV_SIZE))
310#define SM_mon_sz (SM_mon_id_sz+SM_priv_sz)
311#define SM_monres_sz 2
312#define SM_unmonres_sz 1
313
314static struct rpc_procinfo nsm_procedures[] = {
315[NSMPROC_MON] = {
316 .p_proc = NSMPROC_MON,
328 return 0;
329}
330
331#define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
332#define SM_my_id_sz (SM_my_name_sz+3)
333#define SM_mon_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
334#define SM_mon_id_sz (SM_mon_name_sz+SM_my_id_sz)
335#define SM_priv_sz (XDR_QUADLEN(SM_PRIV_SIZE))
336#define SM_mon_sz (SM_mon_id_sz+SM_priv_sz)
337#define SM_monres_sz 2
338#define SM_unmonres_sz 1
339
340static struct rpc_procinfo nsm_procedures[] = {
341[NSMPROC_MON] = {
342 .p_proc = NSMPROC_MON,
317 .p_encode = (kxdrproc_t) xdr_encode_mon,
318 .p_decode = (kxdrproc_t) xdr_decode_stat_res,
343 .p_encode = (kxdrproc_t)xdr_enc_mon,
344 .p_decode = (kxdrproc_t)xdr_dec_stat_res,
319 .p_arglen = SM_mon_sz,
320 .p_replen = SM_monres_sz,
321 .p_statidx = NSMPROC_MON,
322 .p_name = "MONITOR",
323 },
324[NSMPROC_UNMON] = {
325 .p_proc = NSMPROC_UNMON,
345 .p_arglen = SM_mon_sz,
346 .p_replen = SM_monres_sz,
347 .p_statidx = NSMPROC_MON,
348 .p_name = "MONITOR",
349 },
350[NSMPROC_UNMON] = {
351 .p_proc = NSMPROC_UNMON,
326 .p_encode = (kxdrproc_t) xdr_encode_unmon,
327 .p_decode = (kxdrproc_t) xdr_decode_stat,
352 .p_encode = (kxdrproc_t)xdr_enc_unmon,
353 .p_decode = (kxdrproc_t)xdr_dec_stat,
328 .p_arglen = SM_mon_id_sz,
329 .p_replen = SM_unmonres_sz,
330 .p_statidx = NSMPROC_UNMON,
331 .p_name = "UNMONITOR",
332 },
333};
334
335static struct rpc_version nsm_version1 = {

--- 18 unchanged lines hidden ---
354 .p_arglen = SM_mon_id_sz,
355 .p_replen = SM_unmonres_sz,
356 .p_statidx = NSMPROC_UNMON,
357 .p_name = "UNMONITOR",
358 },
359};
360
361static struct rpc_version nsm_version1 = {

--- 18 unchanged lines hidden ---