@@ -20,9 +20,12 @@ import (
2020 netlibdata "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/data"
2121
2222 "github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
23+ "github.com/aws/amazon-ecs-agent/ecs-agent/logger"
2324 "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/appmesh"
25+ "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/ecscni"
2426 "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
2527 "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/serviceconnect"
28+ "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/status"
2629 "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/tasknetworkconfig"
2730
2831 "github.com/aws/aws-sdk-go/aws"
@@ -59,13 +62,29 @@ func (f *firecraker) CreateDNSConfig(taskID string, netNS *tasknetworkconfig.Net
5962 return f .configureSecondaryDNSConfig (taskID , netNS )
6063}
6164
65+ // ConfigureInterface is a firecracker-specific method that adds network interfaces to tasks running on
66+ // Firecracker microVMs. It calls a FC-specific method that configures and connect Branch ENIs to a TAP interface.
6267func (f * firecraker ) ConfigureInterface (
6368 ctx context.Context ,
6469 netNSPath string ,
6570 iface * networkinterface.NetworkInterface ,
6671 netDAO netlibdata.NetworkDataClient ,
6772) error {
68- return f .common .configureInterface (ctx , netNSPath , iface , netDAO )
73+ var err error
74+ switch iface .InterfaceAssociationProtocol {
75+ case networkinterface .DefaultInterfaceAssociationProtocol :
76+ err = f .common .configureRegularENI (ctx , netNSPath , iface )
77+ case networkinterface .VLANInterfaceAssociationProtocol :
78+ err = f .configureBranchENI (ctx , netNSPath , iface )
79+ case networkinterface .V2NInterfaceAssociationProtocol :
80+ err = f .common .configureGENEVEInterface (ctx , netNSPath , iface , netDAO )
81+ case networkinterface .VETHInterfaceAssociationProtocol :
82+ // Do nothing. Virtual Ethernet Interfaces do not need to be configured by the Linux Kernel.
83+ return nil
84+ default :
85+ err = errors .New ("invalid interface association protocol " + iface .InterfaceAssociationProtocol )
86+ }
87+ return err
6988}
7089
7190func (f * firecraker ) ConfigureAppMesh (ctx context.Context , netNSPath string , cfg * appmesh.AppMesh ) error {
@@ -171,3 +190,33 @@ func assignInterfacesToNamespaces(taskPayload *ecsacs.Task) (map[string]string,
171190
172191 return i2n , nil
173192}
193+
194+ // configureBranchENI configures a network interface for a branch ENI.
195+ func (f * firecraker ) configureBranchENI (ctx context.Context , netNSPath string , eni * networkinterface.NetworkInterface ) error {
196+ logger .Info ("Configuring branch ENI" , map [string ]interface {}{
197+ "ENIName" : eni .Name ,
198+ "NetNSPath" : netNSPath ,
199+ })
200+
201+ var cniNetConf ecscni.PluginConfig
202+ var err error
203+ add := true
204+
205+ // Generate CNI network configuration based on the ENI's desired state.
206+ switch eni .DesiredStatus {
207+ case status .NetworkReadyPull :
208+ cniNetConf = createBranchENIConfig (netNSPath , eni , VPCBranchENIInterfaceTypeVlan )
209+ case status .NetworkReady :
210+ cniNetConf = createBranchENIConfig (netNSPath , eni , VPCBranchENIInterfaceTypeTap )
211+ case status .NetworkDeleted :
212+ cniNetConf = createBranchENIConfig (netNSPath , eni , VPCBranchENIInterfaceTypeTap )
213+ add = false
214+ }
215+
216+ _ , err = f .common .executeCNIPlugin (ctx , add , cniNetConf )
217+ if err != nil {
218+ err = errors .Wrap (err , "failed to setup branch eni" )
219+ }
220+
221+ return err
222+ }
0 commit comments