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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #include <c2/audit_kernel.h>
29 #include <c2/audit_record.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>
39 zone_key_t au_zone_key
;
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
55 global_zone
->zone_audit_kctxt
= kctx
;
57 kctx
->auk_policy
= global_kctx
->auk_policy
;
58 curproc
->p_zone
->zone_audit_kctxt
= kctx
;
60 kctx
->auk_valid
= AUK_VALID
;
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
;
80 kmem_alloc(AU_DBUF_HEADER
+ kctx
->auk_queue
.bufsz
, KM_SLEEP
);
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
);
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
);
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
));
152 zone_key_create(&au_zone_key
, au_zone_init
, au_zone_shutdown
,
158 au_zone_getstate(const au_kcontext_t
*context
)
160 au_kcontext_t
*tcontext
;
163 return (context
->auk_auditstate
);
164 tcontext
= GET_KCTX_PZ
;
165 return (tcontext
->auk_auditstate
);