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