-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare windows support for cni server
- Loading branch information
1 parent
88b0749
commit 0c0a030
Showing
17 changed files
with
2,701 additions
and
2,566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package daemon | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net" | ||
|
||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
func getIfaceOwnPodIP(podIP string) (*net.Interface, error) { | ||
links, err := netlink.LinkList() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, link := range links { | ||
addrs, err := netlink.AddrList(link, netlink.FAMILY_ALL) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get a list of IP addresses %v", err) | ||
} | ||
for _, addr := range addrs { | ||
if addr.IPNet.Contains(net.ParseIP(podIP)) && addr.IP.String() == podIP { | ||
return &net.Interface{ | ||
Index: link.Attrs().Index, | ||
MTU: link.Attrs().MTU, | ||
Name: link.Attrs().Name, | ||
HardwareAddr: link.Attrs().HardwareAddr, | ||
Flags: link.Attrs().Flags, | ||
}, nil | ||
} | ||
} | ||
} | ||
|
||
return nil, errors.New("unable to find podIP interface") | ||
} |
Oops, something went wrong.