當前位置: 首頁>>代碼示例>>Golang>>正文


Golang netlink.Link類代碼示例

本文整理匯總了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/vishvananda/netlink.Link的典型用法代碼示例。如果您正苦於以下問題:Golang Link類的具體用法?Golang Link怎麽用?Golang Link使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Link類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AddHostRoute

// AddHostRoute adds a host-scoped route to a device.
func AddHostRoute(ipn *net.IPNet, gw net.IP, dev netlink.Link) error {
	return netlink.RouteAdd(&netlink.Route{
		LinkIndex: dev.Attrs().Index,
		Scope:     netlink.SCOPE_HOST,
		Dst:       ipn,
		Gw:        gw,
	})
}
開發者ID:balagopalraj,項目名稱:clearlinux,代碼行數:9,代碼來源:route.go

示例2: addRoute

func addRoute(link netlink.Link, podIP net.IP) error {
	route := netlink.Route{
		LinkIndex: link.Attrs().Index,
		Scope:     netlink.SCOPE_LINK,
		Dst: &net.IPNet{
			IP:   podIP,
			Mask: net.IPv4Mask(0xff, 0xff, 0xff, 0xff),
		},
	}
	return netlink.RouteAdd(&route)
}
開發者ID:matomesc,項目名稱:rkt,代碼行數:11,代碼來源:kvm.go

示例3: newDHCPClient

func newDHCPClient(link netlink.Link) (*dhcp4client.Client, error) {
	pktsock, err := dhcp4client.NewPacketSock(link.Attrs().Index)
	if err != nil {
		return nil, err
	}

	return dhcp4client.New(
		dhcp4client.HardwareAddr(link.Attrs().HardwareAddr),
		dhcp4client.Timeout(5*time.Second),
		dhcp4client.Broadcast(false),
		dhcp4client.Connection(pktsock),
	)
}
開發者ID:samarvin,項目名稱:rkt,代碼行數:13,代碼來源:lease.go

示例4: removeAllRoutesOnLink

func removeAllRoutesOnLink(link netlink.Link) error {
	routes, err := netlink.RouteList(link, netlink.FAMILY_V4)
	if err != nil {
		return fmt.Errorf("cannot list routes on link %q: %v", link.Attrs().Name, err)
	}

	for _, route := range routes {
		if err := netlink.RouteDel(&route); err != nil {
			return fmt.Errorf("error in time of route removal for route %q: %v", route, err)
		}
	}

	return nil
}
開發者ID:matomesc,項目名稱:rkt,代碼行數:14,代碼來源:kvm.go

示例5: ensureHasAddr

func ensureHasAddr(link netlink.Link, ipn *net.IPNet) error {
	addrs, err := netlink.AddrList(link, syscall.AF_INET)
	if err != nil && err != syscall.ENOENT {
		return fmt.Errorf("could not get list of IP addresses: %v", err)
	}

	// if there're no addresses on the interface, it's ok -- we'll add one
	if len(addrs) > 0 {
		ipnStr := ipn.String()
		for _, a := range addrs {
			// string comp is actually easiest for doing IPNet comps
			if a.IPNet.String() == ipnStr {
				return nil
			}
		}
		return fmt.Errorf("%q already has an IP address different from %v", link.Attrs().Name, ipn.String())
	}

	addr := &netlink.Addr{IPNet: ipn, Label: link.Attrs().Name}
	if err := netlink.AddrAdd(link, addr); err != nil {
		return fmt.Errorf("could not add IP address to %q: %v", link.Attrs().Name, err)
	}
	return nil
}
開發者ID:matomesc,項目名稱:rkt,代碼行數:24,代碼來源:kvm.go


注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/vishvananda/netlink.Link類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。