Server IP : 103.169.32.36 / Your IP : 216.73.217.13 Web Server : Apache System : Linux web.dpmptsp 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : apache ( 48) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/opt/eset/efs/eventd/eset_rtp/ |
Upload File : |
| Current File : /var/opt/eset/efs/eventd/eset_rtp/ertp_event_container.c |
/*
* eset_rtp (ESET Real-time file system protection module)
* Copyright (C) 1992-2023 ESET, spol. s r.o.
*
* 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 3 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. If not, see <https://www.gnu.org/licenses/>.
*
* In case of any questions, you can contact us at ESET, spol. s r.o., Einsteinova 24, 851 01 Bratislava, Slovakia.
*/
#include "ertp_event_container.h"
#include "ertp_event.h"
#include "ertp_logs.h"
#include <linux/slab.h>
int ertp_event_container_init(struct ertp_event_container *container) {
container->items = kzalloc(sizeof(struct list_head), GFP_KERNEL);
if (!container->items) {
return -ENOMEM;
}
INIT_LIST_HEAD(container->items);
container->prepared_events_start = NULL;
return 0;
};
void ertp_event_container_deinit(struct ertp_event_container *container) {
kfree(container->items);
container->prepared_events_start = NULL;
};
void ertp_event_container_swap(struct ertp_event_container *a,
struct ertp_event_container *b) {
struct list_head *items_tmp = a->items;
struct list_head *prepared_events_start_tmp = a->prepared_events_start;
a->items = b->items;
a->prepared_events_start = b->prepared_events_start;
b->items = items_tmp;
b->prepared_events_start = prepared_events_start_tmp;
};
static inline void move_prepared_events_start(
struct ertp_event_container *container) {
if (!list_is_last(container->prepared_events_start, container->items)) {
container->prepared_events_start = container->prepared_events_start->next;
} else {
container->prepared_events_start = NULL;
}
}
void ertp_event_container_prepared_add(struct ertp_event_container *container,
struct ertp_event *event) {
ertp_event_ref(event);
list_add_tail(&event->req_list, container->items);
if (!container->prepared_events_start) {
container->prepared_events_start = container->items->prev;
}
}
void ertp_event_container_prepared_add_first(
struct ertp_event_container *container, struct ertp_event *event) {
ertp_event_ref(event);
if (container->prepared_events_start) {
list_add_tail(&event->req_list, container->prepared_events_start);
container->prepared_events_start = container->prepared_events_start->prev;
} else {
list_add_tail(&event->req_list, container->items);
container->prepared_events_start = &event->req_list;
}
}
static void remove_from_list_and_unref(struct ertp_event *event) {
if (!list_empty(&event->req_list)) {
list_del_init(&event->req_list);
ertp_event_unref(event);
}
}
void ertp_event_container_remove(struct ertp_event_container *container,
struct ertp_event *event) {
if (!event) {
return;
}
if (&event->req_list == container->prepared_events_start) {
move_prepared_events_start(container);
}
remove_from_list_and_unref(event);
}
struct ertp_event *ertp_event_container_find_by_info(
const struct ertp_event_container *container,
const struct ertp_event_generic_info *event_info) {
struct ertp_event *event;
list_for_each_entry(event, container->items, req_list) {
if (event->has_same_info(event, event_info)) {
return ertp_event_ref(event);
}
}
return NULL;
}
struct ertp_event *ertp_event_container_find_by_path(
const struct ertp_event_container *container, const struct path *path) {
struct ertp_event *event;
list_for_each_entry_reverse(event, container->items, req_list) {
if (event->has_same_path(event, path)) {
return ertp_event_ref(event);
}
}
return NULL;
}
void ertp_event_container_clear(struct ertp_event_container *container) {
struct ertp_event *event;
struct ertp_event *tmp;
list_for_each_entry_safe(event, tmp, container->items, req_list) {
ertp_pr_log(ERTP_LOG_EVENTS,
"event with id %d removed on scanner disconnect", event->id);
remove_from_list_and_unref(event);
}
container->prepared_events_start = NULL;
}
struct ertp_event *ertp_event_container_scanner_add_next(
struct ertp_event_container *container) {
struct ertp_event *event;
if (unlikely(list_empty(container->items) &&
container->prepared_events_start)) {
BUG();
}
if (!container->prepared_events_start) {
return NULL;
}
event =
list_entry(container->prepared_events_start, struct ertp_event, req_list);
ertp_event_ref(event);
move_prepared_events_start(container);
return event;
}
static struct ertp_event *find_event_in_scanner(
struct ertp_event_container *container, int32_t id) {
struct ertp_event *event;
struct list_head *pos;
list_for_each(pos, container->items) {
if (pos == container->prepared_events_start) {
return NULL;
}
event = list_entry(pos, struct ertp_event, req_list);
if (event->id == id) {
return event;
}
}
return NULL;
}
struct ertp_event *ertp_event_container_scanner_remove(
struct ertp_event_container *container, int32_t id) {
struct ertp_event *event = find_event_in_scanner(container, id);
if (likely(event)) {
list_del_init(&event->req_list);
} else {
ertp_pr_warning("event with id %d not found", id);
}
return event;
}
void ertp_event_container_scanner_unblock_all(
struct ertp_event_container *container) {
struct ertp_event *event;
struct list_head *pos;
struct list_head *tmp;
list_for_each_safe(pos, tmp, container->items) {
if (pos == container->prepared_events_start) {
break;
}
event = list_entry(pos, struct ertp_event, req_list);
list_del_init(&event->req_list);
ertp_event_unblock(event);
ertp_event_unref(event);
}
}