Skip to content

Commit

Permalink
Merge pull request #389 from hhyasdf/release/v0.8.3
Browse files Browse the repository at this point in the history
[CHERRY PICK] release for v0.8.3
  • Loading branch information
hhyasdf authored Jun 21, 2023
2 parents bc62c0c + 6ccfd57 commit 4b0ef6a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,27 @@ func generateCNIResult(cniVersion string, cniResponse *request.PodResponse, ifNa
result.Routes = append(result.Routes, &route)
}

// fetch interface info by name in container namespace
if err := netNs.Do(func(_ ns.NetNS) error {
createdInterface, err := netlink.LinkByName(ifName)
// fetch created host interface by name
hostInterface, err := netlink.LinkByName(cniResponse.HostInterface)
if err != nil {
return nil, fmt.Errorf("unable to get created host interface %q: %v", cniResponse.HostInterface, err)
}

result.Interfaces = append(result.Interfaces, &current.Interface{
Name: hostInterface.Attrs().Name,
Mac: hostInterface.Attrs().HardwareAddr.String(),
})

// fetch created container interface by name in container namespace
if err = netNs.Do(func(_ ns.NetNS) error {
containerInterface, err := netlink.LinkByName(ifName)
if err != nil {
return fmt.Errorf("unable to get created interface %q: %v", ifName, err)
return fmt.Errorf("unable to get created container interface %q: %v", ifName, err)
}

result.Interfaces = append(result.Interfaces, &current.Interface{
Name: ifName,
Mac: createdInterface.Attrs().HardwareAddr.String(),
Name: containerInterface.Attrs().Name,
Mac: containerInterface.Attrs().HardwareAddr.String(),
Sandbox: netNs.Path(),
})

Expand All @@ -152,9 +163,9 @@ func generateCNIResult(cniVersion string, cniResponse *request.PodResponse, ifNa
return nil, err
}

// bind ips with created interface
// bind ips with created container interface
for _, ip := range result.IPs {
ip.Interface = current.Int(0)
ip.Interface = current.Int(1)
}

return result, nil
Expand Down

0 comments on commit 4b0ef6a

Please sign in to comment.