Whamcloud - gitweb
branch: b_new_cmd
[fs/lustre-release.git] / lustre / include / lustre_sec.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2004-2006 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef _LUSTRE_SEC_H_
23 #define _LUSTRE_SEC_H_
24
25 /*
26  * to avoid include
27  */
28 struct obd_import;
29 struct ptlrpc_request;
30 struct ptlrpc_reply_state;
31 struct ptlrpc_bulk_desc;
32 struct brw_page;
33
34 /*
35  * forward declaration
36  */
37 struct ptlrpc_sec_policy;
38 struct ptlrpc_sec_cops;
39 struct ptlrpc_sec_sops;
40 struct ptlrpc_sec;
41 struct ptlrpc_svc_ctx;
42 struct ptlrpc_cli_ctx;
43 struct ptlrpc_ctx_ops;
44
45 /*
46  * flavor constants
47  */
48 enum sptlrpc_policies {
49         SPTLRPC_POLICY_NULL             = 0,
50         SPTLRPC_POLICY_PLAIN            = 1,
51         SPTLRPC_POLICY_GSS              = 2,
52         SPTLRPC_POLICY_MAX,
53 };
54
55 enum sptlrpc_subpolicy_null {
56         SPTLRPC_SUBPOLICY_NULL          = 0,
57         SPTLRPC_SUBPOLICY_NULL_MAX,
58 };
59
60 enum sptlrpc_subpolicy_plain {
61         SPTLRPC_SUBPOLICY_PLAIN         = 0,
62         SPTLRPC_SUBPOLICY_PLAIN_MAX,
63 };
64
65 enum sptlrpc_subpolicy_gss {
66         SPTLRPC_SUBPOLICY_GSS_NONE      = 0,
67         SPTLRPC_SUBPOLICY_GSS_KRB5      = 1,
68         SPTLRPC_SUBPOLICY_GSS_MAX,
69 };
70
71 enum sptlrpc_service_type {
72         SPTLRPC_SVC_NONE                = 0,    /* no security */
73         SPTLRPC_SVC_AUTH                = 1,    /* authentication */
74         SPTLRPC_SVC_PRIV                = 2,    /* privacy */
75         SPTLRPC_SVC_MAX,
76 };
77
78 /*
79  * flavor compose/extract
80  */
81
82 typedef __u32 ptlrpc_sec_flavor_t;
83
84 /*
85  *  8b (reserved) | 8b (flags) | 6b (policy) | 6b (subpolicy) | 4b (svc)
86  */
87 #define SEC_FLAVOR_FLAGS_OFFSET         (16)
88 #define SEC_FLAVOR_POLICY_OFFSET        (10)
89 #define SEC_FLAVOR_SUBPOLICY_OFFSET     (4)
90 #define SEC_FLAVOR_SVC_OFFSET           (0)
91
92 #define SEC_MAKE_RPC_FLAVOR(policy, subpolicy, svc)                     \
93         (((__u32)(policy) << SEC_FLAVOR_POLICY_OFFSET) |                \
94          ((__u32)(subpolicy) << SEC_FLAVOR_SUBPOLICY_OFFSET) |          \
95          ((__u32)(svc) << SEC_FLAVOR_SVC_OFFSET))
96
97 #define SEC_MAKE_RPC_SUBFLAVOR(subpolicy, svc)                          \
98         (((__u32)(subpolicy) << SEC_FLAVOR_SUBPOLICY_OFFSET) |          \
99          ((__u32)(svc) << SEC_FLAVOR_SVC_OFFSET))
100
101 #define SEC_FLAVOR_POLICY(flavor)                                       \
102         ((((__u32)(flavor)) >> SEC_FLAVOR_POLICY_OFFSET) & 0x3F)
103 #define SEC_FLAVOR_SUBPOLICY(flavor)                                    \
104         ((((__u32)(flavor)) >> SEC_FLAVOR_SUBPOLICY_OFFSET) & 0x3F)
105 #define SEC_FLAVOR_SVC(flavor)                                          \
106         ((((__u32)(flavor)) >> SEC_FLAVOR_SVC_OFFSET) & 0xF)
107 #define SEC_FLAVOR_SUB(flavor)                                          \
108         ((((__u32)(flavor)) >> SEC_FLAVOR_SVC_OFFSET) & 0x3FF)
109
110 #define SEC_FLAVOR_RPC(f)                                               \
111         (((__u32) f) & ((1 << SEC_FLAVOR_FLAGS_OFFSET) - 1))
112
113 /*
114  * general gss flavors
115  */
116 #define SPTLRPC_FLVR_GSS_NONE                                   \
117         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_GSS,                 \
118                             SPTLRPC_SUBPOLICY_GSS_NONE,         \
119                             SPTLRPC_SVC_NONE)
120 #define SPTLRPC_FLVR_GSS_AUTH                                   \
121         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_GSS,                 \
122                             SPTLRPC_SUBPOLICY_GSS_NONE,         \
123                             SPTLRPC_SVC_AUTH)
124 #define SPTLRPC_FLVR_GSS_PRIV                                   \
125         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_GSS,                 \
126                             SPTLRPC_SUBPOLICY_GSS_NONE,         \
127                             SPTLRPC_SVC_PRIV)
128
129 /*
130  * gss subflavors
131  */
132 #define SPTLRPC_SUBFLVR_KRB5                                    \
133         SEC_MAKE_RPC_SUBFLAVOR(SPTLRPC_SUBPOLICY_GSS_KRB5,      \
134                                SPTLRPC_SVC_NONE)
135 #define SPTLRPC_SUBFLVR_KRB5I                                   \
136         SEC_MAKE_RPC_SUBFLAVOR(SPTLRPC_SUBPOLICY_GSS_KRB5,      \
137                                SPTLRPC_SVC_AUTH)
138 #define SPTLRPC_SUBFLVR_KRB5P                                   \
139         SEC_MAKE_RPC_SUBFLAVOR(SPTLRPC_SUBPOLICY_GSS_KRB5,      \
140                                SPTLRPC_SVC_PRIV)
141
142 /*
143  * "end user" flavors
144  */
145 #define SPTLRPC_FLVR_NULL                                       \
146         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_NULL,                \
147                             SPTLRPC_SUBPOLICY_NULL,             \
148                             SPTLRPC_SVC_NONE)
149 #define SPTLRPC_FLVR_PLAIN                                      \
150         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_PLAIN,               \
151                             SPTLRPC_SUBPOLICY_PLAIN,            \
152                             SPTLRPC_SVC_NONE)
153 #define SPTLRPC_FLVR_KRB5                                       \
154         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_GSS,                 \
155                             SPTLRPC_SUBPOLICY_GSS_KRB5,         \
156                             SPTLRPC_SVC_NONE)
157 #define SPTLRPC_FLVR_KRB5I                                      \
158         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_GSS,                 \
159                             SPTLRPC_SUBPOLICY_GSS_KRB5,         \
160                             SPTLRPC_SVC_AUTH)
161 #define SPTLRPC_FLVR_KRB5P                                      \
162         SEC_MAKE_RPC_FLAVOR(SPTLRPC_POLICY_GSS,                 \
163                             SPTLRPC_SUBPOLICY_GSS_KRB5,         \
164                             SPTLRPC_SVC_PRIV)
165
166 #define SPTLRPC_FLVR_INVALID            (-1)
167
168 #define SPTLRPC_FLVR_DEFAULT            SPTLRPC_FLVR_NULL
169
170 /*
171  * flavor flags (maximum 8 flags)
172  */
173 #define SEC_FLAVOR_FL_BULK              (1 << (0 + SEC_FLAVOR_FLAGS_OFFSET))
174 #define SEC_FLAVOR_FL_USER              (1 << (1 + SEC_FLAVOR_FLAGS_OFFSET))
175
176 #define SEC_FLAVOR_HAS_BULK(flavor)             \
177         (((flavor) & SEC_FLAVOR_FL_BULK) != 0)
178 #define SEC_FLAVOR_HAS_USER(flavor)             \
179         (((flavor) & SEC_FLAVOR_FL_USER) != 0)
180
181
182 struct sec_flavor_config {
183         __u32   sfc_rpc_flavor; /* main rpc flavor */
184         __u32   sfc_bulk_priv;  /* bulk encryption algorithm */
185         __u32   sfc_bulk_csum;  /* bulk checksum algorithm */
186         __u32   sfc_flags;      /* extra flags */
187 };
188
189 enum lustre_part {
190         LUSTRE_CLI      = 0,
191         LUSTRE_MDT,
192         LUSTRE_OST,
193         LUSTRE_MGC,
194         LUSTRE_MGS,
195 };
196
197 /* The maximum length of security payload. 1024 is enough for Kerberos 5,
198  * and should be enough for other future mechanisms but not sure.
199  * Only used by pre-allocated request/reply pool.
200  */
201 #define SPTLRPC_MAX_PAYLOAD     (1024)
202
203
204 struct vfs_cred {
205         uint64_t        vc_pag;
206         uint32_t        vc_uid;
207         uint32_t        vc_gid;
208 };
209
210 struct ptlrpc_ctx_ops {
211         int     (*match)       (struct ptlrpc_cli_ctx *ctx,
212                                 struct vfs_cred *vcred);
213         int     (*refresh)     (struct ptlrpc_cli_ctx *ctx);
214         int     (*display)     (struct ptlrpc_cli_ctx *ctx,
215                                 char *buf, int bufsize);
216         /*
217          * rpc data transform
218          */
219         int     (*sign)        (struct ptlrpc_cli_ctx *ctx,
220                                 struct ptlrpc_request *req);
221         int     (*verify)      (struct ptlrpc_cli_ctx *ctx,
222                                 struct ptlrpc_request *req);
223         int     (*seal)        (struct ptlrpc_cli_ctx *ctx,
224                                 struct ptlrpc_request *req);
225         int     (*unseal)      (struct ptlrpc_cli_ctx *ctx,
226                                 struct ptlrpc_request *req);
227         /*
228          * bulk transform
229          */
230         int     (*wrap_bulk)   (struct ptlrpc_cli_ctx *ctx,
231                                 struct ptlrpc_request *req,
232                                 struct ptlrpc_bulk_desc *desc);
233         int     (*unwrap_bulk) (struct ptlrpc_cli_ctx *ctx,
234                                 struct ptlrpc_request *req,
235                                 struct ptlrpc_bulk_desc *desc);
236 };
237
238 #define PTLRPC_CTX_UPTODATE_BIT        (0)  /* uptodate */
239 #define PTLRPC_CTX_DEAD_BIT            (1)  /* mark expired gracefully */
240 #define PTLRPC_CTX_ERROR_BIT           (2)  /* fatal error (refresh, etc.) */
241 #define PTLRPC_CTX_HASHED_BIT          (8)  /* in hash table */
242 #define PTLRPC_CTX_ETERNAL_BIT         (9)  /* always valid */
243
244 #define PTLRPC_CTX_UPTODATE            (1 << PTLRPC_CTX_UPTODATE_BIT)
245 #define PTLRPC_CTX_DEAD                (1 << PTLRPC_CTX_DEAD_BIT)
246 #define PTLRPC_CTX_ERROR               (1 << PTLRPC_CTX_ERROR_BIT)
247 #define PTLRPC_CTX_HASHED              (1 << PTLRPC_CTX_HASHED_BIT)
248 #define PTLRPC_CTX_ETERNAL             (1 << PTLRPC_CTX_ETERNAL_BIT)
249
250 #define PTLRPC_CTX_STATUS_MASK         (PTLRPC_CTX_UPTODATE   |       \
251                                         PTLRPC_CTX_DEAD       |       \
252                                         PTLRPC_CTX_ERROR)
253
254 struct ptlrpc_cli_ctx {
255         struct hlist_node       cc_hash;       /* linked into hash table */
256         atomic_t                cc_refcount;
257         struct ptlrpc_sec      *cc_sec;
258         struct ptlrpc_ctx_ops  *cc_ops;
259         cfs_time_t              cc_expire;     /* in seconds */
260         unsigned long           cc_flags;
261         struct vfs_cred         cc_vcred;
262         spinlock_t              cc_lock;
263         struct list_head        cc_req_list;   /* waiting reqs linked here */
264 };
265
266 struct ptlrpc_sec_cops {
267         /*
268          * ptlrpc_sec constructor/destructor
269          */
270         struct ptlrpc_sec *     (*create_sec)  (struct obd_import *imp,
271                                                 struct ptlrpc_svc_ctx *ctx,
272                                                 __u32 flavor,
273                                                 unsigned long flags);
274         void                    (*destroy_sec) (struct ptlrpc_sec *sec);
275         /*
276          * search ctx for a certain user, if this function is missing,
277          * a generic function will be invoked by caller. implement this
278          * for any special need.
279          */
280         struct ptlrpc_cli_ctx * (*lookup_ctx)  (struct ptlrpc_sec *sec,
281                                                 struct vfs_cred *vcred);
282         /*
283          * ptlrpc_cli_ctx constructor/destructor
284          */
285         struct ptlrpc_cli_ctx * (*create_ctx)  (struct ptlrpc_sec *sec,
286                                                 struct vfs_cred *vcred);
287         void                    (*destroy_ctx) (struct ptlrpc_sec *sec,
288                                                 struct ptlrpc_cli_ctx *ctx);
289         /* reverse service */
290         int                     (*install_rctx)(struct obd_import *imp,
291                                                 struct ptlrpc_sec *sec,
292                                                 struct ptlrpc_cli_ctx *ctx);
293         /*
294          * request/reply buffer manipulation
295          */
296         int                     (*alloc_reqbuf)(struct ptlrpc_sec *sec,
297                                                 struct ptlrpc_request *req,
298                                                 int lustre_msg_size);
299         void                    (*free_reqbuf) (struct ptlrpc_sec *sec,
300                                                 struct ptlrpc_request *req);
301         int                     (*alloc_repbuf)(struct ptlrpc_sec *sec,
302                                                 struct ptlrpc_request *req,
303                                                 int lustre_msg_size);
304         void                    (*free_repbuf) (struct ptlrpc_sec *sec,
305                                                 struct ptlrpc_request *req);
306         int                     (*enlarge_reqbuf)
307                                                (struct ptlrpc_sec *sec,
308                                                 struct ptlrpc_request *req,
309                                                 int segment, int newsize);
310 };
311
312 struct ptlrpc_sec_sops {
313         int                     (*accept)      (struct ptlrpc_request *req);
314         int                     (*authorize)   (struct ptlrpc_request *req);
315         /* buffer manipulation */
316         int                     (*alloc_rs)    (struct ptlrpc_request *req,
317                                                 int msgsize);
318         void                    (*free_rs)     (struct ptlrpc_reply_state *rs);
319         void                    (*free_ctx)    (struct ptlrpc_svc_ctx *ctx);
320         /* reverse credential */
321         int                     (*install_rctx)(struct obd_import *imp,
322                                                 struct ptlrpc_svc_ctx *ctx);
323         /* bulk transform */
324         int                     (*unwrap_bulk) (struct ptlrpc_request *req,
325                                                 struct ptlrpc_bulk_desc *desc);
326         int                     (*wrap_bulk)   (struct ptlrpc_request *req,
327                                                 struct ptlrpc_bulk_desc *desc);
328 };
329
330 struct ptlrpc_sec_policy {
331         struct module                  *sp_owner;
332         char                           *sp_name;
333         __u32                           sp_policy; /* policy number */
334         struct ptlrpc_sec_cops         *sp_cops;   /* client ops */
335         struct ptlrpc_sec_sops         *sp_sops;   /* server ops */
336 };
337
338 #define PTLRPC_SEC_FL_REVERSE           0x0001 /* reverse sec */
339 #define PTLRPC_SEC_FL_ROOTONLY          0x0002 /* treat everyone as root */
340 #define PTLRPC_SEC_FL_BULK              0x0004 /* intensive bulk i/o expected */
341 #define PTLRPC_SEC_FL_PAG               0x0008 /* PAG enabled */
342
343 struct ptlrpc_sec {
344         struct ptlrpc_sec_policy       *ps_policy;
345         atomic_t                        ps_refcount;
346         __u32                           ps_flavor;      /* rpc flavor */
347         unsigned long                   ps_flags;       /* PTLRPC_SEC_FL_XX */
348         struct obd_import              *ps_import;      /* owning import */
349         spinlock_t                      ps_lock;        /* protect ccache */
350         int                             ps_ccache_size; /* must be 2^n */
351         struct hlist_head              *ps_ccache;      /* ctx cache hash */
352         atomic_t                        ps_busy;        /* busy count */
353         cfs_time_t                      ps_gc_interval; /* in seconds */
354         cfs_time_t                      ps_gc_next;     /* in seconds */
355 };
356
357 struct ptlrpc_svc_ctx {
358         atomic_t                        sc_refcount;
359         struct ptlrpc_sec_policy       *sc_policy;
360 };
361
362 /*
363  * PAG
364  */
365 #ifdef HAVE_LINUX_PAG
366 #define CURRENT_PAG     ((uint64_t) current->pag)
367 #else
368 #define CURRENT_PAG     ((uint64_t) current->uid)
369 #endif
370
371 /*
372  * user identity descriptor
373  */
374 #define LUSTRE_MAX_GROUPS               (128)
375
376 struct ptlrpc_user_desc {
377         __u32           pud_uid;
378         __u32           pud_gid;
379         __u32           pud_fsuid;
380         __u32           pud_fsgid;
381         __u32           pud_cap;
382         __u32           pud_ngroups;
383         __u32           pud_groups[0];
384 };
385
386 /*
387  * bulk flavors
388  */
389 enum bulk_checksum_alg {
390         BULK_CSUM_ALG_NULL      = 0,
391         BULK_CSUM_ALG_CRC32,
392         BULK_CSUM_ALG_MD5,
393         BULK_CSUM_ALG_SHA1,
394         BULK_CSUM_ALG_SHA256,
395         BULK_CSUM_ALG_SHA384,
396         BULK_CSUM_ALG_SHA512,
397         BULK_CSUM_ALG_MAX
398 };
399
400 enum bulk_encrypt_alg {
401         BULK_PRIV_ALG_NULL      = 0,
402         BULK_PRIV_ALG_ARC4,
403         BULK_PRIV_ALG_MAX
404 };
405
406 struct ptlrpc_bulk_sec_desc {
407         __u32           bsd_version;
408         __u32           bsd_pad;
409         __u32           bsd_csum_alg;   /* checksum algorithm */
410         __u32           bsd_priv_alg;   /* encrypt algorithm */
411         __u8            bsd_iv[16];     /* encrypt iv */
412         __u8            bsd_csum[0];
413 };
414
415 const char * sptlrpc_bulk_csum_alg2name(__u32 csum_alg);
416 const char * sptlrpc_bulk_priv_alg2name(__u32 priv_alg);
417
418 /*
419  * lprocfs
420  */
421 struct proc_dir_entry;
422 extern struct proc_dir_entry *sptlrpc_proc_root;
423
424 /*
425  * round size up to next power of 2, for slab allocation.
426  * @size must be sane (can't overflow after round up)
427  */
428 static inline int size_roundup_power2(int size)
429 {
430         size--;
431         size |= size >> 1;
432         size |= size >> 2;
433         size |= size >> 4;
434         size |= size >> 8;
435         size |= size >> 16;
436         size++;
437         return size;
438 }
439
440 /*
441  * internal support libraries
442  */
443 void _sptlrpc_enlarge_msg_inplace(struct lustre_msg *msg,
444                                   int segment, int newsize);
445
446 /*
447  * security type
448  */
449 int sptlrpc_register_policy(struct ptlrpc_sec_policy *policy);
450 int sptlrpc_unregister_policy(struct ptlrpc_sec_policy *policy);
451
452 __u32 sptlrpc_name2flavor(const char *name);
453 char *sptlrpc_flavor2name(__u32 flavor);
454
455 static inline
456 struct ptlrpc_sec_policy *sptlrpc_policy_get(struct ptlrpc_sec_policy *policy)
457 {
458         __module_get(policy->sp_owner);
459         return policy;
460 }
461
462 static inline
463 void sptlrpc_policy_put(struct ptlrpc_sec_policy *policy)
464 {
465         module_put(policy->sp_owner);
466 }
467
468 /*
469  * client credential
470  */
471 struct ptlrpc_cli_ctx *sptlrpc_ctx_get(struct ptlrpc_cli_ctx *ctx);
472 void sptlrpc_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync);
473 void sptlrpc_ctx_expire(struct ptlrpc_cli_ctx *ctx);
474 void sptlrpc_ctx_replace(struct ptlrpc_sec *sec, struct ptlrpc_cli_ctx *new);
475 void sptlrpc_ctx_wakeup(struct ptlrpc_cli_ctx *ctx);
476 int sptlrpc_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
477
478 /*
479  * client wrap/buffers
480  */
481 int sptlrpc_cli_wrap_request(struct ptlrpc_request *req);
482 int sptlrpc_cli_unwrap_reply(struct ptlrpc_request *req);
483 int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize);
484 void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req);
485 int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize);
486 void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req);
487 int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
488                                int segment, int newsize);
489 void sptlrpc_request_out_callback(struct ptlrpc_request *req);
490
491 /*
492  * higher interface of import & request
493  */
494 int sptlrpc_import_get_sec(struct obd_import *imp, struct ptlrpc_svc_ctx *svc_ctx,
495                            __u32 flavor, unsigned long flags);
496 void sptlrpc_import_put_sec(struct obd_import *imp);
497 int sptlrpc_import_check_ctx(struct obd_import *imp);
498 void sptlrpc_import_flush_root_ctx(struct obd_import *imp);
499 void sptlrpc_import_flush_my_ctx(struct obd_import *imp);
500 void sptlrpc_import_flush_all_ctx(struct obd_import *imp);
501 int  sptlrpc_req_get_ctx(struct ptlrpc_request *req);
502 void sptlrpc_req_put_ctx(struct ptlrpc_request *req);
503 int  sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout);
504 void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode);
505
506 int sptlrpc_parse_flavor(enum lustre_part from, enum lustre_part to,
507                          char *str, struct sec_flavor_config *conf);
508 /* misc */
509 const char * sec2target_str(struct ptlrpc_sec *sec);
510 int sptlrpc_lprocfs_rd(char *page, char **start, off_t off, int count,
511                        int *eof, void *data);
512
513 /*
514  * server side
515  */
516 enum secsvc_accept_res {
517         SECSVC_OK       = 0,
518         SECSVC_COMPLETE,
519         SECSVC_DROP,
520 };
521
522 int  sptlrpc_svc_unwrap_request(struct ptlrpc_request *req);
523 int  sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen);
524 int  sptlrpc_svc_wrap_reply(struct ptlrpc_request *req);
525 void sptlrpc_svc_free_rs(struct ptlrpc_reply_state *rs);
526 void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req);
527 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req);
528
529 /*
530  * reverse context
531  */
532 int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
533                                 struct ptlrpc_svc_ctx *ctx);
534 int sptlrpc_cli_install_rvs_ctx(struct obd_import *imp,
535                                 struct ptlrpc_cli_ctx *ctx);
536
537 /* bulk security api */
538 int sptlrpc_enc_pool_add_user(void);
539 int sptlrpc_enc_pool_del_user(void);
540 int  sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc);
541 void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc);
542
543 int sptlrpc_cli_wrap_bulk(struct ptlrpc_request *req,
544                           struct ptlrpc_bulk_desc *desc);
545 int sptlrpc_cli_unwrap_bulk_read(struct ptlrpc_request *req,
546                                  int nob, obd_count pg_count,
547                                  struct brw_page **pga);
548 int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
549                                   struct ptlrpc_bulk_desc *desc);
550 int sptlrpc_svc_wrap_bulk(struct ptlrpc_request *req,
551                           struct ptlrpc_bulk_desc *desc);
552 int sptlrpc_svc_unwrap_bulk(struct ptlrpc_request *req,
553                             struct ptlrpc_bulk_desc *desc);
554
555 /* user descriptor helpers */
556 int sptlrpc_user_desc_size(void);
557 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset);
558 int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset);
559
560 /* bulk helpers (internal use only by policies) */
561 int bulk_sec_desc_size(__u32 csum_alg, int request, int read);
562 int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset);
563
564 int bulk_csum_cli_request(struct ptlrpc_bulk_desc *desc, int read,
565                           __u32 alg, struct lustre_msg *rmsg, int roff);
566 int bulk_csum_cli_reply(struct ptlrpc_bulk_desc *desc, int read,
567                         struct lustre_msg *rmsg, int roff,
568                         struct lustre_msg *vmsg, int voff);
569 int bulk_csum_svc(struct ptlrpc_bulk_desc *desc, int read,
570                   struct lustre_msg *vmsg, int voff,
571                   struct lustre_msg *rmsg, int roff);
572
573
574 #endif /* _LUSTRE_SEC_H_ */