Skip to content

Commit

Permalink
refactor(userspace/libsinsp)!: drop support to protodecoders
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Nov 24, 2023
1 parent 7611bb8 commit d9a7511
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 871 deletions.
1 change: 0 additions & 1 deletion userspace/chisel/chisel_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ limitations under the License.
#include "utils.h"
#include "chisel.h"
#include "chisel_utils.h"
#include "protodecoder.h"

#ifndef PATH_MAX
#define PATH_MAX 4096
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ set(SINSP_SOURCES
plugin_table_api.cpp
plugin_filtercheck.cpp
prefix_search.cpp
protodecoder.cpp
sinsp_syslog.cpp
threadinfo.cpp
tuples.cpp
sinsp.cpp
Expand Down
68 changes: 0 additions & 68 deletions userspace/libsinsp/fdinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ template<> sinsp_fdinfo_t::sinsp_fdinfo()
{
m_type = SCAP_FD_UNINITIALIZED;
m_flags = FLAGS_NONE;
m_callbacks = NULL;
m_usrstate = NULL;
m_name = "";
m_name_raw = "";
Expand All @@ -47,8 +46,6 @@ template<> void sinsp_fdinfo_t::reset()
{
m_type = SCAP_FD_UNINITIALIZED;
m_flags = FLAGS_NONE;
delete(m_callbacks);
m_callbacks = NULL;
m_usrstate = NULL;
m_name = "";
m_name_raw = "";
Expand Down Expand Up @@ -271,71 +268,6 @@ template<> scap_l4_proto sinsp_fdinfo_t::get_l4proto()
}
}

template<> void sinsp_fdinfo_t::register_event_callback(sinsp_pd_callback_type etype, sinsp_protodecoder* dec)
{
if(this->m_callbacks == NULL)
{
m_callbacks = new fd_callbacks_info();
}

switch(etype)
{
case CT_READ:
m_callbacks->m_read_callbacks.push_back(dec);
break;
case CT_WRITE:
m_callbacks->m_write_callbacks.push_back(dec);
break;
default:
ASSERT(false);
break;
}

return;
}

template<> void sinsp_fdinfo_t::unregister_event_callback(sinsp_pd_callback_type etype, sinsp_protodecoder* dec)
{
std::vector<sinsp_protodecoder*>::iterator it;

if(m_callbacks == NULL)
{
ASSERT(false);
return;
}

switch(etype)
{
case CT_READ:
for(it = m_callbacks->m_read_callbacks.begin(); it != m_callbacks->m_read_callbacks.end(); ++it)
{
if(*it == dec)
{
m_callbacks->m_read_callbacks.erase(it);
return;
}
}

break;
case CT_WRITE:
for(it = m_callbacks->m_write_callbacks.begin(); it != m_callbacks->m_write_callbacks.end(); ++it)
{
if(*it == dec)
{
m_callbacks->m_write_callbacks.erase(it);
return;
}
}

break;
default:
ASSERT(false);
break;
}

return;
}

///////////////////////////////////////////////////////////////////////////////
// sinsp_fdtable implementation
///////////////////////////////////////////////////////////////////////////////
Expand Down
58 changes: 11 additions & 47 deletions userspace/libsinsp/fdinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
*/

#pragma once
#include "sinsp_pd_callback_type.h"

#include "tuples.h"

#include <unordered_map>
#include <vector>

Expand All @@ -27,8 +29,6 @@ limitations under the License.
#define CANCELED_FD_NUMBER std::numeric_limits<int64_t>::max()
#endif

class sinsp_protodecoder;

// fd type characters
#define CHAR_FD_FILE 'f'
#define CHAR_FD_IPV4_SOCK '4'
Expand Down Expand Up @@ -66,13 +66,6 @@ typedef union _sinsp_sockinfo
unix_tuple m_unixinfo; ///< The tuple if this a unix socket.
}sinsp_sockinfo;

class fd_callbacks_info
{
public:
std::vector<sinsp_protodecoder*> m_write_callbacks;
std::vector<sinsp_protodecoder*> m_read_callbacks;
};

/*!
\brief File Descriptor information class.
This class contains the full state for a FD, and a bunch of functions to
Expand All @@ -94,11 +87,6 @@ class SINSP_PUBLIC sinsp_fdinfo

~sinsp_fdinfo()
{
if(m_callbacks != NULL)
{
delete m_callbacks;
}

if(m_usrstate != NULL)
{
delete m_usrstate;
Expand Down Expand Up @@ -130,27 +118,12 @@ class SINSP_PUBLIC sinsp_fdinfo

if(free_state)
{
if(m_callbacks != NULL)
{
delete m_callbacks;
}

if(m_usrstate != NULL)
{
delete m_usrstate;
}
}

if(other.m_callbacks != NULL)
{
m_callbacks = new fd_callbacks_info();
*m_callbacks = *other.m_callbacks;
}
else
{
m_callbacks = NULL;
}

if(other.m_usrstate != NULL)
{
m_usrstate = new T(*other.m_usrstate);
Expand Down Expand Up @@ -180,6 +153,14 @@ class SINSP_PUBLIC sinsp_fdinfo
*/
std::string tostring_clean();

/*!
\brief Return true if this is a log device.
*/
inline bool is_syslog() const
{
return m_name.find("/dev/log") != std::string::npos;
}

/*!
\brief Returns true if this is a unix socket.
*/
Expand Down Expand Up @@ -306,16 +287,6 @@ class SINSP_PUBLIC sinsp_fdinfo
*/
scap_l4_proto get_l4proto();

/*!
\brief Used by protocol decoders to register callbacks related to this FD.
*/
void register_event_callback(sinsp_pd_callback_type etype, sinsp_protodecoder* dec);

/*!
\brief Used by protocol decoders to unregister callbacks related to this FD.
*/
void unregister_event_callback(sinsp_pd_callback_type etype, sinsp_protodecoder* dec);

/*!
\brief Return true if this FD is a socket server
*/
Expand Down Expand Up @@ -373,11 +344,6 @@ class SINSP_PUBLIC sinsp_fdinfo
std::string m_name_raw; // Human readable rendering of this FD. See m_name, only used if fd is a file path. Path is kept "raw" with limited sanitization and without absolute path derivation.
std::string m_oldname; // The name of this fd at the beginning of event parsing. Used to detect name changes that result from parsing an event.

inline bool has_decoder_callbacks()
{
return (m_callbacks != NULL);
}

/*!
\brief FD flags.
*/
Expand Down Expand Up @@ -518,8 +484,6 @@ class SINSP_PUBLIC sinsp_fdinfo
uint32_t m_mount_id;
uint64_t m_ino;
int64_t m_pid; // only if fd is a pidfd

fd_callbacks_info* m_callbacks;
};

/*@}*/
Expand Down
Loading

0 comments on commit d9a7511

Please sign in to comment.