-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add a Nets field, deprecate the Net field. #470
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) 2016 Tigera, Inc. All rights reserved. | ||
// Copyright (c) 2016-2017 Tigera, Inc. All rights reserved. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -75,7 +75,7 @@ type ICMPFields struct { | |
// to a particular entity (that is either the source or destination). | ||
// | ||
// A source EntityRule matches the source endpoint and originating traffic. | ||
// A desination EntityRule matches the destination endpoint and terminating traffic. | ||
// A destination EntityRule matches the destination endpoint and terminating traffic. | ||
type EntityRule struct { | ||
// Tag is an optional field that restricts the rule to only apply to traffic that | ||
// originates from (or terminates at) endpoints that have profiles with the given tag | ||
|
@@ -84,8 +84,13 @@ type EntityRule struct { | |
|
||
// Net is an optional field that restricts the rule to only apply to traffic that | ||
// originates from (or terminates at) IP addresses in the given subnet. | ||
// Deprecated: superseded by the Nets field. | ||
Net *net.IPNet `json:"net,omitempty" validate:"omitempty"` | ||
|
||
// Nets is an optional field that restricts the rule to only apply to traffic that | ||
// originates from (or terminates at) IP addresses in any of the given subnets. | ||
Nets []*net.IPNet `json:"nets,omitempty" validate:"omitempty"` | ||
|
||
// Selector is an optional field that contains a selector expression (see Policy for | ||
// sample syntax). Only traffic that originates from (terminates at) endpoints matching | ||
// the selector will be matched. | ||
|
@@ -115,9 +120,15 @@ type EntityRule struct { | |
// NotTag is the negated version of the Tag field. | ||
NotTag string `json:"notTag,omitempty" validate:"omitempty,tag"` | ||
|
||
// NotNet is the negated version of the Net field. | ||
// NotNet is an optional field that restricts the rule to only apply to traffic that | ||
// does not originate from (or terminate at) an IP address in the given subnet. | ||
// Deprecated: superseded by NotNets. | ||
NotNet *net.IPNet `json:"notNet,omitempty" validate:"omitempty"` | ||
|
||
// NotNets is an optional field that restricts the rule to only apply to traffic that | ||
// does not originate from (or terminate at) an IP address in any of the given subnets. | ||
NotNets []*net.IPNet `json:"nets,omitempty" validate:"omitempty"` | ||
|
||
// NotSelector is the negated version of the Selector field. See Selector field for | ||
// subtleties with negated selectors. | ||
NotSelector string `json:"notSelector,omitempty" validate:"omitempty,selector"` | ||
|
@@ -128,3 +139,28 @@ type EntityRule struct { | |
// Protocol match in the Rule to be set to "tcp" or "udp". | ||
NotPorts []numorstring.Port `json:"notPorts,omitempty" validate:"omitempty,dive"` | ||
} | ||
|
||
func combineNets(n *net.IPNet, nets []*net.IPNet) []*net.IPNet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a requirement to support both Maybe we could simplify this by just validating that only one of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup I agree - I think I'd suggested similar on the other PR :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @robbrockbank That was the approach I took, the validation function for the front-end does do that so a normal user shouldn't be able to hit this. I thought it was better to have felix tolerate having both in the backend though; no point dropping a policy on the floor if it has a fairly sensible interpretation. |
||
if n == nil { | ||
return nets | ||
} | ||
if len(nets) == 0 { | ||
return []*net.IPNet{n} | ||
} | ||
combined := make([]*net.IPNet, len(nets)+1) | ||
copy(combined, nets) | ||
combined[len(combined)-1] = n | ||
return combined | ||
} | ||
|
||
// GetNets returns either r.Nets or a slice containing r.Net. It is useful for unifying the | ||
// two representations. | ||
func (r EntityRule) GetNets() []*net.IPNet { | ||
return combineNets(r.Net, r.Nets) | ||
} | ||
|
||
// GetNets returns either r.NotNets or a slice containing NotNet. It is useful for unifying the | ||
// two representations. | ||
func (r EntityRule) GetNotNets() []*net.IPNet { | ||
return combineNets(r.NotNet, r.NotNets) | ||
} |
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.
Spurred by the conversation in slack - is there a good place to add a warning log when users use
Nets
, so we can indicate that it's deprecated?