1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/fm/protocol.h> 29 30 #include <strings.h> 31 #include <libgen.h> 32 #include <regex.h> 33 #include <libnvpair.h> 34 35 #include <fmd_log_impl.h> 36 #include <fmd_log.h> 37 38 /*ARGSUSED*/ 39 int 40 fmd_log_filter_class(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 41 { 42 return (gmatch(rp->rec_class, arg)); 43 } 44 45 /*ARGSUSED*/ 46 int 47 fmd_log_filter_uuid(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 48 { 49 char *uuid; 50 51 /* 52 * Note: the uuid filter matches *any* member whose name is 'uuid'. 53 * This permits us to match not only a list.suspect uuid but any 54 * other event that decides to embed uuids, too, using the same name. 55 */ 56 return (nvlist_lookup_string(rp->rec_nvl, 57 "uuid", &uuid) == 0 && strcmp(uuid, arg) == 0); 58 } 59 60 /*ARGSUSED*/ 61 int 62 fmd_log_filter_before(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 63 { 64 uint64_t sec = ((struct timeval *)arg)->tv_sec; 65 uint64_t nsec = ((struct timeval *)arg)->tv_usec * (NANOSEC / MICROSEC); 66 return (rp->rec_sec == sec ? rp->rec_nsec <= nsec : rp->rec_sec <= sec); 67 } 68 69 /*ARGSUSED*/ 70 int 71 fmd_log_filter_after(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 72 { 73 uint64_t sec = ((struct timeval *)arg)->tv_sec; 74 uint64_t nsec = ((struct timeval *)arg)->tv_usec * (NANOSEC / MICROSEC); 75 return (rp->rec_sec == sec ? rp->rec_nsec >= nsec : rp->rec_sec >= sec); 76 } 77 78 /*ARGSUSED*/ 79 int 80 fmd_log_filter_nv(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 81 { 82 fmd_log_filter_nvarg_t *argt = (fmd_log_filter_nvarg_t *)arg; 83 char *name = argt->nvarg_name; 84 char *value = argt->nvarg_value; 85 regex_t *value_regex = argt->nvarg_value_regex; 86 nvpair_t *nvp; 87 int ai; 88 89 /* see if nvlist has named member */ 90 if (nvlist_lookup_nvpair_embedded_index(rp->rec_nvl, name, 91 &nvp, &ai, NULL) != 0) 92 return (0); /* name filter failure */ 93 94 /* check value match for matching nvpair */ 95 if ((value == NULL) || 96 (nvpair_value_match_regex(nvp, ai, value, value_regex, NULL) == 1)) 97 return (1); /* name/value filter pass */ 98 99 return (0); /* value filter failure */ 100 } 101