diff --git a/agent/handlers/v4/response.go b/agent/handlers/v4/response.go index e563078d2d4..a0e926e1a4d 100644 --- a/agent/handlers/v4/response.go +++ b/agent/handlers/v4/response.go @@ -14,8 +14,6 @@ package v4 import ( - "net" - "github.com/aws/amazon-ecs-agent/agent/api" apitask "github.com/aws/amazon-ecs-agent/agent/api/task" "github.com/aws/amazon-ecs-agent/agent/containermetadata" @@ -168,12 +166,6 @@ func toV4NetworkResponse( // task. func newNetworkInterfaceProperties(task *apitask.Task) (NetworkInterfaceProperties, error) { eni := task.GetPrimaryENI() - _, ipv4Net, err := net.ParseCIDR(eni.SubnetGatewayIPV4Address) - if err != nil { - return NetworkInterfaceProperties{}, errors.Wrapf(err, - "v4 metadata response: unable to parse subnet ipv4 address '%s'", - eni.SubnetGatewayIPV4Address) - } var attachmentIndexPtr *int if task.IsNetworkModeAWSVPC() { @@ -186,7 +178,8 @@ func newNetworkInterfaceProperties(task *apitask.Task) (NetworkInterfaceProperti // `Index` field for an ENI, we should set it as per that. Since we // only support 1 ENI per task anyway, setting it to `0` is acceptable AttachmentIndex: attachmentIndexPtr, - IPV4SubnetCIDRBlock: ipv4Net.String(), + IPV4SubnetCIDRBlock: eni.GetIPv4SubnetCIDRBlock(), + IPv6SubnetCIDRBlock: eni.GetIPv6SubnetCIDRBlock(), MACAddress: eni.MacAddress, DomainNameServers: eni.DomainNameServers, DomainNameSearchList: eni.DomainNameSearchList, diff --git a/agent/handlers/v4/response_test.go b/agent/handlers/v4/response_test.go index c88c38a1b8b..c32b2e441ec 100644 --- a/agent/handlers/v4/response_test.go +++ b/agent/handlers/v4/response_test.go @@ -45,6 +45,9 @@ const ( cpu = 1024 memory = 512 eniIPv4Address = "192.168.0.5" + ipv4SubnetCIDRBlock = "192.168.0.0/24" + eniIPv6Address = "2600:1f18:619e:f900:8467:78b2:81c4:207d" + ipv6SubnetCIDRBlock = "2600:1f18:619e:f900::/64" subnetGatewayIPV4Address = "192.168.0.1/24" volName = "volume1" volSource = "/var/lib/volume1" @@ -73,6 +76,11 @@ func TestNewTaskContainerResponses(t *testing.T) { Address: eniIPv4Address, }, }, + IPV6Addresses: []*apieni.ENIIPV6Address{ + { + Address: eniIPv6Address, + }, + }, SubnetGatewayIPV4Address: subnetGatewayIPV4Address, }, }, @@ -130,7 +138,9 @@ func TestNewTaskContainerResponses(t *testing.T) { _, err = json.Marshal(taskResponse) require.NoError(t, err) assert.Equal(t, created.UTC().String(), taskResponse.Containers[0].CreatedAt.String()) - assert.Equal(t, "192.168.0.0/24", taskResponse.Containers[0].Networks[0].IPV4SubnetCIDRBlock) + assert.Equal(t, ipv4SubnetCIDRBlock, taskResponse.Containers[0].Networks[0].IPV4SubnetCIDRBlock) + assert.Equal(t, eniIPv6Address, taskResponse.Containers[0].Networks[0].IPv6Addresses[0]) + assert.Equal(t, ipv6SubnetCIDRBlock, taskResponse.Containers[0].Networks[0].IPv6SubnetCIDRBlock) assert.Equal(t, subnetGatewayIPV4Address, taskResponse.Containers[0].Networks[0].SubnetGatewayIPV4Address) gomock.InOrder(