-
Notifications
You must be signed in to change notification settings - Fork 297
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
santad: Allow configuring a static set of rules via configuration profile #846
Conversation
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.
Overall looks good, some minor things.
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.
LGTM.
@@ -549,6 +560,21 @@ - (void)setRemountUSBMode:(NSArray<NSString *> *)args { | |||
return args; | |||
} | |||
|
|||
- (NSDictionary<NSString *, SNTRule *> *)staticRules { | |||
NSArray *currentRules = self.configState[kStaticRules]; |
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.
We need to make sure this is indeed an NSArray.
@@ -549,6 +560,21 @@ - (void)setRemountUSBMode:(NSArray<NSString *> *)args { | |||
return args; | |||
} | |||
|
|||
- (NSDictionary<NSString *, SNTRule *> *)staticRules { | |||
NSArray *currentRules = self.configState[kStaticRules]; | |||
if (currentRules.hash != self.cachedStaticRulesHash) { |
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.
How expensive is this hashing? For a really large set I can see the cost adding up since we need to hash for every exec. Instead of initializing lazily here we should move the parsing closer to when the rules are added to the profile. We could add a new property for the unprocessed rules and KVO observe changes. We could do the parsing there. This method turns into a fast getter for the current set of rules.
|
||
self = [super init]; | ||
if (self) { | ||
_identifier = dict[kRuleIdentifier]; |
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.
Anything we get out of the dictionary we can’t trust. We need to check the types are what we expect.
In #846 I forgot that is only a count of the entries so if the config changes but the number of rules remains the same we would never update the cache. This PR moves the processing of the raw config into the KVO handler code so it is not at all in the hot-path.
This PR adds a new top-level configuration key
StaticRules
that allows setting a static set of rules utilized before any rules in the database. This allows for 2 things:Fixes #777 and #285