suricata
util-debug-filters.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2013 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \file
20 *
21 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22 *
23 * Debug filter utility functions
24 */
25
26#include "suricata-common.h"
27#include "util-debug-filters.h"
28#include "threads.h"
29#include "util-debug.h"
30
31/* both of these are defined in util-debug.c */
33extern int sc_log_module_cleaned;
34
35/* used to indicate if any FG filters are registered */
37
38/* used to indicate if any FD filters are registered */
40
41/**
42 * \brief Holds the fine-grained filters
43 */
45
46/**
47 * \brief Mutex for accessing the fine-grained filters sc_log_fg_filters
48 */
49static SCMutex sc_log_fg_filters_m[SC_LOG_FILTER_MAX] = { SCMUTEX_INITIALIZER,
51
52/**
53 * \brief Holds the function-dependent filters
54 */
55static SCLogFDFilter *sc_log_fd_filters = NULL;
56
57/**
58 * \brief Mutex for accessing the function-dependent filters sc_log_fd_filters
59 */
60static SCMutex sc_log_fd_filters_m = SCMUTEX_INITIALIZER;
61
62/**
63 * \brief Holds the thread_list required by function-dependent filters
64 */
65static SCLogFDFilterThreadList *sc_log_fd_filters_tl = NULL;
66
67/**
68 * \brief Mutex for accessing the FD thread_list sc_log_fd_filters_tl
69 */
70static SCMutex sc_log_fd_filters_tl_m = SCMUTEX_INITIALIZER;
71
72/**
73 * \brief Helper function used internally to add a FG filter
74 *
75 * \param file File_name of the filter
76 * \param function Function_name of the filter
77 * \param line Line number of the filter
78 * \param listtype The filter listtype. Can be either a blacklist or whitelist
79 * filter listtype(SC_LOG_FILTER_BL or SC_LOG_FILTER_WL)
80 *
81 * \retval 0 on successfully adding the filter;
82 * \retval -1 on failure
83 */
84static int SCLogAddFGFilter(const char *file, const char *function,
85 int line, int listtype)
86{
87 SCLogFGFilterFile *fgf_file = NULL;
88 SCLogFGFilterFile *prev_fgf_file = NULL;
89
90 SCLogFGFilterFunc *fgf_func = NULL;
91 SCLogFGFilterFunc *prev_fgf_func = NULL;
92
93 SCLogFGFilterLine *fgf_line = NULL;
94 SCLogFGFilterLine *prev_fgf_line = NULL;
95
96 int found = 0;
97
99 printf("Logging module not initialized. Call SCLogInitLogModule() "
100 "first before using the debug API\n");
101 return -1 ;
102 }
103
104 if (file == NULL && function == NULL && line < 0) {
105 printf("Error: Invalid arguments supplied to SCLogAddFGFilter\n");
106 return -1;
107 }
108
109 SCMutex *m = &sc_log_fg_filters_m[listtype];
110
111 SCMutexLock(m);
112
113 fgf_file = sc_log_fg_filters[listtype];
114
115 prev_fgf_file = fgf_file;
116 while (fgf_file != NULL) {
117 prev_fgf_file = fgf_file;
118 if (file == NULL && fgf_file->file == NULL)
119 found = 1;
120 else if (file != NULL && fgf_file->file != NULL)
121 found = (strcmp(file, fgf_file->file) == 0);
122 else
123 found = 0;
124
125 if (found == 1)
126 break;
127
128 fgf_file = fgf_file->next;
129 }
130
131 if (found == 0) {
132 SCLogAddToFGFFileList(prev_fgf_file, file, function, line, listtype);
133 goto done;
134 }
135
136 found = 0;
137 fgf_func = fgf_file->func;
138 prev_fgf_func = fgf_func;
139 while (fgf_func != NULL) {
140 prev_fgf_func = fgf_func;
141 if (function == NULL && fgf_func->func == NULL)
142 found = 1;
143 else if (function != NULL && fgf_func->func != NULL)
144 found = (strcmp(function, fgf_func->func) == 0);
145 else
146 found = 0;
147
148 if (found == 1)
149 break;
150
151 fgf_func = fgf_func->next;
152 }
153
154 if (found == 0) {
155 SCLogAddToFGFFuncList(fgf_file, prev_fgf_func, function, line);
156 goto done;
157 }
158
159 found = 0;
160 fgf_line = fgf_func->line;
161 prev_fgf_line = fgf_line;
162 while(fgf_line != NULL) {
163 prev_fgf_line = fgf_line;
164 if (line == fgf_line->line) {
165 found = 1;
166 break;
167 }
168
169 fgf_line = fgf_line->next;
170 }
171
172 if (found == 0) {
173 SCLogAddToFGFLineList(fgf_func, prev_fgf_line, line);
174 goto done;
175 }
176
177 done:
178 SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
180
181 return 0;
182}
183
184/**
185 * \brief Internal function used to check for matches against registered FG
186 * filters. Checks if there is a match for the incoming log_message with
187 * any of the FG filters. Based on whether the filter type is whitelist
188 * or blacklist, the function allows the message to be logged or not.
189 *
190 * \param file File_name from where the log_message originated
191 * \param function Function_name from where the log_message originated
192 * \param line Line number from where the log_message originated
193 * \param listtype The filter listtype. Can be either a blacklist or whitelist
194 * filter listtype(SC_LOG_FILTER_BL or SC_LOG_FILTER_WL)
195 *
196 * \retval 1 if there is a match
197 * \retval 0 on no match
198 * \retval -1 on failure
199 */
200static int SCLogMatchFGFilter(const char *file, const char *function, int line,
201 int listtype)
202{
203 SCLogFGFilterFile *fgf_file = NULL;
204 SCLogFGFilterFunc *fgf_func = NULL;
205 SCLogFGFilterLine *fgf_line = NULL;
206 int match = 1;
207
208 if (sc_log_module_initialized != 1) {
209 printf("Logging module not initialized. Call SCLogInitLogModule() "
210 "first before using the debug API\n");
211 return -1;
212 }
213
214 SCMutexLock(&sc_log_fg_filters_m[listtype]);
215
216 fgf_file = sc_log_fg_filters[listtype];
217
218 if (fgf_file == NULL) {
219 SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
220 return 1;
221 }
222
223 while(fgf_file != NULL) {
224 match = 1;
225
226 match &= (fgf_file->file != NULL)? !strcmp(file, fgf_file->file): 1;
227
228 if (match == 0) {
229 fgf_file = fgf_file->next;
230 continue;
231 }
232
233 fgf_func = fgf_file->func;
234 while (fgf_func != NULL) {
235 match = 1;
236
237 match &= (fgf_func->func != NULL)? !strcmp(function, fgf_func->func): 1;
238
239 if (match == 0) {
240 fgf_func = fgf_func->next;
241 continue;
242 }
243
244 fgf_line = fgf_func->line;
245 while (fgf_line != NULL) {
246 match = 1;
247
248 match &= (fgf_line->line != -1)? (line == fgf_line->line): 1;
249
250 if (match == 1)
251 break;
252
253 fgf_line = fgf_line->next;
254 }
255
256 if (match == 1)
257 break;
258
259 fgf_func = fgf_func->next;
260 }
261
262 if (match == 1) {
263 SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
264 if (listtype == SC_LOG_FILTER_WL)
265 return 1;
266 else
267 return 0;
268 }
269
270 fgf_file = fgf_file->next;
271 }
272
273 SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
274
275 if (listtype == SC_LOG_FILTER_WL)
276 return 0;
277 else
278 return 1;
279}
280
281/**
282 * \brief Checks if there is a match for the incoming log_message with any
283 * of the FG filters. If there is a match, it allows the message
284 * to be logged, else it rejects that message.
285 *
286 * \param file File_name from where the log_message originated
287 * \param function Function_name from where the log_message originated
288 * \param line Line number from where the log_message originated
289 *
290 * \retval 1 if there is a match
291 * \retval 0 on no match
292 * \retval -1 on failure
293 */
294int SCLogMatchFGFilterWL(const char *file, const char *function, int line)
295{
296 return SCLogMatchFGFilter(file, function, line, SC_LOG_FILTER_WL);
297}
298
299/**
300 * \brief Checks if there is a match for the incoming log_message with any
301 * of the FG filters. If there is a match it rejects the logging
302 * for that messages, else it allows that message to be logged
303 *
304 * \param file File_name from where the log_message originated
305 * \param function Function_name from where the log_message originated
306 * \param line Line number from where the log_message originated
307 *
308 * \retval 1 if there is a match
309 * \retval 0 on no match
310 * \retval -1 on failure
311 */
312int SCLogMatchFGFilterBL(const char *file, const char *function, int line)
313{
314 return SCLogMatchFGFilter(file, function, line, SC_LOG_FILTER_BL);
315}
316
317/**
318 * \brief Adds a Blacklist(BL) fine-grained(FG) filter. A FG filter BL filter
319 * allows messages that don't match this filter, to be logged, while the
320 * filter is defined using a file_name, function_name and line_number
321 *
322 * If a particular parameter in the fg-filter(file, function and line),
323 * shouldn't be considered while logging the message, one can supply
324 * NULL for the file_name or function_name and a negative line_no.
325 *
326 * \param file File_name of the filter
327 * \param function Function_name of the filter
328 * \param line Line number of the filter
329 *
330 * \retval 0 on successfully adding the filter
331 * \retval -1 on failure
332 */
333int SCLogAddFGFilterBL(const char *file, const char *function, int line)
334{
335 return SCLogAddFGFilter(file, function, line, SC_LOG_FILTER_BL);
336}
337
339{
340 SCLogFGFilterFile *fgf_file = NULL;
341 SCLogFGFilterFunc *fgf_func = NULL;
342 SCLogFGFilterLine *fgf_line = NULL;
343
344 void *temp = NULL;
345
346 int i = 0;
347
348 for (i = 0; i < SC_LOG_FILTER_MAX; i++) {
349 SCMutexLock(&sc_log_fg_filters_m[i]);
350
351 fgf_file = sc_log_fg_filters[i];
352 while (fgf_file != NULL) {
353
354 fgf_func = fgf_file->func;
355 while (fgf_func != NULL) {
356
357 fgf_line = fgf_func->line;
358 while(fgf_line != NULL) {
359 temp = fgf_line;
360 fgf_line = fgf_line->next;
361 SCFree(temp);
362 }
363
364 if (fgf_func->func != NULL)
365 SCFree(fgf_func->func);
366 temp = fgf_func;
367 fgf_func = fgf_func->next;
368 SCFree(temp);
369 }
370
371 if (fgf_file->file != NULL)
372 SCFree(fgf_file->file);
373 temp = fgf_file;
374 fgf_file = fgf_file->next;
375 SCFree(temp);
376 }
377
378 SCMutexUnlock(&sc_log_fg_filters_m[i]);
379 sc_log_fg_filters[i] = NULL;
380 }
381}
382
383/**
384 * \brief Prints the FG filters(both WL and BL). Used for debugging purposes.
385 *
386 * \retval count The no of FG filters
387 */
389{
390 SCLogFGFilterFile *fgf_file = NULL;
391 SCLogFGFilterFunc *fgf_func = NULL;
392 SCLogFGFilterLine *fgf_line = NULL;
393
394 int count = 0;
395 int i = 0;
396
397 if (sc_log_module_initialized != 1) {
398 printf("Logging module not initialized. Call SCLogInitLogModule() "
399 "first before using the debug API\n");
400 return 0;
401 }
402
403#ifdef DEBUG
404 printf("Fine grained filters:\n");
405#endif
406
407 for (i = 0; i < SC_LOG_FILTER_MAX; i++) {
408 SCMutexLock(&sc_log_fg_filters_m[i]);
409
410 fgf_file = sc_log_fg_filters[i];
411 while (fgf_file != NULL) {
412
413 fgf_func = fgf_file->func;
414 while (fgf_func != NULL) {
415
416 fgf_line = fgf_func->line;
417 while(fgf_line != NULL) {
418#ifdef DEBUG
419 printf("%s - ", fgf_file->file);
420 printf("%s - ", fgf_func->func);
421 printf("%d\n", fgf_line->line);
422#endif
423
424 count++;
425
426 fgf_line = fgf_line->next;
427 }
428
429 fgf_func = fgf_func->next;
430 }
431
432 fgf_file = fgf_file->next;
433 }
434 SCMutexUnlock(&sc_log_fg_filters_m[i]);
435 }
436
437 return count;
438}
439
440
441
442/* --------------------------------------------------|--------------------------
443 * -------------------------- Code for the FD Filter |--------------------------
444 * --------------------------------------------------V--------------------------
445 */
446
447/**
448 * \brief Checks if there is a match for the incoming log_message with any
449 * of the FD filters
450 *
451 * \param function Function_name from where the log_message originated
452 *
453 * \retval 1 if there is a match
454 * \retval 0 on no match;
455 */
456int SCLogMatchFDFilter(const char *function)
457{
458#ifndef DEBUG
459 return 1;
460#else
461 SCLogFDFilterThreadList *thread_list = NULL;
462
463 pthread_t self = pthread_self();
464
465 if (sc_log_module_initialized != 1) {
466 printf("Logging module not initialized. Call SCLogInitLogModule() "
467 "first before using the debug API\n");
468 return 0;
469 }
470
471 SCMutexLock(&sc_log_fd_filters_tl_m);
472
473 if (sc_log_fd_filters_tl == NULL) {
474 SCMutexUnlock(&sc_log_fd_filters_tl_m);
475 if (sc_log_fd_filters != NULL)
476 return 0;
477 return 1;
478 }
479
480 thread_list = sc_log_fd_filters_tl;
481 while (thread_list != NULL) {
482 if (pthread_equal(self, thread_list->t)) {
483 if (thread_list->entered > 0) {
484 SCMutexUnlock(&sc_log_fd_filters_tl_m);
485 return 1;
486 }
487 SCMutexUnlock(&sc_log_fd_filters_tl_m);
488 return 0;
489 }
490
491 thread_list = thread_list->next;
492 }
493
494 SCMutexUnlock(&sc_log_fd_filters_tl_m);
495
496 return 0;
497#endif
498}
499
500/**
501 * \brief Updates a FD filter, based on whether the function that calls this
502 * function, is registered as a FD filter or not. This is called by
503 * a function only on its entry
504 *
505 * \param function Function_name from where the log_message originated
506 *
507 * \retval 1 Since it is a hack to get things working inside the macros
508 */
509int SCLogCheckFDFilterEntry(const char *function)
510{
511 SCLogFDFilter *curr = NULL;
512
513 SCLogFDFilterThreadList *thread_list = NULL;
514 SCLogFDFilterThreadList *thread_list_temp = NULL;
515
516 //pid_t self = syscall(SYS_gettid);
517 pthread_t self = pthread_self();
518
519 if (sc_log_module_initialized != 1) {
520 printf("Logging module not initialized. Call SCLogInitLogModule() "
521 "first before using the debug API\n");
522 return 0;
523 }
524
525 SCMutexLock(&sc_log_fd_filters_m);
526
527 curr = sc_log_fd_filters;
528
529 while (curr != NULL) {
530 if (strcmp(function, curr->func) == 0)
531 break;
532
533 curr = curr->next;
534 }
535
536 if (curr == NULL) {
537 SCMutexUnlock(&sc_log_fd_filters_m);
538 return 1;
539 }
540
541 SCMutexUnlock(&sc_log_fd_filters_m);
542
543 SCMutexLock(&sc_log_fd_filters_tl_m);
544
545 thread_list = sc_log_fd_filters_tl;
546 while (thread_list != NULL) {
547 if (pthread_equal(self, thread_list->t))
548 break;
549
550 thread_list = thread_list->next;
551 }
552
553 if (thread_list != NULL) {
554 thread_list->entered++;
555 SCMutexUnlock(&sc_log_fd_filters_tl_m);
556 return 1;
557 }
558
559 if ((thread_list_temp = SCCalloc(1, sizeof(SCLogFDFilterThreadList))) == NULL) {
560 SCMutexUnlock(&sc_log_fd_filters_tl_m);
561 return 0;
562 }
563
564 thread_list_temp->t = self;
565 thread_list_temp->entered++;
566
567 sc_log_fd_filters_tl = thread_list_temp;
568
569 SCMutexUnlock(&sc_log_fd_filters_tl_m);
570
571 return 1;
572}
573
574/**
575 * \brief Updates a FD filter, based on whether the function that calls this
576 * function, is registered as a FD filter or not. This is called by
577 * a function only before its exit.
578 *
579 * \param function Function_name from where the log_message originated
580 *
581 */
582void SCLogCheckFDFilterExit(const char *function)
583{
584 SCLogFDFilter *curr = NULL;
585
586 SCLogFDFilterThreadList *thread_list = NULL;
587
588 //pid_t self = syscall(SYS_gettid);
589 pthread_t self = pthread_self();
590
591 if (sc_log_module_initialized != 1) {
592 printf("Logging module not initialized. Call SCLogInitLogModule() "
593 "first before using the debug API\n");
594 return;
595 }
596
597 SCMutexLock(&sc_log_fd_filters_m);
598
599 curr = sc_log_fd_filters;
600
601 while (curr != NULL) {
602 if (strcmp(function, curr->func) == 0)
603 break;
604
605 curr = curr->next;
606 }
607
608 if (curr == NULL) {
609 SCMutexUnlock(&sc_log_fd_filters_m);
610 return;
611 }
612
613 SCMutexUnlock(&sc_log_fd_filters_m);
614
615 SCMutexLock(&sc_log_fd_filters_tl_m);
616
617 thread_list = sc_log_fd_filters_tl;
618 while (thread_list != NULL) {
619 if (pthread_equal(self, thread_list->t))
620 break;
621
622 thread_list = thread_list->next;
623 }
624
625 SCMutexUnlock(&sc_log_fd_filters_tl_m);
626
627 if (thread_list != NULL)
628 thread_list->entered--;
629}
630
631/**
632 * \brief Adds a Function-Dependent(FD) filter
633 *
634 * \param Name of the function for which a FD filter has to be registered
635 *
636 * \retval 0 on success
637 * \retval -1 on failure
638 */
639int SCLogAddFDFilter(const char *function)
640{
641 SCLogFDFilter *curr = NULL;
642 SCLogFDFilter *prev = NULL;
643 SCLogFDFilter *temp = NULL;
644
645 if (sc_log_module_initialized != 1) {
646 printf("Logging module not initialized. Call SCLogInitLogModule() "
647 "first before using the debug API\n");
648 return -1;
649 }
650
651 if (function == NULL) {
652 printf("Invalid argument supplied to SCLogAddFDFilter\n");
653 return -1;
654 }
655
656 SCMutexLock(&sc_log_fd_filters_m);
657
658 curr = sc_log_fd_filters;
659 while (curr != NULL) {
660 prev = curr;
661
662 if (strcmp(function, curr->func) == 0) {
663
664 SCMutexUnlock(&sc_log_fd_filters_m);
665 return 0;
666 }
667
668 curr = curr->next;
669 }
670
671 if ((temp = SCCalloc(1, sizeof(SCLogFDFilter))) == NULL) {
672 printf("Error Allocating memory (SCCalloc)\n");
673 exit(EXIT_FAILURE);
674 }
675
676 if ( (temp->func = SCStrdup(function)) == NULL) {
677 printf("Error Allocating memory (SCStrdup)\n");
678 exit(EXIT_FAILURE);
679 }
680
681 if (sc_log_fd_filters == NULL)
682 sc_log_fd_filters = temp;
683 /* clang thinks prev can be NULL, but it can't be unless
684 * sc_log_fd_filters is also NULL which is handled here.
685 * Doing this "fix" to shut clang up. */
686 else if (prev != NULL)
687 prev->next = temp;
688
689 SCMutexUnlock(&sc_log_fd_filters_m);
691
692 return 0;
693}
694
695/**
696 * \brief Releases all the FD filters added to the logging module
697 */
699{
700 SCLogFDFilter *fdf = NULL;
701 SCLogFDFilter *temp = NULL;
702
703 SCMutexLock(&sc_log_fd_filters_m);
704
705 fdf = sc_log_fd_filters;
706 while (fdf != NULL) {
707 temp = fdf;
708 fdf = fdf->next;
710 }
711
712 sc_log_fd_filters = NULL;
713
714 SCMutexUnlock(&sc_log_fd_filters_m);
715}
716
717/**
718 * \brief Removes a Function-Dependent(FD) filter
719 *
720 * \param Name of the function for which a FD filter has to be unregistered
721 *
722 * \retval 0 on success(the filter was removed or the filter was not present)
723 * \retval -1 on failure/error
724 */
725int SCLogRemoveFDFilter(const char *function)
726{
727 SCLogFDFilter *curr = NULL;
728 SCLogFDFilter *prev = NULL;
729
730 if (sc_log_module_initialized != 1) {
731 printf("Logging module not initialized. Call SCLogInitLogModule() "
732 "first before using the debug API\n");
733 return -1 ;
734 }
735
736 if (function == NULL) {
737 printf("Invalid argument(s) supplied to SCLogRemoveFDFilter\n");
738 return -1;
739 }
740
741 SCMutexLock(&sc_log_fd_filters_m);
742
743 if (sc_log_fd_filters == NULL) {
744 SCMutexUnlock(&sc_log_fd_filters_m);
745 return 0;
746 }
747
748 curr = sc_log_fd_filters;
749 prev = curr;
750 while (curr != NULL) {
751 if (strcmp(function, curr->func) == 0)
752 break;
753
754 prev = curr;
755 curr = curr->next;
756 }
757
758 if (curr == NULL) {
759
760 SCMutexUnlock(&sc_log_fd_filters_m);
761
762 return 0;
763 }
764
765 if (sc_log_fd_filters == curr)
766 sc_log_fd_filters = curr->next;
767 else
768 prev->next = curr->next;
769
771
772 SCMutexUnlock(&sc_log_fd_filters_m);
773
774 if (sc_log_fd_filters == NULL)
776
777 return 0;
778}
779
780/**
781 * \brief Prints the FG filters(both WL and BL). Used for debugging purposes.
782 *
783 * \retval count The no of FG filters
784 */
786{
787 SCLogFDFilter *fdf = NULL;
788 int count = 0;
789
790 if (sc_log_module_initialized != 1) {
791 printf("Logging module not initialized. Call SCLogInitLogModule() "
792 "first before using the debug API\n");
793 return 0;
794 }
795
796#ifdef DEBUG
797 printf("FD filters:\n");
798#endif
799
800 SCMutexLock(&sc_log_fd_filters_m);
801
802 fdf = sc_log_fd_filters;
803 while (fdf != NULL) {
804#ifdef DEBUG
805 printf("%s \n", fdf->func);
806#endif
807 fdf = fdf->next;
808 count++;
809 }
810
811 SCMutexUnlock(&sc_log_fd_filters_m);
812
813 return count;
814}
815
816/**
817 * \brief Helper function used internally to add a FG filter. This function is
818 * called when the file component of the incoming filter has no entry
819 * in the filter list.
820 *
821 * \param fgf_file The file component(basically the position in the list) from
822 * the filter list, after which the new filter has to be added
823 * \param file File_name of the filter
824 * \param function Function_name of the filter
825 * \param line Line number of the filter
826 * \param listtype The filter listtype. Can be either a blacklist or whitelist
827 * filter listtype(SC_LOG_FILTER_BL or SC_LOG_FILTER_WL)
828 */
830 const char *file,
831 const char *function, int line,
832 int listtype)
833{
834 SCLogFGFilterFile *fgf_file_temp = NULL;
835 SCLogFGFilterFunc *fgf_func_temp = NULL;
836 SCLogFGFilterLine *fgf_line_temp = NULL;
837
838 if ((fgf_file_temp = SCCalloc(1, sizeof(SCLogFGFilterFile))) == NULL) {
839 FatalError("Fatal error encountered in SCLogAddToFGFFileList. Exiting...");
840 }
841
842 if ( file != NULL && (fgf_file_temp->file = SCStrdup(file)) == NULL) {
843 printf("Error Allocating memory\n");
844 exit(EXIT_FAILURE);
845 }
846
847 if ((fgf_func_temp = SCCalloc(1, sizeof(SCLogFGFilterFunc))) == NULL) {
848 FatalError("Fatal error encountered in SCLogAddToFGFFileList. Exiting...");
849 }
850
851 if ( function != NULL && (fgf_func_temp->func = SCStrdup(function)) == NULL) {
852 printf("Error Allocating memory\n");
853 exit(EXIT_FAILURE);
854 }
855
856 if ((fgf_line_temp = SCCalloc(1, sizeof(SCLogFGFilterLine))) == NULL) {
857 FatalError("Fatal error encountered in SCLogAddToFGFFileList. Exiting...");
858 }
859
860 fgf_line_temp->line = line;
861
862 /* add to the lists */
863 fgf_func_temp->line = fgf_line_temp;
864
865 fgf_file_temp->func = fgf_func_temp;
866
867 if (fgf_file == NULL)
868 sc_log_fg_filters[listtype] = fgf_file_temp;
869 else
870 fgf_file->next = fgf_file_temp;
871}
872
873/**
874 * \brief Helper function used internally to add a FG filter. This function is
875 * called when the file component of the incoming filter has an entry
876 * in the filter list, but the function component doesn't have an entry
877 * for the corresponding file component
878 *
879 * \param fgf_file The file component from the filter list to which the new
880 * filter has to be added
881 * \param fgf_func The function component(basically the position in the list),
882 * from the filter list, after which the new filter has to be
883 * added
884 * \param function Function_name of the filter
885 * \param line Line number of the filter
886 */
888 SCLogFGFilterFunc *fgf_func,
889 const char *function, int line)
890{
891 SCLogFGFilterFunc *fgf_func_temp = NULL;
892 SCLogFGFilterLine *fgf_line_temp = NULL;
893
894 if ((fgf_func_temp = SCCalloc(1, sizeof(SCLogFGFilterFunc))) == NULL) {
895 FatalError("Fatal error encountered in SCLogAddToFGFFuncList. Exiting...");
896 }
897
898 if ( function != NULL && (fgf_func_temp->func = SCStrdup(function)) == NULL) {
899 printf("Error Allocating memory\n");
900 exit(EXIT_FAILURE);
901 }
902
903 if ((fgf_line_temp = SCCalloc(1, sizeof(SCLogFGFilterLine))) == NULL) {
904 FatalError("Fatal error encountered in SCLogAddToFGFFuncList. Exiting...");
905 }
906
907 fgf_line_temp->line = line;
908
909 /* add to the lists */
910 fgf_func_temp->line = fgf_line_temp;
911
912 if (fgf_func == NULL)
913 fgf_file->func = fgf_func_temp;
914 else
915 fgf_func->next = fgf_func_temp;
916}
917
918/**
919 * \brief Helper function used internally to add a FG filter. This function is
920 * called when the file and function components of the incoming filter
921 * have an entry in the filter list, but the line component doesn't have
922 * an entry for the corresponding function component
923 *
924 * \param fgf_func The function component from the filter list to which the new
925 * filter has to be added
926 * \param fgf_line The function component(basically the position in the list),
927 * from the filter list, after which the new filter has to be
928 * added
929 * \param line Line number of the filter
930 */
932 SCLogFGFilterLine *fgf_line,
933 int line)
934{
935 SCLogFGFilterLine *fgf_line_temp = NULL;
936
937 if ((fgf_line_temp = SCCalloc(1, sizeof(SCLogFGFilterLine))) == NULL) {
938 FatalError("Fatal error encountered in SCLogAddToFGFLineList. Exiting...");
939 }
940
941 fgf_line_temp->line = line;
942
943 /* add to the lists */
944 if (fgf_line == NULL)
945 fgf_func->line = fgf_line_temp;
946 else
947 fgf_line->next = fgf_line_temp;
948}
949
950/**
951 * \brief Releases the memory alloted to a FD filter
952 *
953 * \param Pointer to the FD filter that has to be freed
954 */
956{
957 if (fdf != NULL) {
958 if (fdf->func != NULL)
959 SCFree(fdf->func);
960 SCFree(fdf);
961 }
962}
SCMutex m
Definition flow-hash.h:6
Structure used to hold the thread_list used by FD filters.
struct SCLogFDFilterThreadList_ * next
Structure that holds the FD filters.
struct SCLogFDFilter_ * next
Structure used to hold FG filters. Encapsulates filename details, func details, which inturn encapsul...
SCLogFGFilterFunc * func
struct SCLogFGFilterFile_ * next
structure used to hold the function details of a FG filter
SCLogFGFilterLine * line
struct SCLogFGFilterFunc_ * next
Structure used to hold the line_no details of a FG filter.
struct SCLogFGFilterLine_ * next
#define SCMUTEX_INITIALIZER
#define SCMutex
#define SCMutexUnlock(mut)
#define SCMutexLock(mut)
int SCLogMatchFGFilterWL(const char *file, const char *function, int line)
Checks if there is a match for the incoming log_message with any of the FG filters....
void SCLogAddToFGFLineList(SCLogFGFilterFunc *fgf_func, SCLogFGFilterLine *fgf_line, int line)
Helper function used internally to add a FG filter. This function is called when the file and functio...
int sc_log_fd_filters_present
int sc_log_module_cleaned
Used to indicate whether the logging module has been cleaned or not.
Definition util-debug.c:111
int SCLogMatchFDFilter(const char *function)
Checks if there is a match for the incoming log_message with any of the FD filters.
void SCLogAddToFGFFuncList(SCLogFGFilterFile *fgf_file, SCLogFGFilterFunc *fgf_func, const char *function, int line)
Helper function used internally to add a FG filter. This function is called when the file component o...
void SCLogReleaseFDFilters(void)
Releases all the FD filters added to the logging module.
void SCLogAddToFGFFileList(SCLogFGFilterFile *fgf_file, const char *file, const char *function, int line, int listtype)
Helper function used internally to add a FG filter. This function is called when the file component o...
int SCLogCheckFDFilterEntry(const char *function)
Updates a FD filter, based on whether the function that calls this function, is registered as a FD fi...
int SCLogPrintFGFilters(void)
Prints the FG filters(both WL and BL). Used for debugging purposes.
int sc_log_module_initialized
Used to indicate whether the logging module has been init or not.
Definition util-debug.c:106
int SCLogMatchFGFilterBL(const char *file, const char *function, int line)
Checks if there is a match for the incoming log_message with any of the FG filters....
int sc_log_fg_filters_present
void SCLogReleaseFGFilters(void)
int SCLogAddFDFilter(const char *function)
Adds a Function-Dependent(FD) filter.
int SCLogRemoveFDFilter(const char *function)
Removes a Function-Dependent(FD) filter.
int SCLogPrintFDFilters(void)
Prints the FG filters(both WL and BL). Used for debugging purposes.
int SCLogAddFGFilterBL(const char *file, const char *function, int line)
Adds a Blacklist(BL) fine-grained(FG) filter. A FG filter BL filter allows messages that don't match ...
SCLogFGFilterFile * sc_log_fg_filters[SC_LOG_FILTER_MAX]
Holds the fine-grained filters.
void SCLogReleaseFDFilter(SCLogFDFilter *fdf)
Releases the memory alloted to a FD filter.
void SCLogCheckFDFilterExit(const char *function)
Updates a FD filter, based on whether the function that calls this function, is registered as a FD fi...
@ SC_LOG_FILTER_MAX
@ SC_LOG_FILTER_BL
@ SC_LOG_FILTER_WL
#define FatalError(...)
Definition util-debug.h:510
#define SCFree(p)
Definition util-mem.h:61
#define SCCalloc(nm, sz)
Definition util-mem.h:53
#define SCStrdup(s)
Definition util-mem.h:56