-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
policy: Add ICMP and ICMPv6 API with feature flag
This commit implements ICMP/ICMPv6 API for CNP and CCNP. The `icmp` field is added to CNP and CCNP manifests, and policy can be added by setting ICMP type to that field. Currentlly, this ICMP CNP feature is disabled by default because of the kernel complexity issue, and it is enabled when the "enable-icmp-rule" hidden flag is set. Example manifest: ``` apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: "cnp-icmp" spec: endpointSelector: matchLabels: org: empire class: deathstar ingress: - fromEndpoints: - matchLabels: org: empire icmps: - fields: - type: 8 # ICMPv6 - type: 128 family: IPv6 ``` Signed-off-by: Tomoki Sugiura <cheztomo513@gmail.com>
- Loading branch information
1 parent
98b5fb3
commit 0bb3eed
Showing
19 changed files
with
1,408 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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
274 changes: 274 additions & 0 deletions
274
pkg/k8s/apis/cilium.io/client/crds/v2/ciliumclusterwidenetworkpolicies.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
274 changes: 274 additions & 0 deletions
274
pkg/k8s/apis/cilium.io/client/crds/v2/ciliumnetworkpolicies.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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,107 @@ | ||
// Copyright 2021 Authors of Cilium | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package api | ||
|
||
import "strconv" | ||
|
||
const ( | ||
IPv4Family = "IPv4" | ||
IPv6Family = "IPv6" | ||
) | ||
|
||
type ICMPRules []ICMPRule | ||
|
||
// ICMPRule is a list of ICMP fields. | ||
type ICMPRule struct { | ||
// Fields is a list of ICMP fields. | ||
// | ||
// +kubebuilder:validation:Optional | ||
Fields []ICMPField `json:"fields,omitempty"` | ||
} | ||
|
||
// ICMPField is a ICMP field. | ||
type ICMPField struct { | ||
// Family is a IP address version. | ||
// Currently, we support `IPv4` and `IPv6`. | ||
// `IPv4` is set as default. | ||
// | ||
// +kubebuilder:default=IPv4 | ||
// +kubebuilder:validation:Optional | ||
// +kubebuilder:validation:Enum=IPv4;IPv6 | ||
Family string `json:"family,omitempty"` | ||
|
||
// Type is a ICMP-type. | ||
// It should be 0-255 (8bit). | ||
// | ||
// +kubebuilder:validation:Maximum=255 | ||
// +kubebuilder:validation:Minimum=0 | ||
Type uint8 `json:"type"` | ||
} | ||
|
||
// Iterate iterates over all elements of ICMPRules. | ||
func (ir ICMPRules) Iterate(f func(pr Ports) error) error { | ||
for i := range ir { | ||
if err := f(&ir[i]); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// Len returns the length of the elements of ICMPRules. | ||
func (ir ICMPRules) Len() int { | ||
return len(ir) | ||
} | ||
|
||
// GetPortProtocols generates PortProtocol slice from ICMPRule and returns it. | ||
func (ir ICMPRule) GetPortProtocols() []PortProtocol { | ||
var pps []PortProtocol | ||
for _, t := range ir.Fields { | ||
pp := t.PortProtocol() | ||
pps = append(pps, *pp) | ||
} | ||
return pps | ||
} | ||
|
||
// GetPortRule generates PortRule from ICMPRule and returns it. | ||
func (ir ICMPRule) GetPortRule() *PortRule { | ||
var pps []PortProtocol | ||
for _, t := range ir.Fields { | ||
pp := t.PortProtocol() | ||
pps = append(pps, *pp) | ||
} | ||
pr := PortRule{ | ||
Ports: pps, | ||
} | ||
return &pr | ||
} | ||
|
||
// PortProtocol translates ICMPType to PortProtocol. | ||
func (i ICMPField) PortProtocol() *PortProtocol { | ||
var proto L4Proto | ||
|
||
typeStr := strconv.Itoa(int(i.Type)) | ||
if i.Family == IPv6Family { | ||
proto = ProtoICMPv6 | ||
} else { | ||
proto = ProtoICMP | ||
} | ||
|
||
pr := PortProtocol{ | ||
Port: typeStr, | ||
Protocol: proto, | ||
} | ||
return &pr | ||
} |
This file contains 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 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
Oops, something went wrong.