Lines Matching refs:ap
180 #define AUDIT_PIPE_LOCK(ap) mtx_lock(&(ap)->ap_mtx) argument
181 #define AUDIT_PIPE_LOCK_ASSERT(ap) mtx_assert(&(ap)->ap_mtx, MA_OWNED) argument
182 #define AUDIT_PIPE_LOCK_DESTROY(ap) mtx_destroy(&(ap)->ap_mtx) argument
183 #define AUDIT_PIPE_LOCK_INIT(ap) mtx_init(&(ap)->ap_mtx, \ argument
185 #define AUDIT_PIPE_UNLOCK(ap) mtx_unlock(&(ap)->ap_mtx) argument
186 #define AUDIT_PIPE_MTX(ap) (&(ap)->ap_mtx) argument
188 #define AUDIT_PIPE_SX_LOCK_DESTROY(ap) sx_destroy(&(ap)->ap_sx) argument
189 #define AUDIT_PIPE_SX_LOCK_INIT(ap) sx_init(&(ap)->ap_sx, "audit_pipe_sx") argument
190 #define AUDIT_PIPE_SX_XLOCK_ASSERT(ap) sx_assert(&(ap)->ap_sx, SA_XLOCKED) argument
191 #define AUDIT_PIPE_SX_XLOCK_SIG(ap) sx_xlock_sig(&(ap)->ap_sx) argument
192 #define AUDIT_PIPE_SX_XUNLOCK(ap) sx_xunlock(&(ap)->ap_sx) argument
272 audit_pipe_preselect_find(struct audit_pipe *ap, au_id_t auid) in audit_pipe_preselect_find() argument
276 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_preselect_find()
278 TAILQ_FOREACH(app, &ap->ap_preselect_list, app_list) { in audit_pipe_preselect_find()
289 audit_pipe_preselect_get(struct audit_pipe *ap, au_id_t auid, in audit_pipe_preselect_get() argument
295 AUDIT_PIPE_LOCK(ap); in audit_pipe_preselect_get()
296 app = audit_pipe_preselect_find(ap, auid); in audit_pipe_preselect_get()
302 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_preselect_get()
311 audit_pipe_preselect_set(struct audit_pipe *ap, au_id_t auid, au_mask_t mask) in audit_pipe_preselect_set() argument
320 AUDIT_PIPE_LOCK(ap); in audit_pipe_preselect_set()
321 app = audit_pipe_preselect_find(ap, auid); in audit_pipe_preselect_set()
326 TAILQ_INSERT_TAIL(&ap->ap_preselect_list, app, app_list); in audit_pipe_preselect_set()
329 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_preselect_set()
338 audit_pipe_preselect_delete(struct audit_pipe *ap, au_id_t auid) in audit_pipe_preselect_delete() argument
343 AUDIT_PIPE_LOCK(ap); in audit_pipe_preselect_delete()
344 app = audit_pipe_preselect_find(ap, auid); in audit_pipe_preselect_delete()
346 TAILQ_REMOVE(&ap->ap_preselect_list, app, app_list); in audit_pipe_preselect_delete()
350 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_preselect_delete()
360 audit_pipe_preselect_flush_locked(struct audit_pipe *ap) in audit_pipe_preselect_flush_locked() argument
364 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_preselect_flush_locked()
366 while ((app = TAILQ_FIRST(&ap->ap_preselect_list)) != NULL) { in audit_pipe_preselect_flush_locked()
367 TAILQ_REMOVE(&ap->ap_preselect_list, app, app_list); in audit_pipe_preselect_flush_locked()
373 audit_pipe_preselect_flush(struct audit_pipe *ap) in audit_pipe_preselect_flush() argument
376 AUDIT_PIPE_LOCK(ap); in audit_pipe_preselect_flush()
377 audit_pipe_preselect_flush_locked(ap); in audit_pipe_preselect_flush()
378 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_preselect_flush()
392 audit_pipe_preselect_check(struct audit_pipe *ap, au_id_t auid, in audit_pipe_preselect_check() argument
397 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_preselect_check()
399 switch (ap->ap_preselect_mode) { in audit_pipe_preselect_check()
404 app = audit_pipe_preselect_find(ap, auid); in audit_pipe_preselect_check()
408 &ap->ap_preselect_naflags, sorf)); in audit_pipe_preselect_check()
411 &ap->ap_preselect_flags, sorf)); in audit_pipe_preselect_check()
418 ap->ap_preselect_mode); in audit_pipe_preselect_check()
432 struct audit_pipe *ap; in audit_pipe_preselect() local
439 TAILQ_FOREACH(ap, &audit_pipe_list, ap_list) { in audit_pipe_preselect()
440 AUDIT_PIPE_LOCK(ap); in audit_pipe_preselect()
441 if (audit_pipe_preselect_check(ap, auid, event, class, sorf, in audit_pipe_preselect()
443 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_preselect()
447 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_preselect()
459 audit_pipe_append(struct audit_pipe *ap, void *record, u_int record_len) in audit_pipe_append() argument
463 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_append()
465 if (ap->ap_qlen >= ap->ap_qlimit) { in audit_pipe_append()
466 ap->ap_drops++; in audit_pipe_append()
473 ap->ap_drops++; in audit_pipe_append()
481 ap->ap_drops++; in audit_pipe_append()
489 TAILQ_INSERT_TAIL(&ap->ap_queue, ape, ape_queue); in audit_pipe_append()
490 ap->ap_inserts++; in audit_pipe_append()
491 ap->ap_qlen++; in audit_pipe_append()
492 ap->ap_qbyteslen += ape->ape_record_len; in audit_pipe_append()
493 selwakeuppri(&ap->ap_selinfo, PSOCK); in audit_pipe_append()
494 KNOTE_LOCKED(&ap->ap_selinfo.si_note, 0); in audit_pipe_append()
495 if (ap->ap_flags & AUDIT_PIPE_ASYNC) in audit_pipe_append()
496 pgsigio(&ap->ap_sigio, SIGIO, 0); in audit_pipe_append()
497 cv_broadcast(&ap->ap_cv); in audit_pipe_append()
508 struct audit_pipe *ap; in audit_pipe_submit() local
517 TAILQ_FOREACH(ap, &audit_pipe_list, ap_list) { in audit_pipe_submit()
518 AUDIT_PIPE_LOCK(ap); in audit_pipe_submit()
519 if (audit_pipe_preselect_check(ap, auid, event, class, sorf, in audit_pipe_submit()
521 audit_pipe_append(ap, record, record_len); in audit_pipe_submit()
522 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_submit()
541 struct audit_pipe *ap; in audit_pipe_submit_user() local
550 TAILQ_FOREACH(ap, &audit_pipe_list, ap_list) { in audit_pipe_submit_user()
551 AUDIT_PIPE_LOCK(ap); in audit_pipe_submit_user()
552 audit_pipe_append(ap, record, record_len); in audit_pipe_submit_user()
553 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_submit_user()
568 struct audit_pipe *ap; in audit_pipe_alloc() local
570 ap = malloc(sizeof(*ap), M_AUDIT_PIPE, M_NOWAIT | M_ZERO); in audit_pipe_alloc()
571 if (ap == NULL) in audit_pipe_alloc()
573 ap->ap_qlimit = AUDIT_PIPE_QLIMIT_DEFAULT; in audit_pipe_alloc()
574 TAILQ_INIT(&ap->ap_queue); in audit_pipe_alloc()
575 knlist_init_mtx(&ap->ap_selinfo.si_note, AUDIT_PIPE_MTX(ap)); in audit_pipe_alloc()
576 AUDIT_PIPE_LOCK_INIT(ap); in audit_pipe_alloc()
577 AUDIT_PIPE_SX_LOCK_INIT(ap); in audit_pipe_alloc()
578 cv_init(&ap->ap_cv, "audit_pipe"); in audit_pipe_alloc()
587 bzero(&ap->ap_preselect_flags, sizeof(ap->ap_preselect_flags)); in audit_pipe_alloc()
588 bzero(&ap->ap_preselect_naflags, sizeof(ap->ap_preselect_naflags)); in audit_pipe_alloc()
589 TAILQ_INIT(&ap->ap_preselect_list); in audit_pipe_alloc()
590 ap->ap_preselect_mode = AUDITPIPE_PRESELECT_MODE_TRAIL; in audit_pipe_alloc()
596 TAILQ_INSERT_HEAD(&audit_pipe_list, ap, ap_list); in audit_pipe_alloc()
601 return (ap); in audit_pipe_alloc()
608 audit_pipe_flush(struct audit_pipe *ap) in audit_pipe_flush() argument
612 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_flush()
614 while ((ape = TAILQ_FIRST(&ap->ap_queue)) != NULL) { in audit_pipe_flush()
615 TAILQ_REMOVE(&ap->ap_queue, ape, ape_queue); in audit_pipe_flush()
616 ap->ap_qbyteslen -= ape->ape_record_len; in audit_pipe_flush()
618 ap->ap_qlen--; in audit_pipe_flush()
620 ap->ap_qoffset = 0; in audit_pipe_flush()
622 KASSERT(ap->ap_qlen == 0, ("audit_pipe_free: ap_qbyteslen")); in audit_pipe_flush()
623 KASSERT(ap->ap_qbyteslen == 0, ("audit_pipe_flush: ap_qbyteslen")); in audit_pipe_flush()
633 audit_pipe_free(struct audit_pipe *ap) in audit_pipe_free() argument
637 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_free()
639 audit_pipe_preselect_flush_locked(ap); in audit_pipe_free()
640 audit_pipe_flush(ap); in audit_pipe_free()
641 cv_destroy(&ap->ap_cv); in audit_pipe_free()
642 AUDIT_PIPE_SX_LOCK_DESTROY(ap); in audit_pipe_free()
643 AUDIT_PIPE_LOCK_DESTROY(ap); in audit_pipe_free()
644 seldrain(&ap->ap_selinfo); in audit_pipe_free()
645 knlist_destroy(&ap->ap_selinfo.si_note); in audit_pipe_free()
646 TAILQ_REMOVE(&audit_pipe_list, ap, ap_list); in audit_pipe_free()
647 free(ap, M_AUDIT_PIPE); in audit_pipe_free()
654 struct audit_pipe *ap; in audit_pipe_dtor() local
656 ap = arg; in audit_pipe_dtor()
657 funsetown(&ap->ap_sigio); in audit_pipe_dtor()
659 AUDIT_PIPE_LOCK(ap); in audit_pipe_dtor()
660 audit_pipe_free(ap); in audit_pipe_dtor()
672 struct audit_pipe *ap; in audit_pipe_open() local
675 ap = audit_pipe_alloc(); in audit_pipe_open()
676 if (ap == NULL) in audit_pipe_open()
678 fsetown(td->td_proc->p_pid, &ap->ap_sigio); in audit_pipe_open()
679 error = devfs_set_cdevpriv(ap, audit_pipe_dtor); in audit_pipe_open()
681 audit_pipe_dtor(ap); in audit_pipe_open()
694 struct audit_pipe *ap; in audit_pipe_ioctl() local
699 error = devfs_get_cdevpriv((void **)&ap); in audit_pipe_ioctl()
710 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
712 ap->ap_flags |= AUDIT_PIPE_NBIO; in audit_pipe_ioctl()
714 ap->ap_flags &= ~AUDIT_PIPE_NBIO; in audit_pipe_ioctl()
715 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
720 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
721 *(int *)data = ap->ap_qbyteslen - ap->ap_qoffset; in audit_pipe_ioctl()
722 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
727 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
729 ap->ap_flags |= AUDIT_PIPE_ASYNC; in audit_pipe_ioctl()
731 ap->ap_flags &= ~AUDIT_PIPE_ASYNC; in audit_pipe_ioctl()
732 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
737 error = fsetown(*(int *)data, &ap->ap_sigio); in audit_pipe_ioctl()
741 *(int *)data = fgetown(&ap->ap_sigio); in audit_pipe_ioctl()
746 *(u_int *)data = ap->ap_qlen; in audit_pipe_ioctl()
751 *(u_int *)data = ap->ap_qlimit; in audit_pipe_ioctl()
759 ap->ap_qlimit = *(u_int *)data; in audit_pipe_ioctl()
776 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
778 *maskp = ap->ap_preselect_flags; in audit_pipe_ioctl()
779 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
784 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
786 ap->ap_preselect_flags = *maskp; in audit_pipe_ioctl()
787 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
792 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
794 *maskp = ap->ap_preselect_naflags; in audit_pipe_ioctl()
795 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
800 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
802 ap->ap_preselect_naflags = *maskp; in audit_pipe_ioctl()
803 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
809 error = audit_pipe_preselect_get(ap, aip->aip_auid, in audit_pipe_ioctl()
815 audit_pipe_preselect_set(ap, aip->aip_auid, aip->aip_mask); in audit_pipe_ioctl()
821 error = audit_pipe_preselect_delete(ap, auid); in audit_pipe_ioctl()
825 audit_pipe_preselect_flush(ap); in audit_pipe_ioctl()
830 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
831 *(int *)data = ap->ap_preselect_mode; in audit_pipe_ioctl()
832 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
841 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
842 ap->ap_preselect_mode = mode; in audit_pipe_ioctl()
843 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
853 if (AUDIT_PIPE_SX_XLOCK_SIG(ap) != 0) in audit_pipe_ioctl()
855 AUDIT_PIPE_LOCK(ap); in audit_pipe_ioctl()
856 audit_pipe_flush(ap); in audit_pipe_ioctl()
857 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_ioctl()
858 AUDIT_PIPE_SX_XUNLOCK(ap); in audit_pipe_ioctl()
868 *(u_int *)data = ap->ap_inserts; in audit_pipe_ioctl()
873 *(u_int *)data = ap->ap_reads; in audit_pipe_ioctl()
878 *(u_int *)data = ap->ap_drops; in audit_pipe_ioctl()
901 struct audit_pipe *ap; in audit_pipe_read() local
905 error = devfs_get_cdevpriv((void **)&ap); in audit_pipe_read()
913 if (AUDIT_PIPE_SX_XLOCK_SIG(ap) != 0) in audit_pipe_read()
915 AUDIT_PIPE_LOCK(ap); in audit_pipe_read()
916 while (TAILQ_EMPTY(&ap->ap_queue)) { in audit_pipe_read()
917 if (ap->ap_flags & AUDIT_PIPE_NBIO) { in audit_pipe_read()
918 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_read()
919 AUDIT_PIPE_SX_XUNLOCK(ap); in audit_pipe_read()
922 error = cv_wait_sig(&ap->ap_cv, AUDIT_PIPE_MTX(ap)); in audit_pipe_read()
924 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_read()
925 AUDIT_PIPE_SX_XUNLOCK(ap); in audit_pipe_read()
937 ap->ap_reads++; in audit_pipe_read()
938 while ((ape = TAILQ_FIRST(&ap->ap_queue)) != NULL && in audit_pipe_read()
940 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_read()
942 KASSERT(ape->ape_record_len > ap->ap_qoffset, in audit_pipe_read()
944 toread = MIN(ape->ape_record_len - ap->ap_qoffset, in audit_pipe_read()
946 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_read()
947 error = uiomove((char *)ape->ape_record + ap->ap_qoffset, in audit_pipe_read()
950 AUDIT_PIPE_SX_XUNLOCK(ap); in audit_pipe_read()
958 AUDIT_PIPE_LOCK(ap); in audit_pipe_read()
959 KASSERT(TAILQ_FIRST(&ap->ap_queue) == ape, in audit_pipe_read()
961 ap->ap_qoffset += toread; in audit_pipe_read()
962 KASSERT(ape->ape_record_len >= ap->ap_qoffset, in audit_pipe_read()
964 if (ap->ap_qoffset == ape->ape_record_len) { in audit_pipe_read()
965 TAILQ_REMOVE(&ap->ap_queue, ape, ape_queue); in audit_pipe_read()
966 ap->ap_qbyteslen -= ape->ape_record_len; in audit_pipe_read()
968 ap->ap_qlen--; in audit_pipe_read()
969 ap->ap_qoffset = 0; in audit_pipe_read()
972 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_read()
973 AUDIT_PIPE_SX_XUNLOCK(ap); in audit_pipe_read()
983 struct audit_pipe *ap; in audit_pipe_poll() local
987 error = devfs_get_cdevpriv((void **)&ap); in audit_pipe_poll()
991 AUDIT_PIPE_LOCK(ap); in audit_pipe_poll()
992 if (TAILQ_FIRST(&ap->ap_queue) != NULL) in audit_pipe_poll()
995 selrecord(td, &ap->ap_selinfo); in audit_pipe_poll()
996 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_poll()
1007 struct audit_pipe *ap; in audit_pipe_kqfilter() local
1010 error = devfs_get_cdevpriv((void **)&ap); in audit_pipe_kqfilter()
1017 kn->kn_hook = ap; in audit_pipe_kqfilter()
1019 AUDIT_PIPE_LOCK(ap); in audit_pipe_kqfilter()
1020 knlist_add(&ap->ap_selinfo.si_note, kn, 1); in audit_pipe_kqfilter()
1021 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_kqfilter()
1031 struct audit_pipe *ap; in audit_pipe_kqread() local
1033 ap = (struct audit_pipe *)kn->kn_hook; in audit_pipe_kqread()
1034 AUDIT_PIPE_LOCK_ASSERT(ap); in audit_pipe_kqread()
1036 if (ap->ap_qlen != 0) { in audit_pipe_kqread()
1037 kn->kn_data = ap->ap_qbyteslen - ap->ap_qoffset; in audit_pipe_kqread()
1051 struct audit_pipe *ap; in audit_pipe_kqdetach() local
1053 ap = (struct audit_pipe *)kn->kn_hook; in audit_pipe_kqdetach()
1054 AUDIT_PIPE_LOCK(ap); in audit_pipe_kqdetach()
1055 knlist_remove(&ap->ap_selinfo.si_note, kn, 1); in audit_pipe_kqdetach()
1056 AUDIT_PIPE_UNLOCK(ap); in audit_pipe_kqdetach()