Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for new field types in plugins #1005

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,8 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string &errstr)
strlcpy(tf.m_display, fdisplay.c_str(), sizeof(tf.m_display));
strlcpy(tf.m_description, fdesc.c_str(), sizeof(tf.m_description));
tf.m_print_format = PF_DEC;

if (ftype == "string") {
tf.m_type = PT_CHARBUF;
} else if (ftype == "uint64") {
tf.m_type = PT_UINT64;
if(m_pt_lut.find(ftype) != m_pt_lut.end()) {
tf.m_type = m_pt_lut.at(ftype);
} else {
throw sinsp_exception(
string("error in plugin ") + name() + ": invalid field type " + ftype);
Expand Down
14 changes: 14 additions & 0 deletions userspace/libsinsp/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ class sinsp_plugin
private:
ss_plugin_t* m_state;
plugin_handle_t* m_handle;
//
// Plugin Type Look Up Table
//
const std::unordered_map<std::string, ppm_param_type> m_pt_lut = {
{"string", PT_CHARBUF},
{"uint64", PT_UINT64},
{"reltime", PT_RELTIME},
{"abstime", PT_ABSTIME},
{"bool", PT_BOOL},
{"ipv4addr", PT_IPV4ADDR},
{"ipv4net", PT_IPV4NET},
{"ipv6addr", PT_IPV6ADDR},
{"ipv6net", PT_IPV6NET},
};

/** Event Sourcing **/
scap_source_plugin m_scap_source_plugin;
Expand Down
24 changes: 21 additions & 3 deletions userspace/libsinsp/plugin_filtercheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,34 @@ bool sinsp_filter_check_plugin::extract(sinsp_evt *evt, OUT vector<extract_value
extract_value_t res;
switch(type)
{
case PT_UINT64:
case PT_RELTIME:
case PT_ABSTIME:
{
res.len = sizeof(uint64_t);
res.ptr = (uint8_t*) &efield.res.u64[i];
break;
}
// maybe these fields could use directly str instead buf
case PT_IPV4NET:
case PT_IPV6ADDR:
case PT_IPV6NET:
{
res.len = (uint32_t) efield.res.buf[i].len;
res.ptr = (uint8_t*) efield.res.buf[i].ptr;
break;
}
case PT_CHARBUF:
{
res.len = strlen(efield.res.str[i]);
res.ptr = (uint8_t*) efield.res.str[i];
break;
}
case PT_UINT64:
case PT_BOOL:
case PT_IPV4ADDR:
{
res.len = sizeof(uint64_t);
res.ptr = (uint8_t*) &efield.res.u64[i];
res.len = sizeof(uint32_t);
res.ptr = (uint8_t*) &efield.res.u32[i];
break;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions userspace/plugin/plugin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
// API versions of this plugin framework
//
#define PLUGIN_API_VERSION_MAJOR 2
#define PLUGIN_API_VERSION_MINOR 0
#define PLUGIN_API_VERSION_MINOR 1
#define PLUGIN_API_VERSION_PATCH 0

//
Expand Down Expand Up @@ -387,4 +387,4 @@ typedef struct

#ifdef __cplusplus
}
#endif
#endif
10 changes: 9 additions & 1 deletion userspace/plugin/plugin_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ typedef struct ss_plugin_event
uint64_t ts;
} ss_plugin_event;

typedef struct ss_plugin_byte_buffer{
uint32_t len;
const void* ptr;
} ss_plugin_byte_buffer;

// Used in extract_fields functions below to receive a field/arg
// pair and return an extracted value.
// field_id: id of the field, as of its index in the list of
Expand Down Expand Up @@ -126,6 +131,9 @@ typedef struct ss_plugin_extract_field
{
const char** str;
uint64_t* u64;
uint32_t* u32;
bool* boolean;
ss_plugin_byte_buffer* buf;
} res;
uint64_t res_len;

Expand Down Expand Up @@ -162,4 +170,4 @@ typedef void ss_instance_t;

#ifdef __cplusplus
}
#endif
#endif