4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_SEC
39 #include <linux/init.h>
40 #include <linux/module.h>
41 #include <linux/slab.h>
42 #include <linux/dcache.h>
44 #include <linux/mutex.h>
46 #include <liblustre.h>
50 #include <obd_class.h>
51 #include <obd_support.h>
52 #include <lustre/lustre_idl.h>
53 #include <lustre_net.h>
54 #include <lustre_import.h>
55 #include <lprocfs_status.h>
56 #include <lustre_sec.h>
59 #include "gss_internal.h"
62 static struct proc_dir_entry *gss_proc_root = NULL;
63 static struct proc_dir_entry *gss_proc_lk = NULL;
66 * statistic of "out-of-sequence-window"
70 cfs_atomic_t oos_cli_count; /* client occurrence */
71 int oos_cli_behind; /* client max seqs behind */
72 cfs_atomic_t oos_svc_replay[3]; /* server replay detected */
73 cfs_atomic_t oos_svc_pass[3]; /* server verified ok */
75 .oos_cli_count = CFS_ATOMIC_INIT(0),
77 .oos_svc_replay = { CFS_ATOMIC_INIT(0), },
78 .oos_svc_pass = { CFS_ATOMIC_INIT(0), },
81 void gss_stat_oos_record_cli(int behind)
83 cfs_atomic_inc(&gss_stat_oos.oos_cli_count);
85 spin_lock(&gss_stat_oos.oos_lock);
86 if (behind > gss_stat_oos.oos_cli_behind)
87 gss_stat_oos.oos_cli_behind = behind;
88 spin_unlock(&gss_stat_oos.oos_lock);
91 void gss_stat_oos_record_svc(int phase, int replay)
93 LASSERT(phase >= 0 && phase <= 2);
96 cfs_atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
98 cfs_atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
101 static int gss_proc_read_oos(char *page, char **start, off_t off, int count,
102 int *eof, void *data)
106 written = snprintf(page, count,
109 "client fall behind seqwin\n"
111 " max seq behind: %d\n"
112 "server replay detected:\n"
116 "server verify ok:\n"
120 cfs_atomic_read(&gss_stat_oos.oos_cli_count),
121 gss_stat_oos.oos_cli_behind,
122 cfs_atomic_read(&gss_stat_oos.oos_svc_replay[0]),
123 cfs_atomic_read(&gss_stat_oos.oos_svc_replay[1]),
124 cfs_atomic_read(&gss_stat_oos.oos_svc_replay[2]),
125 cfs_atomic_read(&gss_stat_oos.oos_svc_pass[2]));
130 static int gss_proc_write_secinit(struct file *file, const char *buffer,
131 unsigned long count, void *data)
135 rc = gss_do_ctx_init_rpc((char *) buffer, count);
141 return ((int) count);
144 static struct lprocfs_vars gss_lprocfs_vars[] = {
145 { "replays", gss_proc_read_oos, NULL },
146 { "init_channel", NULL, gss_proc_write_secinit, NULL, NULL, 0222 },
151 * for userspace helper lgss_keyring.
153 * debug_level: [0, 4], defined in utils/gss/lgss_utils.h
155 static int gss_lk_debug_level = 1;
157 static int gss_lk_proc_read_dl(char *page, char **start, off_t off,
158 int count, int *eof, void *data)
160 return snprintf(page, count, "%u\n", gss_lk_debug_level);
163 static int gss_lk_proc_write_dl(struct file *file, const char *buffer,
164 unsigned long count, void *data)
168 rc = lprocfs_write_helper(buffer, count, &val);
172 if (val < 0 || val > 4)
175 gss_lk_debug_level = val;
179 static struct lprocfs_vars gss_lk_lprocfs_vars[] = {
180 { "debug_level", gss_lk_proc_read_dl, gss_lk_proc_write_dl, NULL },
184 void gss_exit_lproc(void)
187 lprocfs_remove(&gss_proc_lk);
192 lprocfs_remove(&gss_proc_root);
193 gss_proc_root = NULL;
197 int gss_init_lproc(void)
201 spin_lock_init(&gss_stat_oos.oos_lock);
203 gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
204 gss_lprocfs_vars, NULL);
205 if (IS_ERR(gss_proc_root)) {
206 gss_proc_root = NULL;
207 GOTO(err_out, rc = PTR_ERR(gss_proc_root));
210 gss_proc_lk = lprocfs_register("lgss_keyring", gss_proc_root,
211 gss_lk_lprocfs_vars, NULL);
212 if (IS_ERR(gss_proc_lk)) {
214 GOTO(err_out, rc = PTR_ERR(gss_proc_root));
220 CERROR("failed to initialize gss lproc entries: %d\n", rc);