Skip to content

Commit 964bfd6

Browse files
committed
return error on interface not found and always clean up snat ep
1 parent c818bd9 commit 964bfd6

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

network/endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type apipaClient interface {
151151
}
152152

153153
func (epInfo *EndpointInfo) PrettyString() string {
154-
return fmt.Sprintf("Id:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v Data:%+v NICType: %s NetworkContainerID: %s HostIfName: %s NetNs: %s Options: %v",
154+
return fmt.Sprintf("EndpointID:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v Data:%+v NICType: %s NetworkContainerID: %s HostIfName: %s NetNs: %s Options: %v",
155155
epInfo.EndpointID, epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName, epInfo.IfIndex, epInfo.MacAddress.String(), epInfo.IPAddresses,
156156
epInfo.Gateways, epInfo.Data, epInfo.NICType, epInfo.NetworkContainerID, epInfo.HostIfName, epInfo.NetNs, epInfo.Options)
157157
}

network/snat/snat_linux.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ func (client *Client) AllowInboundFromHostToNC() error {
223223
return newErrorSnatClient(err.Error())
224224
}
225225

226-
snatContainerVeth, _ := net.InterfaceByName(client.containerSnatVethName)
226+
snatContainerVeth, err := net.InterfaceByName(client.containerSnatVethName)
227+
if err != nil {
228+
logger.Info("Could not find interface", zap.String("containerSnatVethName", client.containerSnatVethName))
229+
return errors.Wrap(newErrorSnatClient(err.Error()), "could not find container snat veth name for allow host to nc")
230+
}
227231

228232
// Add static arp entry for localIP to prevent arp going out of VM
229233
logger.Info("Adding static arp entry for ip", zap.Any("containerIP", containerIP),
@@ -319,7 +323,11 @@ func (client *Client) AllowInboundFromNCToHost() error {
319323
return err
320324
}
321325

322-
snatContainerVeth, _ := net.InterfaceByName(client.containerSnatVethName)
326+
snatContainerVeth, err := net.InterfaceByName(client.containerSnatVethName)
327+
if err != nil {
328+
logger.Info("Could not find interface", zap.String("containerSnatVethName", client.containerSnatVethName))
329+
return errors.Wrap(newErrorSnatClient(err.Error()), "could not find container snat veth name for allow nc to host")
330+
}
323331

324332
// Add static arp entry for localIP to prevent arp going out of VM
325333
logger.Info("Adding static arp entry for ip", zap.Any("containerIP", containerIP), zap.String("HardwareAddr", snatContainerVeth.HardwareAddr.String()))

network/transparent_vlan_endpointclient_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func (client *TransparentVlanEndpointClient) DeleteEndpoints(ep *endpoint) error
635635
return client.DeleteEndpointsImpl(ep, getNumRoutesLeft)
636636
})
637637
if err != nil {
638-
return err
638+
logger.Warn("could not delete transparent vlan endpoints", zap.String("errorMsg", err.Error()))
639639
}
640640

641641
// VM NS

0 commit comments

Comments
 (0)