-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Grzegorz Nosek <[email protected]>
- Loading branch information
Showing
5 changed files
with
104 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "devset.h" | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
#ifndef _WIN32 | ||
#include <sys/mman.h> | ||
#endif | ||
|
||
#include "../../common/strlcpy.h" | ||
#include "../scap.h" | ||
#include "../scap-int.h" | ||
|
||
int32_t devset_init(struct scap_device_set *devset, size_t num_devs, char *lasterr) | ||
{ | ||
devset->m_ndevs = num_devs; | ||
|
||
devset->m_devs = (scap_device*) calloc(sizeof(scap_device), devset->m_ndevs); | ||
if(!devset->m_devs) | ||
{ | ||
strlcpy(lasterr, "error allocating the device handles", SCAP_LASTERR_SIZE); | ||
return SCAP_FAILURE; | ||
} | ||
|
||
for(size_t j = 0; j < num_devs; ++j) | ||
{ | ||
devset->m_devs[j].m_buffer = MAP_FAILED; | ||
devset->m_devs[j].m_bufinfo = MAP_FAILED; | ||
devset->m_devs[j].m_bufstatus = MAP_FAILED; | ||
devset->m_devs[j].m_fd = -1; | ||
devset->m_devs[j].m_bufinfo_fd = -1; | ||
devset->m_devs[j].m_lastreadsize = 0; | ||
devset->m_devs[j].m_sn_len = 0; | ||
} | ||
devset->m_buffer_empty_wait_time_us = BUFFER_EMPTY_WAIT_TIME_US_START; | ||
devset->m_lasterr = lasterr; | ||
|
||
return SCAP_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright (C) 2022 The Falco Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
struct ppm_ring_buffer_info; | ||
struct udig_ring_buffer_status; | ||
|
||
// | ||
// The device descriptor | ||
// | ||
typedef struct scap_device | ||
{ | ||
int m_fd; | ||
int m_bufinfo_fd; // used by udig | ||
char* m_buffer; | ||
uint32_t m_buffer_size; // used by udig | ||
uint32_t m_lastreadsize; | ||
char* m_sn_next_event; // Pointer to the next event available for scap_next | ||
uint32_t m_sn_len; // Number of bytes available in the buffer pointed by m_sn_next_event | ||
union | ||
{ | ||
// Anonymous struct with ppm stuff | ||
struct | ||
{ | ||
struct ppm_ring_buffer_info* m_bufinfo; | ||
struct udig_ring_buffer_status* m_bufstatus; // used by udig | ||
}; | ||
}; | ||
} scap_device; | ||
|
||
struct scap_device_set | ||
{ | ||
scap_device* m_devs; | ||
uint32_t m_ndevs; | ||
uint64_t m_buffer_empty_wait_time_us; | ||
char* m_lasterr; | ||
}; | ||
|
||
int32_t devset_init(struct scap_device_set *devset, size_t num_devs, char *lasterr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters