Skip to content
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

support ipv6 in antctl #1995

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/antctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
14 changes: 12 additions & 2 deletions pkg/antctl/raw/traceflow/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/antctl/raw/traceflow/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down