本文整理汇总了Golang中github.com/vishvananda/netlink.LinkList函数的典型用法代码示例。如果您正苦于以下问题:Golang LinkList函数的具体用法?Golang LinkList怎么用?Golang LinkList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LinkList函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createSlaveInterfaces
func createSlaveInterfaces(netCfg *NetworkConfig) {
links, err := netlink.LinkList()
if err != nil {
log.Errorf("Failed to list links: %v", err)
return
}
for _, link := range links {
match, ok := findMatch(link, netCfg)
if !ok {
continue
}
vlanDefs, err := ParseVlanDefinitions(match.Vlans)
if err != nil {
log.Errorf("Failed to create vlans on device %s: %v", link.Attrs().Name, err)
continue
}
for _, vlanDef := range vlanDefs {
if _, err = NewVlan(link, vlanDef.Name, vlanDef.Id); err != nil {
log.Errorf("Failed to create vlans on device %s, id %d: %v", link.Attrs().Name, vlanDef.Id, err)
}
}
}
}
开发者ID:rancher,项目名称:netconf,代码行数:26,代码来源:netconf_linux.go
示例2: handleAddr
// Address specific
func handleAddr(update netlink.AddrUpdate, callback func(supervisor.NetlinkUpdate)) {
if update.NewAddr {
fmt.Printf("[Add a address]")
} else {
fmt.Printf("[Delete a address]")
}
if update.LinkAddress.IP.To4() != nil {
fmt.Printf("[IPv4]\t%+v\n", update)
} else {
// We would not like to handle IPv6 at present.
fmt.Printf("[IPv6]\t%+v\n", update)
return
}
netlinkUpdate := supervisor.NetlinkUpdate{}
netlinkUpdate.Addr = update
netlinkUpdate.UpdateType = supervisor.UpdateTypeAddr
links, err := netlink.LinkList()
if err != nil {
glog.Error(err)
}
for _, link := range links {
if link.Attrs().Index == update.LinkIndex && link.Type() == "veth" {
netlinkUpdate.Veth = link.(*netlink.Veth)
break
}
}
callback(netlinkUpdate)
}
开发者ID:hyperhq,项目名称:runv,代码行数:31,代码来源:nslistener.go
示例3: resourceLXCBridgeDelete
func resourceLXCBridgeDelete(d *schema.ResourceData, meta interface{}) error {
bridgeIndex, err := strconv.Atoi(d.Id())
if err != nil {
return fmt.Errorf("Internal error reading resource ID: %v", err)
}
bridge, err := netlink.LinkByIndex(bridgeIndex)
if err != nil {
return fmt.Errorf("Unable to find bridge %v: %v", bridgeIndex, err)
}
links, err := netlink.LinkList()
if err != nil {
return fmt.Errorf("Error listing interfaces: %v", err)
}
bridgeEmpty := true
for _, link := range links {
if link.Attrs().MasterIndex == bridge.Attrs().Index {
bridgeEmpty = false
log.Printf("[INFO] Link %s is still attached to bridge %s", link.Attrs().Name, bridge.Attrs().Name)
}
}
if bridgeEmpty == false {
return fmt.Errorf("Unable to delete bridge %s. Interfaces are still attached to it.", bridge.Attrs().Name)
} else {
if err := netlink.LinkDel(bridge); err != nil {
return fmt.Errorf("Error deleting bridge: %s", err)
}
}
return nil
}
开发者ID:munye,项目名称:tp-lxc,代码行数:34,代码来源:resource_lxc_bridge.go
示例4: NewNetlinkMonitor
func NewNetlinkMonitor(g canvas.Graph, r *Renderer, modules *bpf.BpfTable) (res *NetlinkMonitor, err error) {
nlmon := &NetlinkMonitor{
updates: make(chan netlink.LinkUpdate),
done: make(chan struct{}),
flush: make(chan struct{}),
nodes: make(map[int]*ExtInterface),
g: g,
r: r,
modules: modules,
}
err = netlink.LinkSubscribe(nlmon.updates, nlmon.done)
defer func() {
if err != nil {
nlmon.Close()
}
}()
if err != nil {
return
}
links, err := netlink.LinkList()
if err != nil {
return
}
for _, link := range links {
nlmon.handleNewlink(link)
}
Debug.Println("NewNetlinkMonitor DONE")
go nlmon.ParseLinkUpdates()
res = nlmon
return
}
开发者ID:iovisor,项目名称:iomodules,代码行数:31,代码来源:netlink_monitor.go
示例5: waitForIface
func waitForIface() (netlink.Link, error) {
logrus.Debugf("Starting to wait for network interface")
start := time.Now()
for {
fmt.Printf(".")
if time.Since(start) > 5*time.Second {
fmt.Printf("\n")
return nil, fmt.Errorf("failed to find veth interface in 5 seconds")
}
// get list of all interfaces
lst, err := netlink.LinkList()
if err != nil {
fmt.Printf("\n")
return nil, err
}
for _, l := range lst {
// if we found "veth" interface - it's time to continue setup
if l.Type() == "veth" {
fmt.Printf("\n")
return l, nil
}
}
time.Sleep(100 * time.Millisecond)
}
}
开发者ID:v1k0d3n,项目名称:unc,代码行数:25,代码来源:network.go
示例6: RunDhcp
func RunDhcp(netCfg *NetworkConfig, setHostname, setDns bool) error {
populateDefault(netCfg)
links, err := netlink.LinkList()
if err != nil {
return err
}
dhcpLinks := map[string]string{}
for _, link := range links {
if match, ok := findMatch(link, netCfg); ok && match.DHCP {
dhcpLinks[link.Attrs().Name] = match.DHCPArgs
}
}
//run dhcp
wg := sync.WaitGroup{}
for iface, args := range dhcpLinks {
wg.Add(1)
go func(iface, args string) {
runDhcp(netCfg, iface, args, setHostname, setDns)
wg.Done()
}(iface, args)
}
wg.Wait()
return err
}
开发者ID:rancher,项目名称:netconf,代码行数:28,代码来源:netconf_linux.go
示例7: GetNetlinkAddrList
// GetNetlinkAddrList returns a list of local IP addresses
func GetNetlinkAddrList() ([]string, error) {
var addrList []string
// get the link list
linkList, err := netlink.LinkList()
if err != nil {
return addrList, err
}
log.Debugf("Got link list(%d): %+v", len(linkList), linkList)
// Loop thru each interface and add its ip addr to list
for _, link := range linkList {
if strings.HasPrefix(link.Attrs().Name, "docker") || strings.HasPrefix(link.Attrs().Name, "veth") ||
strings.HasPrefix(link.Attrs().Name, "vport") || strings.HasPrefix(link.Attrs().Name, "lo") {
continue
}
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
if err != nil {
return addrList, err
}
for _, addr := range addrs {
addrList = append(addrList, addr.IP.String())
}
}
return addrList, err
}
开发者ID:jojimt,项目名称:netplugin,代码行数:29,代码来源:netutils.go
示例8: ApplyNetworkConfigs
func ApplyNetworkConfigs(netCfg *NetworkConfig) error {
populateDefault(netCfg)
log.Debugf("Config: %#v", netCfg)
runCmds(netCfg.PreCmds, "")
createInterfaces(netCfg)
createSlaveInterfaces(netCfg)
links, err := netlink.LinkList()
if err != nil {
return err
}
//apply network config
for _, link := range links {
linkName := link.Attrs().Name
if match, ok := findMatch(link, netCfg); ok && !match.DHCP {
if err := applyInterfaceConfig(link, match); err != nil {
log.Errorf("Failed to apply settings to %s : %v", linkName, err)
}
}
}
runCmds(netCfg.PostCmds, "")
return err
}
开发者ID:rancher,项目名称:netconf,代码行数:28,代码来源:netconf_linux.go
示例9: FindNetDevs
// Search the network namespace of a process for interfaces matching a predicate
func FindNetDevs(procPath string, processID int, match func(string) bool) ([]NetDev, error) {
var netDevs []NetDev
ns, err := netns.GetFromPath(fmt.Sprintf("%s/%d/ns/net", procPath, processID))
if err != nil {
return nil, err
}
defer ns.Close()
err = WithNetNS(ns, func() error {
links, err := netlink.LinkList()
if err != nil {
return err
}
for _, link := range links {
if match(link.Attrs().Name) {
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
if err != nil {
return err
}
netDev := NetDev{MAC: link.Attrs().HardwareAddr}
for _, addr := range addrs {
netDev.CIDRs = append(netDev.CIDRs, addr.IPNet)
}
netDevs = append(netDevs, netDev)
}
}
return nil
})
return netDevs, err
}
开发者ID:brb,项目名称:weave,代码行数:34,代码来源:utils.go
示例10: RouteMap
// Returns a list of routes
func RouteMap() *map[string]Route {
links, _ := netlink.LinkList()
linksMap := make(map[int]string)
for _, l := range links {
attrs := *l.Attrs()
linksMap[attrs.Index] = attrs.Name
}
routes := make(map[string]Route)
routeList, _ := netlink.RouteList(nil, netlink.FAMILY_V4)
for _, r := range routeList {
if_ := linksMap[r.LinkIndex]
rdst := r.Dst
var dst string
if rdst != nil {
dst = rdst.String()
} else {
dst = "default"
}
route := Route{
Via: r.Gw,
Dev: if_,
Src: r.Src,
}
routes[dst] = route
}
return &routes
}
开发者ID:araobp,项目名称:nlan,代码行数:30,代码来源:netlink.go
示例11: GetBridgeFromIndex
func GetBridgeFromIndex(idx int) (string, error) {
var attr, bridge *netlink.LinkAttrs
links, err := netlink.LinkList()
if err != nil {
glog.Error(err)
return "", err
}
for _, link := range links {
if link.Type() != "veth" {
continue
}
if link.Attrs().Index == idx {
attr = link.Attrs()
break
}
}
if attr == nil {
return "", fmt.Errorf("cann't find nic whose ifindex is %d", idx)
}
for _, link := range links {
if link.Type() != "bridge" && link.Type() != "openvswitch" {
continue
}
if link.Attrs().Index == attr.MasterIndex {
bridge = link.Attrs()
break
}
}
if bridge == nil {
return "", fmt.Errorf("cann't find bridge contains nic whose ifindex is %d", idx)
}
if bridge.Name == "ovs-system" {
veth, err := netlink.LinkByIndex(idx)
if err != nil {
return "", err
}
out, err := exec.Command("ovs-vsctl", "port-to-br", veth.Attrs().Name).CombinedOutput()
if err != nil {
return "", err
}
bridge.Name = strings.TrimSpace(string(out))
}
glog.Infof("find bridge %s", bridge.Name)
return bridge.Name, nil
}
开发者ID:feiskyer,项目名称:runv,代码行数:56,代码来源:hyperpod.go
示例12: initialize
func (u *NetLinkProbe) initialize() {
links, err := netlink.LinkList()
if err != nil {
logging.GetLogger().Errorf("Unable to list interfaces: %s", err.Error())
return
}
for _, link := range links {
u.addLinkToTopology(link)
}
}
开发者ID:lebauce,项目名称:skydive,代码行数:11,代码来源:netlink.go
示例13: linkListing
func linkListing() {
links, err := netlink.LinkList()
if err != nil {
panic(err)
}
fmt.Println("Interface listing:")
for _, link := range links {
fmt.Println(link.Attrs().Name)
}
}
开发者ID:mycroft,项目名称:go-snippets,代码行数:11,代码来源:main.go
示例14: IsVethExists
func IsVethExists(vethHostName string) (bool, error) {
links, err := netlink.LinkList()
if err != nil {
return false, errors.Wrap(err, "Veth existing check error")
}
for _, link := range links {
if link.Attrs().Name == vethHostName {
return true, nil
}
}
return false, nil
}
开发者ID:projectcalico,项目名称:libnetwork-plugin,代码行数:12,代码来源:netns.go
示例15: forEachLink
func forEachLink(f func(netlink.Link) error) error {
links, err := netlink.LinkList()
if err != nil {
return err
}
for _, link := range links {
if err := f(link); err != nil {
return err
}
}
return nil
}
开发者ID:n054,项目名称:weave,代码行数:12,代码来源:utils.go
示例16: cleanup
func (d *Driver) cleanup(netID string) {
links, err := d.getLinks(netID)
if err != nil {
log.Errorf("Error getting links: %v", err)
return
}
VxlanIndex := links.Vxlan.LinkAttrs.Index
allLinks, err := netlink.LinkList()
if err != nil {
log.Errorf("Error getting all links: %v", err)
return
}
// Do nothing if other interfaces are slaves of the vxlan interface
for _, link := range allLinks {
if link.Attrs().MasterIndex == VxlanIndex {
log.Debugf("Interface still attached to vxlan: %v", link)
return
}
}
// Do nothing if there are other containers in this network
netResource, err := d.docker.NetworkInspect(context.Background(), netID)
if err != nil {
log.Errorf("Error inspecting network: %v", err)
return
}
netName := netResource.Name
containers, err := d.docker.ContainerList(context.Background(), dockertypes.ContainerListOptions{})
if err != nil {
log.Errorf("Error getting containers: %v", err)
return
}
for _, container := range containers {
if _, ok := container.NetworkSettings.Networks[netName]; ok {
log.Debugf("Other containers are still connected to this network")
return
}
}
log.Debugf("No interfaces attached to vxlan: deleting vxlan interface.")
err = d.deleteNics(netID)
if err != nil {
log.Errorf("Error deleting nics: %v", err)
}
return
}
开发者ID:TrilliumIT,项目名称:docker-vxlan-plugin,代码行数:49,代码来源:driver.go
示例17: Interfaces
func (adapter *HostAdapter) Interfaces() <-chan Interface {
ch := make(chan Interface)
go func() {
defer close(ch)
links, err := netlink.LinkList()
if err != nil {
return
}
for _, link := range links {
ch <- &HostInterface{
id: link.Attrs().Index,
name: link.Attrs().Name,
}
}
}()
return ch
}
开发者ID:alagalah,项目名称:iomodules,代码行数:17,代码来源:adapter_host.go
示例18: getLinkIndex
func getLinkIndex(ip net.IP) (int, error) {
links, err := netlink.LinkList()
if err != nil {
return -1, fmt.Errorf("Failed to get links")
}
for _, link := range links {
addrs, err := netlink.AddrList(link, netlink.FAMILY_ALL)
if err != nil {
return -1, fmt.Errorf("Failed to get addrs")
}
for _, addr := range addrs {
if addr.IP.Equal(ip) {
return link.Attrs().Index, nil
}
}
}
return -1, fmt.Errorf("Could not find address")
}
开发者ID:vishvananda,项目名称:wormhole,代码行数:18,代码来源:tunnel.go
示例19: ApplyNetworkConfigs
func ApplyNetworkConfigs(netCfg *NetworkConfig) error {
populateDefault(netCfg)
log.Debugf("Config: %#v", netCfg)
runCmds(netCfg.PreCmds, "")
createInterfaces(netCfg)
createSlaveInterfaces(netCfg)
links, err := netlink.LinkList()
if err != nil {
return err
}
dhcpLinks := map[string]string{}
//apply network config
for _, link := range links {
linkName := link.Attrs().Name
if match, ok := findMatch(link, netCfg); ok {
if match.DHCP {
dhcpLinks[link.Attrs().Name] = match.DHCPArgs
} else if err = applyInterfaceConfig(link, match); err != nil {
log.Errorf("Failed to apply settings to %s : %v", linkName, err)
}
}
}
//run dhcp
wg := sync.WaitGroup{}
for iface, args := range dhcpLinks {
wg.Add(1)
go func(iface, args string) {
runDhcp(iface, args)
wg.Done()
}(iface, args)
}
wg.Wait()
runCmds(netCfg.PostCmds, "")
return err
}
开发者ID:rancher,项目名称:docker-from-scratch,代码行数:43,代码来源:netconf_linux.go
示例20: deleteVxlanByVNI
func deleteVxlanByVNI(vni uint32) error {
defer osl.InitOSContext()()
links, err := netlink.LinkList()
if err != nil {
return fmt.Errorf("failed to list interfaces while deleting vxlan interface by vni: %v", err)
}
for _, l := range links {
if l.Type() == "vxlan" && l.(*netlink.Vxlan).VxlanId == int(vni) {
err = netlink.LinkDel(l)
if err != nil {
return fmt.Errorf("error deleting vxlan interface with id %d: %v", vni, err)
}
return nil
}
}
return fmt.Errorf("could not find a vxlan interface to delete with id %d", vni)
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:21,代码来源:ov_utils.go
注:本文中的github.com/vishvananda/netlink.LinkList函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论