1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_SEC
42 #include <linux/init.h>
43 #include <linux/module.h>
44 #include <linux/slab.h>
45 #include <linux/dcache.h>
47 #include <linux/random.h>
48 #include <linux/mutex.h>
50 #include <liblustre.h>
54 #include <obd_class.h>
55 #include <obd_support.h>
56 #include <lustre/lustre_idl.h>
57 #include <lustre_net.h>
58 #include <lustre_import.h>
59 #include <lprocfs_status.h>
60 #include <lustre_sec.h>
63 #include "gss_internal.h"
66 static struct proc_dir_entry *gss_proc_root = NULL;
67 static struct proc_dir_entry *gss_proc_lk = NULL;
70 * statistic of "out-of-sequence-window"
74 atomic_t oos_cli_count; /* client occurrence */
75 int oos_cli_behind; /* client max seqs behind */
76 atomic_t oos_svc_replay[3]; /* server replay detected */
77 atomic_t oos_svc_pass[3]; /* server verified ok */
79 .oos_cli_count = ATOMIC_INIT(0),
81 .oos_svc_replay = { ATOMIC_INIT(0), },
82 .oos_svc_pass = { ATOMIC_INIT(0), },
85 void gss_stat_oos_record_cli(int behind)
87 atomic_inc(&gss_stat_oos.oos_cli_count);
89 spin_lock(&gss_stat_oos.oos_lock);
90 if (behind > gss_stat_oos.oos_cli_behind)
91 gss_stat_oos.oos_cli_behind = behind;
92 spin_unlock(&gss_stat_oos.oos_lock);
95 void gss_stat_oos_record_svc(int phase, int replay)
97 LASSERT(phase >= 0 && phase <= 2);
100 atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
102 atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
105 static int gss_proc_read_oos(char *page, char **start, off_t off, int count,
106 int *eof, void *data)
110 written = snprintf(page, count,
113 "client fall behind seqwin\n"
115 " max seq behind: %d\n"
116 "server replay detected:\n"
120 "server verify ok:\n"
124 atomic_read(&gss_stat_oos.oos_cli_count),
125 gss_stat_oos.oos_cli_behind,
126 atomic_read(&gss_stat_oos.oos_svc_replay[0]),
127 atomic_read(&gss_stat_oos.oos_svc_replay[1]),
128 atomic_read(&gss_stat_oos.oos_svc_replay[2]),
129 atomic_read(&gss_stat_oos.oos_svc_pass[2]));
134 static int gss_proc_write_secinit(struct file *file, const char *buffer,
135 unsigned long count, void *data)
139 rc = gss_do_ctx_init_rpc((char *) buffer, count);
145 return ((int) count);
148 static struct lprocfs_vars gss_lprocfs_vars[] = {
149 { "replays", gss_proc_read_oos, NULL },
150 { "init_channel", NULL, gss_proc_write_secinit, NULL, NULL, 0222 },
155 * for userspace helper lgss_keyring.
157 * debug_level: [0, 4], defined in utils/gss/lgss_utils.h
159 static int gss_lk_debug_level = 1;
161 static int gss_lk_proc_read_dl(char *page, char **start, off_t off,
162 int count, int *eof, void *data)
164 return snprintf(page, count, "%u\n", gss_lk_debug_level);
167 static int gss_lk_proc_write_dl(struct file *file, const char *buffer,
168 unsigned long count, void *data)
172 rc = lprocfs_write_helper(buffer, count, &val);
176 if (val < 0 || val > 4)
179 gss_lk_debug_level = val;
183 static struct lprocfs_vars gss_lk_lprocfs_vars[] = {
184 { "debug_level", gss_lk_proc_read_dl, gss_lk_proc_write_dl, NULL },
188 void gss_exit_lproc(void)
191 lprocfs_remove(&gss_proc_lk);
196 lprocfs_remove(&gss_proc_root);
197 gss_proc_root = NULL;
201 int gss_init_lproc(void)
205 spin_lock_init(&gss_stat_oos.oos_lock);
207 gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
208 gss_lprocfs_vars, NULL);
209 if (IS_ERR(gss_proc_root)) {
210 gss_proc_root = NULL;
211 GOTO(err_out, rc = PTR_ERR(gss_proc_root));
214 gss_proc_lk = lprocfs_register("lgss_keyring", gss_proc_root,
215 gss_lk_lprocfs_vars, NULL);
216 if (IS_ERR(gss_proc_lk)) {
218 GOTO(err_out, rc = PTR_ERR(gss_proc_root));
224 CERROR("failed to initialize gss lproc entries: %d\n", rc);