uts: make emu10k non-verbose
[unleashed.git] / kernel / os / audit_zone.c
blobc8026d062a432ac24085256f745f6a017d5a4668
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <c2/audit.h>
28 #include <c2/audit_kernel.h>
29 #include <c2/audit_record.h>
30 #include <sys/kmem.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/taskq.h>
34 #include <sys/t_lock.h>
35 #include <sys/thread.h>
36 #include <sys/types.h>
37 #include <sys/zone.h>
39 zone_key_t au_zone_key;
41 /*ARGSUSED*/
42 static void *
43 au_zone_init(zoneid_t zone)
45 au_kcontext_t *kctx = kmem_zalloc(sizeof (au_kcontext_t), KM_SLEEP);
46 static au_kcontext_t *global_kctx = NULL;
49 * INGLOBALZONE(curproc) is invalid at this point, so check for
50 * zone 0
53 if (zone == 0) {
54 global_kctx = kctx;
55 global_zone->zone_audit_kctxt = kctx;
56 } else {
57 kctx->auk_policy = global_kctx->auk_policy;
58 curproc->p_zone->zone_audit_kctxt = kctx;
60 kctx->auk_valid = AUK_VALID;
61 kctx->auk_zid = zone;
63 kctx->auk_info.ai_termid.at_type = AU_IPv4;
64 kctx->auk_info.ai_auid = AU_NOAUDITID;
65 kctx->auk_auditstate = AUC_INIT_AUDIT;
67 /* setup defaults for audit queue flow control */
68 kctx->auk_queue.hiwater = AQ_HIWATER;
69 kctx->auk_queue.lowater = AQ_LOWATER;
70 kctx->auk_queue.bufsz = AQ_BUFSZ;
71 kctx->auk_queue.buflen = AQ_BUFSZ;
72 kctx->auk_queue.delay = AQ_DELAY;
74 /* statistics per zone */
75 kctx->auk_statistics.as_version = TOKEN_VERSION;
76 kctx->auk_statistics.as_numevent = MAX_KEVENTS;
78 /* door IO buffer: */
79 kctx->auk_dbuffer =
80 kmem_alloc(AU_DBUF_HEADER + kctx->auk_queue.bufsz, KM_SLEEP);
82 /* locks and cv's */
84 mutex_init(&(kctx->auk_eagain_mutex), NULL, MUTEX_DEFAULT, NULL);
85 cv_init(&(kctx->auk_eagain_cv), NULL, CV_DRIVER, NULL);
87 mutex_init(&(kctx->auk_svc_lock), NULL, MUTEX_DEFAULT, NULL);
89 mutex_init(&(kctx->auk_queue.lock), NULL, MUTEX_DEFAULT, NULL);
90 cv_init(&(kctx->auk_queue.write_cv), NULL, CV_DRIVER, NULL);
91 cv_init(&(kctx->auk_queue.read_cv), NULL, CV_DRIVER, NULL);
93 return (kctx);
96 /*ARGSUSED*/
97 static void
98 au_zone_shutdown(zoneid_t zone, void *arg)
100 au_kcontext_t *kctx = arg;
102 if (audit_active == C2AUDIT_LOADED && (kctx->auk_zid == GLOBAL_ZONEID ||
103 (audit_policy | AUDIT_PERZONE)) && (kctx->auk_current_vp != NULL))
104 (void) au_doormsg(kctx, AU_DBUF_SHUTDOWN, NULL);
106 kctx->auk_valid = AUK_INVALID;
108 /* shutdown the output thread if it is still running */
109 kctx->auk_auditstate = AUC_NOAUDIT;
111 if (kctx->auk_output_active) {
112 mutex_enter(&(kctx->auk_queue.lock));
113 cv_broadcast(&(kctx->auk_queue.read_cv));
114 mutex_exit(&(kctx->auk_queue.lock));
116 taskq_destroy(kctx->auk_taskq);
120 /*ARGSUSED*/
121 static void
122 au_zone_destroy(zoneid_t zone, void *arg)
124 au_kcontext_t *kctx = arg;
126 ASSERT(kctx->auk_auditstate == AUC_NOAUDIT);
128 mutex_destroy(&(kctx->auk_eagain_mutex));
129 cv_destroy(&(kctx->auk_eagain_cv));
131 mutex_destroy(&(kctx->auk_svc_lock));
133 mutex_enter(&(kctx->auk_queue.lock));
134 if (kctx->auk_queue.head != NULL) {
135 au_free_rec(kctx->auk_queue.head);
137 mutex_exit(&(kctx->auk_queue.lock));
139 mutex_destroy(&(kctx->auk_queue.lock));
141 cv_destroy(&(kctx->auk_queue.write_cv));
142 cv_destroy(&(kctx->auk_queue.read_cv));
144 kmem_free(kctx->auk_dbuffer, AU_DBUF_HEADER + kctx->auk_queue.buflen);
146 kmem_free(kctx, sizeof (au_kcontext_t));
149 void
150 au_zone_setup()
152 zone_key_create(&au_zone_key, au_zone_init, au_zone_shutdown,
153 au_zone_destroy);
158 au_zone_getstate(const au_kcontext_t *context)
160 au_kcontext_t *tcontext;
162 if (context != NULL)
163 return (context->auk_auditstate);
164 tcontext = GET_KCTX_PZ;
165 return (tcontext->auk_auditstate);