]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/log_filter.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / log_filter.c
index 721e57a62804cdd1678f2b30b623ded72bd43867..e8d99d79254d67f0a551a6a306fd0efe8f0662e7 100644 (file)
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Logging - Filtered file log target
  * Copyright (C) 2019 Cumulus Networks, Inc.
  *                    Stephen Worley
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -43,14 +30,14 @@ static int zlog_filter_lookup(const char *lookup)
 
 void zlog_filter_clear(void)
 {
-       frr_with_mutex(&logfilterlock) {
+       frr_with_mutex (&logfilterlock) {
                zlog_filter_count = 0;
        }
 }
 
 int zlog_filter_add(const char *filter)
 {
-       frr_with_mutex(&logfilterlock) {
+       frr_with_mutex (&logfilterlock) {
                if (zlog_filter_count >= ZLOG_FILTERS_MAX)
                        return 1;
 
@@ -74,7 +61,7 @@ int zlog_filter_add(const char *filter)
 
 int zlog_filter_del(const char *filter)
 {
-       frr_with_mutex(&logfilterlock) {
+       frr_with_mutex (&logfilterlock) {
                int found_idx = zlog_filter_lookup(filter);
                int last_idx = zlog_filter_count - 1;
 
@@ -96,7 +83,7 @@ int zlog_filter_dump(char *buf, size_t max_size)
 {
        int len = 0;
 
-       frr_with_mutex(&logfilterlock) {
+       frr_with_mutex (&logfilterlock) {
                for (int i = 0; i < zlog_filter_count; i++) {
                        int ret;
 
@@ -111,13 +98,14 @@ int zlog_filter_dump(char *buf, size_t max_size)
        return len;
 }
 
-static int search_buf(const char *buf)
+static int search_buf(const char *buf, size_t len)
 {
        char *found = NULL;
 
-       frr_with_mutex(&logfilterlock) {
+       frr_with_mutex (&logfilterlock) {
                for (int i = 0; i < zlog_filter_count; i++) {
-                       found = strstr(buf, zlog_filters[i]);
+                       found = memmem(buf, len, zlog_filters[i],
+                                      strlen(zlog_filters[i]));
                        if (found != NULL)
                                return 0;
                }
@@ -131,12 +119,15 @@ static void zlog_filterfile_fd(struct zlog_target *zt, struct zlog_msg *msgs[],
 {
        struct zlog_msg *msgfilt[nmsgs];
        size_t i, o = 0;
+       const char *text;
+       size_t text_len;
 
        for (i = 0; i < nmsgs; i++) {
-               if (zlog_msg_prio(msgs[i]) >= LOG_DEBUG
-                   && search_buf(zlog_msg_text(msgs[i], NULL)) < 0)
-                       continue;
-
+               if (zlog_msg_prio(msgs[i]) >= LOG_DEBUG) {
+                       text = zlog_msg_text(msgs[i], &text_len);
+                       if (search_buf(text, text_len) < 0)
+                               continue;
+               }
                msgfilt[o++] = msgs[i];
        }