本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/vishvananda/netlink.LinkSetUp函数的典型用法代码示例。如果您正苦于以下问题:Golang LinkSetUp函数的具体用法?Golang LinkSetUp怎么用?Golang LinkSetUp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LinkSetUp函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetupVeth
// SetupVeth sets up a virtual ethernet link.
// Should be in container netns.
func SetupVeth(contVethName string, mtu int, hostNS *os.File) (hostVeth, contVeth netlink.Link, err error) {
var hostVethName string
hostVethName, contVeth, err = makeVeth(contVethName, mtu)
if err != nil {
return
}
if err = netlink.LinkSetUp(contVeth); err != nil {
err = fmt.Errorf("failed to set %q up: %v", contVethName, err)
return
}
hostVeth, err = netlink.LinkByName(hostVethName)
if err != nil {
err = fmt.Errorf("failed to lookup %q: %v", hostVethName, err)
return
}
if err = netlink.LinkSetUp(hostVeth); err != nil {
err = fmt.Errorf("failed to set %q up: %v", contVethName, err)
return
}
if err = netlink.LinkSetNsFd(hostVeth, int(hostNS.Fd())); err != nil {
err = fmt.Errorf("failed to move veth to host netns: %v", err)
return
}
return
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:32,代码来源:link.go
示例2: SetupVeth
// SetupVeth sets up a virtual ethernet link.
// Should be in container netns.
// TODO(eyakubovich): get rid of entropy and ask kernel to pick name via pattern
func SetupVeth(entropy, contVethName string, mtu int, hostNS *os.File) (hostVeth, contVeth netlink.Link, err error) {
// NetworkManager (recent versions) will ignore veth devices that start with "veth"
hostVethName := RandomVethName(entropy)
hostVeth, err = makeVeth(hostVethName, contVethName, mtu)
if err != nil {
err = fmt.Errorf("failed to make veth pair: %v", err)
return
}
if err = netlink.LinkSetUp(hostVeth); err != nil {
err = fmt.Errorf("failed to set %q up: %v", hostVethName, err)
return
}
contVeth, err = netlink.LinkByName(contVethName)
if err != nil {
err = fmt.Errorf("failed to lookup %q: %v", contVethName, err)
return
}
if err = netlink.LinkSetUp(contVeth); err != nil {
err = fmt.Errorf("failed to set %q up: %v", contVethName, err)
return
}
if err = netlink.LinkSetNsFd(hostVeth, int(hostNS.Fd())); err != nil {
err = fmt.Errorf("failed to move veth to host netns: %v", err)
return
}
return
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:35,代码来源:link.go
示例3: ConfigureIface
// ConfigureIface takes the result of IPAM plugin and
// applies to the ifName interface
func ConfigureIface(ifName string, res *Result) error {
link, err := netlink.LinkByName(ifName)
if err != nil {
return fmt.Errorf("failed to lookup %q: %v", ifName, err)
}
if err := netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("failed to set %q UP: %v", ifName, err)
}
// TODO(eyakubovich): IPv6
addr := &netlink.Addr{IPNet: &res.IP4.IP, Label: ""}
if err = netlink.AddrAdd(link, addr); err != nil {
return fmt.Errorf("failed to add IP addr to %q: %v", ifName, err)
}
for _, r := range res.IP4.Routes {
gw := r.GW
if gw == nil {
gw = res.IP4.Gateway
}
if err = ip.AddRoute(&r.Dst, gw, link); err != nil {
// we skip over duplicate routes as we assume the first one wins
if !os.IsExist(err) {
return fmt.Errorf("failed to add route '%v via %v dev %v': %v", r.Dst, gw, ifName, err)
}
}
}
return nil
}
开发者ID:NeilW,项目名称:rkt,代码行数:33,代码来源:ipam.go
示例4: ensureBridge
func ensureBridge(brName string, mtu int, ipn *net.IPNet) (*netlink.Bridge, error) {
br := &netlink.Bridge{
LinkAttrs: netlink.LinkAttrs{
Name: brName,
MTU: mtu,
},
}
if err := netlink.LinkAdd(br); err != nil {
if err != syscall.EEXIST {
return nil, fmt.Errorf("could not add %q: %v", brName, err)
}
// it's ok if the device already exists as long as config is similar
br, err = bridgeByName(brName)
if err != nil {
return nil, err
}
}
if err := netlink.LinkSetUp(br); err != nil {
return nil, err
}
if ipn != nil {
return br, ensureBridgeAddr(br, ipn)
}
return br, nil
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:30,代码来源:bridge.go
示例5: acquire
func (l *DHCPLease) acquire() error {
c, err := newDHCPClient(l.link)
if err != nil {
return err
}
defer c.Close()
if (l.link.Attrs().Flags & net.FlagUp) != net.FlagUp {
log.Printf("Link %q down. Attempting to set up", l.link.Attrs().Name)
if err = netlink.LinkSetUp(l.link); err != nil {
return err
}
}
pkt, err := backoffRetry(func() (*dhcp4.Packet, error) {
ok, ack, err := c.Request()
switch {
case err != nil:
return nil, err
case !ok:
return nil, fmt.Errorf("DHCP server NACK'd own offer")
default:
return &ack, nil
}
})
if err != nil {
return err
}
return l.commit(pkt)
}
开发者ID:matomesc,项目名称:rkt,代码行数:31,代码来源:lease.go
示例6: loUp
func loUp() error {
lo, err := netlink.LinkByName("lo")
if err != nil {
return fmt.Errorf("failed to lookup lo: %v", err)
}
if err := netlink.LinkSetUp(lo); err != nil {
return fmt.Errorf("failed to set lo up: %v", err)
}
return nil
}
开发者ID:matomesc,项目名称:rkt,代码行数:12,代码来源:networking.go
示例7: setupTapDevice
// setupTapDevice creates persistent tap devices
// and returns a newly created netlink.Link structure
func setupTapDevice() (netlink.Link, error) {
ifName, err := tuntap.CreatePersistentIface(tuntap.Tap)
if err != nil {
return nil, fmt.Errorf("tuntap persist %v", err)
}
link, err := netlink.LinkByName(ifName)
if err != nil {
return nil, fmt.Errorf("cannot find link %q: %v", ifName, err)
}
err = netlink.LinkSetUp(link)
if err != nil {
return nil, fmt.Errorf("cannot set link up %q: %v", ifName, err)
}
return link, nil
}
开发者ID:vincentvdk,项目名称:rkt,代码行数:17,代码来源:kvm.go
示例8: setupTapDevice
// setupTapDevice creates persistent tap devices
// and returns a newly created netlink.Link structure
func setupTapDevice(podID types.UUID) (netlink.Link, error) {
// network device names are limited to 16 characters
// the suffix %d will be replaced by the kernel with a suitable number
nameTemplate := fmt.Sprintf("rkt-%s-tap%%d", podID.String()[0:4])
ifName, err := tuntap.CreatePersistentIface(nameTemplate, tuntap.Tap)
if err != nil {
return nil, fmt.Errorf("tuntap persist %v", err)
}
link, err := netlink.LinkByName(ifName)
if err != nil {
return nil, fmt.Errorf("cannot find link %q: %v", ifName, err)
}
err = netlink.LinkSetUp(link)
if err != nil {
return nil, fmt.Errorf("cannot set link up %q: %v", ifName, err)
}
return link, nil
}
开发者ID:harpe1999,项目名称:rkt,代码行数:20,代码来源:kvm.go
注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/vishvananda/netlink.LinkSetUp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论