本文整理匯總了Golang中github.com/cilium/cilium/pkg/endpoint.Endpoint.LXCMAC方法的典型用法代碼示例。如果您正苦於以下問題:Golang Endpoint.LXCMAC方法的具體用法?Golang Endpoint.LXCMAC怎麽用?Golang Endpoint.LXCMAC使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cilium/cilium/pkg/endpoint.Endpoint
的用法示例。
在下文中一共展示了Endpoint.LXCMAC方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetupVeth
// SetupVeth sets up the net interface, the temporary interface and fills up some endpoint
// fields such as LXCMAC, NodeMac, IfIndex and IfName. Returns a pointer for the created
// veth, a pointer for the temporary link, the name of the temporary link and error if
// something fails.
func SetupVeth(id string, mtu int, ep *endpoint.Endpoint) (*netlink.Veth, *netlink.Link, string, error) {
lxcIfName := Endpoint2IfName(id)
tmpIfName := temporaryInterfacePrefix + id[:5]
veth := &netlink.Veth{
LinkAttrs: netlink.LinkAttrs{Name: lxcIfName},
PeerName: tmpIfName,
}
if err := netlink.LinkAdd(veth); err != nil {
return nil, nil, "", fmt.Errorf("unable to create veth pair: %s", err)
}
var err error
defer func() {
if err != nil {
if err = netlink.LinkDel(veth); err != nil {
log.Warningf("failed to clean up veth %q: %s", veth.Name, err)
}
}
}()
log.Debugf("Created veth pair %s <-> %s", lxcIfName, veth.PeerName)
// Disable reverse path filter on the host side veth peer to allow
// container addresses to be used as source address when the linux
// stack performs routing.
args := []string{"-w", "net.ipv4.conf." + lxcIfName + ".rp_filter=0"}
_, err = exec.Command("sysctl", args...).CombinedOutput()
if err != nil {
return nil, nil, "", fmt.Errorf("unable to disable rp_filter on %s: %s",
lxcIfName, err)
}
peer, err := netlink.LinkByName(tmpIfName)
if err != nil {
return nil, nil, "", fmt.Errorf("unable to lookup veth peer just created: %s", err)
}
if err = netlink.LinkSetMTU(peer, mtu); err != nil {
return nil, nil, "", fmt.Errorf("unable to set MTU to %q: %s", tmpIfName, err)
}
hostVeth, err := netlink.LinkByName(lxcIfName)
if err != nil {
return nil, nil, "", fmt.Errorf("unable to lookup veth just created: %s", err)
}
if err = netlink.LinkSetMTU(hostVeth, mtu); err != nil {
return nil, nil, "", fmt.Errorf("unable to set MTU to %q: %s", lxcIfName, err)
}
if err = netlink.LinkSetUp(veth); err != nil {
return nil, nil, "", fmt.Errorf("unable to bring up veth pair: %s", err)
}
ep.LXCMAC = mac.MAC(peer.Attrs().HardwareAddr)
ep.NodeMAC = mac.MAC(hostVeth.Attrs().HardwareAddr)
ep.IfIndex = hostVeth.Attrs().Index
ep.IfName = lxcIfName
return veth, &peer, tmpIfName, nil
}