Whamcloud - gitweb
LU-8602 gss: Properly port gss to newer crypto api.
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_internal.h
index a844e65..f0b9d28 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  *
  * Author: Eric Mei <ericm@clusterfs.com>
  */
@@ -11,6 +11,8 @@
 #ifndef __PTLRPC_GSS_GSS_INTERNAL_H_
 #define __PTLRPC_GSS_GSS_INTERNAL_H_
 
+#include <crypto/hash.h>
+#include <libcfs/libcfs_crypto.h>
 #include <lustre_sec.h>
 
 /*
@@ -71,17 +73,16 @@ int buffer_extract_bytes(const void **buf, __u32 *buflen,
  */
 #define GSS_GC_INTERVAL                 (60 * 60) /* 60 minutes */
 
-static inline
-unsigned long gss_round_ctx_expiry(unsigned long expiry,
-                                   unsigned long sec_flags)
+static inline time64_t gss_round_ctx_expiry(time64_t expiry,
+                                           unsigned long sec_flags)
 {
-        if (sec_flags & PTLRPC_SEC_FL_REVERSE)
-                return expiry;
+       if (sec_flags & PTLRPC_SEC_FL_REVERSE)
+               return expiry;
 
-        if (get_seconds() + __TIMEOUT_DELTA <= expiry)
-                return expiry - __TIMEOUT_DELTA;
+       if (ktime_get_real_seconds() + __TIMEOUT_DELTA <= expiry)
+               return expiry - __TIMEOUT_DELTA;
 
-        return expiry;
+       return expiry;
 }
 
 /*
@@ -92,7 +93,11 @@ unsigned long gss_round_ctx_expiry(unsigned long expiry,
 /*
  * XXX make it visible of kernel and lgssd/lsvcgssd
  */
-#define GSSD_INTERFACE_VERSION          (1)
+enum {
+       GSSD_INTERFACE_VERSION_V1 = 1,
+       GSSD_INTERFACE_VERSION_V2 = 2,
+       GSSD_INTERFACE_VERSION = GSSD_INTERFACE_VERSION_V2,
+};
 
 #define PTLRPC_GSS_VERSION              (1)
 
@@ -119,16 +124,24 @@ enum ptlrpc_gss_header_flags {
 static inline
 __u32 import_to_gss_svc(struct obd_import *imp)
 {
-        const char *name = imp->imp_obd->obd_type->typ_name;
-
-        if (!strcmp(name, LUSTRE_MGC_NAME))
-                return LUSTRE_GSS_TGT_MGS;
-        if (!strcmp(name, LUSTRE_MDC_NAME))
-                return LUSTRE_GSS_TGT_MDS;
-        if (!strcmp(name, LUSTRE_OSC_NAME))
-                return LUSTRE_GSS_TGT_OSS;
-        LBUG();
-        return 0;
+       int cl_sp_to = LUSTRE_SP_ANY;
+
+       if (imp->imp_obd)
+               cl_sp_to = imp->imp_obd->u.cli.cl_sp_to;
+
+       switch (cl_sp_to) {
+       case LUSTRE_SP_MDT:
+               return LUSTRE_GSS_TGT_MDS;
+       case LUSTRE_SP_OST:
+               return LUSTRE_GSS_TGT_OSS;
+       case LUSTRE_SP_MGC:
+       case LUSTRE_SP_MGS:
+               return LUSTRE_GSS_TGT_MGS;
+       case LUSTRE_SP_CLI:
+       case LUSTRE_SP_ANY:
+       default:
+               return 0;
+       }
 }
 
 /*
@@ -261,15 +274,15 @@ struct gss_svc_reqctx {
 };
 
 struct gss_cli_ctx {
-        struct ptlrpc_cli_ctx   gc_base;
-        __u32                   gc_flavor;
-        __u32                   gc_proc;
-        __u32                   gc_win;
-        cfs_atomic_t            gc_seq;
-        rawobj_t                gc_handle;
-        struct gss_ctx         *gc_mechctx;
-        /* handle for the buddy svc ctx */
-        rawobj_t                gc_svc_handle;
+       struct ptlrpc_cli_ctx   gc_base;
+       __u32                   gc_flavor;
+       __u32                   gc_proc;
+       __u32                   gc_win;
+       atomic_t                gc_seq;
+       rawobj_t                gc_handle;
+       struct gss_ctx          *gc_mechctx;
+       /* handle for the buddy svc ctx */
+       rawobj_t                gc_svc_handle;
 };
 
 struct gss_cli_ctx_keyring {
@@ -286,9 +299,9 @@ struct gss_sec {
 };
 
 struct gss_sec_pipefs {
-        struct gss_sec          gsp_base;
-        int                     gsp_chash_size;  /* must be 2^n */
-        cfs_hlist_head_t        gsp_chash[0];
+       struct gss_sec          gsp_base;
+       int                     gsp_chash_size; /* must be 2^n */
+       struct hlist_head       gsp_chash[0];
 };
 
 /*
@@ -301,7 +314,7 @@ struct gss_sec_keyring {
         /*
          * all contexts listed here. access is protected by sec spinlock.
          */
-        cfs_hlist_head_t        gsk_clist;
+       struct hlist_head       gsk_clist;
         /*
          * specially point to root ctx (only one at a time). access is
          * protected by sec spinlock.
@@ -468,7 +481,7 @@ __u32 g_verify_token_header(rawobj_t *mech, int *body_size,
 
 
 /* gss_cli_upcall.c */
-int gss_do_ctx_init_rpc(char *buffer, unsigned long count);
+int gss_do_ctx_init_rpc(char __user *buffer, unsigned long count);
 int gss_do_ctx_fini_rpc(struct gss_cli_ctx *gctx);
 
 int  __init gss_init_cli_upcall(void);
@@ -512,6 +525,14 @@ void cleanup_null_module(void);
 int __init init_kerberos_module(void);
 void cleanup_kerberos_module(void);
 
+/* gss_sk_mech.c */
+#ifdef HAVE_OPENSSL_SSK
+int __init init_sk_module(void);
+void cleanup_sk_module(void);
+#else
+static inline int init_sk_module(void) { return 0; }
+static inline void cleanup_sk_module(void) { return; }
+#endif /* HAVE_OPENSSL_SSK */
 
 /* debug */
 static inline
@@ -533,4 +554,13 @@ void __dbg_memdump(char *name, void *ptr, int size)
         OBD_FREE(buf, bufsize);
 }
 
+static inline unsigned int ll_read_key_usage(struct key *key)
+{
+#ifdef HAVE_KEY_USAGE_REFCOUNT
+       return refcount_read(&key->usage);
+#else
+       return atomic_read(&key->usage);
+#endif
+}
+
 #endif /* __PTLRPC_GSS_GSS_INTERNAL_H_ */