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