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 9f1cbd98cee..def1ffbb352 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,19 @@ 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 { + protocol := v + pkt.IPv6Header.NextHeader = &protocol + } 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..fff23b81f16 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 {