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

[part 1/n] Introduce vtable-based dispatch #213

Merged
merged 15 commits into from
Jun 6, 2022

Conversation

gnosek
Copy link
Contributor

@gnosek gnosek commented Feb 16, 2022

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area driver-kmod

/area driver-ebpf

/area libscap

/area libsinsp

/area tests

/area proposals

What this PR does / why we need it:

This is the first in a series of PRs that aim to encapsulate all engine-specific behavior of libscap behind a series of vtables, instead of ifs and #ifdefs.

The motivation is:

  • to clean up the code and make it more maintainable
  • to enable alternative instrumentation engines

Special notes for your reviewer:

This PR (temporarily) makes things much uglier and is just the first one in a series. With this PR, the most important scap functions are routed through a vtable, if present. This PR creates separate implementations for the nodriver, source_plugin and udig engines. eBPF, kmod and savefile are still TODO, as are additional vtables, which are used mostly at initialization time.

Does this PR introduce a user-facing change?:

NONE

userspace/libscap/scap.c Outdated Show resolved Hide resolved
userspace/libscap/scap.h Outdated Show resolved Hide resolved
@FedeDP
Copy link
Contributor

FedeDP commented Feb 17, 2022

All in all, it looks quite good to me as an intermediate step!
I want to gather some more feedback by other maintainers before approving this, but IMO this is a +1.

@gnosek
Copy link
Contributor Author

gnosek commented Feb 17, 2022

This is a bigger discussion I suppose, do you want to see the end result (or at least some future steps) before merging part 1 or do you trust me that we won't end up in worse shape than we already are? ;)

@jasondellaluce
Copy link
Contributor

This is looking good!

@leogr
Copy link
Member

leogr commented Feb 18, 2022

This is a bigger discussion I suppose, do you want to see the end result (or at least some future steps) before merging part 1 or do you trust me that we won't end up in worse shape than we already are? ;)

I trust you 💙

@FedeDP
Copy link
Contributor

FedeDP commented Feb 18, 2022

This is a bigger discussion I suppose, do you want to see the end result (or at least some future steps) before merging part 1 or do you trust me that we won't end up in worse shape than we already are? ;)

I trust you blue_heart

Me too 💟

Comment on lines 1192 to 1196
// eventually, it will contain a pointer to a struct containing
// only the engine-specific bits
struct scap_engine_handle {
struct scap* m_handle;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the comment, it seems like this struct, that now contains a pointer to the global scap handler, will contain a single pointer to the engine-specific context. My question is, what's the advantage of having a structure with a single member instead of a single opaque pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it made some type safety easier (fewer casts between void* and a concrete T*). But I agree it's not too pretty so I'll try and see if just using a pointer works.

(note: in the public header, we don't really know what the type of the opaque handle is--that's the point of being an opaque handle :D)

@LucaGuerra
Copy link
Contributor

This will make maintaining and extending libscap so much easier! 🚀

@LucaGuerra
Copy link
Contributor

I believe this can go in as I find this to be a much better way of handling the system call providers we have. The only question I had was about the handle, but if you feel that doing it like proposed makes casting and type safety easier it's absolutely fine :)

@gnosek gnosek changed the title [part 1/n] Introduce vtable-based dispatch wip: [part 1/n] Introduce vtable-based dispatch Mar 17, 2022
@Andreagit97
Copy link
Member

Wow! This is huge! Thank you @gnosek for all this work, I can't wait to see it merged 😍 🚀

gnosek added 13 commits May 25, 2022 17:42
This way we can have multiple implementations of platform-specific
functions instead of `#ifdef`s all over the place

Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Almost everything can be overridden, which we'll need
once we switch eBPF to use it too.

Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana poiana added the lgtm label Jun 6, 2022
@poiana
Copy link
Contributor

poiana commented Jun 6, 2022

LGTM label has been added.

Git tree hash: f9d603cd78d90942d5d21de20b45e2e46db008eb

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Jun 6, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, gnosek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,gnosek]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Andreagit97
Copy link
Member

/retest

@FedeDP
Copy link
Contributor

FedeDP commented Jun 6, 2022

/unhold

@FedeDP
Copy link
Contributor

FedeDP commented Jun 6, 2022

/test build-libs

@poiana poiana merged commit fed8ce3 into falcosecurity:master Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants