本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/vishvananda/netlink.Link.Attrs方法的典型用法代码示例。如果您正苦于以下问题:Golang Link.Attrs方法的具体用法?Golang Link.Attrs怎么用?Golang Link.Attrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/rkt/Godeps/_workspace/src/github.com/vishvananda/netlink.Link
的用法示例。
在下文中一共展示了Link.Attrs方法的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,
})
}
示例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)
}
示例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),
)
}
示例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
}
示例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
}