本文整理汇总了Golang中github.com/vishvananda/netlink.Link类的典型用法代码示例。如果您正苦于以下问题:Golang Link类的具体用法?Golang Link怎么用?Golang Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Link类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ensureEgressFd
func ensureEgressFd(link netlink.Link, fd int) error {
q, err := ensureQdisc(link, "fq_codel", netlink.MakeHandle(1, 0), netlink.HANDLE_ROOT)
if err != nil {
return err
}
fHandle := netlink.MakeHandle(0, 2)
filter := &netlink.U32{
FilterAttrs: netlink.FilterAttrs{
LinkIndex: link.Attrs().Index,
Parent: q.Attrs().Handle,
Priority: 1,
Protocol: syscall.ETH_P_ALL,
},
Actions: []netlink.Action{
&netlink.BpfAction{Fd: fd, Name: "bpf1"},
},
ClassId: fHandle,
}
filters, err := netlink.FilterList(link, netlink.HANDLE_MIN_EGRESS)
if err != nil {
return fmt.Errorf("failed fetching egress filter list: %s", err)
}
for _, f := range filters {
if f, ok := f.(*netlink.U32); ok {
if f.ClassId == fHandle {
return nil
}
}
}
if err := netlink.FilterAdd(filter); err != nil {
return fmt.Errorf("failed adding egress filter: %v", err)
}
return nil
}
开发者ID:iovisor,项目名称:iomodules,代码行数:34,代码来源:patch.go
示例2: getDynamicIP
func getDynamicIP(t Netlink, link netlink.Link, dc client.Client) (*dhcp.Packet, error) {
var ack *dhcp.Packet
var err error
// use dhcp to acquire address
id, err := client.NewID(link.Attrs().Index, link.Attrs().HardwareAddr)
if err != nil {
return nil, err
}
ack, err = dc.Request(id)
if err != nil {
log.Errorf("error sending dhcp request: %s", err)
return nil, err
}
if ack.YourIP() == nil || ack.SubnetMask() == nil {
err = fmt.Errorf("dhcp assigned nil ip or subnet mask")
log.Error(err)
return nil, err
}
log.Infof("DHCP response: IP=%s, SubnetMask=%s, Gateway=%s, DNS=%s, Lease Time=%s", ack.YourIP(), ack.SubnetMask(), ack.Gateway(), ack.DNS(), ack.LeaseTime())
defer func() {
if err != nil && ack != nil {
dc.Release(ack)
}
}()
return ack, nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:31,代码来源:ops_linux.go
示例3: delRouteIface
// delRouteIface clean up the required L3 mode default ns route
func delRouteIface(ipVlanL3Network *net.IPNet, iface netlink.Link) error {
return netlink.RouteDel(&netlink.Route{
LinkIndex: iface.Attrs().Index,
Scope: netlink.SCOPE_LINK,
Dst: ipVlanL3Network,
})
}
开发者ID:zenvdeluca,项目名称:ipvlan-docker-plugin,代码行数:8,代码来源:driver.go
示例4: setFqCodelFd
func setFqCodelFd(iface netlink.Link, path string) error {
fd, err := netlink.BpfOpen(path)
if err != nil {
return fmt.Errorf("failed loading bpf program %v", err)
}
defer syscall.Close(fd)
fq := &netlink.GenericQdisc{
QdiscAttrs: netlink.QdiscAttrs{
LinkIndex: iface.Attrs().Index,
Handle: netlink.MakeHandle(1, 0),
Parent: netlink.HANDLE_ROOT,
},
QdiscType: "fq_codel",
}
if err := netlink.QdiscAdd(fq); err != nil {
return fmt.Errorf("failed setting egress qdisc: %v", err)
}
u32 := &netlink.U32{
FilterAttrs: netlink.FilterAttrs{
LinkIndex: iface.Attrs().Index,
Parent: fq.QdiscAttrs.Handle,
Protocol: syscall.ETH_P_ALL,
//Handle: 10,
//Priority: 10,
},
ClassId: netlink.MakeHandle(1, 2),
BpfFd: fd,
}
if err := netlink.FilterAdd(u32); err != nil {
return fmt.Errorf("failed adding egress filter: %v", err)
}
return nil
}
开发者ID:drzaeus77,项目名称:docker-plugin,代码行数:33,代码来源:iov-plug.go
示例5: onLinkDeleted
func (u *NetLinkProbe) onLinkDeleted(link netlink.Link) {
index := link.Attrs().Index
u.Graph.Lock()
defer u.Graph.Unlock()
intf := u.Graph.LookupFirstChild(u.Root, graph.Metadata{"IfIndex": index})
// case of removing the interface from a bridge
if intf != nil {
parents := u.Graph.LookupParents(intf, graph.Metadata{"Type": "bridge"})
for _, parent := range parents {
u.Graph.Unlink(parent, intf)
}
}
// check whether the interface has been deleted or not
// we get a delete event when an interace is removed from a bridge
_, err := u.netlink.LinkByIndex(index)
if err != nil && intf != nil {
// if openvswitch do not remove let's do the job by ovs piece of code
if intf.Metadata()["Driver"] == "openvswitch" && intf.Metadata()["UUID"] != "" {
u.Graph.Unlink(u.Root, intf)
} else {
u.Graph.DelNode(intf)
}
}
delete(u.indexToChildrenQueue, int64(index))
}
开发者ID:skydive-project,项目名称:skydive,代码行数:30,代码来源:netlink.go
示例6: linkAddrUpdate
func linkAddrUpdate(old, new *net.IPNet, t Netlink, link netlink.Link) error {
log.Infof("setting ip address %s for link %s", new, link.Attrs().Name)
if old != nil && !old.IP.Equal(new.IP) {
log.Debugf("removing old address %s", old)
if err := t.AddrDel(link, &netlink.Addr{IPNet: old}); err != nil {
if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EADDRNOTAVAIL {
log.Errorf("failed to remove existing address %s: %s", old, err)
return err
}
}
log.Debugf("removed old address %s for link %s", old, link.Attrs().Name)
}
// assign IP to NIC
if err := t.AddrAdd(link, &netlink.Addr{IPNet: new}); err != nil {
if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EEXIST {
log.Errorf("failed to assign ip %s for link %s", new, link.Attrs().Name)
return err
}
log.Warnf("address %s already set on interface %s", new, link.Attrs().Name)
}
log.Debugf("added address %s to link %s", new, link.Attrs().Name)
return nil
}
开发者ID:vmware,项目名称:vic,代码行数:29,代码来源:ops_linux.go
示例7: AddRouteIface
// addRouteIface required for L3 mode adds a link scoped route in the default ns
func AddRouteIface(ipVlanL3Network *net.IPNet, iface netlink.Link) error {
return netlink.RouteAdd(&netlink.Route{
LinkIndex: iface.Attrs().Index,
Scope: netlink.SCOPE_UNIVERSE,
Dst: ipVlanL3Network,
})
}
开发者ID:nerdalert,项目名称:gitnet-overlay,代码行数:8,代码来源:driver.go
示例8: updateDefaultRoute
func updateDefaultRoute(t Netlink, link netlink.Link, endpoint *NetworkEndpoint) error {
// Add routes
if !endpoint.Network.Default || ip.IsUnspecifiedIP(endpoint.Network.Gateway.IP) {
log.Debugf("not setting route for network: default=%v gateway=%s", endpoint.Network.Default, endpoint.Network.Gateway.IP)
return nil
}
_, defaultNet, _ := net.ParseCIDR("0.0.0.0/0")
// delete default route first
if err := t.RouteDel(&netlink.Route{LinkIndex: link.Attrs().Index, Dst: defaultNet}); err != nil {
if errno, ok := err.(syscall.Errno); !ok || errno != syscall.ESRCH {
return fmt.Errorf("could not update default route: %s", err)
}
}
log.Infof("Setting default gateway to %s", endpoint.Network.Gateway.IP)
route := &netlink.Route{LinkIndex: link.Attrs().Index, Dst: defaultNet, Gw: endpoint.Network.Gateway.IP}
if err := t.RouteAdd(route); err != nil {
detail := fmt.Sprintf("failed to add gateway route for endpoint %s: %s", endpoint.Network.Name, err)
return errors.New(detail)
}
log.Infof("updated default route to %s interface, gateway: %s", endpoint.Network.Name, endpoint.Network.Gateway.IP)
return nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:ops_linux.go
示例9: addGenericLinkToTopology
func (u *NetLinkProbe) addGenericLinkToTopology(link netlink.Link, m graph.Metadata) *graph.Node {
name := link.Attrs().Name
index := int64(link.Attrs().Index)
var intf *graph.Node
if name != "lo" {
intf = u.Graph.LookupFirstChild(u.Root, graph.Metadata{
"IfIndex": index,
})
}
if intf == nil {
intf = u.Graph.NewNode(graph.GenID(), m)
}
if intf == nil {
return nil
}
if !u.Graph.AreLinked(u.Root, intf) {
u.Graph.Link(u.Root, intf)
}
u.handleIntfIsChild(intf, link)
u.handleIntfIsVeth(intf, link)
u.handleIntfIsBond(intf, link)
return intf
}
开发者ID:safchain,项目名称:skydive,代码行数:29,代码来源:netlink.go
示例10: addIPConfigToLink
func addIPConfigToLink(ipConfig *ipam.IPConfig, link netlink.Link, ifName string) error {
log.Debugf("Configuring link %+v/%s with %+v", link, ifName, ipConfig)
addr := &netlink.Addr{IPNet: &ipConfig.IP}
if err := netlink.AddrAdd(link, addr); err != nil {
return fmt.Errorf("failed to add addr to %q: %v", ifName, err)
}
// Sort provided routes to make sure we apply any more specific
// routes first which may be used as nexthops in wider routes
sort.Sort(ipam.ByMask(ipConfig.Routes))
for _, r := range ipConfig.Routes {
log.Debugf("Adding route %+v", r)
rt := &netlink.Route{
LinkIndex: link.Attrs().Index,
Scope: netlink.SCOPE_UNIVERSE,
Dst: &r.Destination,
Gw: r.NextHop,
}
if r.IsL2() {
rt.Scope = netlink.SCOPE_LINK
}
if err := netlink.RouteAdd(rt); err != nil {
if !os.IsExist(err) {
return fmt.Errorf("failed to add route '%s via %v dev %v': %v",
r.Destination.String(), r.NextHop, ifName, err)
}
}
}
return nil
}
开发者ID:cilium-team,项目名称:cilium,代码行数:35,代码来源:cilium-cni.go
示例11: setIngressFd
func setIngressFd(iface netlink.Link, path string) error {
fd, err := netlink.BpfOpen(path)
if err != nil {
return fmt.Errorf("failed loading bpf program %v", err)
}
defer syscall.Close(fd)
ingress := &netlink.Ingress{
QdiscAttrs: netlink.QdiscAttrs{
LinkIndex: iface.Attrs().Index,
Handle: netlink.MakeHandle(0xffff, 0),
Parent: netlink.HANDLE_INGRESS,
},
}
if err := netlink.QdiscAdd(ingress); err != nil {
return fmt.Errorf("failed setting ingress qdisc: %v", err)
}
u32 := &netlink.U32{
FilterAttrs: netlink.FilterAttrs{
LinkIndex: iface.Attrs().Index,
Parent: ingress.QdiscAttrs.Handle,
Priority: 1,
Protocol: syscall.ETH_P_ALL,
},
ClassId: netlink.MakeHandle(1, 1),
BpfFd: fd,
}
if err := netlink.FilterAdd(u32); err != nil {
return fmt.Errorf("failed adding ingress filter: %v", err)
}
return nil
}
开发者ID:drzaeus77,项目名称:docker-plugin,代码行数:31,代码来源:iov-plug.go
示例12: LinkSetUp
func (t *Mocker) LinkSetUp(link netlink.Link) error {
defer trace.End(trace.Begin(fmt.Sprintf("Bringing %s up", link.Attrs().Name)))
iface := link.(*Interface)
iface.Up = true
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:7,代码来源:ops_linux_test.go
示例13: LinkSetAlias
func (t *Mocker) LinkSetAlias(link netlink.Link, alias string) error {
defer trace.End(trace.Begin(fmt.Sprintf("Adding alias %s to %s", alias, link.Attrs().Name)))
iface := link.(*Interface)
iface.Alias = alias
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:7,代码来源:ops_linux_test.go
示例14: LinkSetDown
func (t *Mocker) LinkSetDown(link netlink.Link) error {
defer trace.End(trace.Begin(fmt.Sprintf("Bringing %s down", link.Attrs().Name)))
iface := link.(*Interface)
iface.Up = false
// TODO: should this drop addresses?
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:8,代码来源:ops_linux_test.go
示例15: delRemoteRoute
// delRemoteRoute deletes a host-scoped route to a device.
func delRemoteRoute(neighborNetwork *net.IPNet, nextHop net.IP, iface netlink.Link) error {
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: iface.Attrs().Index,
Dst: neighborNetwork,
Gw: nextHop,
})
}
开发者ID:jc-m,项目名称:ipvlan-docker-plugin,代码行数:9,代码来源:del_routes.go
示例16: delRoute
// delRoute deletes any netlink route
func delRoute(route netlink.Route, iface netlink.Link) error {
return netlink.RouteDel(&netlink.Route{
Scope: route.Scope,
LinkIndex: iface.Attrs().Index,
Dst: route.Dst,
Gw: route.Gw,
})
}
开发者ID:jc-m,项目名称:ipvlan-docker-plugin,代码行数:9,代码来源:del_routes.go
示例17: 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:NeilW,项目名称:cni,代码行数:9,代码来源:route.go
示例18: AddRoute
func (rm *RouteManager) AddRoute(link netlink.Link, network *net.IPNet, gateway net.IP) error {
return rm.Netlinker.RouteAdd(&netlink.Route{
LinkIndex: link.Attrs().Index,
Scope: netlink.SCOPE_UNIVERSE,
Dst: network,
Gw: gateway,
})
}
开发者ID:zachgersh,项目名称:ducati-cni-plugins,代码行数:8,代码来源:routes.go
示例19: delRemoteRoute
// delRemoteRoute deletes a host-scoped route to a device.
func delRemoteRoute(neighborNetwork *net.IPNet, nextHop net.IP, iface netlink.Link) error {
log.Debugf("Deleting route: IP Prefix: [ %s ] - Next Hop: [ %s ] - Source Interface: [ %s ]", neighborNetwork, nextHop, iface.Attrs().Name)
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: iface.Attrs().Index,
Dst: neighborNetwork,
Gw: nextHop,
})
}
开发者ID:nerdalert,项目名称:bgp-ipvlan-docker,代码行数:10,代码来源:del_routes.go
示例20: AddNeighbor
func (n *networkNamespace) AddNeighbor(dstIP net.IP, dstMac net.HardwareAddr, options ...NeighOption) error {
nh := n.findNeighbor(dstIP, dstMac)
if nh != nil {
// If it exists silently return
return nil
}
nh = &neigh{
dstIP: dstIP,
dstMac: dstMac,
}
nh.processNeighOptions(options...)
if nh.linkName != "" {
nh.linkDst = n.findDst(nh.linkName, false)
if nh.linkDst == "" {
return fmt.Errorf("could not find the interface with name %s", nh.linkName)
}
}
return nsInvoke(n.nsPath(), func(nsFD int) error { return nil }, func(callerFD int) error {
var iface netlink.Link
if nh.linkDst != "" {
var err error
iface, err = netlink.LinkByName(nh.linkDst)
if err != nil {
return fmt.Errorf("could not find interface with destination name %s: %v",
nh.linkDst, err)
}
}
nlnh := &netlink.Neigh{
IP: dstIP,
HardwareAddr: dstMac,
State: netlink.NUD_PERMANENT,
Family: nh.family,
}
if nlnh.Family > 0 {
nlnh.Flags = netlink.NTF_SELF
}
if nh.linkDst != "" {
nlnh.LinkIndex = iface.Attrs().Index
}
if err := netlink.NeighSet(nlnh); err != nil {
return fmt.Errorf("could not add neighbor entry: %v", err)
}
n.neighbors = append(n.neighbors, nh)
return nil
})
}
开发者ID:souravbh,项目名称:lattice-release,代码行数:57,代码来源:neigh_linux.go
注:本文中的github.com/vishvananda/netlink.Link类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论