-
Notifications
You must be signed in to change notification settings - Fork 25
Ovalenti/rox 29399 directional ext i ps jv 2 #2142
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
Open
JoukoVirtanen
wants to merge
16
commits into
master
Choose a base branch
from
ovalenti/ROX-29399-directional-extIPs-jv-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ae32b56
Use the working version of the proto defs
ovalenti d4c351c
External-IPs can be enabled just in one direction
ovalenti 7195315
Additional unit tests with ingres and egress directions
ovalenti 13f2ef5
Rewrite to make the logic clearer
ovalenti 2e17cf4
Move ExternalIPsConfig to its own file.
ovalenti 41109ea
Directly make use of the ExternalIPsConfig in ConnTracker
ovalenti a4faa05
Trigger afterglow early connection close independently for each direc…
ovalenti bb0afb6
Move config change detection logic to Conntracker
ovalenti 36fb9f4
Refactor: limit the number of public methods and improve readability
ovalenti a42d526
Extract config to variable for more readability
ovalenti 9b8ae8a
Factorize the lambda content
ovalenti 75384fb
Use the finalized version of the proto defs
ovalenti 5ea1a23
Document runtime-config and the `direction` attribute
ovalenti 26e1b99
X-Smart-Branch-Parent: ovalenti/ROX-29399-directional-extIPs
JoukoVirtanen a873d4a
Fixed issue with NONE. Added tests that check for the problem
JoukoVirtanen bf62f72
Added a couple of unit tests
JoukoVirtanen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
#include "ExternalIPsConfig.h" | ||
|
||
namespace collector { | ||
|
||
ExternalIPsConfig::ExternalIPsConfig(std::optional<sensor::CollectorConfig> runtime_config, bool default_enabled) { | ||
if (!runtime_config.has_value()) { | ||
direction_enabled_ = default_enabled ? Direction::BOTH : Direction::NONE; | ||
return; | ||
} | ||
|
||
// At this point we know runtime_config has a value, we can access it directly | ||
const auto& external_ips = runtime_config->networking().external_ips(); | ||
if (external_ips.enabled() != sensor::ExternalIpsEnabled::ENABLED) { | ||
direction_enabled_ = Direction::NONE; | ||
return; | ||
} | ||
|
||
switch (external_ips.direction()) { | ||
case sensor::ExternalIpsDirection::INGRESS: | ||
direction_enabled_ = Direction::INGRESS; | ||
break; | ||
case sensor::ExternalIpsDirection::EGRESS: | ||
direction_enabled_ = Direction::EGRESS; | ||
break; | ||
default: | ||
direction_enabled_ = Direction::BOTH; | ||
break; | ||
} | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const ExternalIPsConfig& config) { | ||
os << "direction("; | ||
|
||
switch (config.GetDirection()) { | ||
case ExternalIPsConfig::Direction::NONE: | ||
os << "NONE"; | ||
break; | ||
case ExternalIPsConfig::Direction::INGRESS: | ||
os << "INGRESS"; | ||
break; | ||
case ExternalIPsConfig::Direction::EGRESS: | ||
os << "EGRESS"; | ||
break; | ||
case ExternalIPsConfig::Direction::BOTH: | ||
os << "BOTH"; | ||
break; | ||
default: | ||
os << "invalid"; | ||
break; | ||
} | ||
|
||
return os << ")"; | ||
} | ||
|
||
} // namespace collector |
This file contains hidden or 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 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <ostream> | ||
|
||
#include <internalapi/sensor/collector.pb.h> | ||
|
||
namespace collector { | ||
|
||
// Encapsulates the configuration of the External-IPs feature | ||
class ExternalIPsConfig { | ||
public: | ||
enum Direction { | ||
NONE = 1 << 2, | ||
INGRESS = 1 << 0, | ||
EGRESS = 1 << 1, | ||
BOTH = INGRESS | EGRESS, | ||
}; | ||
|
||
// Are External-IPs enabled in the provided direction ? | ||
bool IsEnabled(Direction direction) const { return (direction & direction_enabled_) == direction; } | ||
|
||
// Direction in which External-IPs are enabled | ||
Direction GetDirection() const { return direction_enabled_; } | ||
|
||
// Extract the External-IPs configuration from the provided runtime-conf. | ||
// If the runtime-configuration is unset then 'default_enabled' is used | ||
// as a fallback to enable in both directions. | ||
// 'runtime_config' should be locked prior to calling. | ||
ExternalIPsConfig(std::optional<sensor::CollectorConfig> runtime_config, bool default_enabled); | ||
|
||
ExternalIPsConfig(Direction direction = Direction::NONE) : direction_enabled_(direction) {} | ||
|
||
private: | ||
Direction direction_enabled_; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const ExternalIPsConfig& config); | ||
|
||
} // end namespace collector |
This file contains hidden or 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
Submodule stackrox
updated
3556 files
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to change
IsEnabled
like this:On a different note, I don't think
IsEnabled(Direction::NONE)
is something anyone would write, so I'm not convinced the extra overhead for the check is worth it. Maybe we can do a static check instead?Or, if a compile time check is not possible, then just use good old
assert
to make the invariant explicit.