Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: wgrayson <[email protected]>
  • Loading branch information
GraysonWu committed Apr 12, 2022
1 parent fcc1a9f commit 177bb9d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
28 changes: 14 additions & 14 deletions pkg/apis/crd/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ const (
// List the supported protocols and their codes in traceflow.
// According to code in Antrea agent and controller, default protocol is ICMP if protocol is not inputted by users.
const (
ICMPProtocol int32 = 1
TCPProtocol int32 = 6
UDPProtocol int32 = 17
SCTPProtocol int32 = 132
ICMPProtocolNumber int32 = 1
TCPProtocolNumber int32 = 6
UDPProtocolNumber int32 = 17
SCTPProtocolNumber int32 = 132
)

var SupportedProtocols = map[string]int32{
"TCP": TCPProtocol,
"UDP": UDPProtocol,
"ICMP": ICMPProtocol,
"TCP": TCPProtocolNumber,
"UDP": UDPProtocolNumber,
"ICMP": ICMPProtocolNumber,
}

var ProtocolsToString = map[int32]string{
TCPProtocol: "TCP",
UDPProtocol: "UDP",
ICMPProtocol: "ICMP",
SCTPProtocol: "SCTP",
TCPProtocolNumber: "TCP",
UDPProtocolNumber: "UDP",
ICMPProtocolNumber: "ICMP",
SCTPProtocolNumber: "SCTP",
}

// List the supported destination types in traceflow.
Expand Down Expand Up @@ -608,13 +608,13 @@ type NamespacedName struct {
// NetworkPolicyProtocol defines additional protocols that are not supported by
// `ports`. All fields should be used as a standalone field.
type NetworkPolicyProtocol struct {
ICMP *ICMPProtocolSpec `json:"icmp,omitempty"`
ICMP *ICMPProtocol `json:"icmp,omitempty"`
}

// ICMPProtocolSpec matches ICMP traffic with specific ICMPType and/or ICMPCode. All
// ICMPProtocol matches ICMP traffic with specific ICMPType and/or ICMPCode. All
// fields could be used alone or together. If all fields are not provided, this
// matches all ICMP traffic.
type ICMPProtocolSpec struct {
type ICMPProtocol struct {
ICMPType *int32 `json:"icmpType,omitempty"`
ICMPCode *int32 `json:"icmpCode,omitempty"`
}
10 changes: 5 additions & 5 deletions pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/networkpolicy/antreanetworkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func TestProcessAntreaNetworkPolicy(t *testing.T) {
{
Protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{
ICMP: &crdv1alpha1.ICMPProtocol{
ICMPType: &icmpType8,
ICMPCode: &icmpCode0,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/networkpolicy/clusternetworkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ func TestAddCNP(t *testing.T) {
{
Protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{
ICMP: &crdv1alpha1.ICMPProtocol{
ICMPType: &icmpType8,
ICMPCode: &icmpCode0,
},
Expand All @@ -1896,7 +1896,7 @@ func TestAddCNP(t *testing.T) {
{
Protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{},
ICMP: &crdv1alpha1.ICMPProtocol{},
},
},
To: []crdv1alpha1.NetworkPolicyPeer{
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/networkpolicy/crd_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestToAntreaServicesForCRD(t *testing.T) {
{
protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{
ICMP: &crdv1alpha1.ICMPProtocol{
ICMPType: &icmpType8,
ICMPCode: &icmpCode0,
},
Expand All @@ -104,7 +104,7 @@ func TestToAntreaServicesForCRD(t *testing.T) {
{
protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{
ICMP: &crdv1alpha1.ICMPProtocol{
ICMPType: &icmpType8,
},
},
Expand All @@ -120,7 +120,7 @@ func TestToAntreaServicesForCRD(t *testing.T) {
{
protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{},
ICMP: &crdv1alpha1.ICMPProtocol{},
},
},
expServices: []controlplane.Service{
Expand All @@ -139,7 +139,7 @@ func TestToAntreaServicesForCRD(t *testing.T) {
},
protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{
ICMP: &crdv1alpha1.ICMPProtocol{
ICMPType: &icmpType8,
ICMPCode: &icmpCode0,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/networkpolicy/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func TestValidateAntreaPolicy(t *testing.T) {
Action: &allowAction,
Protocols: []crdv1alpha1.NetworkPolicyProtocol{
{
ICMP: &crdv1alpha1.ICMPProtocolSpec{},
ICMP: &crdv1alpha1.ICMPProtocol{},
},
},
ToServices: []crdv1alpha1.NamespacedName{
Expand Down
6 changes: 3 additions & 3 deletions plugins/octant/cmd/antrea-octant-plugin/traceflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func checkTimeout(request *service.ActionRequest) (bool, uint16) {

func updateIPHeader(tf *crdv1alpha1.Traceflow, hasSrcPort bool, hasDstPort bool, srcPort uint16, dstPort uint16) {
switch tf.Spec.Packet.IPHeader.Protocol {
case crdv1alpha1.TCPProtocol:
case crdv1alpha1.TCPProtocolNumber:
tf.Spec.Packet.TransportHeader.TCP = &crdv1alpha1.TCPHeader{
Flags: 2,
}
Expand All @@ -539,15 +539,15 @@ func updateIPHeader(tf *crdv1alpha1.Traceflow, hasSrcPort bool, hasDstPort bool,
if hasDstPort {
tf.Spec.Packet.TransportHeader.TCP.DstPort = int32(dstPort)
}
case crdv1alpha1.UDPProtocol:
case crdv1alpha1.UDPProtocolNumber:
tf.Spec.Packet.TransportHeader.UDP = &crdv1alpha1.UDPHeader{}
if hasSrcPort {
tf.Spec.Packet.TransportHeader.UDP.SrcPort = int32(srcPort)
}
if hasDstPort {
tf.Spec.Packet.TransportHeader.UDP.DstPort = int32(dstPort)
}
case crdv1alpha1.ICMPProtocol:
case crdv1alpha1.ICMPProtocolNumber:
tf.Spec.Packet.TransportHeader.ICMP = &crdv1alpha1.ICMPEchoRequestHeader{
ID: 0,
Sequence: 0,
Expand Down

0 comments on commit 177bb9d

Please sign in to comment.