-
Notifications
You must be signed in to change notification settings - Fork 0
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
Generic Data Structures #33
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.
Looks good, added few initial comments.
09bcd6a
to
50c0649
Compare
d0d92a5
to
b0b97bd
Compare
We may need to use ordered maps instead of hash maps, so the lists of partitions are consistently ordered. |
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.
few more questions and comments
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
Also, rename NewMap to NewHashMap Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
Added an elaborated README, and changed implementation of MultiMap to use HashSet. |
BTW, I think the class ICMP is better named ICMPRule, and is a set. The file icmp.go in the netp package should only have functions that are related to ICMP proper. Such change would also solve the need to expose implementation details of the ICMP class to the ICMPSet class. |
@adisos is there anything left for me to implement/document so this PR can be merged? |
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.
few small comments and questions
return m.m.IsEmpty() | ||
} | ||
|
||
// Size returns the number of unique pairs in the Product object |
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.
the Size documentation is incorrect? it does not return the number of pairs..
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'm not sure I understand. Maybe the issue here is the notion of "pair" - here it means the mathematical pair of underlying elements, [x, y], not a pair of sets [s1, s2] (usually implicitly encoding s1 x s2, as is the case in the return value of Partitions()
).
added few small comments, still reviewing the tests and some implementation details. |
Co-authored-by: Adi Sosnovich <82078442+adisos@users.noreply.github.com>
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
interval: * Separate tests from interval_test.go * Improve documentation. * Export and set-like functions that are well defined. * Rename interval.Subtract to interval.SubtractSplit, and add tests. * Handle empty cases first. * Preallocate Elements. intervalset: * Guard Size() from overflow, and use intervalset.CalculateSize(). * Handle empty cases first. * Remove String() method, since it is not obvious; clients should implement. Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
@elazarg I'm working on optimizing SGs. I have divided all the rules according to the protocol and the remote and converted them into slices or pairs. In both cases, each unit contains one CIDR. These units are disjoint and do not overlap, thanks to the generic implementation. It would be great if there was a way to compare two CIDRs from different slices (e.g., rules with the TCP protocol vs. all protocols). Could you please also add a method to check whether two CIDRs are touching? Spec1:
In this case two rules are enough:
Spec2:
In this case three rules are sufficient because the CIDRs don't touch |
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
Isn't it what you get when you convert a set of CIDRs into an ipblock and then take the partitions of Regardless of this specific case, much of the point of the models data structures is this kind of optimization, so if it's not already supported it should probably be added later, both for specific sets (such as ipblocks) and for products, as in the case of the triple I don't want to add too many features at this point, since already this PR is huge and is a lot of work for @adisos to review. It's better merged first, and updated later. |
Signed-off-by: adisos <adisos@il.ibm.com>
I think the new types should implement basic |
Signed-off-by: adisos <adisos@il.ibm.com>
For |
And in the case of Product (and TripleSet), the string format should be less specific to the analyzer. I suggest
So the client - which might not be even aware of this library or its inner working - have an idea what's encoded. Commas can be ambiguous. |
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
pkg/netset/icmpset.go
Outdated
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 have second thoughts about restricting our model to only reason about standard ICMP types and codes.
In both firewalls mechanisms (e.g., NACL) and in actual traffic there is no such restriction.
One may write an NACL rule, denying ICMP traffic with type 20, and although this type is nonstandard, the NACL will do exactly as told: if it observes an ICMP packet with type==20 in its header (possibly tailor-made by an attacker?), the NACL will block this packet.
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.
From synthesis POV, I think the case for allowing nonstandard ICMP is likely to be unintentional. It can be denied by default, supported via a special class.
Which makes me think, for both analysis and synthesis, we can have a union of ICMPset | ICMPInvalid
. That may be better than just handling interval set everywhere in that (a) it's trivial to check and work with well defined ICMP messages and (b) it forces the handling of invalid ICMP messages to be explicit.
Regardless, I think this discussion is better deferred to a dedicated PR (before creating a new release) to make the review feasible. I will gadly work on it, if needed.
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.
Yes, checking if a given ICMP <code,type> pair is standard can be very useful in multiple places (e.g., analyzer's lint).
I prefer defining StandardICMP
as a subset of the full allowed range (0-254 for type, 0-255 for code).
A separate PR for making this change is a good idea.
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
|
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Signed-off-by: adisos <adisos@il.ibm.com>
Decompose the data structures into domain-specific and generic data structures.
The
ds
package has zero dependencies, and it knows nothing about numbers or network.Interfaces (all in
interfaces.go
):Implementations:
HashMap
- a simple adapter around a go map, allowingHashable
keys.HashSet
MultiMap
is a non-injective map. It gives a simple "inverse" on a HashMap.ProductLeft
and ProductRightis a map-based implementation of a cartesian product; it implementsProduct
as a one-to-one mapping from sets to sets, where each key-value pairs encodes the cross product of its two items.TripleSetLeft
andTripleSetRight
andTripleSetOuter
are right-, left- and outer-associative implementations ofTripleSet
.DisjointSum
is tagged-union of two sets. Go's generics place some limitations on the implementation; The empty element must always be explicitly passed to the constructor.UnitSet
is an idea - using sets of size 1 as the identity element of Product. It's probably not really helpful.The
interval
package hasinterval
andintervalset
. Nothing particularly new about them.netp
is unchanged.The
netset
package is where handles sets of network elements.ICMPSet
is largely the one proposed in Add ICMP set #23.IPBlock
is adapted to implementSet
.TCPUDPSet
is aTripleSet
ofProtocolSet
xPortSet
xPortSet
TransportSet
is a disjoint union ofTCPUDPSet
+ICMPSet
ConnectionSet
is aTripleSet
ofIPBlock
xIPBlock
xTransportSet
The package
connection
now contains the state-aware connectionset (namedSet
), and its json-formatting. In my opinion it should be moved to the analyzer.Many tests are adapted.
but some data structures do not have dedicated tests.There is no implementation of a dynamically-bounded tuple, since I could not find the proper way to fit that into a generic datastructure with a well defined degenerate edge case.
The diff is probably not useful; it should be easier to read the code.