From f087e7c5954d5be1ab4e46f8856e9f350f701451 Mon Sep 17 00:00:00 2001 From: Luo Lan Date: Thu, 25 Mar 2021 14:26:21 +0800 Subject: [PATCH 1/2] support ipv6 in antctl --- pkg/antctl/raw/traceflow/command.go | 13 +++++++++++-- pkg/antctl/raw/traceflow/command_test.go | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/antctl/raw/traceflow/command.go b/pkg/antctl/raw/traceflow/command.go index 9f1cbd98cee..9912445188f 100644 --- a/pkg/antctl/raw/traceflow/command.go +++ b/pkg/antctl/raw/traceflow/command.go @@ -89,7 +89,7 @@ func init() { Command.Flags().StringVarP(&option.destination, "destination", "D", "", "destination of the Traceflow: Namespace/Pod, Pod, Namespace/Service, Service or IP") Command.Flags().StringVarP(&option.outputType, "output", "o", "yaml", "output type: yaml (default), json") Command.Flags().BoolVarP(&option.waiting, "wait", "", true, "if false, command returns without retrieving results") - Command.Flags().StringVarP(&option.flow, "flow", "f", "", "specify the flow (packet headers) of the Traceflow packet, including tcp_src, tcp_dst, tcp_flags, udp_src, udp_dst") + Command.Flags().StringVarP(&option.flow, "flow", "f", "", "specify the flow (packet headers) of the Traceflow packet, including tcp_src, tcp_dst, tcp_flags, udp_src, udp_dst, ipv6") } func runE(cmd *cobra.Command, _ []string) error { @@ -249,9 +249,18 @@ func parseFlow() (*v1alpha1.Packet, error) { } pkt := new(v1alpha1.Packet) + _, isIPv6 := fields["ipv6"] + if isIPv6 { + pkt.IPv6Header = new(v1alpha1.IPv6Header) + } + for k, v := range protocols { if _, ok := fields[k]; ok { - pkt.IPHeader.Protocol = v + if isIPv6 { + pkt.IPv6Header.NextHeader = &v + } else { + pkt.IPHeader.Protocol = v + } break } } diff --git a/pkg/antctl/raw/traceflow/command_test.go b/pkg/antctl/raw/traceflow/command_test.go index ef7cf7ec90a..5826645546b 100644 --- a/pkg/antctl/raw/traceflow/command_test.go +++ b/pkg/antctl/raw/traceflow/command_test.go @@ -22,6 +22,8 @@ import ( "github.com/vmware-tanzu/antrea/pkg/apis/ops/v1alpha1" ) +var protocolTCP = int32(6) + // TestGetPortFields tests if a flow can be turned into a map. func TestGetPortFields(t *testing.T) { tcs := []struct { @@ -118,6 +120,24 @@ func TestParseFlow(t *testing.T) { }, }, }, + { + flow: "tcp,tcp_dst=4321,ipv6", + success: true, + expected: &v1alpha1.Traceflow{ + Spec: v1alpha1.TraceflowSpec{ + Packet: v1alpha1.Packet{ + IPv6Header: &v1alpha1.IPv6Header{ + NextHeader: &protocolTCP, + }, + TransportHeader: v1alpha1.TransportHeader{ + TCP: &v1alpha1.TCPHeader{ + DstPort: 4321, + }, + }, + }, + }, + }, + }, } for _, tc := range tcs { From 62289567253a3c8d40f4902118f8a54bd87a090e Mon Sep 17 00:00:00 2001 From: Luo Lan Date: Fri, 26 Mar 2021 15:34:40 +0800 Subject: [PATCH 2/2] fix lint issue --- docs/antctl.md | 2 +- pkg/antctl/raw/traceflow/command.go | 3 ++- pkg/antctl/raw/traceflow/command_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/antctl.md b/docs/antctl.md index 027c3bd8591..b48e528b2cf 100644 --- a/docs/antctl.md +++ b/docs/antctl.md @@ -400,7 +400,7 @@ consist of Namespace and Pod, Service or IP. The command supports yaml and json output. If users want a non blocking operation, an option: `--wait=false` can be added to start the traceflow without waiting for result. Then, the deletion operation will not be conducted. Besides, users can specify header protocol (ICMP, TCP and UDP), -source/destination ports and TCP flags. +source/destination ports and TCP flags, and can specify if it's IPv6 or not as well. For example: diff --git a/pkg/antctl/raw/traceflow/command.go b/pkg/antctl/raw/traceflow/command.go index 9912445188f..def1ffbb352 100644 --- a/pkg/antctl/raw/traceflow/command.go +++ b/pkg/antctl/raw/traceflow/command.go @@ -257,7 +257,8 @@ func parseFlow() (*v1alpha1.Packet, error) { for k, v := range protocols { if _, ok := fields[k]; ok { if isIPv6 { - pkt.IPv6Header.NextHeader = &v + protocol := v + pkt.IPv6Header.NextHeader = &protocol } else { pkt.IPHeader.Protocol = v } diff --git a/pkg/antctl/raw/traceflow/command_test.go b/pkg/antctl/raw/traceflow/command_test.go index 5826645546b..fff23b81f16 100644 --- a/pkg/antctl/raw/traceflow/command_test.go +++ b/pkg/antctl/raw/traceflow/command_test.go @@ -22,7 +22,7 @@ import ( "github.com/vmware-tanzu/antrea/pkg/apis/ops/v1alpha1" ) -var protocolTCP = int32(6) +var protocolTCP = int32(6) // TestGetPortFields tests if a flow can be turned into a map. func TestGetPortFields(t *testing.T) {