Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / ptlrpc / sec_config.c
index 3534ba2..67287e8 100644 (file)
@@ -1,22 +1,37 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2007 Cluster File Systems, Inc.
+ * GPL HEADER START
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   Lustre is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   Lustre is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #ifndef EXPORT_SYMTAB
@@ -82,6 +97,12 @@ EXPORT_SYMBOL(sptlrpc_target_sec_part);
  * user supplied flavor string parsing  *
  ****************************************/
 
+#ifdef HAVE_ADLER
+#define BULK_HASH_ALG_DEFAULT   BULK_HASH_ALG_ADLER32
+#else
+#define BULK_HASH_ALG_DEFAULT   BULK_HASH_ALG_CRC32
+#endif
+
 typedef enum {
         BULK_TYPE_N = 0,
         BULK_TYPE_I = 1,
@@ -91,8 +112,8 @@ typedef enum {
 static void get_default_flavor(struct sptlrpc_flavor *sf)
 {
         sf->sf_rpc = SPTLRPC_FLVR_NULL;
-        sf->sf_bulk_priv = BULK_PRIV_ALG_NULL;
-        sf->sf_bulk_csum = BULK_CSUM_ALG_NULL;
+        sf->sf_bulk_ciph = BULK_CIPH_ALG_NULL;
+        sf->sf_bulk_hash = BULK_HASH_ALG_NULL;
         sf->sf_flags = 0;
 }
 
@@ -104,35 +125,50 @@ static void get_flavor_by_rpc(struct sptlrpc_rule *rule, __u16 rpc_flavor)
 
         switch (rpc_flavor) {
         case SPTLRPC_FLVR_NULL:
+                break;
         case SPTLRPC_FLVR_PLAIN:
         case SPTLRPC_FLVR_KRB5N:
         case SPTLRPC_FLVR_KRB5A:
+                rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_DEFAULT;
                 break;
         case SPTLRPC_FLVR_KRB5P:
-                rule->sr_flvr.sf_bulk_priv = BULK_PRIV_ALG_ARC4;
+                rule->sr_flvr.sf_bulk_ciph = BULK_CIPH_ALG_AES128;
                 /* fall through */
         case SPTLRPC_FLVR_KRB5I:
-                rule->sr_flvr.sf_bulk_csum = BULK_CSUM_ALG_SHA1;
+                rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_SHA1;
                 break;
         default:
                 LBUG();
         }
 }
 
-static void get_flavor_by_bulk(struct sptlrpc_rule *rule, bulk_type_t bulk_type)
+static void get_flavor_by_bulk(struct sptlrpc_rule *rule,
+                               __u16 rpc_flavor, bulk_type_t bulk_type)
 {
         switch (bulk_type) {
         case BULK_TYPE_N:
-                rule->sr_flvr.sf_bulk_csum = BULK_CSUM_ALG_NULL;
-                rule->sr_flvr.sf_bulk_priv = BULK_PRIV_ALG_NULL;
+                rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_NULL;
+                rule->sr_flvr.sf_bulk_ciph = BULK_CIPH_ALG_NULL;
                 break;
         case BULK_TYPE_I:
-                rule->sr_flvr.sf_bulk_csum = BULK_CSUM_ALG_SHA1;
-                rule->sr_flvr.sf_bulk_priv = BULK_PRIV_ALG_NULL;
+                switch (rpc_flavor) {
+                case SPTLRPC_FLVR_PLAIN:
+                case SPTLRPC_FLVR_KRB5N:
+                case SPTLRPC_FLVR_KRB5A:
+                        rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_DEFAULT;
+                        break;
+                case SPTLRPC_FLVR_KRB5I:
+                case SPTLRPC_FLVR_KRB5P:
+                        rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_SHA1;
+                        break;
+                default:
+                        LBUG();
+                }
+                rule->sr_flvr.sf_bulk_ciph = BULK_CIPH_ALG_NULL;
                 break;
         case BULK_TYPE_P:
-                rule->sr_flvr.sf_bulk_csum = BULK_CSUM_ALG_SHA1;
-                rule->sr_flvr.sf_bulk_priv = BULK_PRIV_ALG_ARC4;
+                rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_SHA1;
+                rule->sr_flvr.sf_bulk_ciph = BULK_CIPH_ALG_AES128;
                 break;
         default:
                 LBUG();
@@ -207,8 +243,8 @@ static int parse_flavor(char *str, struct sptlrpc_rule *rule)
 
         /* verify bulk section */
         if (strcmp(bulk, "bulkn") == 0) {
-                rule->sr_flvr.sf_bulk_csum = BULK_CSUM_ALG_NULL;
-                rule->sr_flvr.sf_bulk_priv = BULK_PRIV_ALG_NULL;
+                rule->sr_flvr.sf_bulk_hash = BULK_HASH_ALG_NULL;
+                rule->sr_flvr.sf_bulk_ciph = BULK_CIPH_ALG_NULL;
                 bulk_type = BULK_TYPE_N;
         } else if (strcmp(bulk, "bulki") == 0)
                 bulk_type = BULK_TYPE_I;
@@ -225,7 +261,7 @@ static int parse_flavor(char *str, struct sptlrpc_rule *rule)
         if (__flavors[i] == SPTLRPC_FLVR_PLAIN && bulk_type == BULK_TYPE_P)
                 GOTO(invalid, -EINVAL);
 
-        get_flavor_by_bulk(rule, bulk_type);
+        get_flavor_by_bulk(rule, __flavors[i], bulk_type);
 
         if (alg == NULL)
                 goto out;
@@ -236,24 +272,24 @@ static int parse_flavor(char *str, struct sptlrpc_rule *rule)
                 *enc++ = '\0';
 
         /* checksum algorithm */
-        for (i = 0; i < BULK_CSUM_ALG_MAX; i++) {
-                if (strcmp(alg, sptlrpc_bulk_csum_alg2name(i)) == 0) {
-                        rule->sr_flvr.sf_bulk_csum = i;
+        for (i = 0; i < BULK_HASH_ALG_MAX; i++) {
+                if (strcmp(alg, sptlrpc_get_hash_name(i)) == 0) {
+                        rule->sr_flvr.sf_bulk_hash = i;
                         break;
                 }
         }
-        if (i >= BULK_CSUM_ALG_MAX)
+        if (i >= BULK_HASH_ALG_MAX)
                 GOTO(invalid, -EINVAL);
 
         /* privacy algorithm */
         if (enc) {
-                for (i = 0; i < BULK_PRIV_ALG_MAX; i++) {
-                        if (strcmp(enc, sptlrpc_bulk_priv_alg2name(i)) == 0) {
-                                rule->sr_flvr.sf_bulk_priv = i;
+                for (i = 0; i < BULK_CIPH_ALG_MAX; i++) {
+                        if (strcmp(enc, sptlrpc_get_ciph_name(i)) == 0) {
+                                rule->sr_flvr.sf_bulk_ciph = i;
                                 break;
                         }
                 }
-                if (i >= BULK_PRIV_ALG_MAX)
+                if (i >= BULK_CIPH_ALG_MAX)
                         GOTO(invalid, -EINVAL);
         }
 
@@ -261,17 +297,17 @@ static int parse_flavor(char *str, struct sptlrpc_rule *rule)
          * bulk combination sanity checks
          */
         if (bulk_type == BULK_TYPE_P &&
-            rule->sr_flvr.sf_bulk_priv == BULK_PRIV_ALG_NULL)
+            rule->sr_flvr.sf_bulk_ciph == BULK_CIPH_ALG_NULL)
                 GOTO(invalid, -EINVAL);
 
         if (bulk_type == BULK_TYPE_I &&
-            (rule->sr_flvr.sf_bulk_csum == BULK_CSUM_ALG_NULL ||
-             rule->sr_flvr.sf_bulk_priv != BULK_PRIV_ALG_NULL))
+            (rule->sr_flvr.sf_bulk_hash == BULK_HASH_ALG_NULL ||
+             rule->sr_flvr.sf_bulk_ciph != BULK_CIPH_ALG_NULL))
                 GOTO(invalid, -EINVAL);
 
         if (bulk_type == BULK_TYPE_N &&
-            (rule->sr_flvr.sf_bulk_csum != BULK_CSUM_ALG_NULL ||
-             rule->sr_flvr.sf_bulk_priv != BULK_PRIV_ALG_NULL))
+            (rule->sr_flvr.sf_bulk_hash != BULK_HASH_ALG_NULL ||
+             rule->sr_flvr.sf_bulk_ciph != BULK_CIPH_ALG_NULL))
                 GOTO(invalid, -EINVAL);
 
 out: