Whamcloud - gitweb
branch: HEAD
[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         uint32_t        vc_uid;
206         uint32_t        vc_gid;
207 };
208
209 struct ptlrpc_ctx_ops {
210         int     (*match)       (struct ptlrpc_cli_ctx *ctx,
211                                 struct vfs_cred *vcred);
212         int     (*refresh)     (struct ptlrpc_cli_ctx *ctx);
213         int     (*display)     (struct ptlrpc_cli_ctx *ctx,
214                                 char *buf, int bufsize);
215         /*
216          * rpc data transform
217          */
218         int     (*sign)        (struct ptlrpc_cli_ctx *ctx,
219                                 struct ptlrpc_request *req);
220         int     (*verify)      (struct ptlrpc_cli_ctx *ctx,
221                                 struct ptlrpc_request *req);
222         int     (*seal)        (struct ptlrpc_cli_ctx *ctx,
223                                 struct ptlrpc_request *req);
224         int     (*unseal)      (struct ptlrpc_cli_ctx *ctx,
225                                 struct ptlrpc_request *req);
226         /*
227          * bulk transform
228          */
229         int     (*wrap_bulk)   (struct ptlrpc_cli_ctx *ctx,
230                                 struct ptlrpc_request *req,
231                                 struct ptlrpc_bulk_desc *desc);
232         int     (*unwrap_bulk) (struct ptlrpc_cli_ctx *ctx,
233                                 struct ptlrpc_request *req,
234                                 struct ptlrpc_bulk_desc *desc);
235 };
236
237 #define PTLRPC_CTX_UPTODATE_BIT        (0)  /* uptodate */
238 #define PTLRPC_CTX_DEAD_BIT            (1)  /* mark expired gracefully */
239 #define PTLRPC_CTX_ERROR_BIT           (2)  /* fatal error (refresh, etc.) */
240 #define PTLRPC_CTX_HASHED_BIT          (8)  /* in hash table */
241 #define PTLRPC_CTX_ETERNAL_BIT         (9)  /* always valid */
242
243 #define PTLRPC_CTX_UPTODATE            (1 << PTLRPC_CTX_UPTODATE_BIT)
244 #define PTLRPC_CTX_DEAD                (1 << PTLRPC_CTX_DEAD_BIT)
245 #define PTLRPC_CTX_ERROR               (1 << PTLRPC_CTX_ERROR_BIT)
246 #define PTLRPC_CTX_HASHED              (1 << PTLRPC_CTX_HASHED_BIT)
247 #define PTLRPC_CTX_ETERNAL             (1 << PTLRPC_CTX_ETERNAL_BIT)
248
249 #define PTLRPC_CTX_STATUS_MASK         (PTLRPC_CTX_UPTODATE   |       \
250                                         PTLRPC_CTX_DEAD       |       \
251                                         PTLRPC_CTX_ERROR)
252
253 struct ptlrpc_cli_ctx {
254         struct hlist_node       cc_hash;       /* linked into hash table */
255         atomic_t                cc_refcount;
256         struct ptlrpc_sec      *cc_sec;
257         struct ptlrpc_ctx_ops  *cc_ops;
258         cfs_time_t              cc_expire;     /* in seconds */
259         unsigned long           cc_flags;
260         struct vfs_cred         cc_vcred;
261         spinlock_t              cc_lock;
262         struct list_head        cc_req_list;   /* waiting reqs linked here */
263 };
264
265 struct ptlrpc_sec_cops {
266         /*
267          * ptlrpc_sec constructor/destructor
268          */
269         struct ptlrpc_sec *     (*create_sec)  (struct obd_import *imp,
270                                                 struct ptlrpc_svc_ctx *ctx,
271                                                 __u32 flavor,
272                                                 unsigned long flags);
273         void                    (*destroy_sec) (struct ptlrpc_sec *sec);
274         /*
275          * search ctx for a certain user, if this function is missing,
276          * a generic function will be invoked by caller. implement this
277          * for any special need.
278          */
279         struct ptlrpc_cli_ctx * (*lookup_ctx)  (struct ptlrpc_sec *sec,
280                                                 struct vfs_cred *vcred);
281         /*
282          * ptlrpc_cli_ctx constructor/destructor
283          */
284         struct ptlrpc_cli_ctx * (*create_ctx)  (struct ptlrpc_sec *sec,
285                                                 struct vfs_cred *vcred);
286         void                    (*destroy_ctx) (struct ptlrpc_sec *sec,
287                                                 struct ptlrpc_cli_ctx *ctx);
288         /* reverse service */
289         int                     (*install_rctx)(struct obd_import *imp,
290                                                 struct ptlrpc_sec *sec,
291                                                 struct ptlrpc_cli_ctx *ctx);
292         /*
293          * request/reply buffer manipulation
294          */
295         int                     (*alloc_reqbuf)(struct ptlrpc_sec *sec,
296                                                 struct ptlrpc_request *req,
297                                                 int lustre_msg_size);
298         void                    (*free_reqbuf) (struct ptlrpc_sec *sec,
299                                                 struct ptlrpc_request *req);
300         int                     (*alloc_repbuf)(struct ptlrpc_sec *sec,
301                                                 struct ptlrpc_request *req,
302                                                 int lustre_msg_size);
303         void                    (*free_repbuf) (struct ptlrpc_sec *sec,
304                                                 struct ptlrpc_request *req);
305         int                     (*enlarge_reqbuf)
306                                                (struct ptlrpc_sec *sec,
307                                                 struct ptlrpc_request *req,
308                                                 int segment, int newsize);
309 };
310
311 struct ptlrpc_sec_sops {
312         int                     (*accept)      (struct ptlrpc_request *req);
313         int                     (*authorize)   (struct ptlrpc_request *req);
314         void                    (*invalidate_ctx)
315                                                (struct ptlrpc_svc_ctx *ctx);
316         /* buffer manipulation */
317         int                     (*alloc_rs)    (struct ptlrpc_request *req,
318                                                 int msgsize);
319         void                    (*free_rs)     (struct ptlrpc_reply_state *rs);
320         void                    (*free_ctx)    (struct ptlrpc_svc_ctx *ctx);
321         /* reverse credential */
322         int                     (*install_rctx)(struct obd_import *imp,
323                                                 struct ptlrpc_svc_ctx *ctx);
324         /* bulk transform */
325         int                     (*unwrap_bulk) (struct ptlrpc_request *req,
326                                                 struct ptlrpc_bulk_desc *desc);
327         int                     (*wrap_bulk)   (struct ptlrpc_request *req,
328                                                 struct ptlrpc_bulk_desc *desc);
329 };
330
331 struct ptlrpc_sec_policy {
332         struct module                  *sp_owner;
333         char                           *sp_name;
334         __u32                           sp_policy; /* policy number */
335         struct ptlrpc_sec_cops         *sp_cops;   /* client ops */
336         struct ptlrpc_sec_sops         *sp_sops;   /* server ops */
337 };
338
339 #define PTLRPC_SEC_FL_REVERSE           0x0001 /* reverse sec */
340 #define PTLRPC_SEC_FL_ROOTONLY          0x0002 /* treat everyone as root */
341 #define PTLRPC_SEC_FL_BULK              0x0004 /* intensive bulk i/o expected */
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  * user identity descriptor
364  */
365 #define LUSTRE_MAX_GROUPS               (128)
366
367 struct ptlrpc_user_desc {
368         __u32           pud_uid;
369         __u32           pud_gid;
370         __u32           pud_fsuid;
371         __u32           pud_fsgid;
372         __u32           pud_cap;
373         __u32           pud_ngroups;
374         __u32           pud_groups[0];
375 };
376
377 /*
378  * bulk flavors
379  */
380 enum bulk_checksum_alg {
381         BULK_CSUM_ALG_NULL      = 0,
382         BULK_CSUM_ALG_CRC32,
383         BULK_CSUM_ALG_MD5,
384         BULK_CSUM_ALG_SHA1,
385         BULK_CSUM_ALG_SHA256,
386         BULK_CSUM_ALG_SHA384,
387         BULK_CSUM_ALG_SHA512,
388         BULK_CSUM_ALG_MAX
389 };
390
391 enum bulk_encrypt_alg {
392         BULK_PRIV_ALG_NULL      = 0,
393         BULK_PRIV_ALG_ARC4,
394         BULK_PRIV_ALG_MAX
395 };
396
397 struct ptlrpc_bulk_sec_desc {
398         __u32           bsd_version;
399         __u32           bsd_pad;
400         __u32           bsd_csum_alg;   /* checksum algorithm */
401         __u32           bsd_priv_alg;   /* encrypt algorithm */
402         __u8            bsd_iv[16];     /* encrypt iv */
403         __u8            bsd_csum[0];
404 };
405
406 const char * sptlrpc_bulk_csum_alg2name(__u32 csum_alg);
407 const char * sptlrpc_bulk_priv_alg2name(__u32 priv_alg);
408 __u32 sptlrpc_bulk_priv_alg2flags(__u32 priv_alg);
409
410 /*
411  * lprocfs
412  */
413 struct proc_dir_entry;
414 extern struct proc_dir_entry *sptlrpc_proc_root;
415
416 /*
417  * round size up to next power of 2, for slab allocation.
418  * @size must be sane (can't overflow after round up)
419  */
420 static inline int size_roundup_power2(int size)
421 {
422         size--;
423         size |= size >> 1;
424         size |= size >> 2;
425         size |= size >> 4;
426         size |= size >> 8;
427         size |= size >> 16;
428         size++;
429         return size;
430 }
431
432 /*
433  * internal support libraries
434  */
435 void _sptlrpc_enlarge_msg_inplace(struct lustre_msg *msg,
436                                   int segment, int newsize);
437
438 /*
439  * security type
440  */
441 int sptlrpc_register_policy(struct ptlrpc_sec_policy *policy);
442 int sptlrpc_unregister_policy(struct ptlrpc_sec_policy *policy);
443
444 __u32 sptlrpc_name2flavor(const char *name);
445 char *sptlrpc_flavor2name(__u32 flavor);
446
447 static inline
448 struct ptlrpc_sec_policy *sptlrpc_policy_get(struct ptlrpc_sec_policy *policy)
449 {
450         __module_get(policy->sp_owner);
451         return policy;
452 }
453
454 static inline
455 void sptlrpc_policy_put(struct ptlrpc_sec_policy *policy)
456 {
457         module_put(policy->sp_owner);
458 }
459
460 /*
461  * client credential
462  */
463 struct ptlrpc_cli_ctx *sptlrpc_ctx_get(struct ptlrpc_cli_ctx *ctx);
464 void sptlrpc_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync);
465 void sptlrpc_ctx_expire(struct ptlrpc_cli_ctx *ctx);
466 void sptlrpc_ctx_replace(struct ptlrpc_sec *sec, struct ptlrpc_cli_ctx *new);
467 void sptlrpc_ctx_wakeup(struct ptlrpc_cli_ctx *ctx);
468 int sptlrpc_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
469
470 /*
471  * client wrap/buffers
472  */
473 int sptlrpc_cli_wrap_request(struct ptlrpc_request *req);
474 int sptlrpc_cli_unwrap_reply(struct ptlrpc_request *req);
475 int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize);
476 void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req);
477 int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize);
478 void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req);
479 int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
480                                int segment, int newsize);
481 void sptlrpc_request_out_callback(struct ptlrpc_request *req);
482
483 /*
484  * higher interface of import & request
485  */
486 int sptlrpc_import_get_sec(struct obd_import *imp, struct ptlrpc_svc_ctx *svc_ctx,
487                            __u32 flavor, unsigned long flags);
488 void sptlrpc_import_put_sec(struct obd_import *imp);
489 int  sptlrpc_import_check_ctx(struct obd_import *imp);
490 void sptlrpc_import_flush_root_ctx(struct obd_import *imp);
491 void sptlrpc_import_flush_my_ctx(struct obd_import *imp);
492 void sptlrpc_import_flush_all_ctx(struct obd_import *imp);
493 int  sptlrpc_req_get_ctx(struct ptlrpc_request *req);
494 void sptlrpc_req_put_ctx(struct ptlrpc_request *req);
495 int  sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout);
496 int  sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req);
497 void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode);
498
499 int sptlrpc_parse_flavor(enum lustre_part from, enum lustre_part to,
500                          char *str, struct sec_flavor_config *conf);
501 /* misc */
502 const char * sec2target_str(struct ptlrpc_sec *sec);
503 int sptlrpc_lprocfs_rd(char *page, char **start, off_t off, int count,
504                        int *eof, void *data);
505
506 /*
507  * server side
508  */
509 enum secsvc_accept_res {
510         SECSVC_OK       = 0,
511         SECSVC_COMPLETE,
512         SECSVC_DROP,
513 };
514
515 int  sptlrpc_svc_unwrap_request(struct ptlrpc_request *req);
516 int  sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen);
517 int  sptlrpc_svc_wrap_reply(struct ptlrpc_request *req);
518 void sptlrpc_svc_free_rs(struct ptlrpc_reply_state *rs);
519 void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req);
520 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req);
521 void sptlrpc_svc_ctx_invalidate(struct ptlrpc_request *req);
522
523 /*
524  * reverse context
525  */
526 int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
527                                 struct ptlrpc_svc_ctx *ctx);
528 int sptlrpc_cli_install_rvs_ctx(struct obd_import *imp,
529                                 struct ptlrpc_cli_ctx *ctx);
530
531 /* bulk security api */
532 int sptlrpc_enc_pool_add_user(void);
533 int sptlrpc_enc_pool_del_user(void);
534 int  sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc);
535 void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc);
536
537 int sptlrpc_cli_wrap_bulk(struct ptlrpc_request *req,
538                           struct ptlrpc_bulk_desc *desc);
539 int sptlrpc_cli_unwrap_bulk_read(struct ptlrpc_request *req,
540                                  int nob, obd_count pg_count,
541                                  struct brw_page **pga);
542 int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
543                                   struct ptlrpc_bulk_desc *desc);
544 int sptlrpc_svc_wrap_bulk(struct ptlrpc_request *req,
545                           struct ptlrpc_bulk_desc *desc);
546 int sptlrpc_svc_unwrap_bulk(struct ptlrpc_request *req,
547                             struct ptlrpc_bulk_desc *desc);
548
549 /* user descriptor helpers */
550 static inline int sptlrpc_user_desc_size(int ngroups)
551 {
552         return sizeof(struct ptlrpc_user_desc) + ngroups * sizeof(__u32);
553 }
554
555 int sptlrpc_current_user_desc_size(void);
556 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset);
557 int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset);
558
559 /* bulk helpers (internal use only by policies) */
560 int bulk_sec_desc_size(__u32 csum_alg, int request, int read);
561 int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset);
562
563 int bulk_csum_cli_request(struct ptlrpc_bulk_desc *desc, int read,
564                           __u32 alg, struct lustre_msg *rmsg, int roff);
565 int bulk_csum_cli_reply(struct ptlrpc_bulk_desc *desc, int read,
566                         struct lustre_msg *rmsg, int roff,
567                         struct lustre_msg *vmsg, int voff);
568 int bulk_csum_svc(struct ptlrpc_bulk_desc *desc, int read,
569                   struct lustre_msg *vmsg, int voff,
570                   struct lustre_msg *rmsg, int roff);
571
572
573 #endif /* _LUSTRE_SEC_H_ */